Code coverage report for ./src/ocLazyLoad.directive.js

Statements: 100% (13 / 13)      Branches: 50% (2 / 4)      Functions: 100% (7 / 7)      Lines: 100% (13 / 13)      Ignored: none     

All files » ./src/ » ocLazyLoad.directive.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    1     1 1           1 1   1 1 1 8   1 1       1   1                  
'use strict';
 
(function (angular) {
    'use strict';
 
    angular.module('oc.lazyLoad').directive('ocLazyLoad', function ($ocLazyLoad, $compile, $animate, $parse, $timeout) {
        return {
            restrict: 'A',
            terminal: true,
            priority: 1000,
            compile: function compile(element, attrs) {
                // we store the content and remove it before compilation
                var content = element[0].innerHTML;
                element.html('');
 
                return function ($scope, $element, $attr) {
                    var model = $parse($attr.ocLazyLoad);
                    $scope.$watch(function () {
                        return model($scope) || $attr.ocLazyLoad; // it can be a module name (string), an object, an array, or a scope reference to any of this
                    }, function (moduleName) {
                        Eif (angular.isDefined(moduleName)) {
                            $ocLazyLoad.load(moduleName).then(function () {
                                // Attach element contents to DOM and then compile them.
                                // This prevents an issue where IE invalidates saved element objects (HTMLCollections)
                                // of the compiled contents when attaching to the parent DOM.
                                $animate.enter(content, $element);
                                // get the new content & compile it
                                $compile($element.contents())($scope);
                            });
                        }
                    }, true);
                };
            }
        };
    });
})(angular);
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIkM6L3d3dy9vY0xhenlMb2FkL3NyYy9vY0xhenlMb2FkLmRpcmVjdGl2ZS5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLENBQUMsVUFBQSxPQUFPLEVBQUk7QUFDUixnQkFBWSxDQUFDOztBQUViLFdBQU8sQ0FBQyxNQUFNLENBQUMsYUFBYSxDQUFDLENBQUMsU0FBUyxDQUFDLFlBQVksRUFBRSxVQUFTLFdBQVcsRUFBRSxRQUFRLEVBQUUsUUFBUSxFQUF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FBQSxDQUFFLE9BQU8sQ0FBQyxDQUFDIiwiZmlsZSI6IkM6L3d3dy9vY0xhenlMb2FkL3NyYy9vY0xhenlMb2FkLmRpcmVjdGl2ZS5qcyIsInNvdXJjZXNDb250ZW50IjpbIihhbmd1bGFyID0+IHtcclxuICAgICd1c2Ugc3RyaWN0JztcclxuXHJcbiAgICBhbmd1bGFyLm1vZHVsZSgnb2MubGF6eUxvYWQnKS5kaXJlY3RpdmUoJ29jTGF6eUxvYWQnLCBmdW5jdGlvbigkb2NMYXp5TG9hZCwgJGNvbXBpbGUsICRhbmltYXRlLCAkcGFyc2UsICR0aW1lb3V0KSB7XHJcbiAgICAgICAgcmV0dXJuIHtcclxuICAgICAgICAgICAgcmVzdHJpY3Q6ICdBJyxcclxuICAgICAgICAgICAgdGVybWluYWw6IHRydWUsXHJcbiAgICAgICAgICAgIHByaW9yaXR5OiAxMDAwLFxyXG4gICAgICAgICAgICBjb21waWxlOiBmdW5jdGlvbihlbGVtZW50LCBhdHRycykge1xyXG4gICAgICAgICAgICAgICAgLy8gd2Ugc3RvcmUgdGhlIGNvbnRlbnQgYW5kIHJlbW92ZSBpdCBiZWZvcmUgY29tcGlsYXRpb25cclxuICAgICAgICAgICAgICAgIHZhciBjb250ZW50ID0gZWxlbWVudFswXS5pbm5lckhUTUw7XHJcbiAgICAgICAgICAgICAgICBlbGVtZW50Lmh0bWwoJycpO1xyXG5cclxuICAgICAgICAgICAgICAgIHJldHVybiBmdW5jdGlvbigkc2NvcGUsICRlbGVtZW50LCAkYXR0cikge1xyXG4gICAgICAgICAgICAgICAgICAgIHZhciBtb2RlbCA9ICRwYXJzZSgkYXR0ci5vY0xhenlMb2FkKTtcclxuICAgICAgICAgICAgICAgICAgICAkc2NvcGUuJHdhdGNoKCgpID0+IHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIG1vZGVsKCRzY29wZSkgfHwgJGF0dHIub2NMYXp5TG9hZDsgLy8gaXQgY2FuIGJlIGEgbW9kdWxlIG5hbWUgKHN0cmluZyksIGFuIG9iamVjdCwgYW4gYXJyYXksIG9yIGEgc2NvcGUgcmVmZXJlbmNlIHRvIGFueSBvZiB0aGlzXHJcbiAgICAgICAgICAgICAgICAgICAgfSwgbW9kdWxlTmFtZSA9PiB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmKGFuZ3VsYXIuaXNEZWZpbmVkKG1vZHVsZU5hbWUpKSB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAkb2NMYXp5TG9hZC5sb2FkKG1vZHVsZU5hbWUpLnRoZW4oKCkgPT4ge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIC8vIEF0dGFjaCBlbGVtZW50IGNvbnRlbnRzIHRvIERPTSBhbmQgdGhlbiBjb21waWxlIHRoZW0uXHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgLy8gVGhpcyBwcmV2ZW50cyBhbiBpc3N1ZSB3aGVyZSBJRSBpbnZhbGlkYXRlcyBzYXZlZCBlbGVtZW50IG9iamVjdHMgKEhUTUxDb2xsZWN0aW9ucylcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAvLyBvZiB0aGUgY29tcGlsZWQgY29udGVudHMgd2hlbiBhdHRhY2hpbmcgdG8gdGhlIHBhcmVudCBET00uXHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgJGFuaW1hdGUuZW50ZXIoY29udGVudCwgJGVsZW1lbnQpO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIC8vIGdldCB0aGUgbmV3IGNvbnRlbnQgJiBjb21waWxlIGl0XHJcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgJGNvbXBpbGUoJGVsZW1lbnQuY29udGVudHMoKSkoJHNjb3BlKTtcclxuICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0pO1xyXG4gICAgICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICAgICAgfSwgdHJ1ZSk7XHJcbiAgICAgICAgICAgICAgICB9O1xyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgfTtcclxuICAgIH0pO1xyXG5cclxufSkoYW5ndWxhcik7XHJcbiJdfQ==