Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option to define a global default configuration #335

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion dist/modules/ocLazyLoad.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
debug = false,
events = false,
moduleCache = [],
modulePromises = {};
modulePromises = {},
moduleDefaults = {};

moduleCache.push = function (value) {
if (this.indexOf(value) === -1) {
Expand All @@ -55,6 +56,10 @@
if (angular.isDefined(config.events)) {
events = config.events;
}

if (angular.isDefined(config.moduleDefaults)) {
moduleDefaults = config.moduleDefaults;
}
};

/**
Expand Down Expand Up @@ -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 {*}
Expand Down
13 changes: 9 additions & 4 deletions dist/modules/ocLazyLoad.loaders.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion dist/modules/ocLazyLoad.loaders.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions dist/modules/ocLazyLoad.loaders.templatesLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
33 changes: 27 additions & 6 deletions dist/ocLazyLoad.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
debug = false,
events = false,
moduleCache = [],
modulePromises = {};
modulePromises = {},
moduleDefaults = {};

moduleCache.push = function (value) {
if (this.indexOf(value) === -1) {
Expand All @@ -62,6 +63,10 @@
if (angular.isDefined(config.events)) {
events = config.events;
}

if (angular.isDefined(config.moduleDefaults)) {
moduleDefaults = config.moduleDefaults;
}
};

/**
Expand Down Expand Up @@ -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 {*}
Expand Down Expand Up @@ -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)
Expand All @@ -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;
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down
Loading