WIP: Note editing, markdown to html
[oweals/karmaworld.git] / karmaworld / apps / wysihtml5 / static / wysihtml5 / wysihtml-0.4.17 / src / dom / delegate.js
1 /**
2  * Event Delegation
3  *
4  * @example
5  *    wysihtml5.dom.delegate(document.body, "a", "click", function() {
6  *      // foo
7  *    });
8  */
9 (function(wysihtml5) {
10
11   wysihtml5.dom.delegate = function(container, selector, eventName, handler) {
12     return wysihtml5.dom.observe(container, eventName, function(event) {
13       var target    = event.target,
14           match     = wysihtml5.lang.array(container.querySelectorAll(selector));
15
16       while (target && target !== container) {
17         if (match.contains(target)) {
18           handler.call(target, event);
19           break;
20         }
21         target = target.parentNode;
22       }
23     });
24   };
25
26 })(wysihtml5);