UNPKG

only.js

Version:

Automatically load and execute selector-based dependencies

88 lines (75 loc) 2.71 kB
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Only.js tests (Only.js with custom attributes)</title> <!-- testing custom attributes --> <script src="../src/Only.js"></script> <script> var timeDiff = function(){ var d, time; return { setStartTime:function (){ d = new Date(); time = d.getTime(); }, getDiff:function (){ d = new Date(); return (d.getTime()-time); } }; }(); function done() { var log_value_text = "Loading/Execution Time: "+timeDiff.getDiff()+"\n"; (function fn(){ var load_log = document.getElementById("load_log"); if (load_log !== null) load_log.value += log_value_text; else setTimeout(fn,10); })(); } timeDiff.setStartTime(); $O.ready(function () { $O // the famous gumby-init in LABjs issues (TODO: add issue # and link) .js({ "src" : "test-3-dependency-chaining.js", "attributes" : { "gumby-init" : "false" } }) .wait(done) // conditional loading with more than one dependency .test('form') .js([ { "src" : "test-2-form-plugin.js", "type" : "text/javascript", "attributes" : { "gumby-init" : "true" } }, { "src" : "test-3-form-plugin.js", "charset" : "utf-8", "attributes" : { "gumby-init" : "false", "data-init" : "self" // you can add more... } } ]) .wait(done); }); </script> </head> <body> <h1>Only.js tests (Only.js with custom attributes)</h1> <img src="img1.jpg" width="100" hspace="5" alt="image 1" title="size: 379kb" /> <img src="img2.jpg" width="100" hspace="5" alt="image 2" title="size: 20kb" /> <br /> <form name="log_form"> <label> <textarea id="load_log" name="load_log" cols="80" rows="10"></textarea> </label> </form> </body> </html>