Last active
August 29, 2015 14:00
-
-
Save thure/91b5cd743356a5cd3bb3 to your computer and use it in GitHub Desktop.
An AMD module that gives a semantic string for the element that can be used in event dispatchers and/or switch statements.
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
| define(function(){ | |
| return function(el){ | |
| var id = el.getAttribute('id'); | |
| if(id) { | |
| return '#' + id; | |
| }else if(typeof el.className === 'string' && el.className.length > 0){ | |
| var classes = el.className.hasOwnProperty('baseVal') ? el.className.baseVal.split(/ +/) : el.className.split(/ +/); | |
| classes.unshift(el.tagName.toLowerCase()); | |
| return classes.join('.'); | |
| }else{ | |
| return el.tagName.toLowerCase(); | |
| } | |
| }; | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment