Created
December 6, 2011 11:36
-
-
Save sapegin/1437893 to your computer and use it in GitHub Desktop.
Components initialization
This file contains 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
(function() { | |
initComponents({ | |
pony: function(container) { | |
} | |
}); | |
})(); |
This file contains 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
/** | |
* Initialize components | |
* | |
* <div data-component="pony"></div> | |
*/ | |
function initComponents(funcs) { | |
function getContainers() { | |
if (document.querySelectorAll) { | |
return document.querySelectorAll('[data-component]'); | |
} | |
else { | |
var elems = document.getElementsByTagName('*'), | |
containers = []; | |
for (var elemIdx = 0, elemCnt = elems.length; elemIdx < elemCnt; elemIdx++) { | |
var elem = elems[elemIdx]; | |
if (elem.getAttribute('data-component')) { | |
containers.push(elem); | |
} | |
} | |
return containers; | |
} | |
} | |
var containers = getContainers(); | |
for (var containerIdx = 0, containerCnt = containers.length; containerIdx < containerCnt; containerIdx++) { | |
var container = containers[containerIdx], | |
component = container.getAttribute('data-component'); | |
if (funcs[component]) { | |
funcs[component](container); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment