Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add $script.done to manually trigger dependencies

  • Loading branch information...
commit 5ed4a4daba8969d9827037e15a1a24968fdabcef 1 parent 711b931
@rykov authored
View
24 dist/script.js
@@ -41,17 +41,8 @@
, done = idOrDoneIsDone ? idOrDone : optDone
, id = idOrDoneIsDone ? paths.join('') : idOrDone
, queue = paths.length
- function loopFn(item) {
- return item.call ? item() : list[item]
- }
function callback() {
- if (!--queue) {
- list[id] = 1
- done && done()
- for (var dset in delay) {
- every(dset.split('|'), loopFn) && !each(delay[dset], loopFn) && (delay[dset] = [])
- }
- }
+ if (!--queue) complete(id, done)
}
setTimeout(function () {
each(paths, function(path) {
@@ -67,6 +58,19 @@
return $script
}
+ function complete(id, done) {
+ function loopFn(item) {
+ return item.call ? item() : list[item]
+ }
+ list[id] = 1
+ done && done()
+ for (var dset in delay) {
+ every(dset.split('|'), loopFn) && !each(delay[dset], loopFn) && (delay[dset] = [])
+ }
+ }
+
+ $script.done = complete
+
function create(path, fn) {
var el = doc.createElement('script')
, loaded = f
View
2  dist/script.min.js
@@ -4,4 +4,4 @@
* (c) Dustin Diaz, Jacob Thornton 2011
* License: MIT
*/
-!function(a,b){typeof define=="function"?define(b):typeof module!="undefined"?module.exports=b():this[a]=b()}("$script",function(){function r(a,b,c){for(c=0,j=a.length;c<j;++c)if(!b(a[c]))return l;return 1}function s(a,b){r(a,function(a){return!b(a)})}function t(a,b,c){function o(a){return a.call?a():e[a]}function p(){if(!--n){e[l]=1,k&&k();for(var a in g)r(a.split("|"),o)&&!s(g[a],o)&&(g[a]=[])}}a=a[m]?a:[a];var j=b&&b.call,k=j?b:c,l=j?a.join(""):b,n=a.length;return setTimeout(function(){s(a,function(a){if(i[a])return l&&(f[l]=1),i[a]==2&&p();i[a]=1,l&&(f[l]=1),u(!d.test(a)&&h?h+a+".js":a,p)})},0),t}function u(a,d){var e=b.createElement("script"),f=l;e.onload=e.onerror=e[q]=function(){if(e[o]&&!/^c|loade/.test(e[o])||f)return;e.onload=e[q]=null,f=1,i[a]=2,d()},e.async=1,e.src=a,c.insertBefore(e,c.firstChild)}var a=this,b=document,c=b.getElementsByTagName("head")[0],d=/^https?:\/\//,e={},f={},g={},h,i={},k="string",l=!1,m="push",n="DOMContentLoaded",o="readyState",p="addEventListener",q="onreadystatechange";return!b[o]&&b[p]&&(b[p](n,function v(){b.removeEventListener(n,v,l),b[o]="complete"},l),b[o]="loading"),t.get=u,t.order=function(a,b,c){(function d(e){e=a.shift(),a.length?t(e,d):t(e,b,c)})()},t.path=function(a){h=a},t.ready=function(a,b,c){a=a[m]?a:[a];var d=[];return!s(a,function(a){e[a]||d[m](a)})&&r(a,function(a){return e[a]})?b():!function(a){g[a]=g[a]||[],g[a][m](b),c&&c(d)}(a.join("|")),t},t})
+!function(a,b){typeof define=="function"?define(b):typeof module!="undefined"?module.exports=b():this[a]=b()}("$script",function(){function r(a,b,c){for(c=0,j=a.length;c<j;++c)if(!b(a[c]))return l;return 1}function s(a,b){r(a,function(a){return!b(a)})}function t(a,b,c){function l(){--k||u(j,g)}a=a[m]?a:[a];var e=b&&b.call,g=e?b:c,j=e?a.join(""):b,k=a.length;return setTimeout(function(){s(a,function(a){if(i[a])return j&&(f[j]=1),i[a]==2&&l();i[a]=1,j&&(f[j]=1),v(!d.test(a)&&h?h+a+".js":a,l)})},0),t}function u(a,b){function c(a){return a.call?a():e[a]}e[a]=1,b&&b();for(var d in g)r(d.split("|"),c)&&!s(g[d],c)&&(g[d]=[])}function v(a,d){var e=b.createElement("script"),f=l;e.onload=e.onerror=e[q]=function(){if(e[o]&&!/^c|loade/.test(e[o])||f)return;e.onload=e[q]=null,f=1,i[a]=2,d()},e.async=1,e.src=a,c.insertBefore(e,c.firstChild)}var a=this,b=document,c=b.getElementsByTagName("head")[0],d=/^https?:\/\//,e={},f={},g={},h,i={},k="string",l=!1,m="push",n="DOMContentLoaded",o="readyState",p="addEventListener",q="onreadystatechange";return!b[o]&&b[p]&&(b[p](n,function w(){b.removeEventListener(n,w,l),b[o]="complete"},l),b[o]="loading"),t.done=u,t.get=v,t.order=function(a,b,c){(function d(e){e=a.shift(),a.length?t(e,d):t(e,b,c)})()},t.path=function(a){h=a},t.ready=function(a,b,c){a=a[m]?a:[a];var d=[];return!s(a,function(a){e[a]||d[m](a)})&&r(a,function(a){return e[a]})?b():!function(a){g[a]=g[a]||[],g[a][m](b),c&&c(d)}(a.join("|")),t},t})
View
24 src/script.js
@@ -35,17 +35,8 @@
, done = idOrDoneIsDone ? idOrDone : optDone
, id = idOrDoneIsDone ? paths.join('') : idOrDone
, queue = paths.length
- function loopFn(item) {
- return item.call ? item() : list[item]
- }
function callback() {
- if (!--queue) {
- list[id] = 1
- done && done()
- for (var dset in delay) {
- every(dset.split('|'), loopFn) && !each(delay[dset], loopFn) && (delay[dset] = [])
- }
- }
+ if (!--queue) complete(id, done)
}
setTimeout(function () {
each(paths, function(path) {
@@ -61,6 +52,19 @@
return $script
}
+ function complete(id, done) {
+ function loopFn(item) {
+ return item.call ? item() : list[item]
+ }
+ list[id] = 1
+ done && done()
+ for (var dset in delay) {
+ every(dset.split('|'), loopFn) && !each(delay[dset], loopFn) && (delay[dset] = [])
+ }
+ }
+
+ $script.done = complete
+
function create(path, fn) {
var el = doc.createElement('script')
, loaded = f
View
7 tests/tests.js
@@ -102,6 +102,13 @@ script('../node_modules/domready/ready.js', function () {
})
})
+ test('manual activation by name', 1, function () {
+ script.ready('manual', function () {
+ ok(true, 'done() called for manual')
+ })
+ script.done('manual')
+ })
+
})
start()
})
Please sign in to comment.
Something went wrong with that request. Please try again.