| | 33 | |
| | 34 | HIM = { |
| | 35 | _registeredEvents: {}, |
| | 36 | |
| | 37 | handleEvent: function(event) { |
| | 38 | |
| | 39 | if (typeof this._registeredEvents[event] == 'undefined') return; |
| | 40 | for (var i=0; i<this._registeredEvents[event].length; i++) { |
| | 41 | if (typeof this._registeredEvents[event][i] == 'function') { |
| | 42 | this._registeredEvents[event][i](); |
| | 43 | } |
| | 44 | } |
| | 45 | }, |
| | 46 | |
| | 47 | registerHandler: function(event, handler) { |
| | 48 | if (typeof this._registeredEvents[event] == 'undefined') |
| | 49 | this._registeredEvents[event] = []; |
| | 50 | this._registeredEvents[event].push(handler); |
| | 51 | }, |
| | 52 | |
| | 53 | expandAll: function(className) { |
| | 54 | document.getElementsByClassName(className).forEach(HIM.el.show); |
| | 55 | }, |
| | 56 | |
| | 57 | colapseAll: function(className) { |
| | 58 | document.getElementsByClassName(className).forEach(HIM.el.hide); |
| | 59 | }, |
| | 60 | |
| | 61 | el: { |
| | 62 | byId: function(id) { |
| | 63 | return document.getElementById(id); |
| | 64 | }, |
| | 65 | |
| | 66 | hide: function(el) { |
| | 67 | if (typeof el == 'string') // asume id given |
| | 68 | el = HIM.el.byId(el); |
| | 69 | el.style.display = 'none'; |
| | 70 | }, |
| | 71 | |
| | 72 | show: function(el) { |
| | 73 | if (typeof el == 'string') // asume id given |
| | 74 | el = HIM.el.byId(el); |
| | 75 | el.style.display = ''; |
| | 76 | }, |
| | 77 | |
| | 78 | toggle: function(el, activateFun, deactivateFun) { |
| | 79 | if (typeof el == 'string') // asume id given |
| | 80 | el = HIM.el.byId(el); |
| | 81 | if (el.style.display == 'none') { |
| | 82 | this.show(el); |
| | 83 | if (activateFun && typeof activateFun == 'function') |
| | 84 | activateFun(); |
| | 85 | } else { |
| | 86 | this.hide(el); |
| | 87 | if (deactivateFun && typeof deactivateFun == 'function') |
| | 88 | deactivateFun(); |
| | 89 | } |
| | 90 | }, |
| | 91 | |
| | 92 | next: function(element, nodeName) { |
| | 93 | // searches for next sibling with given nodeName for element |
| | 94 | return this._sibling('next', element, nodeName); |
| | 95 | }, |
| | 96 | |
| | 97 | prev: function(element, nodeName) { |
| | 98 | // search for previous sibling with given nodeName for element |
| | 99 | return this._sibling('prev', element, nodeName); |
| | 100 | }, |
| | 101 | |
| | 102 | _sibling: function(dir, element, nodeName) { |
| | 103 | if (typeof element == 'string') |
| | 104 | element = HIM.el.byId(element); |
| | 105 | if (!element) |
| | 106 | return; |
| | 107 | dir = (dir == 'next')?'nextSibling':'previousSibling'; |
| | 108 | var sibling = element[dir]; |
| | 109 | if (!sibling || !sibling.nodeName) |
| | 110 | return; |
| | 111 | if (nodeName && typeof nodeName == 'string' && nodeName != '') { |
| | 112 | nodeName = nodeName.toLowerCase(); |
| | 113 | while (sibling.nodeName.toLowerCase() != nodeName && sibling[dir]) |
| | 114 | sibling = sibling[dir]; |
| | 115 | if (sibling.nodeName.toLowerCase() != nodeName) |
| | 116 | return; |
| | 117 | } |
| | 118 | return sibling; |
| | 119 | }, |
| | 120 | |
| | 121 | firstChild: function(element, nodeName) { |
| | 122 | if (typeof element == 'string') |
| | 123 | element = HIM.el.byId(element); |
| | 124 | if (!element) |
| | 125 | return; |
| | 126 | for (var i=0; i<element.childNodes.length; i++) { |
| | 127 | if (element.childNodes.item(i).nodeName && |
| | 128 | element.childNodes.item(i).nodeName.toLowerCase() == nodeName.toLowerCase()) |
| | 129 | return element.childNodes.item(i); |
| | 130 | } |
| | 131 | }, |
| | 132 | |
| | 133 | parentNode: function(element, nodeName) { |
| | 134 | if (typeof element == 'string') |
| | 135 | element = HIM.el.byId(element); |
| | 136 | if (!element) |
| | 137 | return; |
| | 138 | var parent = element.parentNode; |
| | 139 | while (parent.nodeName.toLowerCase() != nodeName.toLowerCase() && |
| | 140 | parent.parentNode) |
| | 141 | parent = parent.parentNode; |
| | 142 | if (parent.nodeName && parent.nodeName.toLowerCase() == nodeName.toLowerCase()) |
| | 143 | return parent; |
| | 144 | return; |
| | 145 | } |
| | 146 | } |
| | 147 | }; |
| 415 | | HIM = { |
| 416 | | _registeredEvents: {}, |
| 417 | | |
| 418 | | handleEvent: function(event) { |
| 419 | | |
| 420 | | if (typeof this._registeredEvents[event] == 'undefined') return; |
| 421 | | for (var i=0; i<this._registeredEvents[event].length; i++) { |
| 422 | | if (typeof this._registeredEvents[event][i] == 'function') { |
| 423 | | this._registeredEvents[event][i](); |
| 424 | | } |
| 425 | | } |
| 426 | | }, |
| 427 | | |
| 428 | | registerHandler: function(event, handler) { |
| 429 | | if (typeof this._registeredEvents[event] == 'undefined') |
| 430 | | this._registeredEvents[event] = []; |
| 431 | | this._registeredEvents[event].push(handler); |
| 432 | | }, |
| 433 | | |
| 434 | | expandAll: function(className) { |
| 435 | | document.getElementsByClassName(className).forEach(HIM.el.show); |
| 436 | | }, |
| 437 | | |
| 438 | | colapseAll: function(className) { |
| 439 | | document.getElementsByClassName(className).forEach(HIM.el.hide); |
| 440 | | }, |
| 441 | | |
| 442 | | el: { |
| 443 | | byId: function(id) { |
| 444 | | return document.getElementById(id); |
| 445 | | }, |
| 446 | | |
| 447 | | hide: function(el) { |
| 448 | | if (typeof el == 'string') // asume id given |
| 449 | | el = HIM.el.byId(el); |
| 450 | | el.style.display = 'none'; |
| 451 | | }, |
| 452 | | |
| 453 | | show: function(el) { |
| 454 | | if (typeof el == 'string') // asume id given |
| 455 | | el = HIM.el.byId(el); |
| 456 | | el.style.display = ''; |
| 457 | | }, |
| 458 | | |
| 459 | | toggle: function(el, activateFun, deactivateFun) { |
| 460 | | if (typeof el == 'string') // asume id given |
| 461 | | el = HIM.el.byId(el); |
| 462 | | if (el.style.display == 'none') { |
| 463 | | this.show(el); |
| 464 | | if (activateFun && typeof activateFun == 'function') |
| 465 | | activateFun(); |
| 466 | | } else { |
| 467 | | this.hide(el); |
| 468 | | if (deactivateFun && typeof deactivateFun == 'function') |
| 469 | | deactivateFun(); |
| 470 | | } |
| 471 | | }, |
| 472 | | |
| 473 | | next: function(element, nodeName) { |
| 474 | | // searches for next sibling with given nodeName for element |
| 475 | | return this._sibling('next', element, nodeName); |
| 476 | | }, |
| 477 | | |
| 478 | | prev: function(element, nodeName) { |
| 479 | | // search for previous sibling with given nodeName for element |
| 480 | | return this._sibling('prev', element, nodeName); |
| 481 | | }, |
| 482 | | |
| 483 | | _sibling: function(dir, element, nodeName) { |
| 484 | | if (typeof element == 'string') |
| 485 | | element = HIM.el.byId(element); |
| 486 | | if (!element) |
| 487 | | return; |
| 488 | | dir = (dir == 'next')?'nextSibling':'previousSibling'; |
| 489 | | var sibling = element[dir]; |
| 490 | | if (!sibling || !sibling.nodeName) |
| 491 | | return; |
| 492 | | if (nodeName && typeof nodeName == 'string' && nodeName != '') { |
| 493 | | nodeName = nodeName.toLowerCase(); |
| 494 | | while (sibling.nodeName.toLowerCase() != nodeName && sibling[dir]) |
| 495 | | sibling = sibling[dir]; |
| 496 | | if (sibling.nodeName.toLowerCase() != nodeName) |
| 497 | | return; |
| 498 | | } |
| 499 | | return sibling; |
| 500 | | }, |
| 501 | | |
| 502 | | firstChild: function(element, nodeName) { |
| 503 | | if (typeof element == 'string') |
| 504 | | element = HIM.el.byId(element); |
| 505 | | if (!element) |
| 506 | | return; |
| 507 | | for (var i=0; i<element.childNodes.length; i++) { |
| 508 | | if (element.childNodes.item(i).nodeName && |
| 509 | | element.childNodes.item(i).nodeName.toLowerCase() == nodeName.toLowerCase()) |
| 510 | | return element.childNodes.item(i); |
| 511 | | } |
| 512 | | }, |
| 513 | | |
| 514 | | parentNode: function(element, nodeName) { |
| 515 | | if (typeof element == 'string') |
| 516 | | element = HIM.el.byId(element); |
| 517 | | if (!element) |
| 518 | | return; |
| 519 | | var parent = element.parentNode; |
| 520 | | while (parent.nodeName.toLowerCase() != nodeName.toLowerCase() && |
| 521 | | parent.parentNode) |
| 522 | | parent = parent.parentNode; |
| 523 | | if (parent.nodeName && parent.nodeName.toLowerCase() == nodeName.toLowerCase()) |
| 524 | | return parent; |
| 525 | | return; |
| 526 | | } |
| 527 | | } |
| 528 | | }; |