edit-paragraphs.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /* Copyright 2014 Alex Schroeder <alex@gnu.org>
  2. based on http://git.savannah.gnu.org/cgit/oddmuse.git/plain/plinks.js
  3. for more information see http://oddmuse.org/wiki/Purple_Numbers_Extension
  4. based on http://simon.incutio.com/archive/2004/05/30/plinks#p-13
  5. Copyright 2004 Simon Willison
  6. This program is free software: you can redistribute it and/or modify it under
  7. the terms of the GNU General Public License as published by the Free Software
  8. Foundation, either version 3 of the License, or (at your option) any later
  9. version.
  10. This program is distributed in the hope that it will be useful, but WITHOUT
  11. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  12. FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License along with
  14. this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. function add_edit_links() {
  17. /* Only show edit links on ordinary pages: They either use
  18. * path_info or keywords in the URL, not parameters. */
  19. if (/=/.test(document.location.href)) {
  20. return;
  21. }
  22. // find all the pencil links
  23. var links = new Array;
  24. var elem = document.getElementsByTagName('a');
  25. for (var i = 0; i < elem.length; i++) {
  26. var atr = elem[i].getAttribute('class');
  27. if (atr != null) {
  28. var classes = atr.split(" ");
  29. for (var j = 0; j < classes.length; j++) {
  30. if (classes[j] == 'pencil') {
  31. links.push(elem[i]);
  32. }
  33. }
  34. }
  35. }
  36. // make them invisible
  37. for (var i = 0; i < links.length; i++) {
  38. var link = links[i];
  39. var func = function(thislink) {
  40. return function() {
  41. if (thislink.style.visibility == "visible") {
  42. thislink.style.transition = "visibility 0s 1s, opacity 1s linear";
  43. thislink.style.visibility = "hidden";
  44. thislink.style.opacity = "0";
  45. } else {
  46. thislink.style.transition = "opacity 1s linear";
  47. thislink.style.visibility = "visible";
  48. thislink.style.opacity = "1";
  49. };
  50. }
  51. };
  52. link.style.transition = "visibility 0s 1s, opacity 1s linear";
  53. link.style.visibility = "hidden";
  54. link.style.opacity = "0";
  55. link.parentNode.onclick = func(link);
  56. }
  57. }
  58. function add_load_event(func) {
  59. var oldonload = window.onload;
  60. if (typeof window.onload != 'function') {
  61. window.onload = func;
  62. } else {
  63. window.onload = function() {
  64. oldonload();
  65. func();
  66. }
  67. }
  68. }
  69. add_load_event(add_edit_links);