allmessages.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. var allmessages_nodelist = false;
  2. var allmessages_modified = false;
  3. var allmessages_timeout = false;
  4. var allmessages_running = false;
  5. function allmessagesmodified() {
  6. allmessages_modified = !allmessages_modified;
  7. allmessagesfilter();
  8. }
  9. function allmessagesfilter() {
  10. if ( allmessages_timeout )
  11. window.clearTimeout( allmessages_timeout );
  12. if ( !allmessages_running )
  13. allmessages_timeout = window.setTimeout( 'allmessagesfilter_do();', 500 );
  14. }
  15. function allmessagesfilter_do() {
  16. if ( !allmessages_nodelist )
  17. return;
  18. var text = document.getElementById('allmessagesinput').value.toLowerCase();
  19. var nodef = allmessages_modified;
  20. allmessages_running = true;
  21. for ( var name in allmessages_nodelist ) {
  22. var nodes = allmessages_nodelist[name];
  23. var display = ( name.toLowerCase().indexOf( text ) == -1 ? 'none' : '' );
  24. for ( var i = 0; i < nodes.length; i++)
  25. nodes[i].style.display =
  26. ( nodes[i].className == "def" && nodef
  27. ? 'none' : display );
  28. }
  29. if ( text != document.getElementById('allmessagesinput').value.toLowerCase() ||
  30. nodef != allmessages_modified )
  31. allmessagesfilter_do(); // repeat
  32. allmessages_running = false;
  33. }
  34. function allmessagesfilter_init() {
  35. if ( allmessages_nodelist )
  36. return;
  37. var nodelist = new Array();
  38. var templist = new Array();
  39. var table = document.getElementById('allmessagestable');
  40. if ( !table ) return;
  41. var rows = document.getElementsByTagName('tr');
  42. for ( var i = 0; i < rows.length; i++ ) {
  43. var id = rows[i].getAttribute('id')
  44. if ( id && id.substring(0,16) != 'sp-allmessages-r' ) continue;
  45. templist[ id ] = rows[i];
  46. }
  47. var spans = table.getElementsByTagName('span');
  48. for ( var i = 0; i < spans.length; i++ ) {
  49. var id = spans[i].getAttribute('id')
  50. if ( id && id.substring(0,17) != 'sp-allmessages-i-' ) continue;
  51. if ( !spans[i].firstChild || spans[i].firstChild.nodeType != 3 ) continue;
  52. var nodes = new Array();
  53. var row1 = templist[ id.replace('i', 'r1') ];
  54. var row2 = templist[ id.replace('i', 'r2') ];
  55. if ( row1 ) nodes[nodes.length] = row1;
  56. if ( row2 ) nodes[nodes.length] = row2;
  57. nodelist[ spans[i].firstChild.nodeValue ] = nodes;
  58. }
  59. var k = document.getElementById('allmessagesfilter');
  60. if (k) { k.style.display = ''; }
  61. allmessages_nodelist = nodelist;
  62. }
  63. hookEvent( "load", allmessagesfilter_init );