Pelzini

This is the code documentation for the Pelzini project

source of /viewer/assets/functions.js

Various useful functions
  1. /*
  2. Copyright 2008 Josh Heidenreich
  3.  
  4. This file is part of Pelzini.
  5.  
  6. Pelzini is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10.  
  11. Pelzini is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with Pelzini. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19.  
  20. /**
  21. * Various useful functions
  22. *
  23. * @package Viewer
  24. * @author Josh Heidenreich
  25. * @since 0.1
  26. **/
  27.  
  28.  
  29. /**
  30. * This is used by the "-" buttons to hide content areas
  31. **/
  32. function hide_content(event) {
  33. var elem, nodes, i;
  34.  
  35. // Finds the IMG element in a cross-browser way
  36. if (typeof (event) != 'undefined') {
  37. elem = event.currentTarget;
  38. } else if (typeof (window.event) != 'undefined') {
  39. elem = window.event.srcElement;
  40. } else {
  41. return;
  42. }
  43.  
  44. // Looks for nodes that are children of this parents node
  45. // and if they are of the class 'content', turn them off
  46. nodes = elem.parentNode.getElementsByTagName('*');
  47. for (i = 0; i < nodes.length; i++) {
  48. if (nodes[i].className.indexOf('content') != -1) {
  49. nodes[i].style.display = 'none';
  50. }
  51. }
  52.  
  53. // Looks for nodes that are + or - buttons, and turns them into + buttons
  54. nodes = elem.parentNode.getElementsByTagName('img');
  55. for (i = 0; i < nodes.length; i++) {
  56. if (nodes[i].className.indexOf('showhide') != -1) {
  57. nodes[i].src = 'assets/icon_add.png';
  58. nodes[i].title = 'Show this result';
  59. nodes[i].onclick = show_content;
  60. }
  61. }
  62.  
  63. // Changes the button the a +
  64. elem.src = 'assets/icon_add.png';
  65. elem.title = 'Show this result';
  66. elem.onclick = show_content;
  67. }
  68.  
  69.  
  70. /**
  71. * This is used by the "+" buttons to show content areas
  72. **/
  73. function show_content(event) {
  74. var elem;
  75.  
  76. // Finds the IMG element in a cross-browser way
  77. if (typeof (event) != 'undefined') {
  78. elem = event.currentTarget;
  79. } else if (typeof (window.event) != 'undefined') {
  80. elem = window.event.srcElement;
  81. } else {
  82. return;
  83. }
  84.  
  85. // Looks for nodes that are children of this parents node
  86. // and if they are of the class 'content', turn them on
  87. var nodes = elem.parentNode.getElementsByTagName('*');
  88. for (var i = 0; i < nodes.length; i++) {
  89. if (nodes[i].className.indexOf('content') != -1) {
  90. nodes[i].style.display = '';
  91. }
  92. }
  93.  
  94. // Looks for nodes that are + or - buttons, and turns them into - buttons
  95. nodes = elem.parentNode.getElementsByTagName('img');
  96. for (i = 0; i < nodes.length; i++) {
  97. if (nodes[i].className.indexOf('showhide') != -1) {
  98. nodes[i].src = 'assets/icon_remove.png';
  99. nodes[i].title = 'Hide this result';
  100. nodes[i].onclick = hide_content;
  101. }
  102. }
  103.  
  104. // Changes the button the a +
  105. elem.src = 'assets/icon_remove.png';
  106. elem.title = 'Hide this result';
  107. elem.onclick = hide_content;
  108. }
  109.