# 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,