Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Updated jquery.defer.js and samples to work with recent breaking chan…

…ges in jQuery APIs for Deferred()
  • Loading branch information...
commit 41bbd74b1e6fc898e1df487312ac07c02f65ceb8 1 parent 4afe68f
@BorisMoore authored
View
24 README.md
@@ -1,3 +1,17 @@
+# JsDefer recent Status:
+
+There have been some breaking changes in jQuery APIs for Deferred since JsDefer was implemented.
+
+A recent JsDefer commit modifies jquery.defer.js to make it agains compatible with current
+jQuery APIs.
+
+However the non-jquery version of JsDefer - jsdefer.js - uses the previous Deferred APIs,
+which means that you cannot currently load jsdefer.js and then have it load jQuery!
+You need to determine up front whether you want the version with or without jQuery...
+
+Apart from the above fixes, JsDefer is not being actively updated at the moment, but will
+probably become active again at some point after JsViews V1.0 has shipped.
+
# JsDefer Features:
* Wrapped scripts
@@ -29,16 +43,16 @@ are provided to illustrate different use scenarios for JsDefer.
### Feature tests:
* Basic Features: Currently no unit tests are provided (they will come) but the
-[FeatureTests/Basic](https://github.com/BorisMoore/jsdefer/tree/master/demos/featuretests/basic)
+[FeatureTests/Basic](https://github.com/BorisMoore/jsdefer/tree/master/demos/feature-tests/basic)
folder provides some examples for testing different feature details.
* Advanced Features:
-[This folder](https://github.com/BorisMoore/jsdefer/tree/master/demos/featuretests/withorwithoutjquery)
+[This folder](https://github.com/BorisMoore/jsdefer/tree/master/demos/featuretests/with-or-without-jquery)
shows how to use JsDefer with or without jQuery.
-[These samples](https://github.com/BorisMoore/jsdefer/tree/master/demos/featuretests/advanced)
+[These samples](https://github.com/BorisMoore/jsdefer/tree/master/demos/feature-tests/advanced)
illustrate some less-commonly used features.
-The [AsyncTemplates](https://github.com/BorisMoore/jsdefer/tree/master/demos/featuretests/advanced/asynctemplates)
+The [AsyncTemplates](https://github.com/BorisMoore/jsdefer/tree/master/demos/feature-tests/advanced/async-templates)
folder explores some experimental integration with
-[jQuery Templates](https://github.com/jquery/jquery-tmpl).
+[jQuery Templates](https://github.com/BorisMoore/jquery-tmpl).
## Syntax Examples:
View
2  demos/feature-tests/basic/2a_def.html
@@ -12,7 +12,7 @@
a: {
url: "../resources/folder1/a.js",
minUrl: "../resources/folder1/a.min.js",
- depends: [ "e", "../resources/f.js" ]
+ depends: [ "e", "../../resources/f.js" ]
},
e: "../resources/folder2/e.js"
});
View
6 demos/feature-tests/basic/3_join-with-when.html
@@ -7,12 +7,12 @@
<script src="../../../jquery.defer.js" type="text/javascript"></script>
<script type="text/javascript">
-
+ var $ready = $.ready.promise();
var f = $.defer( "../resources/f.js", {
delayDomReady: true
})
.done( function(){
- log( "f loaded. DomReady: " + $.ready.isResolved() );
+ log( "f loaded. DomReady: " + ($ready.state() === "resolved"));
});
var a = $.defer( "../resources/folder1/a.js" );
@@ -22,7 +22,7 @@
f
)
.done( function(){
- log( "a and f loaded. DomReady: " + $.ready.isResolved() );
+ log( "a and f loaded. DomReady: " + ($ready.state() === "resolved"));
});
$.when(
View
8 demos/feature-tests/resources/f.js
@@ -1,8 +1,8 @@
((window.$deferRun || function( run ){ run(); }) (
-function( $, options ) {
- window.testloaded.f = "";
- return options && options.myVal + ". File: f";
-}
+ function( $, options ) {
+ window.testloaded.f = "";
+ return options && options.myVal + ". File: f";
+ }
));
View
13 demos/feature-tests/resources/folder1/a.js
@@ -1,13 +1,10 @@
((window.$deferRun || function( run ){ run(); }) (
-function( $, options ) {
-
- window.testloaded.a = "";
- if ( $ ) {
- return options && options.myVal + ". File: a";
+ function( $, options ) {
+ window.testloaded.a = "";
+ if ( $ ) {
+ return options && options.myVal + ". File: a";
+ }
}
-}
-
-//);
));
View
10 demos/feature-tests/resources/folder1/a.min.js
@@ -1,8 +1,2 @@
-((window.$deferRun || function( run ){ run(); }) (
-
-function( $, options ) {
- window.testloaded.aMin = "";
- return options && options.myVal + ". File: aMin";
-}
-
-));
+(window.$deferRun||function(n){n()})(function(n,t){return window.testloaded.a="",n?t&&t.myVal+". File: a":void 0});
+//@ sourceMappingURL=a.min.js.map
View
10 demos/feature-tests/resources/folder2/c.js
@@ -1,8 +1,8 @@
((window.$deferRun || function( run ){ run(); }) (
-function( $, options ) {
- window.testloaded.c = "";
- return options && options.myVal + ". File: c";
-}
+ function( $, options ) {
+ window.testloaded.c = "";
+ return options && options.myVal + ". File: c";
+ }
-));
+));
View
8 demos/feature-tests/resources/folder2/d.js
@@ -1,8 +1,8 @@
((window.$deferRun || function( run ){ run(); }) (
-function( $, options ) {
- window.testloaded.d = "";
- return options && options.myVal + ". File: d";
-}
+ function( $, options ) {
+ window.testloaded.d = "";
+ return options && options.myVal + ". File: d";
+ }
));
View
28 demos/feature-tests/with-or-without-jquery/3_non-jquery-version-with-jquery.html
@@ -1,28 +0,0 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html>
-<head>
-
-<!--
- JsDefer.js is the jQuery-independent version of JsDefer, but it will become equivalent
- to jquery.defer.js and will create a jQuery plugin if jQuery IS loaded already.
--->
- <script src="http://code.jquery.com/jquery.js" type="text/javascript"></script>
- <script src="../../../jsdefer.js" type="text/javascript"></script>
-
- <script src="../console-test.js" type="text/javascript"></script>
- <script type="text/javascript">
-
- $.defer( "../resources/folder1/a.js", {
- myVal: "val1",
- delayDomReady: true
- })
- .done( log );
-
- </script>
-</head>
-<body>
-
-<b>Results:</b> <span id="results"></span>
-
-</body>
-</html>
View
50 demos/feature-tests/with-or-without-jquery/4_non-jquery-version-loading-jquery.html
@@ -1,50 +0,0 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html>
-<head>
-
-<!--
- JsDefer.js is the jQuery-independent version of JsDefer, but it will become equivalent
- to jquery.defer.js and will create a jQuery plugin if jQuery IS loaded already.
--->
- <script src="../../../jsdefer.js" type="text/javascript"></script>
-
- <script src="../console-test.js" type="text/javascript"></script>
- <script type="text/javascript">
- $.defer( "../resources/folder1/a.js", {
- myVal: "val1",
- delayDomReady: true
- })
- .done( log );
-
- function loadJQuery() {
- $.defer( "http://code.jquery.com/jquery.js", {
- bare: true
- })
- .done( useJQuery );
- }
-
- function useJQuery() {
- alert( "jQuery tells me that 'console' content is currently: \n" + $( "#results" ).html() );
-
- $.defer( "../resources/folder2/c.js", {
- myVal: "val2"
- })
- .done( log );
- $.defer( "http://www.jslint.com/webjslint.js", {
- bare: true
- })
- .done( function() { log( "jSLint loaded.") } );
- }
-
-
- </script>
-</head>
-<body>
-
-<button onclick="loadJQuery()">Load and use jQuery</button>
-<p>
-<b>Results:</b> <span id="results"></span>
-</p>
-
-</body>
-</html>
View
11 jquery.defer.js
@@ -81,7 +81,7 @@ $.extend({
var i, thisRunCb = runCb || scriptDef.runCb; // For multiple or composite scripts, callback was passed via scriptDef
if ( !(runWait--) ) {
- if ( !asyncLoad.isRejected() ) {
+ if ( asyncLoad.state() !== "rejected" ) {
if ( parentPromise ) {
asyncLoad.resolve(
result ||
@@ -312,15 +312,6 @@ deferSettings = $.deferSettings;
defer = $.defer;
ready = $.ready;
-readyDefer = $.Deferred();
-readyDefer.promise( ready );
-
-// Workaround, to expose domReady promise
-// (only needed because the Dom Ready promise is not exposed by core).
-$( function() {
- readyDefer.resolve();
-});
-
})( jQuery, window );
View
3  jquery.defer.min.js
@@ -1 +1,2 @@
-(function(a,p){var n=p.document,o=n.createElement("a"),i,b,h,j,d={},k=[],f;function e(b,a){if(a.indexOf("://")===-1)a=b+a;o.href=a;return o.href.toLowerCase()}function l(a){return a.slice(0,a.lastIndexOf("/")+1)}function g(a){return typeof a==="string"?[a]:a}function m(a,f){if(!a)return 0;a=g(a);var c,d=a.length;while(d--){c=a[d];if(!b[c])a[d]=e(f,c)}return a}function c(f,a){var c=b[f];if(c)return c;a=e(l(a||""),f);return d[a]||(d[a]={url:a})}a.extend({defer:function(I,j,J){j=j||{};var x,C,l,m,u,E=0,z=j.delayDomReady||i.delayDomReady,L=j.min||i.min,d=c(I,J),r=d.url,K=L&&d.minUrl||d.url,o=a.extend(d,j),s=o.bare,e=o.contains,F=o.loaded,q=o.depends,D=o.multiple,t=d.prntPrms,n=d.promise,G,M,v,A;function H(){var b,g=G||d.runCb;if(!E--){if(!l.isRejected()){if(t)l.resolve(m||(d.result=m=g.call(n,a,j)));else if(e){f=[];g.call(n,a,j);b=e.length;while(b--)c(e[b],r).runCb=f[b].run;f=0;v.resolve();p(e,[],function(){b=e.length;m=[];while(b--)m.push(c(e[b],r).result);l.resolve(m)})}else l.resolve(m||(d.result=m=s?"bare":g.call(n,a,j)));m=D?0:m}z&&h(true)}}function w(){l.reject("fail",r)}function p(d,c,f){c=c||[];var e=d&&d.length;while(e--)c.push(b(d[e],j,r));a.when.apply(a,c).fail(w).done(f||H)}function B(){return a.ajax({url:K,dataType:"script",timeout:o.timeout,cache:!o.noCache,crossDomain:true}).fail(w).done(function(){var b=s?0:k.shift();if(!b){!s&&w();H();return}G=d.runCb=b.run;b.def&&a.deferDef(b.def,r);q=g(b.depends)||[];y(!e&&b.contains);if(q.length){E++;p(q)}})}function y(b){if(b){v=a.Deferred();A=[v.promise()];e=g(b);x=e.length;while(x--)c(e[x],r).prntPrms=A}}if(D||!n){l=a.Deferred();if(F&&eval(F))return l.resolve().promise();if(z)a.readyWait++;u=n;l=a.Deferred();n=d.promise=l.promise();if(s)p(q,0,B);else if(u)p(0,[u]);else if(t)p(q,t);else{y(e);p(q,[B().promise()])}}if(C=j.readyName||d.name)h[C]=n;return n},deferDef:function(f,o){var h,g,i,j=n.getElementsByTagName("script");function k(h,c){if(typeof c==="string")c={url:c};var j=c.minUrl,i=e(g,c.url),f=d[i]||function(){var c=Array.prototype.slice.call(arguments,0);c.unshift(h);return b.apply(a,c)};c.url=i;if(j)c.minUrl=e(g,j);a.extend(f,c);d[i]=b[h]=f;f.name=h}j=j[j.length-1];g=l(o||j.src);if(typeof f==="string")return b[f]||d[e(g,f)];for(h in f)k(h,f[h]);for(h in f){i=c(h);i.depends=m(i.depends,g);i.contains=m(i.contains,g)}},deferSettings:{delayDomReady:false,min:true}});p.$deferRun=function(b,a){a=g(a);a=a&&a.length?{depends:a}:a||{};a.run=b;(f||k).push(a)};i=a.deferSettings;b=a.defer;h=a.ready;j=a.Deferred();j.promise(h);a(function(){j.resolve()})})(jQuery,window);
+jQuery.defer||function(n,t){function u(n,t){return t.indexOf("//")===-1&&(t=n+t),y.href=t}function a(n){return n.slice(0,n.lastIndexOf("/")+1)}function o(n){return typeof n=="string"?[n]:n}function v(n,t){if(!n)return 0;n=o(n);for(var r,f=n.length;f--;)r=n[f],i[r]||(n[f]=u(t,r));return n}function f(n,t){var f,e=i[n];return e?e:(t=u(a(t||""),n),f=t.toLowerCase(),r[f]||(r[f]={url:t}))}var c=t.document,y=c.createElement("a"),s,i,h,r={},l=[],e;n.extend({defer:function(scriptName,options,basePath){function run(){var t,i=runCb||scriptDef.runCb;if(!runWait--){if(asyncLoad.state()!=="rejected"){if(parentPromise)asyncLoad.resolve(result||(scriptDef.result=result=i.call(promise,n,options)));else if(contains){for(e=[],i.call(promise,n,options),t=contains.length;t--;)f(contains[t],url).runCb=e[t].run;e=0,hasRun.resolve(),loadDependencies(contains,[],function(){for(t=contains.length,result=[];t--;)result.push(f(contains[t],url).result);asyncLoad.resolve(result)})}else asyncLoad.resolve(result||(scriptDef.result=result=bare?"bare":i.call(promise,n,options)));result=multiple?0:result}delayDomReady&&h(!0)}}function reject(){asyncLoad.reject("fail",url)}function loadDependencies(t,r,u){r=r||[];for(var f=t&&t.length;f--;)r.push(i(t[f],options,url));n.when.apply(n,r).fail(reject).done(u||run)}function getScript(){return n.ajax({url:loadUrl,dataType:"script",timeout:settings.timeout,cache:!settings.noCache,crossDomain:!0}).fail(reject).done(function(){var t=bare?0:l.shift();if(!t){bare||reject(),run();return}runCb=scriptDef.runCb=t.run,t.def&&n.deferDef(t.def,url),depends=o(t.depends)||[],prepareSubDefs(!contains&&t.contains),depends.length&&(runWait++,loadDependencies(depends))})}function prepareSubDefs(t){if(t)for(hasRun=n.Deferred(),hasRunPromise=[hasRun.promise()],contains=o(t),i=contains.length;i--;)f(contains[i],url).prntPrms=hasRunPromise}options=options||{};var i,readyName,asyncLoad,result,prevPromise,runWait=0,delayDomReady=options.delayDomReady||s.delayDomReady,min=options.min||s.min,scriptDef=f(scriptName,basePath),url=scriptDef.url,loadUrl=min&&scriptDef.minUrl||scriptDef.url,settings=n.extend(scriptDef,options),bare=settings.bare,contains=settings.contains,loaded=settings.loaded,depends=settings.depends,multiple=settings.multiple,parentPromise=scriptDef.prntPrms,promise=scriptDef.promise,runCb,thisPromise,hasRun,hasRunPromise;if(multiple||!promise){if(asyncLoad=n.Deferred(),loaded&&eval(loaded))return asyncLoad.resolve().promise();delayDomReady&&n.readyWait++,prevPromise=promise,asyncLoad=n.Deferred(),promise=scriptDef.promise=asyncLoad.promise(),bare?loadDependencies(depends,0,getScript):prevPromise?loadDependencies(0,[prevPromise]):parentPromise?loadDependencies(depends,parentPromise):(prepareSubDefs(contains),loadDependencies(depends,[getScript().promise()]))}return(readyName=options.readyName||scriptDef.name)&&(h[readyName]=promise),promise},deferDef:function(t,e){function y(t,f){typeof f=="string"&&(f={url:f});var h=f.minUrl,e=u(o,f.url),s=r[e]||function(){var r=Array.prototype.slice.call(arguments,0);return r.unshift(t),i.apply(n,r)};f.url=e,h&&(f.minUrl=u(o,h)),n.extend(s,f),r[e]=i[t]=s,s.name=t}var s,o,h,l=c.getElementsByTagName("script");if(l=l[l.length-1],o=a(e||l.src),typeof t=="string")return i[t]||r[u(o,t)];for(s in t)y(s,t[s]);for(s in t)h=f(s),h.depends=v(h.depends,o),h.contains=v(h.contains,o)},deferSettings:{delayDomReady:!1,min:!0}}),t.$deferRun=function(n,t){t=o(t),t=t&&t.length?{depends:t}:t||{},t.run=n,(e||l).push(t)},s=n.deferSettings,i=n.defer,h=n.ready}(jQuery,window);
+//@ sourceMappingURL=jquery.defer.min.js.map
View
4 jsdefer.js
@@ -9,7 +9,7 @@ var $, document = window.document,
scriptByUrl = {},
loadingScripts = [],
loadingSubScripts,
- promiseMethods = "then done fail isResolved isRejected promise".split( " " ),
+ promiseMethods = "then done fail state promise".split( " " ),
slice = [].slice;
if ( window.jQuery ) {
@@ -26,7 +26,7 @@ if ( window.jQuery ) {
////////////////////////////////////////////////////////////////////////////////////////////////
// jQuery is not loaded. Make $ the jsDefer object
- // Use a 'clone' of the implementation of Deferred from jQuery-1.5.js
+ // Use a 'clone' of the implementation of Deferred from jQuery-1.10.0.js
// to provide identical Deferred APIs and behavior to jQuery.
// Also provide simplified support for $.extend, DomReady and AJAX x-domain requests,
View
3  jsdefer.min.js
@@ -1 +1,2 @@
-window.jsDefer||window.jQuery&&jQuery.defer||function(d,s){var a,b=d.document,v=b.createElement("a"),j,c,n,l,g,f={},p=[],i,m="then done fail isResolved isRejected promise".split(" "),o=[].slice;if(d.jQuery){a=jQuery;a(function(){g.resolveWith(b,[a])})}else{d.jsDefer=d.$=a=function(a){return g.done(a)};a.extend=function(c,b){if(b===s){b=c;c=a}for(var d in b)c[d]=b[d];return c};a.extend({readyWait:1,ready:function(c){if(c===true)a.readyWait--;(!a.readyWait||c!==true&&!a.isReady)&&g.resolveWith(b,[a])},isFunction:function(a){return typeof a==="function"},_Deferred:function(){var d=[],b,e,f,c={done:function(){if(!f){var j=arguments,h,i,e,k,g;if(b){g=b;b=0}for(h=0,i=j.length;h<i;h++){e=j[h];if(e instanceof Array)c.done.apply(c,e);else a.isFunction(e)&&d.push(e)}g&&c.resolveWith(g[0],g[1])}return this},resolveWith:function(c,a){if(!f&&!b&&!e){a=a||[];e=1;try{while(d[0])d.shift().apply(c,a)}finally{b=[c,a];e=0}}return this},resolve:function(){c.resolveWith(this,arguments);return this},isResolved:function(){return!!(e||b)},cancel:function(){f=1;d=[];return this}};return c},Deferred:function(e){var b=a._Deferred(),c=a._Deferred(),d;a.extend(b,{then:function(a,c){b.done(a).fail(c);return this},fail:c.done,rejectWith:c.resolveWith,reject:c.resolve,isRejected:c.isResolved,promise:function(a,c){if(a==null){if(d)return d;d=a={}}c=m.length;while(c--)a[m[c]]=b[m[c]];return a}});b.done(c.cancel).fail(b.cancel);delete b.cancel;e&&e.call(b,b);return b},when:function(e){var c=arguments,d=0,f=c.length,g=f,b=f<=1&&e&&a.isFunction(e.promise)?e:a.Deferred();function h(a){return function(d){c[a]=arguments.length>1?o.call(arguments,0):d;!--g&&b.resolveWith(b,o.call(c,0))}}if(f>1){for(;d<f;d++)if(c[d]&&a.isFunction(c[d].promise))c[d].promise().then(h(d),b.reject);else--g;!g&&b.resolveWith(b,c)}else b!==e&&b.resolveWith(b,f?[e]:[]);return b.promise()}});function u(f){var e=a.Deferred(),d=b.getElementsByTagName("head")[0]||b.documentElement,c=b.createElement("script");c.src=f.url;c.onload=c.onreadystatechange=function(){if(!c.readyState||/loaded|complete/.test(c.readyState)){c.onload=c.onreadystatechange=null;d&&c.parentNode&&d.removeChild(c);c=s;e.resolve()}};d.insertBefore(c,d.firstChild);return e}}function h(b,a){if(a.indexOf("://")===-1)a=b+a;return v.href=a}function q(a){return a.slice(0,a.lastIndexOf("/")+1)}function k(a){return typeof a==="string"?[a]:a}function r(a,e){if(!a)return 0;a=k(a);var b,d=a.length;while(d--){b=a[d];if(!c[b])a[d]=h(e,b)}return a}function e(e,a){var b,d=c[e];if(d)return d;a=h(q(a||""),e);b=a.toLowerCase();return f[b]||(f[b]={url:a})}a.extend({defer:function(L,f,M){f=f||{};var A,F,h,m,x,H=0,C=f.delayDomReady||j.delayDomReady,O=f.min||j.min,b=e(L,M),s=b.url,N=O&&b.minUrl||b.url,t=a.extend(b,f),v=t.bare,g=t.contains,I=t.loaded,q=t.depends,G=t.multiple,w=b.prntPrms,o=b.promise,J,P,y,D;function K(){var c,d=J||b.runCb;if(!H--){if(!h.isRejected()){if(w)h.resolve(m||(b.result=m=d.call(o,a,f)));else if(g){i=[];d.call(o,a,f);c=g.length;while(c--)e(g[c],s).runCb=i[c].run;i=0;y.resolve();r(g,[],function(){c=g.length;m=[];while(c--)m.push(e(g[c],s).result);h.resolve(m)})}else h.resolve(m||(b.result=m=v?"bare":d.call(o,a,f)));m=G?0:m}C&&l(true)}}function z(){h.reject("fail",s)}function r(d,b,g){b=b||[];var e=d&&d.length;while(e--)b.push(c(d[e],f,s));a.when.apply(a,b).fail(z).done(g||K)}function E(){return(a.ajax||u)({url:N,dataType:"script",timeout:f.timeout,cache:!f.noCache,crossDomain:true}).fail(z).done(function(){var e=v?0:p.shift();if(!e){!v&&z();if(d.jQuery&&a!==jQuery)a=jQuery.extend({defer:c,deferSettings:j,deferDef:n});K();return}J=b.runCb=e.run;e.def&&n(e.def,s);q=k(e.depends)||[];B(!g&&e.contains);if(q.length){H++;r(q)}})}function B(b){if(b){y=a.Deferred();D=[y.promise()];g=k(b);A=g.length;while(A--)e(g[A],s).prntPrms=D}}if(G||!o){h=a.Deferred();if(I&&eval(I))return h.resolve().promise();if(C)a.readyWait++;x=o;h=a.Deferred();o=b.promise=h.promise();if(v)r(q,0,E);else if(x)r(q,[x]);else if(w)r(q,w);else{B(g);r(q,[E().promise()])}}if(F=f.readyName||b.name)l[F]=o;return o},deferDef:function(d,m){var i,g,j,k=b.getElementsByTagName("script");function l(e,b){if(typeof b==="string")b={url:b};var j=b.minUrl,i=h(g,b.url),d=f[i]||function(){var b=o.call(arguments,0);b.unshift(e);return c.apply(a,b)};b.url=i;if(j)b.minUrl=h(g,j);a.extend(d,b);f[i]=c[e]=d;d.name=e}k=k[k.length-1];g=q(m||k.src);if(typeof d==="string")return c[d]||f[h(g,d)];for(i in d)l(i,d[i]);for(i in d){j=e(i);j.depends=r(j.depends,g);j.contains=r(j.contains,g)}},deferSettings:{delayDomReady:false,min:true}});d.$deferRun=function(b,a){a=k(a);a=a&&a.length?{depends:a}:a||{};a.run=b;(i||p).push(a)};j=a.deferSettings;c=a.defer;n=a.deferDef;l=a.ready;g=a.Deferred();g.promise(l);if(!d.jQuery){function t(){if(!b.body)return setTimeout(function(){t()},1);a.isReady=true;a.ready(true)}t()}}(window);
+window.jsDefer||window.jQuery&&jQuery.defer||function(n,t){function o(n,t){return t.indexOf("://")===-1&&(t=n+t),g.href=t}function b(n){return n.slice(0,n.lastIndexOf("/")+1)}function a(n){return typeof n=="string"?[n]:n}function k(n,t){if(!n)return 0;n=a(n);for(var i,r=n.length;r--;)i=n[r],u[i]||(n[r]=o(t,i));return n}function s(n,t){var i,r=u[n];return r?r:(t=o(b(t||""),n),i=t.toLowerCase(),e[i]||(e[i]={url:t}))}var i,r=n.document,g=r.createElement("a"),h,u,v,c,f,e={},w=[],l,y="then done fail state promise".split(" "),p=[].slice;if(n.jQuery)i=jQuery,i(function(){f.resolveWith(r,[i])});else{n.jsDefer=n.$=i=function(n){return f.done(n)},i.extend=function(n,r){r===t&&(r=n,n=i);for(var u in r)n[u]=r[u];return n},i.extend({readyWait:1,ready:function(n){n===!0&&i.readyWait--,i.readyWait&&(n===!0||i.isReady)||f.resolveWith(r,[i])},isFunction:function(n){return typeof n=="function"},_Deferred:function(){var r=[],n,u,f,t={done:function(){if(!f){var s=arguments,e,h,u,o;for(n&&(o=n,n=0),e=0,h=s.length;e<h;e++)u=s[e],u instanceof Array?t.done.apply(t,u):i.isFunction(u)&&r.push(u);o&&t.resolveWith(o[0],o[1])}return this},resolveWith:function(t,i){if(!f&&!n&&!u){i=i||[],u=1;try{while(r[0])r.shift().apply(t,i)}finally{n=[t,i],u=0}}return this},resolve:function(){return t.resolveWith(this,arguments),this},isResolved:function(){return!!(u||n)},cancel:function(){return f=1,r=[],this}};return t},Deferred:function(n){var t=i._Deferred(),r=i._Deferred(),u;return i.extend(t,{then:function(n,i){return t.done(n).fail(i),this},fail:r.done,rejectWith:r.resolveWith,reject:r.resolve,isRejected:r.isResolved,promise:function(n,i){if(n==null){if(u)return u;u=n={}}for(i=y.length;i--;)n[y[i]]=t[y[i]];return n}}),t.done(r.cancel).fail(t.cancel),delete t.cancel,n&&n.call(t,t),t},when:function(n){function o(n){return function(i){r[n]=arguments.length>1?p.call(arguments,0):i,--e||t.resolveWith(t,p.call(r,0))}}var r=arguments,u=0,f=r.length,e=f,t=f<=1&&n&&i.isFunction(n.promise)?n:i.Deferred();if(f>1){for(;u<f;u++)r[u]&&i.isFunction(r[u].promise)?r[u].promise().then(o(u),t.reject):--e;e||t.resolveWith(t,r)}else t!==n&&t.resolveWith(t,f?[n]:[]);return t.promise()}});function getAjax(n){var e=i.Deferred(),f=r.getElementsByTagName("head")[0]||r.documentElement,u=r.createElement("script");return u.src=n.url,u.onload=u.onreadystatechange=function(){(!u.readyState||/loaded|complete/.test(u.readyState))&&(u.onload=u.onreadystatechange=null,f&&u.parentNode&&f.removeChild(u),u=t,e.resolve())},f.insertBefore(u,f.firstChild),e}}if(i.extend({defer:function(scriptName,options,basePath){function run(){var n,t=runCb||scriptDef.runCb;if(!runWait--){if(!asyncLoad.isRejected()){if(parentPromise)asyncLoad.resolve(result||(scriptDef.result=result=t.call(promise,i,options)));else if(contains){for(l=[],t.call(promise,i,options),n=contains.length;n--;)s(contains[n],url).runCb=l[n].run;l=0,hasRun.resolve(),loadDependencies(contains,[],function(){for(n=contains.length,result=[];n--;)result.push(s(contains[n],url).result);asyncLoad.resolve(result)})}else asyncLoad.resolve(result||(scriptDef.result=result=bare?"bare":t.call(promise,i,options)));result=multiple?0:result}delayDomReady&&c(!0)}}function reject(){asyncLoad.reject("fail",url)}function loadDependencies(n,t,r){t=t||[];for(var f=n&&n.length;f--;)t.push(u(n[f],options,url));i.when.apply(i,t).fail(reject).done(r||run)}function getScript(){return(i.ajax||getAjax)({url:loadUrl,dataType:"script",timeout:options.timeout,cache:!options.noCache,crossDomain:!0}).fail(reject).done(function(){var t=bare?0:w.shift();if(!t){bare||reject(),n.jQuery&&i!==jQuery&&(i=jQuery.extend({defer:u,deferSettings:h,deferDef:v})),run();return}runCb=scriptDef.runCb=t.run,t.def&&v(t.def,url),depends=a(t.depends)||[],prepareSubDefs(!contains&&t.contains),depends.length&&(runWait++,loadDependencies(depends))})}function prepareSubDefs(n){if(n)for(hasRun=i.Deferred(),hasRunPromise=[hasRun.promise()],contains=a(n),i=contains.length;i--;)s(contains[i],url).prntPrms=hasRunPromise}options=options||{};var i,readyName,asyncLoad,result,prevPromise,runWait=0,delayDomReady=options.delayDomReady||h.delayDomReady,min=options.min||h.min,scriptDef=s(scriptName,basePath),url=scriptDef.url,loadUrl=min&&scriptDef.minUrl||scriptDef.url,settings=i.extend(scriptDef,options),bare=settings.bare,contains=settings.contains,loaded=settings.loaded,depends=settings.depends,multiple=settings.multiple,parentPromise=scriptDef.prntPrms,promise=scriptDef.promise,runCb,thisPromise,hasRun,hasRunPromise;if(multiple||!promise){if(asyncLoad=i.Deferred(),loaded&&eval(loaded))return asyncLoad.resolve().promise();delayDomReady&&i.readyWait++,prevPromise=promise,asyncLoad=i.Deferred(),promise=scriptDef.promise=asyncLoad.promise(),bare?loadDependencies(depends,0,getScript):prevPromise?loadDependencies(depends,[prevPromise]):parentPromise?loadDependencies(depends,parentPromise):(prepareSubDefs(contains),loadDependencies(depends,[getScript().promise()]))}return(readyName=options.readyName||scriptDef.name)&&(c[readyName]=promise),promise},deferDef:function(n,t){function a(n,t){typeof t=="string"&&(t={url:t});var h=t.minUrl,r=o(f,t.url),s=e[r]||function(){var t=p.call(arguments,0);return t.unshift(n),u.apply(i,t)};t.url=r,h&&(t.minUrl=o(f,h)),i.extend(s,t),e[r]=u[n]=s,s.name=n}var h,f,c,l=r.getElementsByTagName("script");if(l=l[l.length-1],f=b(t||l.src),typeof n=="string")return u[n]||e[o(f,n)];for(h in n)a(h,n[h]);for(h in n)c=s(h),c.depends=k(c.depends,f),c.contains=k(c.contains,f)},deferSettings:{delayDomReady:!1,min:!0}}),n.$deferRun=function(n,t){t=a(t),t=t&&t.length?{depends:t}:t||{},t.run=n,(l||w).push(t)},h=i.deferSettings,u=i.defer,v=i.deferDef,c=i.ready,f=i.Deferred(),f.promise(c),!n.jQuery){function d(){if(!r.body)return setTimeout(function(){d()},1);i.isReady=!0,i.ready(!0)}d()}}(window);
+//@ sourceMappingURL=jsdefer.min.js.map
Please sign in to comment.
Something went wrong with that request. Please try again.