'use strict';
(function (angular) {
'use strict';
angular.module('oc.lazyLoad').config(function ($provide) {
$provide.decorator('$ocLazyLoad', function ($delegate, $q, $window, $interval) {
var uaCssChecked = false,
useCssLoadPatch = false,
anchor = $window.document.getElementsByTagName('head')[0] || $window.document.getElementsByTagName('body')[0];
/**
* Load a js/css file
* @param type
* @param path
* @param params
* @returns promise
*/
$delegate.buildElement = function buildElement(type, path, params) {
var deferred = $q.defer(),
el,
loaded,
filesCache = $delegate._getFilesCache(),
cacheBuster = function cacheBuster(url) {
var dc = new Date().getTime();
Iif (url.indexOf('?') >= 0) {
if (url.substring(0, url.length - 1) === '&') {
return url + '_dc=' + dc;
}
return url + '&_dc=' + dc;
} else {
return url + '?_dc=' + dc;
}
};
// Store the promise early so the file load can be detected by other parallel lazy loads
// (ie: multiple routes on one page) a 'true' value isn't sufficient
// as it causes false positive load results.
Eif (angular.isUndefined(filesCache.get(path))) {
filesCache.put(path, deferred.promise);
}
// Switch in case more content types are added later
switch (type) {
case 'css':
el = $window.document.createElement('link');
el.type = 'text/css';
el.rel = 'stylesheet';
el.href = params.cache === false ? cacheBuster(path) : path;
break;
case 'js':
el = $window.document.createElement('script');
el.src = params.cache === false ? cacheBuster(path) : path;
break;
default:
filesCache.remove(path);
deferred.reject(new Error('Requested type "' + type + '" is not known. Could not inject "' + path + '"'));
break;
}
el.onload = el['onreadystatechange'] = function (e) {
Iif (el['readyState'] && !/^c|loade/.test(el['readyState']) || loaded) return;
el.onload = el['onreadystatechange'] = null;
loaded = 1;
$delegate._broadcast('ocLazyLoad.fileLoaded', path);
deferred.resolve(el);
};
el.onerror = function () {
filesCache.remove(path);
deferred.reject(new Error('Unable to load ' + path));
};
el.async = params.serie ? 0 : 1;
var insertBeforeElem = anchor.lastChild;
if (params.insertBefore) {
var element = angular.element(angular.isDefined(window.jQuery) ? params.insertBefore : document.querySelector(params.insertBefore));
Eif (element && element.length > 0) {
insertBeforeElem = element[0];
}
}
insertBeforeElem.parentNode.insertBefore(el, insertBeforeElem);
/*
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)
*/
if (type == 'css') {
Eif (!uaCssChecked) {
var ua = $window.navigator.userAgent.toLowerCase();
Iif (ua.indexOf('phantomjs/1.9') > -1) {
// PhantomJS ~1.9
useCssLoadPatch = true;
} else Iif (/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 Iif (ua.indexOf('android') > -1) {
// Android < 4.4
var androidVersion = parseFloat(ua.slice(ua.indexOf('android') + 8));
useCssLoadPatch = androidVersion < 4.4;
} else Iif (ua.indexOf('safari') > -1) {
// Safari < 6
var versionMatch = ua.match(/version\/([\.\d]+)/i);
useCssLoadPatch = versionMatch && versionMatch[1] && parseFloat(versionMatch[1]) < 6;
}
}
Iif (useCssLoadPatch) {
var tries = 1000; // * 20 = 20000 miliseconds
var interval = $interval(function () {
try {
el.sheet.cssRules;
$interval.cancel(interval);
el.onload();
} catch (e) {
if (--tries <= 0) {
el.onerror();
}
}
}, 20);
}
}
return deferred.promise;
};
return $delegate;
});
});
})(angular);
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIkM6L3d3dy9vY0xhenlMb2FkL3NyYy9vY0xhenlMb2FkLmxvYWRlcnMuY29tbW9uLmpzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQUEsQ0FBQyxVQUFBLE9BQU8sRUFBSTtBQUNSLGdCQUFZLENBQUM7O0FBRWIsV0FBTyxDQUFDLE1BQU0sQ0FBQyxhQUFhLENBQUMsQ0FBQyxNQUFNLENBQUMsVUFBQSxRQUFRLEVBQUk7QUFDN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gICAgICAgKiBMb2FkIGEganMvY3NzIGZpbGVcclxuICAgICAgICAgICAgICogQHBhcmFtIHR5cGVcclxuICAgICAgICAgICAgICogQHBhcmFtIHBhdGhcclxuICAgICAgICAgICAgICogQHBhcmFtIHBhcmFtc1xyXG4gICAgICAgICAgICAgKiBAcmV0dXJucyBwcm9taXNlXHJcbiAgICAgICAgICAgICAqL1xyXG4gICAgICAgICAgICAkZGVsZWdhdGUuYnVpbGRFbGVtZW50ID0gZnVuY3Rpb24gYnVpbGRFbGVtZW50KHR5cGUsIHBhdGgsIHBhcmFtcykge1xyXG4gICAgICAgICAgICAgICAgdmFyIGRlZmVycmVkID0gJHEuZGVmZXIoKSxcclxuICAgICAgICAgICAgICAgICAgICBlbCxcclxuICAgICAgICAgICAgICAgICAgICBsb2FkZWQsXHJcbiAgICAgICAgICAgICAgICAgICAgZmlsZXNDYWNoZSA9ICRkZWxlZ2F0ZS5fZ2V0RmlsZXNDYWNoZSgpLFxyXG4gICAgICAgICAgICAgICAgICAgIGNhY2hlQnVzdGVyID0gZnVuY3Rpb24gY2FjaGVCdXN0ZXIodXJsKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIHZhciBkYyA9IG5ldyBEYXRlKCkuZ2V0VGltZSgpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBpZih1cmwuaW5kZXhPZignPycpID49IDApIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmKHVybC5zdWJzdHJpbmcoMCwgdXJsLmxlbmd0aCAtIDEpID09PSAnJicpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICByZXR1cm4gYCR7IHVybCB9X2RjPSR7IGRjIH1gO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIGAkeyB1cmwgfSZfZGM9JHsgZGMgfWA7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICByZXR1cm4gYCR7IHVybCB9P19kYz0keyBkYyB9YDtcclxuICAgICAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgIH07XHJcblxyXG4gICAgICAgICAgICAgICAgLy8gU3RvcmUgdGhlIHByb21pc2UgZWFybHkgc28gdGhlIGZpbGUgbG9hZCBjYW4gYmUgZGV0ZWN0ZWQgYnkgb3RoZXIgcGFyYWxsZWwgbGF6eSBsb2Fkc1xyXG4gICAgICAgICAgICAgICAgLy8gKGllOiBtdWx0aXBsZSByb3V0ZXMgb24gb25lIHBhZ2UpIGEgJ3RydWUnIHZhbHVlIGlzbid0IHN1ZmZpY2llbnRcclxuICAgICAgICAgICAgICAgIC8vIGFzIGl0IGNhdXNlcyBmYWxzZSBwb3NpdGl2ZSBsb2FkIHJlc3VsdHMuXHJcbiAgICAgICAgICAgICAgICBpZihhbmd1bGFyLmlzVW5kZWZpbmVkKGZpbGVzQ2FjaGUuZ2V0KHBhdGgpKSkge1xyXG4gICAgICAgICAgICAgICAgICAgIGZpbGVzQ2FjaGUucHV0KHBhdGgsIGRlZmVycmVkLnByb21pc2UpO1xyXG4gICAgICAgICAgICAgICAgfVxyXG5cclxuICAgICAgICAgICAgICAgIC8vIFN3aXRjaCBpbiBjYXNlIG1vcmUgY29udGVudCB0eXBlcyBhcmUgYWRkZWQgbGF0ZXJcclxuICAgICAgICAgICAgICAgIHN3aXRjaCh0eXBlKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgY2FzZSAnY3NzJzpcclxuICAgICAgICAgICAgICAgICAgICAgICAgZWwgPSAkd2luZG93LmRvY3VtZW50LmNyZWF0ZUVsZW1lbnQoJ2xpbmsnKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgZWwudHlwZSA9ICd0ZXh0L2Nzcyc7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGVsLnJlbCA9ICdzdHlsZXNoZWV0JztcclxuICAgICAgICAgICAgICAgICAgICAgICAgZWwuaHJlZiA9IHBhcmFtcy5jYWNoZSA9PT0gZmFsc2UgPyBjYWNoZUJ1c3RlcihwYXRoKSA6IHBhdGg7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrO1xyXG4gICAgICAgICAgICAgICAgICAgIGNhc2UgJ2pzJzpcclxuICAgICAgICAgICAgICAgICAgICAgICAgZWwgPSAkd2luZG93LmRvY3VtZW50LmNyZWF0ZUVsZW1lbnQoJ3NjcmlwdCcpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBlbC5zcmMgPSBwYXJhbXMuY2FjaGUgPT09IGZhbHNlID8gY2FjaGVCdXN0ZXIocGF0aCkgOiBwYXRoO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBicmVhaztcclxuICAgICAgICAgICAgICAgICAgICBkZWZhdWx0OlxyXG4gICAgICAgICAgICAgICAgICAgICAgICBmaWxlc0NhY2hlLnJlbW92ZShwYXRoKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgZGVmZXJyZWQucmVqZWN0KG5ldyBFcnJvcihgUmVxdWVzdGVkIHR5cGUgXCIkeyB0eXBlIH1cIiBpcyBub3Qga25vd24uIENvdWxkIG5vdCBpbmplY3QgXCIkeyBwYXRoIH1cImApKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWs7XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICBlbC5vbmxvYWQgPSBlbFsnb25yZWFkeXN0YXRlY2hhbmdlJ10gPSBmdW5jdGlvbihlKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgaWYoKGVsWydyZWFkeVN0YXRlJ10gJiYgIS9eY3xsb2FkZS8udGVzdChlbFsncmVhZHlTdGF0ZSddKSkgfHwgbG9hZGVkKSByZXR1cm47XHJcbiAgICAgICAgICAgICAgICAgICAgZWwub25sb2FkID0gZWxbJ29ucmVhZHlzdGF0ZWNoYW5nZSddID0gbnVsbDtcclxuICAgICAgICAgICAgICAgICAgICBsb2FkZWQgPSAxO1xyXG4gICAgICAgICAgICAgICAgICAgICRkZWxlZ2F0ZS5fYnJvYWRjYXN0KCdvY0xhenlMb2FkLmZpbGVMb2FkZWQnLCBwYXRoKTtcclxuICAgICAgICAgICAgICAgICAgICBkZWZlcnJlZC5yZXNvbHZlKGVsKTtcclxuICAgICAgICAgICAgICAgIH07XHJcbiAgICAgICAgICAgICAgICBlbC5vbmVycm9yID0gZnVuY3Rpb24oKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgZmlsZXNDYWNoZS5yZW1vdmUocGF0aCk7XHJcbiAgICAgICAgICAgICAgICAgICAgZGVmZXJyZWQucmVqZWN0KG5ldyBFcnJvcihgVW5hYmxlIHRvIGxvYWQgJHsgcGF0aCB9YCkpO1xyXG4gICAgICAgICAgICAgICAgfTtcclxuICAgICAgICAgICAgICAgIGVsLmFzeW5jID0gcGFyYW1zLnNlcmllID8gMCA6IDE7XHJcblxyXG4gICAgICAgICAgICAgICAgdmFyIGluc2VydEJlZm9yZUVsZW0gPSBhbmNob3IubGFzdENoaWxkO1xyXG4gICAgICAgICAgICAgICAgaWYocGFyYW1zLmluc2VydEJlZm9yZSkge1xyXG4gICAgICAgICAgICAgICAgICAgIHZhciBlbGVtZW50ID0gYW5ndWxhci5lbGVtZW50KGFuZ3VsYXIuaXNEZWZpbmVkKHdpbmRvdy5qUXVlcnkpID8gcGFyYW1zLmluc2VydEJlZm9yZSA6IGRvY3VtZW50LnF1ZXJ5U2VsZWN0b3IocGFyYW1zLmluc2VydEJlZm9yZSkpO1xyXG4gICAgICAgICAgICAgICAgICAgIGlmKGVsZW1lbnQgJiYgZWxlbWVudC5sZW5ndGggPiAwKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGluc2VydEJlZm9yZUVsZW0gPSBlbGVtZW50WzBdO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIGluc2VydEJlZm9yZUVsZW0ucGFyZW50Tm9kZS5pbnNlcnRCZWZvcmUoZWwsIGluc2VydEJlZm9yZUVsZW0pO1xyXG5cclxuICAgICAgICAgICAgICAgIC8qXHJcbiAgICAgICAgICAgICAgICAgVGhlIGV2ZW50IGxvYWQgb3IgcmVhZHlzdGF0ZWNoYW5nZSBkb2Vzbid0IGZpcmUgaW46XHJcbiAgICAgICAgICAgICAgICAgLSBQaGFudG9tSlMgMS45IChoZWFkbGVzcyB3ZWJraXQgYnJvd3NlcilcclxuICAgICAgICAgICAgICAgICAtIGlPUyA8IDYgICAgICAgKGRlZmF1bHQgbW9iaWxlIGJyb3dzZXIpXHJcbiAgICAgICAgICAgICAgICAgLSBBbmRyb2lkIDwgNC40IChkZWZhdWx0IG1vYmlsZSBicm93c2VyKVxyXG4gICAgICAgICAgICAgICAgIC0gU2FmYXJpIDwgNiAgICAoZGVza3RvcCBicm93c2VyKVxyXG4gICAgICAgICAgICAgICAgICovXHJcbiAgICAgICAgICAgICAgICBpZih0eXBlID09ICdjc3MnKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgaWYoIXVhQ3NzQ2hlY2tlZCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB2YXIgdWEgPSAkd2luZG93Lm5hdmlnYXRvci51c2VyQWdlbnQudG9Mb3dlckNhc2UoKTtcclxuXHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmICh1YS5pbmRleE9mKCdwaGFudG9tanMvMS45JykgPiAtMSkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgLy8gUGhhbnRvbUpTIH4xLjlcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHVzZUNzc0xvYWRQYXRjaCA9IHRydWU7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAoL2lQKGhvbmV8b2R8YWQpLy50ZXN0KCR3aW5kb3cubmF2aWdhdG9yLnBsYXRmb3JtKSkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgLy8gaU9TIDwgNlxyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgdmFyIHYgPSAkd2luZG93Lm5hdmlnYXRvci5hcHBWZXJzaW9uLm1hdGNoKC9PUyAoXFxkKylfKFxcZCspXz8oXFxkKyk/Lyk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB2YXIgaU9TVmVyc2lvbiA9IHBhcnNlRmxvYXQoW3BhcnNlSW50KHZbMV0sIDEwKSwgcGFyc2VJbnQodlsyXSwgMTApLCBwYXJzZUludCh2WzNdIHx8IDAsIDEwKV0uam9pbignLicpKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHVzZUNzc0xvYWRQYXRjaCA9IGlPU1ZlcnNpb24gPCA2O1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKHVhLmluZGV4T2YoJ2FuZHJvaWQnKSA+IC0xKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAvLyBBbmRyb2lkIDwgNC40XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB2YXIgYW5kcm9pZFZlcnNpb24gPSBwYXJzZUZsb2F0KHVhLnNsaWNlKHVhLmluZGV4T2YoJ2FuZHJvaWQnKSArIDgpKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHVzZUNzc0xvYWRQYXRjaCA9IGFuZHJvaWRWZXJzaW9uIDwgNC40O1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKHVhLmluZGV4T2YoJ3NhZmFyaScpID4gLTEpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIC8vIFNhZmFyaSA8IDZcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHZhciB2ZXJzaW9uTWF0Y2ggPSB1YS5tYXRjaCgvdmVyc2lvblxcLyhbXFwuXFxkXSspL2kpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgdXNlQ3NzTG9hZFBhdGNoID0gKHZlcnNpb25NYXRjaCAmJiB2ZXJzaW9uTWF0Y2hbMV0gJiYgcGFyc2VGbG9hdCh2ZXJzaW9uTWF0Y2hbMV0pIDwgNik7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICB9XHJcblxyXG4gICAgICAgICAgICAgICAgICAgIGlmKHVzZUNzc0xvYWRQYXRjaCkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB2YXIgdHJpZXMgPSAxMDAwOyAvLyAqIDIwID0gMjAwMDAgbWlsaXNlY29uZHNcclxuICAgICAgICAgICAgICAgICAgICAgICAgdmFyIGludGVydmFsID0gJGludGVydmFsKCgpID0+IHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIHRyeSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZWwuc2hlZXQuY3NzUnVsZXM7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgJGludGVydmFsLmNhbmNlbChpbnRlcnZhbCk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZWwub25sb2FkKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGNhdGNoKGUpIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZigtLXRyaWVzIDw9IDApIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZWwub25lcnJvcigpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICAgICAgfSwgMjApO1xyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIH1cclxuXHJcbiAgICAgICAgICAgICAgICByZXR1cm4gZGVmZXJyZWQucHJvbWlzZTtcclxuICAgICAgICAgICAgfTtcclxuXHJcbiAgICAgICAgICAgIHJldHVybiAkZGVsZWdhdGU7XHJcbiAgICAgICAgfSlcclxuICAgIH0pO1xyXG5cclxufSkoYW5ndWxhcik7XHJcbiJdfQ== |