Commit 5fb2a0d1 by Иван Кубота

Add support for function-based document onload shorthand

Introduced a shorthand to handle `DOMContentLoaded` or `load` events when a function is passed as the selector in `DOM.js`
parent 041de42d
...@@ -223,6 +223,11 @@ NS.apply = function(a,b) { ...@@ -223,6 +223,11 @@ NS.apply = function(a,b) {
Text: function( val ){ return document.createTextNode( val );} Text: function( val ){ return document.createTextNode( val );}
}; };
D = NS.D = NS.apply(function( selector, ext ) { D = NS.D = NS.apply(function( selector, ext ) {
if(typeof selector === 'function'){
// document onload shorthand
document.addEventListener(ext?'DOMContentLoaded':'load', selector);
return;
}
var out = []; var out = [];
selector = Array.isArray(selector) ? selector : [selector]; selector = Array.isArray(selector) ? selector : [selector];
for( var i = 0, _i = selector.length; i < _i; i++ ){ for( var i = 0, _i = selector.length; i < _i; i++ ){
......
{ {
"name": "react-vanilla", "name": "react-vanilla",
"version": "1.1.26", "version": "1.1.27",
"description": "", "description": "",
"main": "DOM.js", "main": "DOM.js",
"scripts": { "scripts": {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment