diff --git a/dist/modules/ocLazyLoad.core.js b/dist/modules/ocLazyLoad.core.js index 2726463..2bdd703 100644 --- a/dist/modules/ocLazyLoad.core.js +++ b/dist/modules/ocLazyLoad.core.js @@ -28,7 +28,8 @@ debug = false, events = false, moduleCache = [], - modulePromises = {}; + modulePromises = {}, + moduleDefaults = {}; moduleCache.push = function (value) { if (this.indexOf(value) === -1) { @@ -55,6 +56,10 @@ if (angular.isDefined(config.events)) { events = config.events; } + + if (angular.isDefined(config.moduleDefaults)) { + moduleDefaults = config.moduleDefaults; + } }; /** @@ -385,6 +390,15 @@ _$log: $log, + /** + * Returns module configuration defaults + * @returns {object} + * @private + */ + _getModuleDefaults: function getModuleDefaults() { + return moduleDefaults; + }, + /** * Returns the files cache used by the loaders to store the files currently loading * @returns {*} diff --git a/dist/modules/ocLazyLoad.loaders.common.js b/dist/modules/ocLazyLoad.loaders.common.js index d7fcfcc..d680a44 100644 --- a/dist/modules/ocLazyLoad.loaders.common.js +++ b/dist/modules/ocLazyLoad.loaders.common.js @@ -79,6 +79,7 @@ /* The event load or readystatechange doesn't fire in: + - PhantomJS 1.9 (headless webkit browser) - iOS < 6 (default mobile browser) - Android < 4.4 (default mobile browser) - Safari < 6 (desktop browser) @@ -87,16 +88,20 @@ if (!uaCssChecked) { var ua = $window.navigator.userAgent.toLowerCase(); - // iOS < 6 - if (/iP(hone|od|ad)/.test($window.navigator.platform)) { + if (ua.indexOf('phantomjs/1.9') > -1) { + // PhantomJS ~1.9 + useCssLoadPatch = true; + } else if (/iP(hone|od|ad)/.test($window.navigator.platform)) { + // iOS < 6 var v = $window.navigator.appVersion.match(/OS (\d+)_(\d+)_?(\d+)?/); var iOSVersion = parseFloat([parseInt(v[1], 10), parseInt(v[2], 10), parseInt(v[3] || 0, 10)].join('.')); useCssLoadPatch = iOSVersion < 6; - } else if (ua.indexOf("android") > -1) { + } else if (ua.indexOf('android') > -1) { // Android < 4.4 - var androidVersion = parseFloat(ua.slice(ua.indexOf("android") + 8)); + var androidVersion = parseFloat(ua.slice(ua.indexOf('android') + 8)); useCssLoadPatch = androidVersion < 4.4; } else if (ua.indexOf('safari') > -1) { + // Safari < 6 var versionMatch = ua.match(/version\/([\.\d]+)/i); useCssLoadPatch = versionMatch && versionMatch[1] && parseFloat(versionMatch[1]) < 6; } diff --git a/dist/modules/ocLazyLoad.loaders.core.js b/dist/modules/ocLazyLoad.loaders.core.js index 649197c..d09d0f2 100644 --- a/dist/modules/ocLazyLoad.loaders.core.js +++ b/dist/modules/ocLazyLoad.loaders.core.js @@ -21,7 +21,7 @@ $delegate.toggleWatch(true); // start watching angular.module calls - angular.extend(params, config); + params = angular.extend({}, $delegate._getModuleDefaults(), params, config); var pushFile = function pushFile(path) { var file_type = null, diff --git a/dist/modules/ocLazyLoad.loaders.templatesLoader.js b/dist/modules/ocLazyLoad.loaders.templatesLoader.js index 056346b..1481fad 100644 --- a/dist/modules/ocLazyLoad.loaders.templatesLoader.js +++ b/dist/modules/ocLazyLoad.loaders.templatesLoader.js @@ -15,6 +15,8 @@ var promises = [], filesCache = $delegate._getFilesCache(); + params = angular.extend({}, $delegate._getModuleDefaults(), params); + angular.forEach(paths, function (url) { var deferred = $q.defer(); promises.push(deferred.promise); diff --git a/dist/ocLazyLoad.js b/dist/ocLazyLoad.js index a9e57af..1fc877f 100644 --- a/dist/ocLazyLoad.js +++ b/dist/ocLazyLoad.js @@ -35,7 +35,8 @@ debug = false, events = false, moduleCache = [], - modulePromises = {}; + modulePromises = {}, + moduleDefaults = {}; moduleCache.push = function (value) { if (this.indexOf(value) === -1) { @@ -62,6 +63,10 @@ if (angular.isDefined(config.events)) { events = config.events; } + + if (angular.isDefined(config.moduleDefaults)) { + moduleDefaults = config.moduleDefaults; + } }; /** @@ -392,6 +397,15 @@ _$log: $log, + /** + * Returns module configuration defaults + * @returns {object} + * @private + */ + _getModuleDefaults: function getModuleDefaults() { + return moduleDefaults; + }, + /** * Returns the files cache used by the loaders to store the files currently loading * @returns {*} @@ -885,6 +899,7 @@ /* The event load or readystatechange doesn't fire in: + - PhantomJS 1.9 (headless webkit browser) - iOS < 6 (default mobile browser) - Android < 4.4 (default mobile browser) - Safari < 6 (desktop browser) @@ -893,16 +908,20 @@ if (!uaCssChecked) { var ua = $window.navigator.userAgent.toLowerCase(); - // iOS < 6 - if (/iP(hone|od|ad)/.test($window.navigator.platform)) { + if (ua.indexOf('phantomjs/1.9') > -1) { + // PhantomJS ~1.9 + useCssLoadPatch = true; + } else if (/iP(hone|od|ad)/.test($window.navigator.platform)) { + // iOS < 6 var v = $window.navigator.appVersion.match(/OS (\d+)_(\d+)_?(\d+)?/); var iOSVersion = parseFloat([parseInt(v[1], 10), parseInt(v[2], 10), parseInt(v[3] || 0, 10)].join('.')); useCssLoadPatch = iOSVersion < 6; - } else if (ua.indexOf("android") > -1) { + } else if (ua.indexOf('android') > -1) { // Android < 4.4 - var androidVersion = parseFloat(ua.slice(ua.indexOf("android") + 8)); + var androidVersion = parseFloat(ua.slice(ua.indexOf('android') + 8)); useCssLoadPatch = androidVersion < 4.4; } else if (ua.indexOf('safari') > -1) { + // Safari < 6 var versionMatch = ua.match(/version\/([\.\d]+)/i); useCssLoadPatch = versionMatch && versionMatch[1] && parseFloat(versionMatch[1]) < 6; } @@ -954,7 +973,7 @@ $delegate.toggleWatch(true); // start watching angular.module calls - angular.extend(params, config); + params = angular.extend({}, $delegate._getModuleDefaults(), params, config); var pushFile = function pushFile(path) { var file_type = null, @@ -1242,6 +1261,8 @@ var promises = [], filesCache = $delegate._getFilesCache(); + params = angular.extend({}, $delegate._getModuleDefaults(), params); + angular.forEach(paths, function (url) { var deferred = $q.defer(); promises.push(deferred.promise); diff --git a/dist/ocLazyLoad.min.js b/dist/ocLazyLoad.min.js index 77f8f40..33276c1 100644 --- a/dist/ocLazyLoad.min.js +++ b/dist/ocLazyLoad.min.js @@ -5,4 +5,4 @@ * @license MIT * @author Olivier Combe */ -!function(e,n){"use strict";var r=["ng","oc.lazyLoad"],o={},t=[],i=[],a=[],s=[],u=e.noop,c={},l=[],d=e.module("oc.lazyLoad",["ng"]);d.provider("$ocLazyLoad",["$controllerProvider","$provide","$compileProvider","$filterProvider","$injector","$animateProvider",function(d,f,p,m,v,y){function L(n,o,t){if(o){var i,s,d,f=[];for(i=o.length-1;i>=0;i--)if(s=o[i],e.isString(s)||(s=E(s)),s&&-1===l.indexOf(s)&&(!w[s]||-1!==a.indexOf(s))){var h=-1===r.indexOf(s);if(d=g(s),h&&(r.push(s),L(n,d.requires,t)),d._runBlocks.length>0)for(c[s]=[];d._runBlocks.length>0;)c[s].push(d._runBlocks.shift());e.isDefined(c[s])&&(h||t.rerun)&&(f=f.concat(c[s])),j(n,d._invokeQueue,s,t.reconfig),j(n,d._configBlocks,s,t.reconfig),u(h?"ocLazyLoad.moduleLoaded":"ocLazyLoad.moduleReloaded",s),o.pop(),l.push(s)}var p=n.getInstanceInjector();e.forEach(f,function(e){p.invoke(e)})}}function $(n,r){function t(n,r){var o,t=!0;return r.length&&(o=i(n),e.forEach(r,function(e){t=t&&i(e)!==o})),t}function i(n){return e.isArray(n)?M(n.toString()):e.isObject(n)?M(S(n)):e.isDefined(n)&&null!==n?M(n.toString()):n}var a=n[2][0],s=n[1],c=!1;e.isUndefined(o[r])&&(o[r]={}),e.isUndefined(o[r][s])&&(o[r][s]={});var l=function(e,n){o[r][s].hasOwnProperty(e)||(o[r][s][e]=[]),t(n,o[r][s][e])&&(c=!0,o[r][s][e].push(n),u("ocLazyLoad.componentLoaded",[r,s,e]))};if(e.isString(a))l(a,n[2][1]);else{if(!e.isObject(a))return!1;e.forEach(a,function(n,r){e.isString(n)?l(n,a[1]):l(r,n)})}return c}function j(n,r,o,i){if(r){var a,s,u,c;for(a=0,s=r.length;s>a;a++)if(u=r[a],e.isArray(u)){if(null!==n){if(!n.hasOwnProperty(u[0]))throw new Error("unsupported provider "+u[0]);c=n[u[0]]}var l=$(u,o);if("invoke"!==u[1])l&&e.isDefined(c)&&c[u[1]].apply(c,u[2]);else{var d=function(n){var r=t.indexOf(o+"-"+n);(-1===r||i)&&(-1===r&&t.push(o+"-"+n),e.isDefined(c)&&c[u[1]].apply(c,u[2]))};if(e.isFunction(u[2][0]))d(u[2][0]);else if(e.isArray(u[2][0]))for(var f=0,h=u[2][0].length;h>f;f++)e.isFunction(u[2][0][f])&&d(u[2][0][f])}}}}function E(n){var r=null;return e.isString(n)?r=n:e.isObject(n)&&n.hasOwnProperty("name")&&e.isString(n.name)&&(r=n.name),r}function _(n){if(!e.isString(n))return!1;try{return g(n)}catch(r){if(/No module/.test(r)||r.message.indexOf("$injector:nomod")>-1)return!1}}var w={},O={$controllerProvider:d,$compileProvider:p,$filterProvider:m,$provide:f,$injector:v,$animateProvider:y},x=!1,b=!1,z=[],D={};z.push=function(e){-1===this.indexOf(e)&&Array.prototype.push.apply(this,arguments)},this.config=function(n){e.isDefined(n.modules)&&(e.isArray(n.modules)?e.forEach(n.modules,function(e){w[e.name]=e}):w[n.modules.name]=n.modules),e.isDefined(n.debug)&&(x=n.debug),e.isDefined(n.events)&&(b=n.events)},this._init=function(o){if(0===i.length){var t=[o],a=["ng:app","ng-app","x-ng-app","data-ng-app"],u=/\sng[:\-]app(:\s*([\w\d_]+);?)?\s/,c=function(e){return e&&t.push(e)};e.forEach(a,function(n){a[n]=!0,c(document.getElementById(n)),n=n.replace(":","\\:"),"undefined"!=typeof o[0]&&o[0].querySelectorAll&&(e.forEach(o[0].querySelectorAll("."+n),c),e.forEach(o[0].querySelectorAll("."+n+"\\:"),c),e.forEach(o[0].querySelectorAll("["+n+"]"),c))}),e.forEach(t,function(n){if(0===i.length){var r=" "+o.className+" ",t=u.exec(r);t?i.push((t[2]||"").replace(/\s+/g,",")):e.forEach(n.attributes,function(e){0===i.length&&a[e.name]&&i.push(e.value)})}})}0!==i.length||(n.jasmine||n.mocha)&&e.isDefined(e.mock)||console.error("No module found during bootstrap, unable to init ocLazyLoad. You should always use the ng-app directive or angular.boostrap when you use ocLazyLoad.");var l=function d(n){if(-1===r.indexOf(n)){r.push(n);var o=e.module(n);j(null,o._invokeQueue,n),j(null,o._configBlocks,n),e.forEach(o.requires,d)}};e.forEach(i,function(e){l(e)}),i=[],s.pop()};var S=function(n){try{return JSON.stringify(n)}catch(r){var o=[];return JSON.stringify(n,function(n,r){if(e.isObject(r)&&null!==r){if(-1!==o.indexOf(r))return;o.push(r)}return r})}},M=function(e){var n,r,o,t=0;if(0==e.length)return t;for(n=0,o=e.length;o>n;n++)r=e.charCodeAt(n),t=(t<<5)-t+r,t|=0;return t};this.$get=["$log","$rootElement","$rootScope","$cacheFactory","$q",function(n,t,a,c,d){function f(e){var r=d.defer();return n.error(e.message),r.reject(e),r.promise}var p,m=c("ocLazyLoad");return x||(n={},n.error=e.noop,n.warn=e.noop,n.info=e.noop),O.getInstanceInjector=function(){return p?p:p=t.data("$injector")||e.injector()},u=function(e,r){b&&a.$broadcast(e,r),x&&n.info(e,r)},{_broadcast:u,_$log:n,_getFilesCache:function(){return m},toggleWatch:function(e){e?s.push(!0):s.pop()},getModuleConfig:function(n){if(!e.isString(n))throw new Error("You need to give the name of the module to get");return w[n]?e.copy(w[n]):null},setModuleConfig:function(n){if(!e.isObject(n))throw new Error("You need to give the module config object to set");return w[n.name]=n,n},getModules:function(){return r},isLoaded:function(n){var o=function(e){var n=r.indexOf(e)>-1;return n||(n=!!_(e)),n};if(e.isString(n)&&(n=[n]),e.isArray(n)){var t,i;for(t=0,i=n.length;i>t;t++)if(!o(n[t]))return!1;return!0}throw new Error("You need to define the module(s) name(s)")},_getModuleName:E,_getModule:function(e){try{return g(e)}catch(n){throw(/No module/.test(n)||n.message.indexOf("$injector:nomod")>-1)&&(n.message='The module "'+S(e)+'" that you are trying to load does not exist. '+n.message),n}},moduleExists:_,_loadDependencies:function(n,r){var o,t,i,a=[],s=this;if(n=s._getModuleName(n),null===n)return d.when();try{o=s._getModule(n)}catch(u){return f(u)}return t=s.getRequires(o),e.forEach(t,function(o){if(e.isString(o)){var t=s.getModuleConfig(o);if(null===t)return void z.push(o);o=t,t.name=void 0}if(s.moduleExists(o.name))return i=o.files.filter(function(e){return s.getModuleConfig(o.name).files.indexOf(e)<0}),0!==i.length&&s._$log.warn('Module "',n,'" attempted to redefine configuration for dependency. "',o.name,'"\n Additional Files Loaded:',i),e.isDefined(s.filesLoader)?void a.push(s.filesLoader(o,r).then(function(){return s._loadDependencies(o)})):f(new Error("Error: New dependencies need to be loaded from external files ("+o.files+"), but no loader has been defined."));if(e.isArray(o)){var u=[];e.forEach(o,function(e){var n=s.getModuleConfig(e);null===n?u.push(e):n.files&&(u=u.concat(n.files))}),u.length>0&&(o={files:u})}else e.isObject(o)&&o.hasOwnProperty("name")&&o.name&&(s.setModuleConfig(o),z.push(o.name));if(e.isDefined(o.files)&&0!==o.files.length){if(!e.isDefined(s.filesLoader))return f(new Error('Error: the module "'+o.name+'" is defined in external files ('+o.files+"), but no loader has been defined."));a.push(s.filesLoader(o,r).then(function(){return s._loadDependencies(o)}))}}),d.all(a)},inject:function(n){var r=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],o=arguments.length<=2||void 0===arguments[2]?!1:arguments[2],t=this,a=d.defer();if(e.isDefined(n)&&null!==n){if(e.isArray(n)){var s=[];return e.forEach(n,function(e){s.push(t.inject(e,r,o))}),d.all(s)}t._addToLoadList(t._getModuleName(n),!0,o)}if(i.length>0){var u=i.slice(),c=function f(e){z.push(e),D[e]=a.promise,t._loadDependencies(e,r).then(function(){try{l=[],L(O,z,r)}catch(e){return t._$log.error(e.message),void a.reject(e)}i.length>0?f(i.shift()):a.resolve(u)},function(e){a.reject(e)})};c(i.shift())}else{if(r&&r.name&&D[r.name])return D[r.name];a.resolve()}return a.promise},getRequires:function(n){var o=[];return e.forEach(n.requires,function(e){-1===r.indexOf(e)&&o.push(e)}),o},_invokeQueue:j,_registerInvokeList:$,_register:L,_addToLoadList:h,_unregister:function(n){e.isDefined(n)&&e.isArray(n)&&e.forEach(n,function(e){o[e]=void 0})}}}],this._init(e.element(n.document))}]);var f=e.bootstrap;e.bootstrap=function(n,r,o){return e.forEach(r.slice(),function(e){h(e,!0,!0)}),f(n,r,o)};var h=function(n,r,o){(s.length>0||r)&&e.isString(n)&&-1===i.indexOf(n)&&(i.push(n),o&&a.push(n))},g=e.module;e.module=function(e,n,r){return h(e,!1,!0),g(e,n,r)},"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports===exports&&(module.exports="oc.lazyLoad")}(angular,window),function(e){"use strict";e.module("oc.lazyLoad").directive("ocLazyLoad",["$ocLazyLoad","$compile","$animate","$parse","$timeout",function(n,r,o,t,i){return{restrict:"A",terminal:!0,priority:1e3,compile:function(i,a){var s=i[0].innerHTML;return i.html(""),function(i,a,u){var c=t(u.ocLazyLoad);i.$watch(function(){return c(i)||u.ocLazyLoad},function(t){e.isDefined(t)&&n.load(t).then(function(){o.enter(s,a),r(a.contents())(i)})},!0)}}}}])}(angular),function(e){"use strict";e.module("oc.lazyLoad").config(["$provide",function(n){n.decorator("$ocLazyLoad",["$delegate","$q","$window","$interval",function(n,r,o,t){var i=!1,a=!1,s=o.document.getElementsByTagName("head")[0]||o.document.getElementsByTagName("body")[0];return n.buildElement=function(u,c,l){var d,f,h=r.defer(),g=n._getFilesCache(),p=function(e){var n=(new Date).getTime();return e.indexOf("?")>=0?"&"===e.substring(0,e.length-1)?e+"_dc="+n:e+"&_dc="+n:e+"?_dc="+n};switch(e.isUndefined(g.get(c))&&g.put(c,h.promise),u){case"css":d=o.document.createElement("link"),d.type="text/css",d.rel="stylesheet",d.href=l.cache===!1?p(c):c;break;case"js":d=o.document.createElement("script"),d.src=l.cache===!1?p(c):c;break;default:g.remove(c),h.reject(new Error('Requested type "'+u+'" is not known. Could not inject "'+c+'"'))}d.onload=d.onreadystatechange=function(e){d.readyState&&!/^c|loade/.test(d.readyState)||f||(d.onload=d.onreadystatechange=null,f=1,n._broadcast("ocLazyLoad.fileLoaded",c),h.resolve())},d.onerror=function(){g.remove(c),h.reject(new Error("Unable to load "+c))},d.async=l.serie?0:1;var m=s.lastChild;if(l.insertBefore){var v=e.element(e.isDefined(window.jQuery)?l.insertBefore:document.querySelector(l.insertBefore));v&&v.length>0&&(m=v[0])}if(m.parentNode.insertBefore(d,m),"css"==u){if(!i){var y=o.navigator.userAgent.toLowerCase();if(/iP(hone|od|ad)/.test(o.navigator.platform)){var L=o.navigator.appVersion.match(/OS (\d+)_(\d+)_?(\d+)?/),$=parseFloat([parseInt(L[1],10),parseInt(L[2],10),parseInt(L[3]||0,10)].join("."));a=6>$}else if(y.indexOf("android")>-1){var j=parseFloat(y.slice(y.indexOf("android")+8));a=4.4>j}else if(y.indexOf("safari")>-1){var E=y.match(/version\/([\.\d]+)/i);a=E&&E[1]&&parseFloat(E[1])<6}}if(a)var _=1e3,w=t(function(){try{d.sheet.cssRules,t.cancel(w),d.onload()}catch(e){--_<=0&&d.onerror()}},20)}return h.promise},n}])}])}(angular),function(e){"use strict";e.module("oc.lazyLoad").config(["$provide",function(n){n.decorator("$ocLazyLoad",["$delegate","$q",function(n,r){return n.filesLoader=function(o){var t=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],i=[],a=[],s=[],u=[],c=null,l=n._getFilesCache();n.toggleWatch(!0),e.extend(t,o);var d=function(r){var o,d=null;if(e.isObject(r)&&(d=r.type,r=r.path),c=l.get(r),e.isUndefined(c)||t.cache===!1){if(null!==(o=/^(css|less|html|htm|js)?(?=!)/.exec(r))&&(d=o[1],r=r.substr(o[1].length+1,r.length)),!d)if(null!==(o=/[.](css|less|html|htm|js)?((\?|#).*)?$/.exec(r)))d=o[1];else{if(n.jsLoader.hasOwnProperty("ocLazyLoadLoader")||!n.jsLoader.hasOwnProperty("requirejs"))return void n._$log.error("File type could not be determined. "+r);d="js"}"css"!==d&&"less"!==d||-1!==i.indexOf(r)?"html"!==d&&"htm"!==d||-1!==a.indexOf(r)?"js"===d||-1===s.indexOf(r)?s.push(r):n._$log.error("File type is not valid. "+r):a.push(r):i.push(r)}else c&&u.push(c)};if(t.serie?d(t.files.shift()):e.forEach(t.files,function(e){d(e)}),i.length>0){var f=r.defer();n.cssLoader(i,function(r){e.isDefined(r)&&n.cssLoader.hasOwnProperty("ocLazyLoadLoader")?(n._$log.error(r),f.reject(r)):f.resolve()},t),u.push(f.promise)}if(a.length>0){var h=r.defer();n.templatesLoader(a,function(r){e.isDefined(r)&&n.templatesLoader.hasOwnProperty("ocLazyLoadLoader")?(n._$log.error(r),h.reject(r)):h.resolve()},t),u.push(h.promise)}if(s.length>0){var g=r.defer();n.jsLoader(s,function(r){e.isDefined(r)&&(n.jsLoader.hasOwnProperty("ocLazyLoadLoader")||n.jsLoader.hasOwnProperty("requirejs"))?(n._$log.error(r),g.reject(r)):g.resolve()},t),u.push(g.promise)}if(0===u.length){var p=r.defer(),m="Error: no file to load has been found, if you're trying to load an existing module you should use the 'inject' method instead of 'load'.";return n._$log.error(m),p.reject(m),p.promise}return t.serie&&t.files.length>0?r.all(u).then(function(){return n.filesLoader(o,t)}):r.all(u)["finally"](function(e){return n.toggleWatch(!1),e})},n.load=function(o){var t,i=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],a=this,s=null,u=[],c=r.defer(),l=e.copy(o),d=e.copy(i);if(e.isArray(l))return e.forEach(l,function(e){u.push(a.load(e,d))}),r.all(u).then(function(e){c.resolve(e)},function(e){c.reject(e)}),c.promise;if(e.isString(l)?(s=a.getModuleConfig(l),s||(s={files:[l]})):e.isObject(l)&&(s=e.isDefined(l.path)&&e.isDefined(l.type)?{files:[l]}:a.setModuleConfig(l)),null===s){var f=a._getModuleName(l);return t='Module "'+(f||"unknown")+'" is not configured, cannot load.',n._$log.error(t),c.reject(new Error(t)),c.promise}e.isDefined(s.template)&&(e.isUndefined(s.files)&&(s.files=[]),e.isString(s.template)?s.files.push(s.template):e.isArray(s.template)&&s.files.concat(s.template));var h=e.extend({},d,s);return e.isUndefined(s.files)&&e.isDefined(s.name)&&n.moduleExists(s.name)?n.inject(s.name,h,!0):(n.filesLoader(s,h).then(function(){n.inject(null,h).then(function(e){c.resolve(e)},function(e){c.reject(e)})},function(e){c.reject(e)}),c.promise)},n}])}])}(angular),function(e){"use strict";e.module("oc.lazyLoad").config(["$provide",function(n){n.decorator("$ocLazyLoad",["$delegate","$q",function(n,r){return n.cssLoader=function(o,t,i){var a=[];e.forEach(o,function(e){a.push(n.buildElement("css",e,i))}),r.all(a).then(function(){t()},function(e){t(e)})},n.cssLoader.ocLazyLoadLoader=!0,n}])}])}(angular),function(e){"use strict";e.module("oc.lazyLoad").config(["$provide",function(n){n.decorator("$ocLazyLoad",["$delegate","$q",function(n,r){return n.jsLoader=function(o,t,i){var a=[];e.forEach(o,function(e){a.push(n.buildElement("js",e,i))}),r.all(a).then(function(){t()},function(e){t(e)})},n.jsLoader.ocLazyLoadLoader=!0,n}])}])}(angular),function(e){"use strict";e.module("oc.lazyLoad").config(["$provide",function(n){n.decorator("$ocLazyLoad",["$delegate","$templateCache","$q","$http",function(n,r,o,t){return n.templatesLoader=function(i,a,s){var u=[],c=n._getFilesCache();return e.forEach(i,function(n){var i=o.defer();u.push(i.promise),t.get(n,s).success(function(o){e.isString(o)&&o.length>0&&e.forEach(e.element(o),function(e){"SCRIPT"===e.nodeName&&"text/ng-template"===e.type&&r.put(e.id,e.innerHTML)}),e.isUndefined(c.get(n))&&c.put(n,!0),i.resolve()}).error(function(e){i.reject(new Error('Unable to load template file "'+n+'": '+e))})}),o.all(u).then(function(){a()},function(e){a(e)})},n.templatesLoader.ocLazyLoadLoader=!0,n}])}])}(angular),Array.prototype.indexOf||(Array.prototype.indexOf=function(e,n){var r;if(null==this)throw new TypeError('"this" is null or not defined');var o=Object(this),t=o.length>>>0;if(0===t)return-1;var i=+n||0;if(Math.abs(i)===1/0&&(i=0),i>=t)return-1;for(r=Math.max(i>=0?i:t-Math.abs(i),0);t>r;){if(r in o&&o[r]===e)return r;r++}return-1}); \ No newline at end of file +!function(e,n){"use strict";var r=["ng","oc.lazyLoad"],t={},o=[],i=[],a=[],s=[],u=e.noop,l={},c=[],f=e.module("oc.lazyLoad",["ng"]);f.provider("$ocLazyLoad",["$controllerProvider","$provide","$compileProvider","$filterProvider","$injector","$animateProvider",function(f,d,p,m,v,y){function L(n,t,o){if(t){var i,s,f,d=[];for(i=t.length-1;i>=0;i--)if(s=t[i],e.isString(s)||(s=E(s)),s&&-1===c.indexOf(s)&&(!w[s]||-1!==a.indexOf(s))){var h=-1===r.indexOf(s);if(f=g(s),h&&(r.push(s),L(n,f.requires,o)),f._runBlocks.length>0)for(l[s]=[];f._runBlocks.length>0;)l[s].push(f._runBlocks.shift());e.isDefined(l[s])&&(h||o.rerun)&&(d=d.concat(l[s])),j(n,f._invokeQueue,s,o.reconfig),j(n,f._configBlocks,s,o.reconfig),u(h?"ocLazyLoad.moduleLoaded":"ocLazyLoad.moduleReloaded",s),t.pop(),c.push(s)}var p=n.getInstanceInjector();e.forEach(d,function(e){p.invoke(e)})}}function $(n,r){function o(n,r){var t,o=!0;return r.length&&(t=i(n),e.forEach(r,function(e){o=o&&i(e)!==t})),o}function i(n){return e.isArray(n)?A(n.toString()):e.isObject(n)?A(M(n)):e.isDefined(n)&&null!==n?A(n.toString()):n}var a=n[2][0],s=n[1],l=!1;e.isUndefined(t[r])&&(t[r]={}),e.isUndefined(t[r][s])&&(t[r][s]={});var c=function(e,n){t[r][s].hasOwnProperty(e)||(t[r][s][e]=[]),o(n,t[r][s][e])&&(l=!0,t[r][s][e].push(n),u("ocLazyLoad.componentLoaded",[r,s,e]))};if(e.isString(a))c(a,n[2][1]);else{if(!e.isObject(a))return!1;e.forEach(a,function(n,r){e.isString(n)?c(n,a[1]):c(r,n)})}return l}function j(n,r,t,i){if(r){var a,s,u,l;for(a=0,s=r.length;s>a;a++)if(u=r[a],e.isArray(u)){if(null!==n){if(!n.hasOwnProperty(u[0]))throw new Error("unsupported provider "+u[0]);l=n[u[0]]}var c=$(u,t);if("invoke"!==u[1])c&&e.isDefined(l)&&l[u[1]].apply(l,u[2]);else{var f=function(n){var r=o.indexOf(t+"-"+n);(-1===r||i)&&(-1===r&&o.push(t+"-"+n),e.isDefined(l)&&l[u[1]].apply(l,u[2]))};if(e.isFunction(u[2][0]))f(u[2][0]);else if(e.isArray(u[2][0]))for(var d=0,h=u[2][0].length;h>d;d++)e.isFunction(u[2][0][d])&&f(u[2][0][d])}}}}function E(n){var r=null;return e.isString(n)?r=n:e.isObject(n)&&n.hasOwnProperty("name")&&e.isString(n.name)&&(r=n.name),r}function _(n){if(!e.isString(n))return!1;try{return g(n)}catch(r){if(/No module/.test(r)||r.message.indexOf("$injector:nomod")>-1)return!1}}var w={},O={$controllerProvider:f,$compileProvider:p,$filterProvider:m,$provide:d,$injector:v,$animateProvider:y},x=!1,b=!1,z=[],D={},S={};z.push=function(e){-1===this.indexOf(e)&&Array.prototype.push.apply(this,arguments)},this.config=function(n){e.isDefined(n.modules)&&(e.isArray(n.modules)?e.forEach(n.modules,function(e){w[e.name]=e}):w[n.modules.name]=n.modules),e.isDefined(n.debug)&&(x=n.debug),e.isDefined(n.events)&&(b=n.events),e.isDefined(n.moduleDefaults)&&(S=n.moduleDefaults)},this._init=function(t){if(0===i.length){var o=[t],a=["ng:app","ng-app","x-ng-app","data-ng-app"],u=/\sng[:\-]app(:\s*([\w\d_]+);?)?\s/,l=function(e){return e&&o.push(e)};e.forEach(a,function(n){a[n]=!0,l(document.getElementById(n)),n=n.replace(":","\\:"),"undefined"!=typeof t[0]&&t[0].querySelectorAll&&(e.forEach(t[0].querySelectorAll("."+n),l),e.forEach(t[0].querySelectorAll("."+n+"\\:"),l),e.forEach(t[0].querySelectorAll("["+n+"]"),l))}),e.forEach(o,function(n){if(0===i.length){var r=" "+t.className+" ",o=u.exec(r);o?i.push((o[2]||"").replace(/\s+/g,",")):e.forEach(n.attributes,function(e){0===i.length&&a[e.name]&&i.push(e.value)})}})}0!==i.length||(n.jasmine||n.mocha)&&e.isDefined(e.mock)||console.error("No module found during bootstrap, unable to init ocLazyLoad. You should always use the ng-app directive or angular.boostrap when you use ocLazyLoad.");var c=function f(n){if(-1===r.indexOf(n)){r.push(n);var t=e.module(n);j(null,t._invokeQueue,n),j(null,t._configBlocks,n),e.forEach(t.requires,f)}};e.forEach(i,function(e){c(e)}),i=[],s.pop()};var M=function(n){try{return JSON.stringify(n)}catch(r){var t=[];return JSON.stringify(n,function(n,r){if(e.isObject(r)&&null!==r){if(-1!==t.indexOf(r))return;t.push(r)}return r})}},A=function(e){var n,r,t,o=0;if(0==e.length)return o;for(n=0,t=e.length;t>n;n++)r=e.charCodeAt(n),o=(o<<5)-o+r,o|=0;return o};this.$get=["$log","$rootElement","$rootScope","$cacheFactory","$q",function(n,o,a,l,f){function d(e){var r=f.defer();return n.error(e.message),r.reject(e),r.promise}var p,m=l("ocLazyLoad");return x||(n={},n.error=e.noop,n.warn=e.noop,n.info=e.noop),O.getInstanceInjector=function(){return p?p:p=o.data("$injector")||e.injector()},u=function(e,r){b&&a.$broadcast(e,r),x&&n.info(e,r)},{_broadcast:u,_$log:n,_getModuleDefaults:function(){return S},_getFilesCache:function(){return m},toggleWatch:function(e){e?s.push(!0):s.pop()},getModuleConfig:function(n){if(!e.isString(n))throw new Error("You need to give the name of the module to get");return w[n]?e.copy(w[n]):null},setModuleConfig:function(n){if(!e.isObject(n))throw new Error("You need to give the module config object to set");return w[n.name]=n,n},getModules:function(){return r},isLoaded:function(n){var t=function(e){var n=r.indexOf(e)>-1;return n||(n=!!_(e)),n};if(e.isString(n)&&(n=[n]),e.isArray(n)){var o,i;for(o=0,i=n.length;i>o;o++)if(!t(n[o]))return!1;return!0}throw new Error("You need to define the module(s) name(s)")},_getModuleName:E,_getModule:function(e){try{return g(e)}catch(n){throw(/No module/.test(n)||n.message.indexOf("$injector:nomod")>-1)&&(n.message='The module "'+M(e)+'" that you are trying to load does not exist. '+n.message),n}},moduleExists:_,_loadDependencies:function(n,r){var t,o,i,a=[],s=this;if(n=s._getModuleName(n),null===n)return f.when();try{t=s._getModule(n)}catch(u){return d(u)}return o=s.getRequires(t),e.forEach(o,function(t){if(e.isString(t)){var o=s.getModuleConfig(t);if(null===o)return void z.push(t);t=o,o.name=void 0}if(s.moduleExists(t.name))return i=t.files.filter(function(e){return s.getModuleConfig(t.name).files.indexOf(e)<0}),0!==i.length&&s._$log.warn('Module "',n,'" attempted to redefine configuration for dependency. "',t.name,'"\n Additional Files Loaded:',i),e.isDefined(s.filesLoader)?void a.push(s.filesLoader(t,r).then(function(){return s._loadDependencies(t)})):d(new Error("Error: New dependencies need to be loaded from external files ("+t.files+"), but no loader has been defined."));if(e.isArray(t)){var u=[];e.forEach(t,function(e){var n=s.getModuleConfig(e);null===n?u.push(e):n.files&&(u=u.concat(n.files))}),u.length>0&&(t={files:u})}else e.isObject(t)&&t.hasOwnProperty("name")&&t.name&&(s.setModuleConfig(t),z.push(t.name));if(e.isDefined(t.files)&&0!==t.files.length){if(!e.isDefined(s.filesLoader))return d(new Error('Error: the module "'+t.name+'" is defined in external files ('+t.files+"), but no loader has been defined."));a.push(s.filesLoader(t,r).then(function(){return s._loadDependencies(t)}))}}),f.all(a)},inject:function(n){var r=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],t=arguments.length<=2||void 0===arguments[2]?!1:arguments[2],o=this,a=f.defer();if(e.isDefined(n)&&null!==n){if(e.isArray(n)){var s=[];return e.forEach(n,function(e){s.push(o.inject(e,r,t))}),f.all(s)}o._addToLoadList(o._getModuleName(n),!0,t)}if(i.length>0){var u=i.slice(),l=function d(e){z.push(e),D[e]=a.promise,o._loadDependencies(e,r).then(function(){try{c=[],L(O,z,r)}catch(e){return o._$log.error(e.message),void a.reject(e)}i.length>0?d(i.shift()):a.resolve(u)},function(e){a.reject(e)})};l(i.shift())}else{if(r&&r.name&&D[r.name])return D[r.name];a.resolve()}return a.promise},getRequires:function(n){var t=[];return e.forEach(n.requires,function(e){-1===r.indexOf(e)&&t.push(e)}),t},_invokeQueue:j,_registerInvokeList:$,_register:L,_addToLoadList:h,_unregister:function(n){e.isDefined(n)&&e.isArray(n)&&e.forEach(n,function(e){t[e]=void 0})}}}],this._init(e.element(n.document))}]);var d=e.bootstrap;e.bootstrap=function(n,r,t){return e.forEach(r.slice(),function(e){h(e,!0,!0)}),d(n,r,t)};var h=function(n,r,t){(s.length>0||r)&&e.isString(n)&&-1===i.indexOf(n)&&(i.push(n),t&&a.push(n))},g=e.module;e.module=function(e,n,r){return h(e,!1,!0),g(e,n,r)},"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports===exports&&(module.exports="oc.lazyLoad")}(angular,window),function(e){"use strict";e.module("oc.lazyLoad").directive("ocLazyLoad",["$ocLazyLoad","$compile","$animate","$parse","$timeout",function(n,r,t,o,i){return{restrict:"A",terminal:!0,priority:1e3,compile:function(i,a){var s=i[0].innerHTML;return i.html(""),function(i,a,u){var l=o(u.ocLazyLoad);i.$watch(function(){return l(i)||u.ocLazyLoad},function(o){e.isDefined(o)&&n.load(o).then(function(){t.enter(s,a),r(a.contents())(i)})},!0)}}}}])}(angular),function(e){"use strict";e.module("oc.lazyLoad").config(["$provide",function(n){n.decorator("$ocLazyLoad",["$delegate","$q","$window","$interval",function(n,r,t,o){var i=!1,a=!1,s=t.document.getElementsByTagName("head")[0]||t.document.getElementsByTagName("body")[0];return n.buildElement=function(u,l,c){var f,d,h=r.defer(),g=n._getFilesCache(),p=function(e){var n=(new Date).getTime();return e.indexOf("?")>=0?"&"===e.substring(0,e.length-1)?e+"_dc="+n:e+"&_dc="+n:e+"?_dc="+n};switch(e.isUndefined(g.get(l))&&g.put(l,h.promise),u){case"css":f=t.document.createElement("link"),f.type="text/css",f.rel="stylesheet",f.href=c.cache===!1?p(l):l;break;case"js":f=t.document.createElement("script"),f.src=c.cache===!1?p(l):l;break;default:g.remove(l),h.reject(new Error('Requested type "'+u+'" is not known. Could not inject "'+l+'"'))}f.onload=f.onreadystatechange=function(e){f.readyState&&!/^c|loade/.test(f.readyState)||d||(f.onload=f.onreadystatechange=null,d=1,n._broadcast("ocLazyLoad.fileLoaded",l),h.resolve())},f.onerror=function(){g.remove(l),h.reject(new Error("Unable to load "+l))},f.async=c.serie?0:1;var m=s.lastChild;if(c.insertBefore){var v=e.element(e.isDefined(window.jQuery)?c.insertBefore:document.querySelector(c.insertBefore));v&&v.length>0&&(m=v[0])}if(m.parentNode.insertBefore(f,m),"css"==u){if(!i){var y=t.navigator.userAgent.toLowerCase();if(y.indexOf("phantomjs/1.9")>-1)a=!0;else if(/iP(hone|od|ad)/.test(t.navigator.platform)){var L=t.navigator.appVersion.match(/OS (\d+)_(\d+)_?(\d+)?/),$=parseFloat([parseInt(L[1],10),parseInt(L[2],10),parseInt(L[3]||0,10)].join("."));a=6>$}else if(y.indexOf("android")>-1){var j=parseFloat(y.slice(y.indexOf("android")+8));a=4.4>j}else if(y.indexOf("safari")>-1){var E=y.match(/version\/([\.\d]+)/i);a=E&&E[1]&&parseFloat(E[1])<6}}if(a)var _=1e3,w=o(function(){try{f.sheet.cssRules,o.cancel(w),f.onload()}catch(e){--_<=0&&f.onerror()}},20)}return h.promise},n}])}])}(angular),function(e){"use strict";e.module("oc.lazyLoad").config(["$provide",function(n){n.decorator("$ocLazyLoad",["$delegate","$q",function(n,r){return n.filesLoader=function(t){var o=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],i=[],a=[],s=[],u=[],l=null,c=n._getFilesCache();n.toggleWatch(!0),o=e.extend({},n._getModuleDefaults(),o,t);var f=function(r){var t,f=null;if(e.isObject(r)&&(f=r.type,r=r.path),l=c.get(r),e.isUndefined(l)||o.cache===!1){if(null!==(t=/^(css|less|html|htm|js)?(?=!)/.exec(r))&&(f=t[1],r=r.substr(t[1].length+1,r.length)),!f)if(null!==(t=/[.](css|less|html|htm|js)?((\?|#).*)?$/.exec(r)))f=t[1];else{if(n.jsLoader.hasOwnProperty("ocLazyLoadLoader")||!n.jsLoader.hasOwnProperty("requirejs"))return void n._$log.error("File type could not be determined. "+r);f="js"}"css"!==f&&"less"!==f||-1!==i.indexOf(r)?"html"!==f&&"htm"!==f||-1!==a.indexOf(r)?"js"===f||-1===s.indexOf(r)?s.push(r):n._$log.error("File type is not valid. "+r):a.push(r):i.push(r)}else l&&u.push(l)};if(o.serie?f(o.files.shift()):e.forEach(o.files,function(e){f(e)}),i.length>0){var d=r.defer();n.cssLoader(i,function(r){e.isDefined(r)&&n.cssLoader.hasOwnProperty("ocLazyLoadLoader")?(n._$log.error(r),d.reject(r)):d.resolve()},o),u.push(d.promise)}if(a.length>0){var h=r.defer();n.templatesLoader(a,function(r){e.isDefined(r)&&n.templatesLoader.hasOwnProperty("ocLazyLoadLoader")?(n._$log.error(r),h.reject(r)):h.resolve()},o),u.push(h.promise)}if(s.length>0){var g=r.defer();n.jsLoader(s,function(r){e.isDefined(r)&&(n.jsLoader.hasOwnProperty("ocLazyLoadLoader")||n.jsLoader.hasOwnProperty("requirejs"))?(n._$log.error(r),g.reject(r)):g.resolve()},o),u.push(g.promise)}if(0===u.length){var p=r.defer(),m="Error: no file to load has been found, if you're trying to load an existing module you should use the 'inject' method instead of 'load'.";return n._$log.error(m),p.reject(m),p.promise}return o.serie&&o.files.length>0?r.all(u).then(function(){return n.filesLoader(t,o)}):r.all(u)["finally"](function(e){return n.toggleWatch(!1),e})},n.load=function(t){var o,i=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],a=this,s=null,u=[],l=r.defer(),c=e.copy(t),f=e.copy(i);if(e.isArray(c))return e.forEach(c,function(e){u.push(a.load(e,f))}),r.all(u).then(function(e){l.resolve(e)},function(e){l.reject(e)}),l.promise;if(e.isString(c)?(s=a.getModuleConfig(c),s||(s={files:[c]})):e.isObject(c)&&(s=e.isDefined(c.path)&&e.isDefined(c.type)?{files:[c]}:a.setModuleConfig(c)),null===s){var d=a._getModuleName(c);return o='Module "'+(d||"unknown")+'" is not configured, cannot load.',n._$log.error(o),l.reject(new Error(o)),l.promise}e.isDefined(s.template)&&(e.isUndefined(s.files)&&(s.files=[]),e.isString(s.template)?s.files.push(s.template):e.isArray(s.template)&&s.files.concat(s.template));var h=e.extend({},f,s);return e.isUndefined(s.files)&&e.isDefined(s.name)&&n.moduleExists(s.name)?n.inject(s.name,h,!0):(n.filesLoader(s,h).then(function(){n.inject(null,h).then(function(e){l.resolve(e)},function(e){l.reject(e)})},function(e){l.reject(e)}),l.promise)},n}])}])}(angular),function(e){"use strict";e.module("oc.lazyLoad").config(["$provide",function(n){n.decorator("$ocLazyLoad",["$delegate","$q",function(n,r){return n.cssLoader=function(t,o,i){var a=[];e.forEach(t,function(e){a.push(n.buildElement("css",e,i))}),r.all(a).then(function(){o()},function(e){o(e)})},n.cssLoader.ocLazyLoadLoader=!0,n}])}])}(angular),function(e){"use strict";e.module("oc.lazyLoad").config(["$provide",function(n){n.decorator("$ocLazyLoad",["$delegate","$q",function(n,r){return n.jsLoader=function(t,o,i){var a=[];e.forEach(t,function(e){a.push(n.buildElement("js",e,i))}),r.all(a).then(function(){o()},function(e){o(e)})},n.jsLoader.ocLazyLoadLoader=!0,n}])}])}(angular),function(e){"use strict";e.module("oc.lazyLoad").config(["$provide",function(n){n.decorator("$ocLazyLoad",["$delegate","$templateCache","$q","$http",function(n,r,t,o){return n.templatesLoader=function(i,a,s){var u=[],l=n._getFilesCache();return s=e.extend({},n._getModuleDefaults(),s),e.forEach(i,function(n){var i=t.defer();u.push(i.promise),o.get(n,s).success(function(t){e.isString(t)&&t.length>0&&e.forEach(e.element(t),function(e){"SCRIPT"===e.nodeName&&"text/ng-template"===e.type&&r.put(e.id,e.innerHTML)}),e.isUndefined(l.get(n))&&l.put(n,!0),i.resolve()}).error(function(e){i.reject(new Error('Unable to load template file "'+n+'": '+e))})}),t.all(u).then(function(){a()},function(e){a(e)})},n.templatesLoader.ocLazyLoadLoader=!0,n}])}])}(angular),Array.prototype.indexOf||(Array.prototype.indexOf=function(e,n){var r;if(null==this)throw new TypeError('"this" is null or not defined');var t=Object(this),o=t.length>>>0;if(0===o)return-1;var i=+n||0;if(Math.abs(i)===1/0&&(i=0),i>=o)return-1;for(r=Math.max(i>=0?i:o-Math.abs(i),0);o>r;){if(r in t&&t[r]===e)return r;r++}return-1}); \ No newline at end of file diff --git a/dist/ocLazyLoad.require.js b/dist/ocLazyLoad.require.js index 5492718..99f5c98 100644 --- a/dist/ocLazyLoad.require.js +++ b/dist/ocLazyLoad.require.js @@ -35,7 +35,8 @@ debug = false, events = false, moduleCache = [], - modulePromises = {}; + modulePromises = {}, + moduleDefaults = {}; moduleCache.push = function (value) { if (this.indexOf(value) === -1) { @@ -62,6 +63,10 @@ if (angular.isDefined(config.events)) { events = config.events; } + + if (angular.isDefined(config.moduleDefaults)) { + moduleDefaults = config.moduleDefaults; + } }; /** @@ -392,6 +397,15 @@ _$log: $log, + /** + * Returns module configuration defaults + * @returns {object} + * @private + */ + _getModuleDefaults: function getModuleDefaults() { + return moduleDefaults; + }, + /** * Returns the files cache used by the loaders to store the files currently loading * @returns {*} @@ -885,6 +899,7 @@ /* The event load or readystatechange doesn't fire in: + - PhantomJS 1.9 (headless webkit browser) - iOS < 6 (default mobile browser) - Android < 4.4 (default mobile browser) - Safari < 6 (desktop browser) @@ -893,16 +908,20 @@ if (!uaCssChecked) { var ua = $window.navigator.userAgent.toLowerCase(); - // iOS < 6 - if (/iP(hone|od|ad)/.test($window.navigator.platform)) { + if (ua.indexOf('phantomjs/1.9') > -1) { + // PhantomJS ~1.9 + useCssLoadPatch = true; + } else if (/iP(hone|od|ad)/.test($window.navigator.platform)) { + // iOS < 6 var v = $window.navigator.appVersion.match(/OS (\d+)_(\d+)_?(\d+)?/); var iOSVersion = parseFloat([parseInt(v[1], 10), parseInt(v[2], 10), parseInt(v[3] || 0, 10)].join('.')); useCssLoadPatch = iOSVersion < 6; - } else if (ua.indexOf("android") > -1) { + } else if (ua.indexOf('android') > -1) { // Android < 4.4 - var androidVersion = parseFloat(ua.slice(ua.indexOf("android") + 8)); + var androidVersion = parseFloat(ua.slice(ua.indexOf('android') + 8)); useCssLoadPatch = androidVersion < 4.4; } else if (ua.indexOf('safari') > -1) { + // Safari < 6 var versionMatch = ua.match(/version\/([\.\d]+)/i); useCssLoadPatch = versionMatch && versionMatch[1] && parseFloat(versionMatch[1]) < 6; } @@ -954,7 +973,7 @@ $delegate.toggleWatch(true); // start watching angular.module calls - angular.extend(params, config); + params = angular.extend({}, $delegate._getModuleDefaults(), params, config); var pushFile = function pushFile(path) { var file_type = null, @@ -1234,6 +1253,8 @@ var promises = [], filesCache = $delegate._getFilesCache(); + params = angular.extend({}, $delegate._getModuleDefaults(), params); + angular.forEach(paths, function (url) { var deferred = $q.defer(); promises.push(deferred.promise); diff --git a/dist/ocLazyLoad.require.min.js b/dist/ocLazyLoad.require.min.js index 8e2bc4e..17e0ec3 100644 --- a/dist/ocLazyLoad.require.min.js +++ b/dist/ocLazyLoad.require.min.js @@ -5,4 +5,4 @@ * @license MIT * @author Olivier Combe */ -!function(e,n){"use strict";var r=["ng","oc.lazyLoad"],o={},t=[],i=[],a=[],s=[],u=e.noop,c={},l=[],d=e.module("oc.lazyLoad",["ng"]);d.provider("$ocLazyLoad",["$controllerProvider","$provide","$compileProvider","$filterProvider","$injector","$animateProvider",function(d,f,p,m,v,y){function L(n,o,t){if(o){var i,s,d,f=[];for(i=o.length-1;i>=0;i--)if(s=o[i],e.isString(s)||(s=E(s)),s&&-1===l.indexOf(s)&&(!w[s]||-1!==a.indexOf(s))){var h=-1===r.indexOf(s);if(d=g(s),h&&(r.push(s),L(n,d.requires,t)),d._runBlocks.length>0)for(c[s]=[];d._runBlocks.length>0;)c[s].push(d._runBlocks.shift());e.isDefined(c[s])&&(h||t.rerun)&&(f=f.concat(c[s])),j(n,d._invokeQueue,s,t.reconfig),j(n,d._configBlocks,s,t.reconfig),u(h?"ocLazyLoad.moduleLoaded":"ocLazyLoad.moduleReloaded",s),o.pop(),l.push(s)}var p=n.getInstanceInjector();e.forEach(f,function(e){p.invoke(e)})}}function $(n,r){function t(n,r){var o,t=!0;return r.length&&(o=i(n),e.forEach(r,function(e){t=t&&i(e)!==o})),t}function i(n){return e.isArray(n)?M(n.toString()):e.isObject(n)?M(S(n)):e.isDefined(n)&&null!==n?M(n.toString()):n}var a=n[2][0],s=n[1],c=!1;e.isUndefined(o[r])&&(o[r]={}),e.isUndefined(o[r][s])&&(o[r][s]={});var l=function(e,n){o[r][s].hasOwnProperty(e)||(o[r][s][e]=[]),t(n,o[r][s][e])&&(c=!0,o[r][s][e].push(n),u("ocLazyLoad.componentLoaded",[r,s,e]))};if(e.isString(a))l(a,n[2][1]);else{if(!e.isObject(a))return!1;e.forEach(a,function(n,r){e.isString(n)?l(n,a[1]):l(r,n)})}return c}function j(n,r,o,i){if(r){var a,s,u,c;for(a=0,s=r.length;s>a;a++)if(u=r[a],e.isArray(u)){if(null!==n){if(!n.hasOwnProperty(u[0]))throw new Error("unsupported provider "+u[0]);c=n[u[0]]}var l=$(u,o);if("invoke"!==u[1])l&&e.isDefined(c)&&c[u[1]].apply(c,u[2]);else{var d=function(n){var r=t.indexOf(o+"-"+n);(-1===r||i)&&(-1===r&&t.push(o+"-"+n),e.isDefined(c)&&c[u[1]].apply(c,u[2]))};if(e.isFunction(u[2][0]))d(u[2][0]);else if(e.isArray(u[2][0]))for(var f=0,h=u[2][0].length;h>f;f++)e.isFunction(u[2][0][f])&&d(u[2][0][f])}}}}function E(n){var r=null;return e.isString(n)?r=n:e.isObject(n)&&n.hasOwnProperty("name")&&e.isString(n.name)&&(r=n.name),r}function _(n){if(!e.isString(n))return!1;try{return g(n)}catch(r){if(/No module/.test(r)||r.message.indexOf("$injector:nomod")>-1)return!1}}var w={},O={$controllerProvider:d,$compileProvider:p,$filterProvider:m,$provide:f,$injector:v,$animateProvider:y},x=!1,b=!1,z=[],D={};z.push=function(e){-1===this.indexOf(e)&&Array.prototype.push.apply(this,arguments)},this.config=function(n){e.isDefined(n.modules)&&(e.isArray(n.modules)?e.forEach(n.modules,function(e){w[e.name]=e}):w[n.modules.name]=n.modules),e.isDefined(n.debug)&&(x=n.debug),e.isDefined(n.events)&&(b=n.events)},this._init=function(o){if(0===i.length){var t=[o],a=["ng:app","ng-app","x-ng-app","data-ng-app"],u=/\sng[:\-]app(:\s*([\w\d_]+);?)?\s/,c=function(e){return e&&t.push(e)};e.forEach(a,function(n){a[n]=!0,c(document.getElementById(n)),n=n.replace(":","\\:"),"undefined"!=typeof o[0]&&o[0].querySelectorAll&&(e.forEach(o[0].querySelectorAll("."+n),c),e.forEach(o[0].querySelectorAll("."+n+"\\:"),c),e.forEach(o[0].querySelectorAll("["+n+"]"),c))}),e.forEach(t,function(n){if(0===i.length){var r=" "+o.className+" ",t=u.exec(r);t?i.push((t[2]||"").replace(/\s+/g,",")):e.forEach(n.attributes,function(e){0===i.length&&a[e.name]&&i.push(e.value)})}})}0!==i.length||(n.jasmine||n.mocha)&&e.isDefined(e.mock)||console.error("No module found during bootstrap, unable to init ocLazyLoad. You should always use the ng-app directive or angular.boostrap when you use ocLazyLoad.");var l=function d(n){if(-1===r.indexOf(n)){r.push(n);var o=e.module(n);j(null,o._invokeQueue,n),j(null,o._configBlocks,n),e.forEach(o.requires,d)}};e.forEach(i,function(e){l(e)}),i=[],s.pop()};var S=function(n){try{return JSON.stringify(n)}catch(r){var o=[];return JSON.stringify(n,function(n,r){if(e.isObject(r)&&null!==r){if(-1!==o.indexOf(r))return;o.push(r)}return r})}},M=function(e){var n,r,o,t=0;if(0==e.length)return t;for(n=0,o=e.length;o>n;n++)r=e.charCodeAt(n),t=(t<<5)-t+r,t|=0;return t};this.$get=["$log","$rootElement","$rootScope","$cacheFactory","$q",function(n,t,a,c,d){function f(e){var r=d.defer();return n.error(e.message),r.reject(e),r.promise}var p,m=c("ocLazyLoad");return x||(n={},n.error=e.noop,n.warn=e.noop,n.info=e.noop),O.getInstanceInjector=function(){return p?p:p=t.data("$injector")||e.injector()},u=function(e,r){b&&a.$broadcast(e,r),x&&n.info(e,r)},{_broadcast:u,_$log:n,_getFilesCache:function(){return m},toggleWatch:function(e){e?s.push(!0):s.pop()},getModuleConfig:function(n){if(!e.isString(n))throw new Error("You need to give the name of the module to get");return w[n]?e.copy(w[n]):null},setModuleConfig:function(n){if(!e.isObject(n))throw new Error("You need to give the module config object to set");return w[n.name]=n,n},getModules:function(){return r},isLoaded:function(n){var o=function(e){var n=r.indexOf(e)>-1;return n||(n=!!_(e)),n};if(e.isString(n)&&(n=[n]),e.isArray(n)){var t,i;for(t=0,i=n.length;i>t;t++)if(!o(n[t]))return!1;return!0}throw new Error("You need to define the module(s) name(s)")},_getModuleName:E,_getModule:function(e){try{return g(e)}catch(n){throw(/No module/.test(n)||n.message.indexOf("$injector:nomod")>-1)&&(n.message='The module "'+S(e)+'" that you are trying to load does not exist. '+n.message),n}},moduleExists:_,_loadDependencies:function(n,r){var o,t,i,a=[],s=this;if(n=s._getModuleName(n),null===n)return d.when();try{o=s._getModule(n)}catch(u){return f(u)}return t=s.getRequires(o),e.forEach(t,function(o){if(e.isString(o)){var t=s.getModuleConfig(o);if(null===t)return void z.push(o);o=t,t.name=void 0}if(s.moduleExists(o.name))return i=o.files.filter(function(e){return s.getModuleConfig(o.name).files.indexOf(e)<0}),0!==i.length&&s._$log.warn('Module "',n,'" attempted to redefine configuration for dependency. "',o.name,'"\n Additional Files Loaded:',i),e.isDefined(s.filesLoader)?void a.push(s.filesLoader(o,r).then(function(){return s._loadDependencies(o)})):f(new Error("Error: New dependencies need to be loaded from external files ("+o.files+"), but no loader has been defined."));if(e.isArray(o)){var u=[];e.forEach(o,function(e){var n=s.getModuleConfig(e);null===n?u.push(e):n.files&&(u=u.concat(n.files))}),u.length>0&&(o={files:u})}else e.isObject(o)&&o.hasOwnProperty("name")&&o.name&&(s.setModuleConfig(o),z.push(o.name));if(e.isDefined(o.files)&&0!==o.files.length){if(!e.isDefined(s.filesLoader))return f(new Error('Error: the module "'+o.name+'" is defined in external files ('+o.files+"), but no loader has been defined."));a.push(s.filesLoader(o,r).then(function(){return s._loadDependencies(o)}))}}),d.all(a)},inject:function(n){var r=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],o=arguments.length<=2||void 0===arguments[2]?!1:arguments[2],t=this,a=d.defer();if(e.isDefined(n)&&null!==n){if(e.isArray(n)){var s=[];return e.forEach(n,function(e){s.push(t.inject(e,r,o))}),d.all(s)}t._addToLoadList(t._getModuleName(n),!0,o)}if(i.length>0){var u=i.slice(),c=function f(e){z.push(e),D[e]=a.promise,t._loadDependencies(e,r).then(function(){try{l=[],L(O,z,r)}catch(e){return t._$log.error(e.message),void a.reject(e)}i.length>0?f(i.shift()):a.resolve(u)},function(e){a.reject(e)})};c(i.shift())}else{if(r&&r.name&&D[r.name])return D[r.name];a.resolve()}return a.promise},getRequires:function(n){var o=[];return e.forEach(n.requires,function(e){-1===r.indexOf(e)&&o.push(e)}),o},_invokeQueue:j,_registerInvokeList:$,_register:L,_addToLoadList:h,_unregister:function(n){e.isDefined(n)&&e.isArray(n)&&e.forEach(n,function(e){o[e]=void 0})}}}],this._init(e.element(n.document))}]);var f=e.bootstrap;e.bootstrap=function(n,r,o){return e.forEach(r.slice(),function(e){h(e,!0,!0)}),f(n,r,o)};var h=function(n,r,o){(s.length>0||r)&&e.isString(n)&&-1===i.indexOf(n)&&(i.push(n),o&&a.push(n))},g=e.module;e.module=function(e,n,r){return h(e,!1,!0),g(e,n,r)},"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports===exports&&(module.exports="oc.lazyLoad")}(angular,window),function(e){"use strict";e.module("oc.lazyLoad").directive("ocLazyLoad",["$ocLazyLoad","$compile","$animate","$parse","$timeout",function(n,r,o,t,i){return{restrict:"A",terminal:!0,priority:1e3,compile:function(i,a){var s=i[0].innerHTML;return i.html(""),function(i,a,u){var c=t(u.ocLazyLoad);i.$watch(function(){return c(i)||u.ocLazyLoad},function(t){e.isDefined(t)&&n.load(t).then(function(){o.enter(s,a),r(a.contents())(i)})},!0)}}}}])}(angular),function(e){"use strict";e.module("oc.lazyLoad").config(["$provide",function(n){n.decorator("$ocLazyLoad",["$delegate","$q","$window","$interval",function(n,r,o,t){var i=!1,a=!1,s=o.document.getElementsByTagName("head")[0]||o.document.getElementsByTagName("body")[0];return n.buildElement=function(u,c,l){var d,f,h=r.defer(),g=n._getFilesCache(),p=function(e){var n=(new Date).getTime();return e.indexOf("?")>=0?"&"===e.substring(0,e.length-1)?e+"_dc="+n:e+"&_dc="+n:e+"?_dc="+n};switch(e.isUndefined(g.get(c))&&g.put(c,h.promise),u){case"css":d=o.document.createElement("link"),d.type="text/css",d.rel="stylesheet",d.href=l.cache===!1?p(c):c;break;case"js":d=o.document.createElement("script"),d.src=l.cache===!1?p(c):c;break;default:g.remove(c),h.reject(new Error('Requested type "'+u+'" is not known. Could not inject "'+c+'"'))}d.onload=d.onreadystatechange=function(e){d.readyState&&!/^c|loade/.test(d.readyState)||f||(d.onload=d.onreadystatechange=null,f=1,n._broadcast("ocLazyLoad.fileLoaded",c),h.resolve())},d.onerror=function(){g.remove(c),h.reject(new Error("Unable to load "+c))},d.async=l.serie?0:1;var m=s.lastChild;if(l.insertBefore){var v=e.element(e.isDefined(window.jQuery)?l.insertBefore:document.querySelector(l.insertBefore));v&&v.length>0&&(m=v[0])}if(m.parentNode.insertBefore(d,m),"css"==u){if(!i){var y=o.navigator.userAgent.toLowerCase();if(/iP(hone|od|ad)/.test(o.navigator.platform)){var L=o.navigator.appVersion.match(/OS (\d+)_(\d+)_?(\d+)?/),$=parseFloat([parseInt(L[1],10),parseInt(L[2],10),parseInt(L[3]||0,10)].join("."));a=6>$}else if(y.indexOf("android")>-1){var j=parseFloat(y.slice(y.indexOf("android")+8));a=4.4>j}else if(y.indexOf("safari")>-1){var E=y.match(/version\/([\.\d]+)/i);a=E&&E[1]&&parseFloat(E[1])<6}}if(a)var _=1e3,w=t(function(){try{d.sheet.cssRules,t.cancel(w),d.onload()}catch(e){--_<=0&&d.onerror()}},20)}return h.promise},n}])}])}(angular),function(e){"use strict";e.module("oc.lazyLoad").config(["$provide",function(n){n.decorator("$ocLazyLoad",["$delegate","$q",function(n,r){return n.filesLoader=function(o){var t=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],i=[],a=[],s=[],u=[],c=null,l=n._getFilesCache();n.toggleWatch(!0),e.extend(t,o);var d=function(r){var o,d=null;if(e.isObject(r)&&(d=r.type,r=r.path),c=l.get(r),e.isUndefined(c)||t.cache===!1){if(null!==(o=/^(css|less|html|htm|js)?(?=!)/.exec(r))&&(d=o[1],r=r.substr(o[1].length+1,r.length)),!d)if(null!==(o=/[.](css|less|html|htm|js)?((\?|#).*)?$/.exec(r)))d=o[1];else{if(n.jsLoader.hasOwnProperty("ocLazyLoadLoader")||!n.jsLoader.hasOwnProperty("requirejs"))return void n._$log.error("File type could not be determined. "+r);d="js"}"css"!==d&&"less"!==d||-1!==i.indexOf(r)?"html"!==d&&"htm"!==d||-1!==a.indexOf(r)?"js"===d||-1===s.indexOf(r)?s.push(r):n._$log.error("File type is not valid. "+r):a.push(r):i.push(r)}else c&&u.push(c)};if(t.serie?d(t.files.shift()):e.forEach(t.files,function(e){d(e)}),i.length>0){var f=r.defer();n.cssLoader(i,function(r){e.isDefined(r)&&n.cssLoader.hasOwnProperty("ocLazyLoadLoader")?(n._$log.error(r),f.reject(r)):f.resolve()},t),u.push(f.promise)}if(a.length>0){var h=r.defer();n.templatesLoader(a,function(r){e.isDefined(r)&&n.templatesLoader.hasOwnProperty("ocLazyLoadLoader")?(n._$log.error(r),h.reject(r)):h.resolve()},t),u.push(h.promise)}if(s.length>0){var g=r.defer();n.jsLoader(s,function(r){e.isDefined(r)&&(n.jsLoader.hasOwnProperty("ocLazyLoadLoader")||n.jsLoader.hasOwnProperty("requirejs"))?(n._$log.error(r),g.reject(r)):g.resolve()},t),u.push(g.promise)}if(0===u.length){var p=r.defer(),m="Error: no file to load has been found, if you're trying to load an existing module you should use the 'inject' method instead of 'load'.";return n._$log.error(m),p.reject(m),p.promise}return t.serie&&t.files.length>0?r.all(u).then(function(){return n.filesLoader(o,t)}):r.all(u)["finally"](function(e){return n.toggleWatch(!1),e})},n.load=function(o){var t,i=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],a=this,s=null,u=[],c=r.defer(),l=e.copy(o),d=e.copy(i);if(e.isArray(l))return e.forEach(l,function(e){u.push(a.load(e,d))}),r.all(u).then(function(e){c.resolve(e)},function(e){c.reject(e)}),c.promise;if(e.isString(l)?(s=a.getModuleConfig(l),s||(s={files:[l]})):e.isObject(l)&&(s=e.isDefined(l.path)&&e.isDefined(l.type)?{files:[l]}:a.setModuleConfig(l)),null===s){var f=a._getModuleName(l);return t='Module "'+(f||"unknown")+'" is not configured, cannot load.',n._$log.error(t),c.reject(new Error(t)),c.promise}e.isDefined(s.template)&&(e.isUndefined(s.files)&&(s.files=[]),e.isString(s.template)?s.files.push(s.template):e.isArray(s.template)&&s.files.concat(s.template));var h=e.extend({},d,s);return e.isUndefined(s.files)&&e.isDefined(s.name)&&n.moduleExists(s.name)?n.inject(s.name,h,!0):(n.filesLoader(s,h).then(function(){n.inject(null,h).then(function(e){c.resolve(e)},function(e){c.reject(e)})},function(e){c.reject(e)}),c.promise)},n}])}])}(angular),function(e){"use strict";e.module("oc.lazyLoad").config(["$provide",function(n){n.decorator("$ocLazyLoad",["$delegate","$q",function(n,r){return n.cssLoader=function(o,t,i){var a=[];e.forEach(o,function(e){a.push(n.buildElement("css",e,i))}),r.all(a).then(function(){t()},function(e){t(e)})},n.cssLoader.ocLazyLoadLoader=!0,n}])}])}(angular),function(e){"use strict";e.module("oc.lazyLoad").config(["$provide",function(e){e.decorator("$ocLazyLoad",["$delegate","$q",function(e,n){return e.jsLoader=function(e,n,r){require(e,n.bind(null,void 0),n,r)},e.jsLoader.requirejs=!0,e}])}])}(angular),function(e){"use strict";e.module("oc.lazyLoad").config(["$provide",function(n){n.decorator("$ocLazyLoad",["$delegate","$templateCache","$q","$http",function(n,r,o,t){return n.templatesLoader=function(i,a,s){var u=[],c=n._getFilesCache();return e.forEach(i,function(n){var i=o.defer();u.push(i.promise),t.get(n,s).success(function(o){e.isString(o)&&o.length>0&&e.forEach(e.element(o),function(e){"SCRIPT"===e.nodeName&&"text/ng-template"===e.type&&r.put(e.id,e.innerHTML)}),e.isUndefined(c.get(n))&&c.put(n,!0),i.resolve()}).error(function(e){i.reject(new Error('Unable to load template file "'+n+'": '+e))})}),o.all(u).then(function(){a()},function(e){a(e)})},n.templatesLoader.ocLazyLoadLoader=!0,n}])}])}(angular),Array.prototype.indexOf||(Array.prototype.indexOf=function(e,n){var r;if(null==this)throw new TypeError('"this" is null or not defined');var o=Object(this),t=o.length>>>0;if(0===t)return-1;var i=+n||0;if(Math.abs(i)===1/0&&(i=0),i>=t)return-1;for(r=Math.max(i>=0?i:t-Math.abs(i),0);t>r;){if(r in o&&o[r]===e)return r;r++}return-1}); \ No newline at end of file +!function(e,n){"use strict";var r=["ng","oc.lazyLoad"],t={},o=[],i=[],a=[],s=[],u=e.noop,l={},d=[],c=e.module("oc.lazyLoad",["ng"]);c.provider("$ocLazyLoad",["$controllerProvider","$provide","$compileProvider","$filterProvider","$injector","$animateProvider",function(c,f,p,m,v,y){function L(n,t,o){if(t){var i,s,c,f=[];for(i=t.length-1;i>=0;i--)if(s=t[i],e.isString(s)||(s=_(s)),s&&-1===d.indexOf(s)&&(!w[s]||-1!==a.indexOf(s))){var h=-1===r.indexOf(s);if(c=g(s),h&&(r.push(s),L(n,c.requires,o)),c._runBlocks.length>0)for(l[s]=[];c._runBlocks.length>0;)l[s].push(c._runBlocks.shift());e.isDefined(l[s])&&(h||o.rerun)&&(f=f.concat(l[s])),j(n,c._invokeQueue,s,o.reconfig),j(n,c._configBlocks,s,o.reconfig),u(h?"ocLazyLoad.moduleLoaded":"ocLazyLoad.moduleReloaded",s),t.pop(),d.push(s)}var p=n.getInstanceInjector();e.forEach(f,function(e){p.invoke(e)})}}function $(n,r){function o(n,r){var t,o=!0;return r.length&&(t=i(n),e.forEach(r,function(e){o=o&&i(e)!==t})),o}function i(n){return e.isArray(n)?q(n.toString()):e.isObject(n)?q(M(n)):e.isDefined(n)&&null!==n?q(n.toString()):n}var a=n[2][0],s=n[1],l=!1;e.isUndefined(t[r])&&(t[r]={}),e.isUndefined(t[r][s])&&(t[r][s]={});var d=function(e,n){t[r][s].hasOwnProperty(e)||(t[r][s][e]=[]),o(n,t[r][s][e])&&(l=!0,t[r][s][e].push(n),u("ocLazyLoad.componentLoaded",[r,s,e]))};if(e.isString(a))d(a,n[2][1]);else{if(!e.isObject(a))return!1;e.forEach(a,function(n,r){e.isString(n)?d(n,a[1]):d(r,n)})}return l}function j(n,r,t,i){if(r){var a,s,u,l;for(a=0,s=r.length;s>a;a++)if(u=r[a],e.isArray(u)){if(null!==n){if(!n.hasOwnProperty(u[0]))throw new Error("unsupported provider "+u[0]);l=n[u[0]]}var d=$(u,t);if("invoke"!==u[1])d&&e.isDefined(l)&&l[u[1]].apply(l,u[2]);else{var c=function(n){var r=o.indexOf(t+"-"+n);(-1===r||i)&&(-1===r&&o.push(t+"-"+n),e.isDefined(l)&&l[u[1]].apply(l,u[2]))};if(e.isFunction(u[2][0]))c(u[2][0]);else if(e.isArray(u[2][0]))for(var f=0,h=u[2][0].length;h>f;f++)e.isFunction(u[2][0][f])&&c(u[2][0][f])}}}}function _(n){var r=null;return e.isString(n)?r=n:e.isObject(n)&&n.hasOwnProperty("name")&&e.isString(n.name)&&(r=n.name),r}function E(n){if(!e.isString(n))return!1;try{return g(n)}catch(r){if(/No module/.test(r)||r.message.indexOf("$injector:nomod")>-1)return!1}}var w={},O={$controllerProvider:c,$compileProvider:p,$filterProvider:m,$provide:f,$injector:v,$animateProvider:y},x=!1,b=!1,D=[],z={},S={};D.push=function(e){-1===this.indexOf(e)&&Array.prototype.push.apply(this,arguments)},this.config=function(n){e.isDefined(n.modules)&&(e.isArray(n.modules)?e.forEach(n.modules,function(e){w[e.name]=e}):w[n.modules.name]=n.modules),e.isDefined(n.debug)&&(x=n.debug),e.isDefined(n.events)&&(b=n.events),e.isDefined(n.moduleDefaults)&&(S=n.moduleDefaults)},this._init=function(t){if(0===i.length){var o=[t],a=["ng:app","ng-app","x-ng-app","data-ng-app"],u=/\sng[:\-]app(:\s*([\w\d_]+);?)?\s/,l=function(e){return e&&o.push(e)};e.forEach(a,function(n){a[n]=!0,l(document.getElementById(n)),n=n.replace(":","\\:"),"undefined"!=typeof t[0]&&t[0].querySelectorAll&&(e.forEach(t[0].querySelectorAll("."+n),l),e.forEach(t[0].querySelectorAll("."+n+"\\:"),l),e.forEach(t[0].querySelectorAll("["+n+"]"),l))}),e.forEach(o,function(n){if(0===i.length){var r=" "+t.className+" ",o=u.exec(r);o?i.push((o[2]||"").replace(/\s+/g,",")):e.forEach(n.attributes,function(e){0===i.length&&a[e.name]&&i.push(e.value)})}})}0!==i.length||(n.jasmine||n.mocha)&&e.isDefined(e.mock)||console.error("No module found during bootstrap, unable to init ocLazyLoad. You should always use the ng-app directive or angular.boostrap when you use ocLazyLoad.");var d=function c(n){if(-1===r.indexOf(n)){r.push(n);var t=e.module(n);j(null,t._invokeQueue,n),j(null,t._configBlocks,n),e.forEach(t.requires,c)}};e.forEach(i,function(e){d(e)}),i=[],s.pop()};var M=function(n){try{return JSON.stringify(n)}catch(r){var t=[];return JSON.stringify(n,function(n,r){if(e.isObject(r)&&null!==r){if(-1!==t.indexOf(r))return;t.push(r)}return r})}},q=function(e){var n,r,t,o=0;if(0==e.length)return o;for(n=0,t=e.length;t>n;n++)r=e.charCodeAt(n),o=(o<<5)-o+r,o|=0;return o};this.$get=["$log","$rootElement","$rootScope","$cacheFactory","$q",function(n,o,a,l,c){function f(e){var r=c.defer();return n.error(e.message),r.reject(e),r.promise}var p,m=l("ocLazyLoad");return x||(n={},n.error=e.noop,n.warn=e.noop,n.info=e.noop),O.getInstanceInjector=function(){return p?p:p=o.data("$injector")||e.injector()},u=function(e,r){b&&a.$broadcast(e,r),x&&n.info(e,r)},{_broadcast:u,_$log:n,_getModuleDefaults:function(){return S},_getFilesCache:function(){return m},toggleWatch:function(e){e?s.push(!0):s.pop()},getModuleConfig:function(n){if(!e.isString(n))throw new Error("You need to give the name of the module to get");return w[n]?e.copy(w[n]):null},setModuleConfig:function(n){if(!e.isObject(n))throw new Error("You need to give the module config object to set");return w[n.name]=n,n},getModules:function(){return r},isLoaded:function(n){var t=function(e){var n=r.indexOf(e)>-1;return n||(n=!!E(e)),n};if(e.isString(n)&&(n=[n]),e.isArray(n)){var o,i;for(o=0,i=n.length;i>o;o++)if(!t(n[o]))return!1;return!0}throw new Error("You need to define the module(s) name(s)")},_getModuleName:_,_getModule:function(e){try{return g(e)}catch(n){throw(/No module/.test(n)||n.message.indexOf("$injector:nomod")>-1)&&(n.message='The module "'+M(e)+'" that you are trying to load does not exist. '+n.message),n}},moduleExists:E,_loadDependencies:function(n,r){var t,o,i,a=[],s=this;if(n=s._getModuleName(n),null===n)return c.when();try{t=s._getModule(n)}catch(u){return f(u)}return o=s.getRequires(t),e.forEach(o,function(t){if(e.isString(t)){var o=s.getModuleConfig(t);if(null===o)return void D.push(t);t=o,o.name=void 0}if(s.moduleExists(t.name))return i=t.files.filter(function(e){return s.getModuleConfig(t.name).files.indexOf(e)<0}),0!==i.length&&s._$log.warn('Module "',n,'" attempted to redefine configuration for dependency. "',t.name,'"\n Additional Files Loaded:',i),e.isDefined(s.filesLoader)?void a.push(s.filesLoader(t,r).then(function(){return s._loadDependencies(t)})):f(new Error("Error: New dependencies need to be loaded from external files ("+t.files+"), but no loader has been defined."));if(e.isArray(t)){var u=[];e.forEach(t,function(e){var n=s.getModuleConfig(e);null===n?u.push(e):n.files&&(u=u.concat(n.files))}),u.length>0&&(t={files:u})}else e.isObject(t)&&t.hasOwnProperty("name")&&t.name&&(s.setModuleConfig(t),D.push(t.name));if(e.isDefined(t.files)&&0!==t.files.length){if(!e.isDefined(s.filesLoader))return f(new Error('Error: the module "'+t.name+'" is defined in external files ('+t.files+"), but no loader has been defined."));a.push(s.filesLoader(t,r).then(function(){return s._loadDependencies(t)}))}}),c.all(a)},inject:function(n){var r=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],t=arguments.length<=2||void 0===arguments[2]?!1:arguments[2],o=this,a=c.defer();if(e.isDefined(n)&&null!==n){if(e.isArray(n)){var s=[];return e.forEach(n,function(e){s.push(o.inject(e,r,t))}),c.all(s)}o._addToLoadList(o._getModuleName(n),!0,t)}if(i.length>0){var u=i.slice(),l=function f(e){D.push(e),z[e]=a.promise,o._loadDependencies(e,r).then(function(){try{d=[],L(O,D,r)}catch(e){return o._$log.error(e.message),void a.reject(e)}i.length>0?f(i.shift()):a.resolve(u)},function(e){a.reject(e)})};l(i.shift())}else{if(r&&r.name&&z[r.name])return z[r.name];a.resolve()}return a.promise},getRequires:function(n){var t=[];return e.forEach(n.requires,function(e){-1===r.indexOf(e)&&t.push(e)}),t},_invokeQueue:j,_registerInvokeList:$,_register:L,_addToLoadList:h,_unregister:function(n){e.isDefined(n)&&e.isArray(n)&&e.forEach(n,function(e){t[e]=void 0})}}}],this._init(e.element(n.document))}]);var f=e.bootstrap;e.bootstrap=function(n,r,t){return e.forEach(r.slice(),function(e){h(e,!0,!0)}),f(n,r,t)};var h=function(n,r,t){(s.length>0||r)&&e.isString(n)&&-1===i.indexOf(n)&&(i.push(n),t&&a.push(n))},g=e.module;e.module=function(e,n,r){return h(e,!1,!0),g(e,n,r)},"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports===exports&&(module.exports="oc.lazyLoad")}(angular,window),function(e){"use strict";e.module("oc.lazyLoad").directive("ocLazyLoad",["$ocLazyLoad","$compile","$animate","$parse","$timeout",function(n,r,t,o,i){return{restrict:"A",terminal:!0,priority:1e3,compile:function(i,a){var s=i[0].innerHTML;return i.html(""),function(i,a,u){var l=o(u.ocLazyLoad);i.$watch(function(){return l(i)||u.ocLazyLoad},function(o){e.isDefined(o)&&n.load(o).then(function(){t.enter(s,a),r(a.contents())(i)})},!0)}}}}])}(angular),function(e){"use strict";e.module("oc.lazyLoad").config(["$provide",function(n){n.decorator("$ocLazyLoad",["$delegate","$q","$window","$interval",function(n,r,t,o){var i=!1,a=!1,s=t.document.getElementsByTagName("head")[0]||t.document.getElementsByTagName("body")[0];return n.buildElement=function(u,l,d){var c,f,h=r.defer(),g=n._getFilesCache(),p=function(e){var n=(new Date).getTime();return e.indexOf("?")>=0?"&"===e.substring(0,e.length-1)?e+"_dc="+n:e+"&_dc="+n:e+"?_dc="+n};switch(e.isUndefined(g.get(l))&&g.put(l,h.promise),u){case"css":c=t.document.createElement("link"),c.type="text/css",c.rel="stylesheet",c.href=d.cache===!1?p(l):l;break;case"js":c=t.document.createElement("script"),c.src=d.cache===!1?p(l):l;break;default:g.remove(l),h.reject(new Error('Requested type "'+u+'" is not known. Could not inject "'+l+'"'))}c.onload=c.onreadystatechange=function(e){c.readyState&&!/^c|loade/.test(c.readyState)||f||(c.onload=c.onreadystatechange=null,f=1,n._broadcast("ocLazyLoad.fileLoaded",l),h.resolve())},c.onerror=function(){g.remove(l),h.reject(new Error("Unable to load "+l))},c.async=d.serie?0:1;var m=s.lastChild;if(d.insertBefore){var v=e.element(e.isDefined(window.jQuery)?d.insertBefore:document.querySelector(d.insertBefore));v&&v.length>0&&(m=v[0])}if(m.parentNode.insertBefore(c,m),"css"==u){if(!i){var y=t.navigator.userAgent.toLowerCase();if(y.indexOf("phantomjs/1.9")>-1)a=!0;else if(/iP(hone|od|ad)/.test(t.navigator.platform)){var L=t.navigator.appVersion.match(/OS (\d+)_(\d+)_?(\d+)?/),$=parseFloat([parseInt(L[1],10),parseInt(L[2],10),parseInt(L[3]||0,10)].join("."));a=6>$}else if(y.indexOf("android")>-1){var j=parseFloat(y.slice(y.indexOf("android")+8));a=4.4>j}else if(y.indexOf("safari")>-1){var _=y.match(/version\/([\.\d]+)/i);a=_&&_[1]&&parseFloat(_[1])<6}}if(a)var E=1e3,w=o(function(){try{c.sheet.cssRules,o.cancel(w),c.onload()}catch(e){--E<=0&&c.onerror()}},20)}return h.promise},n}])}])}(angular),function(e){"use strict";e.module("oc.lazyLoad").config(["$provide",function(n){n.decorator("$ocLazyLoad",["$delegate","$q",function(n,r){return n.filesLoader=function(t){var o=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],i=[],a=[],s=[],u=[],l=null,d=n._getFilesCache();n.toggleWatch(!0),o=e.extend({},n._getModuleDefaults(),o,t);var c=function(r){var t,c=null;if(e.isObject(r)&&(c=r.type,r=r.path),l=d.get(r),e.isUndefined(l)||o.cache===!1){if(null!==(t=/^(css|less|html|htm|js)?(?=!)/.exec(r))&&(c=t[1],r=r.substr(t[1].length+1,r.length)),!c)if(null!==(t=/[.](css|less|html|htm|js)?((\?|#).*)?$/.exec(r)))c=t[1];else{if(n.jsLoader.hasOwnProperty("ocLazyLoadLoader")||!n.jsLoader.hasOwnProperty("requirejs"))return void n._$log.error("File type could not be determined. "+r);c="js"}"css"!==c&&"less"!==c||-1!==i.indexOf(r)?"html"!==c&&"htm"!==c||-1!==a.indexOf(r)?"js"===c||-1===s.indexOf(r)?s.push(r):n._$log.error("File type is not valid. "+r):a.push(r):i.push(r)}else l&&u.push(l)};if(o.serie?c(o.files.shift()):e.forEach(o.files,function(e){c(e)}),i.length>0){var f=r.defer();n.cssLoader(i,function(r){e.isDefined(r)&&n.cssLoader.hasOwnProperty("ocLazyLoadLoader")?(n._$log.error(r),f.reject(r)):f.resolve()},o),u.push(f.promise)}if(a.length>0){var h=r.defer();n.templatesLoader(a,function(r){e.isDefined(r)&&n.templatesLoader.hasOwnProperty("ocLazyLoadLoader")?(n._$log.error(r),h.reject(r)):h.resolve()},o),u.push(h.promise)}if(s.length>0){var g=r.defer();n.jsLoader(s,function(r){e.isDefined(r)&&(n.jsLoader.hasOwnProperty("ocLazyLoadLoader")||n.jsLoader.hasOwnProperty("requirejs"))?(n._$log.error(r),g.reject(r)):g.resolve()},o),u.push(g.promise)}if(0===u.length){var p=r.defer(),m="Error: no file to load has been found, if you're trying to load an existing module you should use the 'inject' method instead of 'load'.";return n._$log.error(m),p.reject(m),p.promise}return o.serie&&o.files.length>0?r.all(u).then(function(){return n.filesLoader(t,o)}):r.all(u)["finally"](function(e){return n.toggleWatch(!1),e})},n.load=function(t){var o,i=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],a=this,s=null,u=[],l=r.defer(),d=e.copy(t),c=e.copy(i);if(e.isArray(d))return e.forEach(d,function(e){u.push(a.load(e,c))}),r.all(u).then(function(e){l.resolve(e)},function(e){l.reject(e)}),l.promise;if(e.isString(d)?(s=a.getModuleConfig(d),s||(s={files:[d]})):e.isObject(d)&&(s=e.isDefined(d.path)&&e.isDefined(d.type)?{files:[d]}:a.setModuleConfig(d)),null===s){var f=a._getModuleName(d);return o='Module "'+(f||"unknown")+'" is not configured, cannot load.',n._$log.error(o),l.reject(new Error(o)),l.promise}e.isDefined(s.template)&&(e.isUndefined(s.files)&&(s.files=[]),e.isString(s.template)?s.files.push(s.template):e.isArray(s.template)&&s.files.concat(s.template));var h=e.extend({},c,s);return e.isUndefined(s.files)&&e.isDefined(s.name)&&n.moduleExists(s.name)?n.inject(s.name,h,!0):(n.filesLoader(s,h).then(function(){n.inject(null,h).then(function(e){l.resolve(e)},function(e){l.reject(e)})},function(e){l.reject(e)}),l.promise)},n}])}])}(angular),function(e){"use strict";e.module("oc.lazyLoad").config(["$provide",function(n){n.decorator("$ocLazyLoad",["$delegate","$q",function(n,r){return n.cssLoader=function(t,o,i){var a=[];e.forEach(t,function(e){a.push(n.buildElement("css",e,i))}),r.all(a).then(function(){o()},function(e){o(e)})},n.cssLoader.ocLazyLoadLoader=!0,n}])}])}(angular),function(e){"use strict";e.module("oc.lazyLoad").config(["$provide",function(e){e.decorator("$ocLazyLoad",["$delegate","$q",function(e,n){return e.jsLoader=function(e,n,r){require(e,n.bind(null,void 0),n,r)},e.jsLoader.requirejs=!0,e}])}])}(angular),function(e){"use strict";e.module("oc.lazyLoad").config(["$provide",function(n){n.decorator("$ocLazyLoad",["$delegate","$templateCache","$q","$http",function(n,r,t,o){return n.templatesLoader=function(i,a,s){var u=[],l=n._getFilesCache();return s=e.extend({},n._getModuleDefaults(),s),e.forEach(i,function(n){var i=t.defer();u.push(i.promise),o.get(n,s).success(function(t){e.isString(t)&&t.length>0&&e.forEach(e.element(t),function(e){"SCRIPT"===e.nodeName&&"text/ng-template"===e.type&&r.put(e.id,e.innerHTML)}),e.isUndefined(l.get(n))&&l.put(n,!0),i.resolve()}).error(function(e){i.reject(new Error('Unable to load template file "'+n+'": '+e))})}),t.all(u).then(function(){a()},function(e){a(e)})},n.templatesLoader.ocLazyLoadLoader=!0,n}])}])}(angular),Array.prototype.indexOf||(Array.prototype.indexOf=function(e,n){var r;if(null==this)throw new TypeError('"this" is null or not defined');var t=Object(this),o=t.length>>>0;if(0===o)return-1;var i=+n||0;if(Math.abs(i)===1/0&&(i=0),i>=o)return-1;for(r=Math.max(i>=0?i:o-Math.abs(i),0);o>r;){if(r in t&&t[r]===e)return r;r++}return-1}); \ No newline at end of file diff --git a/src/ocLazyLoad.core.js b/src/ocLazyLoad.core.js index 63f34a6..41d0daf 100644 --- a/src/ocLazyLoad.core.js +++ b/src/ocLazyLoad.core.js @@ -26,7 +26,8 @@ debug = false, events = false, moduleCache = [], - modulePromises = {}; + modulePromises = {}, + moduleDefaults = {}; moduleCache.push = function(value) { if(this.indexOf(value) === -1) { @@ -53,6 +54,10 @@ if(angular.isDefined(config.events)) { events = config.events; } + + if(angular.isDefined(config.moduleDefaults)) { + moduleDefaults = config.moduleDefaults; + } }; /** @@ -371,6 +376,15 @@ _$log: $log, + /** + * Returns module configuration defaults + * @returns {object} + * @private + */ + _getModuleDefaults: function getModuleDefaults() { + return moduleDefaults; + }, + /** * Returns the files cache used by the loaders to store the files currently loading * @returns {*} diff --git a/src/ocLazyLoad.loaders.core.js b/src/ocLazyLoad.loaders.core.js index f98c2aa..adce855 100644 --- a/src/ocLazyLoad.loaders.core.js +++ b/src/ocLazyLoad.loaders.core.js @@ -19,7 +19,7 @@ $delegate.toggleWatch(true); // start watching angular.module calls - angular.extend(params, config); + params = angular.extend({}, $delegate._getModuleDefaults(), params, config); var pushFile = function(path) { var file_type = null, m; diff --git a/src/ocLazyLoad.loaders.templatesLoader.js b/src/ocLazyLoad.loaders.templatesLoader.js index fa23f57..55cdb37 100644 --- a/src/ocLazyLoad.loaders.templatesLoader.js +++ b/src/ocLazyLoad.loaders.templatesLoader.js @@ -15,6 +15,8 @@ var promises = [], filesCache = $delegate._getFilesCache(); + params = angular.extend({}, $delegate._getModuleDefaults(), params); + angular.forEach(paths, url => { var deferred = $q.defer(); promises.push(deferred.promise);