2&&this[u+1]!==t)u&&r(this.slice(u,u+1).join("-").toLowerCase()+i.section);else{var f=n||"index",e=f.indexOf(".");e>0&&(f=f.substring(0,e));c.id=f.toLowerCase()+i.page;u||r("root"+i.section)}});u.screen={height:n.screen.height,width:n.screen.width};tt();b=0;n.addEventListener?n.addEventListener("resize",it,!1):n.attachEvent("onresize",it)})(window);
3 | /*
4 | //# sourceMappingURL=head.core.min.js.map
5 | */
--------------------------------------------------------------------------------
/_includes/api/1.0.0/load.html:
--------------------------------------------------------------------------------
1 | Resource Loading
2 |
3 |
4 | Speed up your site. Manage your library's dependencies. Load javascript and stylesheets in parallel but execute them in the correct order.
5 |
6 |
7 |
8 |
Resource loading has many different options to cater to various needs
9 |
10 | {% highlight js %}
11 | // queue scripts and fire a callback when loading is finished
12 | head.load("file1.js", "file2.js", function() {
13 | // do something
14 | });
15 |
16 | // same as above, but pass files in as an Array
17 | head.load(["file1.js", "file2.js"], function() {
18 | // do something
19 | });
20 |
21 | // you can also give scripts a name (label)
22 | head.load({ label1: "file1.js" }, { label2: "file2.js" }, function() {
23 | // do something
24 | });
25 |
26 | // same as above, but pass files in as an Array
27 | head.load([{ label1: "file1.js" }, { label2: "file2.js" }], function() {
28 | // do something
29 | });
30 |
31 | // Labels are usually used in conjuntion with: head.ready()
32 | head.ready("label1", function() {
33 | // do something
34 | });
35 |
36 | // Actually if no label is supplied, internally the filename is used for the label
37 | head.ready("file1.js", function() {
38 | // do something
39 | });
40 | {% endhighlight %}
41 |
42 |
All the above examples also work with CSS files.
43 |
44 | {% highlight js %}
45 | // queue scripts and fire a callback when loading is finished
46 | head.load("file1.css", "file2.css");
47 |
48 | // same as above, but pass files in as an Array
49 | head.load(["file1.css", "file2.css"]);
50 | {% endhighlight %}
51 |
52 |
Conditional Loading
53 |
You can also run tests to load file A if a test succeeds, or fallback to file B. This is great for loading Polyfils, or loading dependencies when certain conditions are met.
54 |
55 |
56 | {% highlight js %}
57 | // signature
58 | head.test(condition, success, failure, callback);
59 |
60 | /*
61 | condition: something that evaluates to true/false
62 | success : a file, an array of files, a labeled object, an array of labeled objects
63 | failure : a file, an array of files, a labeled object, an array of labeled objects
64 | callback : a function to call when evaluation & loading is done
65 | */
66 |
67 |
68 | // simplified version 1
69 | head.test(condition, "success.js", "failure.js" , callback);
70 |
71 | // simplified version 2
72 | head.test(condition, ["success1.js", "success1.js"], "failure.js" , callback);
73 |
74 | // object version
75 | head.test({
76 | test : bool,
77 | success : ["file1.js", "file2.js"],
78 | failure : ["poly1.js", "poly2.js"],
79 | callback: function() {
80 | // do stuff
81 | }
82 | );
83 |
84 | // Example
85 | head.test(head.mobile, "normal.js", "fallback.js", function() {
86 | // do stuff
87 | });
88 | {% endhighlight %}
89 |
90 |
91 |
92 |
93 |
94 |
Show Comments
95 |
96 |
97 |
--------------------------------------------------------------------------------
/_includes/api/2.0.0/load.html:
--------------------------------------------------------------------------------
1 | Resource Loading
2 |
3 |
4 | Speed up your site. Manage your library's dependencies. Load javascript and stylesheets in parallel but execute them in the correct order.
5 |
6 |
7 |
8 |
Resource loading has many different options to cater to various needs
9 |
10 | {% highlight js %}
11 | // queue scripts and fire a callback when loading is finished
12 | head.load("file1.js", "file2.js", function() {
13 | // do something
14 | });
15 |
16 | // same as above, but pass files in as an Array
17 | head.load(["file1.js", "file2.js"], function() {
18 | // do something
19 | });
20 |
21 | // you can also give scripts a name (label)
22 | head.load({ label1: "file1.js" }, { label2: "file2.js" }, function() {
23 | // do something
24 | });
25 |
26 | // same as above, but pass files in as an Array
27 | head.load([{ label1: "file1.js" }, { label2: "file2.js" }], function() {
28 | // do something
29 | });
30 |
31 | // Labels are usually used in conjuntion with: head.ready()
32 | head.ready("label1", function() {
33 | // do something
34 | });
35 |
36 | // Actually if no label is supplied, internally the filename is used for the label
37 | head.ready("file1.js", function() {
38 | // do something
39 | });
40 | {% endhighlight %}
41 |
42 |
All the above examples also work with CSS files.
43 |
44 | {% highlight js %}
45 | // queue scripts and fire a callback when loading is finished
46 | head.load("file1.css", "file2.css");
47 |
48 | // same as above, but pass files in as an Array
49 | head.load(["file1.css", "file2.css"]);
50 | {% endhighlight %}
51 |
52 |
Conditional Loading
53 |
You can also run tests to load file A if a test succeeds, or fallback to file B. This is great for loading Polyfils, or loading dependencies when certain conditions are met.
54 |
55 |
56 | {% highlight js %}
57 | // signature
58 | head.test(condition, success, failure, callback);
59 |
60 | /*
61 | condition: something that evaluates to true/false
62 | success : a file, an array of files, a labeled object, an array of labeled objects
63 | failure : a file, an array of files, a labeled object, an array of labeled objects
64 | callback : a function to call when evaluation & loading is done
65 | */
66 |
67 |
68 | // simplified version 1
69 | head.test(condition, "success.js", "failure.js" , callback);
70 |
71 | // simplified version 2
72 | head.test(condition, ["success1.js", "success1.js"], "failure.js" , callback);
73 |
74 | // object version
75 | head.test({
76 | test : bool,
77 | success : ["file1.js", "file2.js"],
78 | failure : ["poly1.js", "poly2.js"],
79 | callback: function() {
80 | // do stuff
81 | }
82 | );
83 |
84 | // Example
85 | head.test(head.mobile, "normal.js", "fallback.js", function() {
86 | // do stuff
87 | });
88 | {% endhighlight %}
89 |
90 |
91 |
92 |
93 |
94 |
Show Comments
95 |
96 |
97 |
--------------------------------------------------------------------------------
/test/unit/0.99/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Head.JS Unit Tests (0.99)
6 |
7 |
8 |
14 |
15 |
16 |
17 |
18 | « Back
19 |
20 | -
21 |
22 | See how other browsers fared with these tests on BrowserScope
23 |
24 |
25 | -
26 |
27 | On certain browsers CSS loading will load the CSS file but not trigger the callback. Still evaluating which browsers that are.
28 |
29 |
30 | -
31 |
32 | If you have tests that fail, try clearing your cache, reloading, or running the tests individually. Some strange stuff with qUnit sometimes it seems.
33 |
34 |
35 | -
36 | If after that a test still fails, be sure to let us know !
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
78 |
79 |
--------------------------------------------------------------------------------
/site/assets/libs/qunit/qunit.min.css:
--------------------------------------------------------------------------------
1 | #qunit-tests,#qunit-header,#qunit-banner,#qunit-testrunner-toolbar,#qunit-userAgent,#qunit-testresult{font-family:"Helvetica Neue Light","HelveticaNeue-Light","Helvetica Neue",Calibri,Helvetica,Arial,sans-serif}#qunit-testrunner-toolbar,#qunit-userAgent,#qunit-testresult,#qunit-tests li{font-size:small}#qunit-tests{font-size:smaller}#qunit-tests,#qunit-header,#qunit-banner,#qunit-userAgent,#qunit-testresult,#qunit-modulefilter{margin:0;padding:0}#qunit-header{padding:.5em 0 .5em 1em;color:#8699a4;background-color:#0d3349;font-size:1.5em;line-height:1em;font-weight:normal;border-radius:5px 5px 0 0;-moz-border-radius:5px 5px 0 0;-webkit-border-top-right-radius:5px;-webkit-border-top-left-radius:5px}#qunit-header a{text-decoration:none;color:#c2ccd1}#qunit-header a:hover,#qunit-header a:focus{color:#fff}#qunit-testrunner-toolbar label{display:inline-block;padding:0 .5em 0 .1em}#qunit-banner{height:5px}#qunit-testrunner-toolbar{padding:.5em 0 .5em 2em;color:#5e740b;background-color:#eee;overflow:hidden}#qunit-userAgent{padding:.5em 0 .5em 2.5em;background-color:#2b81af;color:#fff;text-shadow:rgba(0,0,0,.5) 2px 2px 1px}#qunit-modulefilter-container{float:right}#qunit-tests{list-style-position:inside}#qunit-tests li{padding:.4em .5em .4em 2.5em;border-bottom:1px solid #fff;list-style-position:inside}#qunit-tests.hidepass li.pass,#qunit-tests.hidepass li.running{display:none}#qunit-tests li strong{cursor:pointer}#qunit-tests li a{padding:.5em;color:#c2ccd1;text-decoration:none}#qunit-tests li a:hover,#qunit-tests li a:focus{color:#000}#qunit-tests li .runtime{float:right;font-size:smaller}.qunit-assert-list{margin-top:.5em;padding:.5em;background-color:#fff;border-radius:5px;-moz-border-radius:5px;-webkit-border-radius:5px}.qunit-collapsed{display:none}#qunit-tests table{border-collapse:collapse;margin-top:.2em}#qunit-tests th{text-align:right;vertical-align:top;padding:0 .5em 0 0}#qunit-tests td{vertical-align:top}#qunit-tests pre{margin:0;white-space:pre-wrap;word-wrap:break-word}#qunit-tests del{background-color:#e0f2be;color:#374e0c;text-decoration:none}#qunit-tests ins{background-color:#ffcaca;color:#500;text-decoration:none}#qunit-tests b.counts{color:#000}#qunit-tests b.passed{color:#5e740b}#qunit-tests b.failed{color:#710909}#qunit-tests li li{padding:5px;background-color:#fff;border-bottom:none;list-style-position:inside}#qunit-tests li li.pass{color:#3c510c;background-color:#fff;border-left:10px solid #c6e746}#qunit-tests .pass{color:#528ce0;background-color:#d2e0e6}#qunit-tests .pass .test-name{color:#366097}#qunit-tests .pass .test-actual,#qunit-tests .pass .test-expected{color:#999}#qunit-banner.qunit-pass{background-color:#c6e746}#qunit-tests li li.fail{color:#710909;background-color:#fff;border-left:10px solid #ee5757;white-space:pre}#qunit-tests>li:last-child{border-radius:0 0 5px 5px;-moz-border-radius:0 0 5px 5px;-webkit-border-bottom-right-radius:5px;-webkit-border-bottom-left-radius:5px}#qunit-tests .fail{color:#000;background-color:#ee5757}#qunit-tests .fail .test-name,#qunit-tests .fail .module-name{color:#000}#qunit-tests .fail .test-actual{color:#ee5757}#qunit-tests .fail .test-expected{color:green}#qunit-banner.qunit-fail{background-color:#ee5757}#qunit-testresult{padding:.5em .5em .5em 2.5em;color:#2b81af;background-color:#d2e0e6;border-bottom:1px solid #fff}#qunit-testresult .module-name{font-weight:bold}#qunit-fixture{position:absolute;top:-10000px;left:-10000px;width:1000px;height:1000px}
--------------------------------------------------------------------------------
/test/headjs-ordered.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Test: SCRIPT ordered via HeadJS
6 |
7 |
15 |
16 |
45 |
46 |
47 |
48 |
49 |
55 |
56 |
57 |
58 |
head.js
59 |
60 |
ms
61 |
62 |
63 | Press CTRL+SHIFT+R to reload with an empty cache = first impression.
64 |
65 |
66 |
67 | View source to see how scripts are provided.
68 |
69 |
70 |
71 | Time is calculated when window.onload fires.
72 |
73 |
74 |
75 | Try with different browsers. The time difference varies a lot.
76 |
77 |
78 |
79 | head.js() calls are always separate from the page rendering. Does not matter whether you load on HEAD or on bottom. You can also load programmatically on demand.
80 |
81 |
82 |
83 |
84 |
85 |
89 |
90 |
91 |
92 |
93 |
--------------------------------------------------------------------------------
/test/unit/1.0.0/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Head.JS Unit Tests (1.00)
6 |
7 |
8 |
14 |
15 |
16 |
17 |
18 | « Back
19 |
20 | -
21 |
22 | See how other browsers fared with these tests on BrowserScope
23 |
24 |
25 | -
26 |
27 | On certain browsers CSS loading will load the CSS file but not trigger the callback. Still evaluating which browsers that are.
28 |
29 |
30 | -
31 |
32 | If you have tests that fail, try clearing your cache, reloading, or running the tests individually. Some strange stuff with qUnit sometimes it seems.
33 |
34 |
35 | -
36 | If after that a test still fails, be sure to let us know !
37 |
38 |
39 |
40 |
41 |
42 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
81 |
82 |
--------------------------------------------------------------------------------
/_posts/2013-11-04-HeadJS-v1.0.0-Released.md:
--------------------------------------------------------------------------------
1 | ---
2 | layout: main
3 | title: HeadJS v1.0.0 Released
4 | excerpt: Yes, it's finally out ! Adding a few new features, and a few fixes.
5 | scripts: ["/site/assets/libs/jquery/jquery.min.js", "https://cdn.moot.it/latest/moot.min.js", "/site/assets/js/comments.min.js"]
6 | ---
7 |
8 | #{{ page.title }} ({{ page.date | date_to_string }})
9 |
10 |
11 |
12 | It's finally time for a v1 release !
13 |
14 | First let me say that this release is way past due, so thank's to all that reported features requests and bugs to the issue tracker !
15 |
16 | Also, no fear, this release is drop in compatible with previous versions.
17 |
18 | So what's changed in v1 ?
19 |
20 | - New: Detect Windows 8 Mobile (Surface RT/Pro), IE11, Kindle, and other Android devices
21 | - New: Add Browser & Version CSS no matter what browser breakpoints are configured
22 | - Example: .ff .ff20
23 | - There is no need to cycle through all browser versions in 90% of cases
24 | - Makes it possible to work without any breakpoints at all
25 | - New: Improved CSS Router
26 | - View: [https://github.com/headjs/headjs/issues/227](https://github.com/headjs/headjs/issues/227)
27 | - New: Added "main" HTML5 element to shim
28 | - View on Github
29 | - [https://github.com/headjs/headjs/pull/230](https://github.com/headjs/headjs/pull/230)
30 | - New: Enable/Disable HTML5 Shim in head_conf
31 | - New: Load files from Array of Files or Array of Labels
32 | - ``head.load(["file1", "file2"], callBack);``
33 | - ``head.load([{ label1: "file1" }, { label2: "file2" }], callBack);``
34 | - [https://github.com/headjs/headjs/issues/139](https://github.com/headjs/headjs/issues/139)
35 | - New: Possibility to wait for multiple labels or files
36 | - ``head.ready(["label1", "label2"], callBack);``
37 | - ``head.ready(["file1.js", "file2.js"], callBack);``
38 | - [https://github.com/headjs/headjs/pull/212](https://github.com/headjs/headjs/pull/212)
39 | - New: Load file via data attribute on HeadJS script tag
40 | - ````
41 | - [https://github.com/headjs/headjs/pull/213](https://github.com/headjs/headjs/pull/213)
42 | - New: Source map files have been added for all minified JS files
43 | - Fix: Prevent loading empty strings
44 | - View on Github
45 | - [https://github.com/headjs/headjs/pull/184](https://github.com/headjs/headjs/pull/184)
46 | - Fix: CSS classes getting bigger on successive resizes under Chrome
47 | - View on Github
48 | - [https://github.com/headjs/headjs/issues/226](https://github.com/headjs/headjs/issues/226)
49 | - Fix: Invalid regular expression for CSS detection
50 | - View on Github
51 | - [https://github.com/headjs/headjs/issues/255](https://github.com/headjs/headjs/issues/255)
52 | - Fix: callback failing to trigger under certain cirumstances
53 | - View on Github
54 | - [https://github.com/headjs/headjs/issues/262](https://github.com/headjs/headjs/issues/262)
55 | - Divers: Changed window.frameElement detection
56 | - View on Github
57 | - [https://github.com/headjs/headjs/pull/257](https://github.com/headjs/headjs/pull/257)
58 | - Divers: Cleaned up a bunch of syntaxt to conform to JSHint
59 | - Easier to find quirks
60 | - Now using a very strict .jshintrc
61 | - Divers: Added missing .gitattributes
62 |
63 |
64 |
65 |
Show Comments
66 |
67 |
--------------------------------------------------------------------------------
/dist/0.98/head.load.min.js:
--------------------------------------------------------------------------------
1 | (function(g,x){function n(){}function h(a,b){if(a){"object"===typeof a&&(a=[].slice.call(a));for(var c=0,f=a.length;ce.documentMode)f.onload=f.onreadystatechange=f.onerror=null,d()};f.onerror=function(){f.onload=f.onreadystatechange=f.onerror=null;d()};f.async=!1;f.defer=!1;c=e.head||e.getElementsByTagName("head")[0];c.insertBefore(f,c.lastChild)}function j(){e.body?k||(k=!0,h(B,function(a){i(a)})):
4 | (g.clearTimeout(d.readyTimeout),d.readyTimeout=g.setTimeout(j,50))}function u(){e.addEventListener?(e.removeEventListener("DOMContentLoaded",u,!1),j()):"complete"===e.readyState&&(e.detachEvent("onreadystatechange",u),j())}var e=g.document,B=[],C=[],m={},q={},F="async"in e.createElement("script")||"MozAppearance"in e.documentElement.style||g.opera,D,k,E=g.head_conf&&g.head_conf.head||"head",d=g[E]=g[E]||function(){d.ready.apply(null,arguments)},z=1,y=3,s=4;d.load=F?function(){var a=arguments,b=a[a.length-
5 | 1],c={};l(b)||(b=null);h(a,function(d,e){d!==b&&(d=p(d),c[d.name]=d,t(d,b&&e===a.length-2?function(){r(c)&&i(b)}:null))});return d}:function(){var a=arguments,b=[].slice.call(a,1),c=b[0];if(!D)return C.push(function(){d.load.apply(null,a)}),d;c?(h(b,function(a){if(!l(a)){var b=p(a);b.state===x&&(b.state=z,b.onpreload=[],A({src:b.url,type:"cache"},function(){b.state=2;h(b.onpreload,function(a){a.call()})}))}}),t(p(a[0]),l(c)?c:function(){d.load.apply(null,b)})):t(p(a[0]));return d};d.js=d.load;d.test=
6 | function(a,b,c,e){a="object"===typeof a?a:{test:a,success:b?w("Array",b)?b:[b]:!1,failure:c?w("Array",c)?c:[c]:!1,callback:e||n};(b=!!a.test)&&a.success?(a.success.push(a.callback),d.load.apply(null,a.success)):!b&&a.failure?(a.failure.push(a.callback),d.load.apply(null,a.failure)):e();return d};d.ready=function(a,b){if(a===e)return k?i(b):B.push(b),d;l(a)&&(b=a,a="ALL");if("string"!==typeof a||!l(b))return d;var c=q[a];if(c&&c.state===s||"ALL"===a&&r()&&k)return i(b),d;(c=m[a])?c.push(b):m[a]=[b];
7 | return d};d.ready(e,function(){r()&&h(m.ALL,function(a){i(a)});d.feature&&d.feature("domloaded",!0)});if("complete"===e.readyState)j();else if(e.addEventListener)e.addEventListener("DOMContentLoaded",u,!1),g.addEventListener("load",j,!1);else{e.attachEvent("onreadystatechange",u);g.attachEvent("onload",j);var v=!1;try{v=null==g.frameElement&&e.documentElement}catch(G){}v&&v.doScroll&&function b(){if(!k){try{v.doScroll("left")}catch(c){g.clearTimeout(d.readyTimeout);d.readyTimeout=g.setTimeout(b,50);
8 | return}j()}}()}setTimeout(function(){D=!0;h(C,function(b){b()})},300)})(window);
9 |
--------------------------------------------------------------------------------
/_includes/api/1.0.0/configuration.html:
--------------------------------------------------------------------------------
1 | Configuration
2 |
3 |
4 | Sometimes you will want to change how HeadJS behaves by enabling or disabling certain features.
5 |
6 |
7 |
8 |
This is the default configuration that HeadJS ships with
9 |
10 | {% highlight js %}
11 | conf = {
12 | screens : [240, 320, 480, 640, 768, 800, 1024, 1280, 1440, 1680, 1920],
13 | screensCss: { "gt": true, "gte": false, "lt": true, "lte": false, "eq": false },
14 | browsers : [
15 | { ie: { min: 6, max: 11 } }
16 | //,{ chrome : { min: 8, max: 31 } }
17 | //,{ ff : { min: 3, max: 26 } }
18 | //,{ ios : { min: 3, max: 7 } }
19 | //,{ android: { min: 2, max: 4 } }
20 | //,{ webkit : { min: 9, max: 12 } }
21 | //,{ opera : { min: 9, max: 12 } }
22 | ],
23 | browserCss: { "gt": true, "gte": false, "lt": true, "lte": false, "eq": true },
24 | html5 : true,
25 | page : "-page",
26 | section : "-section",
27 | head : "head"
28 | };
29 | {% endhighlight %}
30 |
31 |
If you wanted to change what screen breakpoints HeadJS uses, then you would do something like this
32 |
33 | {% highlight html %}
34 |
35 |
36 |
41 |
42 |
43 |
44 |
45 |
46 |
47 | {% endhighlight %}
48 |
49 |
The same goes for all the other configurable variables. Just make sure var head_conf is declared BEFORE you include HeadJS.
50 |
51 |
52 | - screens
53 | - Width breakpoints for which lt,lte,gt,gte,eq can be generated (.gt-800, .lt-1680)
54 |
55 | - screensCss
56 | - Enables/Disables the actual insertion of those breakpoints into the HTML
57 |
58 | - browsers
59 | - Browser/Version breakpoints for which lt,lte,gt,gte,eq can be generated (.ie8, .lt-ie9)
60 |
61 | - browserCss
62 | - Enables/Disables the actual insertion of those breakpoints into the HTML
63 |
64 | - html5
65 | - When enabled, IE8 and less will have the « HTML5 Shim » injected, which adds compatibility for the following HTML5 elements: abbr, article, aside, audio, canvas, details, figcaption, figure, footer, header, hgroup, main, mark, meter, nav, output, progress, section, summary, time, video
66 |
67 | - page
68 | - Suffix used by the « CSS Router » when detecting pages (#v1-page)
69 |
70 | - section
71 | - Suffix used by the « CSS Router » when detecting page sections (.api-section)
72 |
73 | - head
74 | - Name of the variable that should be used for HeadJS. If set to something else like: test, you would call test.load() instead of head.load()
75 |
76 |
77 |
78 |
79 |
Show Comments
80 |
81 |
82 |
--------------------------------------------------------------------------------
/_includes/sections/footer.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
Created by
8 |

9 |
14 |
15 |
16 |
17 |
Lead Developer
18 |

19 |
24 |
25 |
26 |
27 |
28 |
29 |
Twitter Talk
30 |
31 |
32 |
33 |
34 |
35 |
Feature Requests
36 |
37 |
38 |
39 |
40 |
Community Support
41 |
42 |
43 |
44 |
45 |
Bug Reports
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 | Copyright © 2010—2014. HeadJS is available under the
MIT License. This site is powered by: HeadJS,
Github &
Jekyll
56 |
57 |
--------------------------------------------------------------------------------
/site/resources.html:
--------------------------------------------------------------------------------
1 | ---
2 | layout: main
3 | title: Resources
4 | scripts: ["/site/assets/libs/jquery/jquery.min.js", "https://cdn.moot.it/latest/moot.min.js", "/site/assets/js/comments.min.js"]
5 | ---
6 |
7 |
82 |
83 |
84 | Got some cool resource to share ?
85 |
86 |
87 |
88 |
89 |
-> Share it!
90 |
91 |
92 |
93 |
94 | Make it the only script in your HEAD.
95 | « A concise solution to universal problems »
96 |
97 |
98 | {% include sections/download.html %}
99 |
100 |
--------------------------------------------------------------------------------
/dist/0.99/head.load.min.js:
--------------------------------------------------------------------------------
1 | /*! head.load v0.99 */
2 | (function(n,t){"use strict";function v(){}function u(n,t){if(n){typeof n=="object"&&(n=[].slice.call(n));for(var i=0,r=n.length;iDocument Ready
2 |
3 | Know when the document or various files have finished loading
4 |
5 |
6 |
The best way to not block rendering of a page is to not put JS all over the page. The best practice is to put all your CSS in the <head> and all your JS right before the </body>
7 |
8 |
Unfortunately this is not always possible, since often various elements depend on certain JS before getting to the </body>. To work around this we can push functions downwards to be able to execute them later when all the JS has finished loading.
9 |
10 | {% highlight html %}
11 |
12 |
13 |
14 |
18 |
19 |
20 |
21 |
22 |
23 |
30 |
31 |
32 |
33 |
34 | {% endhighlight %}
35 |
36 |
Even when not depending on something like jQuery, if we should have inline scripts, it is always faster and safer to push the execution of those scripts to the bottom.
37 |
38 | {% highlight html %}
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
54 |
55 |
56 |
57 |
58 | {% endhighlight %}
59 |
60 |
head.ready() takes the following arguments
61 |
62 | {% highlight js %}
63 | // Attention: subtility here
64 | head.ready(function() {
65 | // push a function to the end of the page for later execution
66 | // runs once all files have finished loading
67 |
68 | // WARNING: if no files are cued for loading this will NOT trigger !
69 | });
70 |
71 | head.ready(document, function() {
72 | // push a function to the end of the page for later execution
73 | // runs as soon as the document is ready
74 | });
75 |
76 | head.ready("file1.js", function() {
77 | // execute this function, only when file1.js has finished loading
78 | // used in conjunction with head.load("file1.js");
79 | });
80 |
81 | head.ready(["file1.js", "file2.js"], function() {
82 | // execute this function, only when file1.js AND file2.js has finished loading
83 | // used in conjunction with head.load("file1.js", "file2.js");
84 | });
85 |
86 | head.ready("label1", function() {
87 | // execute this function, only when label1 has finished loading
88 | // used in conjunction with head.load({ label1: "file1.js" });
89 | });
90 |
91 | head.ready(["label1", "label2"], function() {
92 | // execute this function, only when label1 AND label2 has finished loading
93 | // used in conjunction with head.load([{ label1: "file1.js" }, { label2: "file2.js" }]);
94 | });
95 | {% endhighlight %}
96 |
97 |
98 |
99 |
100 |
Show Comments
101 |
102 |
103 |
--------------------------------------------------------------------------------
/_includes/api/2.0.0/ready.html:
--------------------------------------------------------------------------------
1 | Document Ready
2 |
3 | Know when the document or various files have finished loading
4 |
5 |
6 |
The best way to not block rendering of a page is to not put JS all over the page. The best practice is to put all your CSS in the <head> and all your JS right before the </body>
7 |
8 |
Unfortunately this is not always possible, since often various elements depend on certain JS before getting to the </body>. To work around this we can push functions downwards to be able to execute them later when all the JS has finished loading.
9 |
10 | {% highlight html %}
11 |
12 |
13 |
14 |
18 |
19 |
20 |
21 |
22 |
23 |
30 |
31 |
32 |
33 |
34 | {% endhighlight %}
35 |
36 |
Even when not depending on something like jQuery, if we should have inline scripts, it is always faster and safer to push the execution of those scripts to the bottom.
37 |
38 | {% highlight html %}
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
54 |
55 |
56 |
57 |
58 | {% endhighlight %}
59 |
60 |
head.ready() takes the following arguments
61 |
62 | {% highlight js %}
63 | // Attention: subtility here
64 | head.ready(function() {
65 | // push a function to the end of the page for later execution
66 | // runs once all files have finished loading
67 |
68 | // WARNING: if no files are cued for loading this will NOT trigger !
69 | });
70 |
71 | head.ready(document, function() {
72 | // push a function to the end of the page for later execution
73 | // runs as soon as the document is ready
74 | });
75 |
76 | head.ready("file1.js", function() {
77 | // execute this function, only when file1.js has finished loading
78 | // used in conjunction with head.load("file1.js");
79 | });
80 |
81 | head.ready(["file1.js", "file2.js"], function() {
82 | // execute this function, only when file1.js AND file2.js has finished loading
83 | // used in conjunction with head.load("file1.js", "file2.js");
84 | });
85 |
86 | head.ready("label1", function() {
87 | // execute this function, only when label1 has finished loading
88 | // used in conjunction with head.load({ label1: "file1.js" });
89 | });
90 |
91 | head.ready(["label1", "label2"], function() {
92 | // execute this function, only when label1 AND label2 has finished loading
93 | // used in conjunction with head.load([{ label1: "file1.js" }, { label2: "file2.js" }]);
94 | });
95 | {% endhighlight %}
96 |
97 |
98 |
99 |
100 |
Show Comments
101 |
102 |
103 |
--------------------------------------------------------------------------------
/site/assets/libs/builder/builder.js:
--------------------------------------------------------------------------------
1 | function xhr(path, async, callback) {
2 | async = async || true;
3 | var xhr;
4 | try {
5 | xhr = new window.ActiveXObject("Microsoft.XMLHTTP");
6 | } catch (e) {
7 | xhr = new window.XMLHttpRequest();
8 | }
9 |
10 | xhr.open("GET", path, async);
11 | xhr.onreadystatechange = function () {
12 | if (xhr.readyState == 4) {
13 | alert(xhr.responseText);
14 | }
15 | };
16 | xhr.send(null);
17 | }
18 |
19 | function GetFeatures() {
20 | $.getJSON("/src/features/inventory.json", function (data) {
21 | $(data).each(function (index, item) {
22 | var html = "";
23 |
24 | html += "";
30 |
31 | $("#" + item.category).append(html);
32 | });
33 | });
34 | }
35 |
36 | function generate() {
37 | var result = [];
38 | document.getElementById("out").value = "";
39 | $("[data-package]:checked").each(function () {
40 | $.ajax({
41 | type: "GET",
42 | url: "/src/" + $(this).data("package"),
43 | dataType: "text",
44 | async: false
45 | })
46 | .done(function (data) {
47 | result.push(data);
48 | });
49 | });
50 |
51 | var content = new Packer().pack("var tests = [" + result + "];", $("#pack").is(":checked"), $("#minify").is(":checked"));
52 | document.getElementById("out").value = content;
53 | $("#size").html((content.length / 1024).toFixed(2) + "K");
54 | }
55 |
56 | function getDownload() {
57 | var contents = document.getElementById("out").value;
58 | var filename = "head.custom.js";
59 |
60 | if (head.browser.ie) {
61 | SaveIE(contents, filename);
62 | } else if (head.browser.chrome || head.browser.ff) {
63 | Download.save(contents, filename);
64 | }
65 | }
66 |
67 | /* IE Magic
68 | * http://stackoverflow.com/questions/4458119/display-save-as-dialog-and-save-contents-of-a-selected-text-inside-textarea-to
69 | ****************************************************************************************************************************/
70 | function SaveIE(content, filename) {
71 | if (document.execCommand) {
72 | var oWin = window.open("about:blank", "_blank");
73 |
74 | oWin.document.write(content);
75 | oWin.document.close();
76 |
77 | var success = oWin.document.execCommand('SaveAs', true, filename);
78 | oWin.close();
79 | }
80 | }
81 |
82 | /* Chrome & Firefox Magic
83 | * http://stackoverflow.com/questions/12718210/how-to-save-file-from-textarea-in-javascript-with-a-name
84 | ******************************************************************************************************/
85 | var Download = {
86 | click: function (node) {
87 | var ev = document.createEvent("MouseEvents");
88 |
89 | ev.initMouseEvent("click", true, false, self, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
90 | return node.dispatchEvent(ev);
91 | },
92 | encode: function (data) {
93 | return 'data:application/octet-stream;base64,' + btoa(data);
94 | },
95 | link: function (data, name) {
96 | var a = document.createElement('a');
97 |
98 | a.download = name || self.location.pathname.slice(self.location.pathname.lastIndexOf('/') + 1);
99 | a.href = data || self.location.href;
100 |
101 | return a;
102 | }
103 | };
104 | Download.save = function (data, name) {
105 | this.click(
106 | this.link(
107 | this.encode(data),
108 | name
109 | )
110 | );
111 | };
--------------------------------------------------------------------------------