Created
October 1, 2014 12:51
-
-
Save lordfriend/6c224b777fcd594bae34 to your computer and use it in GitHub Desktop.
Use with event delegate when jquery is not available.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* filter the event target for the nya-bs-option element. | |
* Use this method with event delegate. (attach a event handler on an parent element and listen the special children elements) | |
* @param target event.target node | |
* @param parent {object} the parent, where the event handler attached. | |
* @return the filtered target or null if no element satisfied the selector. | |
*/ | |
var filterTarget = function(target, parent) { | |
var elem = target, | |
className; | |
if(target == parent) { | |
return null; | |
} else { | |
do { | |
className = ' ' + elem.className + ' '; | |
if(elem.nodeType === 1 && className.replace(/[\t\r\n\f]/g, ' ').indexOf('nya-bs-option') >= 0) { | |
return elem; | |
} | |
} while((elem = elem.parentNode) && elem != parent && elem.nodeType !== 9); | |
return null; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment