Code coverage report for ./src/ocLazyLoad.loaders.templatesLoader.js

Statements: 100% (23 / 23)      Branches: 70% (7 / 10)      Functions: 100% (10 / 10)      Lines: 100% (23 / 23)      Ignored: none     

All files » ./src/ » ocLazyLoad.loaders.templatesLoader.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52    1     1 29                 28 4     4 4 4 4 3 3 3 3 3       3 3   3   1     4 3   1     28   28        
'use strict';
 
(function (angular) {
    'use strict';
 
    angular.module('oc.lazyLoad').config(function ($provide) {
        $provide.decorator('$ocLazyLoad', function ($delegate, $templateCache, $q, $http) {
            /**
             * templatesLoader function
             * @type Function
             * @param paths array list of css files to load
             * @param callback to call when everything is loaded. We use a callback and not a promise
             * @param params object config parameters for $http
             * because the user can overwrite templatesLoader and it will probably not use promises :(
             */
            $delegate.templatesLoader = function (paths, callback, params) {
                var promises = [],
                    filesCache = $delegate._getFilesCache();
 
                angular.forEach(paths, function (url) {
                    var deferred = $q.defer();
                    promises.push(deferred.promise);
                    $http.get(url, params).then(function (response) {
                        var data = response.data;
                        Eif (angular.isString(data) && data.length > 0) {
                            angular.forEach(angular.element(data), function (node) {
                                Eif (node.nodeName === 'SCRIPT' && node.type === 'text/ng-template') {
                                    $templateCache.put(node.id, node.innerHTML);
                                }
                            });
                        }
                        Eif (angular.isUndefined(filesCache.get(url))) {
                            filesCache.put(url, true);
                        }
                        deferred.resolve();
                    })['catch'](function (response) {
                        deferred.reject(new Error('Unable to load template file "' + url + '": ' + response.data));
                    });
                });
                return $q.all(promises).then(function () {
                    callback();
                }, function (err) {
                    callback(err);
                });
            };
            $delegate.templatesLoader.ocLazyLoadLoader = true;
 
            return $delegate;
        });
    });
})(angular);
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIkM6L3d3dy9vY0xhenlMb2FkL3NyYy9vY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zTG9hZGVyID0gZnVuY3Rpb24ocGF0aHMsIGNhbGxiYWNrLCBwYXJhbXMpIHtcclxuICAgICAgICAgICAgICAgIHZhciBwcm9taXNlcyA9IFtdLFxyXG4gICAgICAgICAgICAgICAgICAgIGZpbGVzQ2FjaGUgPSAkZGVsZWdhdGUuX2dldEZpbGVzQ2FjaGUoKTtcclxuXHJcbiAgICAgICAgICAgICAgICBhbmd1bGFyLmZvckVhY2gocGF0aHMsIHVybCA9PiB7XHJcbiAgICAgICAgICAgICAgICAgICAgdmFyIGRlZmVycmVkID0gJHEuZGVmZXIoKTtcclxuICAgICAgICAgICAgICAgICAgICBwcm9taXNlcy5wdXNoKGRlZmVycmVkLnByb21pc2UpO1xyXG4gICAgICAgICAgICAgICAgICAgICRodHRwLmdldCh1cmwsIHBhcmFtcykudGhlbihyZXNwb25zZSA9PiB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGxldCBkYXRhID0gcmVzcG9uc2UuZGF0YTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgaWYoYW5ndWxhci5pc1N0cmluZyhkYXRhKSAmJiBkYXRhLmxlbmd0aCA+IDApIHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIGFuZ3VsYXIuZm9yRWFjaChhbmd1bGFyLmVsZW1lbnQoZGF0YSksIG5vZGUgPT4ge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmKG5vZGUubm9kZU5hbWUgPT09ICdTQ1JJUFQnICYmIG5vZGUudHlwZSA9PT0gJ3RleHQvbmctdGVtcGxhdGUnKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICR0ZW1wbGF0ZUNhY2hlLnB1dChub2RlLmlkLCBub2RlLmlubmVySFRNTCk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgfSk7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgICAgICAgICAgaWYoYW5ndWxhci5pc1VuZGVmaW5lZChmaWxlc0NhY2hlLmdldCh1cmwpKSkge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgZmlsZXNDYWNoZS5wdXQodXJsLCB0cnVlKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgICAgICAgICBkZWZlcnJlZC5yZXNvbHZlKCk7XHJcbiAgICAgICAgICAgICAgICAgICAgfSkuY2F0Y2gocmVzcG9uc2UgPT4ge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBkZWZlcnJlZC5yZWplY3QobmV3IEVycm9yKGBVbmFibGUgdG8gbG9hZCB0ZW1wbGF0ZSBmaWxlIFwiJHsgdXJsIH1cIjogJHsgcmVzcG9uc2UuZGF0YSB9YCkpO1xyXG4gICAgICAgICAgICAgICAgICAgIH0pO1xyXG4gICAgICAgICAgICAgICAgfSk7XHJcbiAgICAgICAgICAgICAgICByZXR1cm4gJHEuYWxsKHByb21pc2VzKS50aGVuKCgpID0+IHtcclxuICAgICAgICAgICAgICAgICAgICBjYWxsYmFjaygpO1xyXG4gICAgICAgICAgICAgICAgfSwgZXJyID0+IHtcclxuICAgICAgICAgICAgICAgICAgICBjYWxsYmFjayhlcnIpO1xyXG4gICAgICAgICAgICAgICAgfSk7XHJcbiAgICAgICAgICAgIH07XHJcbiAgICAgICAgICAgICRkZWxlZ2F0ZS50ZW1wbGF0ZXNMb2FkZXIub2NMYXp5TG9hZExvYWRlciA9IHRydWU7XHJcblxyXG4gICAgICAgICAgICByZXR1cm4gJGRlbGVnYXRlO1xyXG4gICAgICAgIH0pXHJcbiAgICB9KTtcclxuXHJcbn0pKGFuZ3VsYXIpO1xyXG4iXX0=