|
36 | 36 | /* global window, document */
|
37 | 37 | (function() {
|
38 | 38 | 'use strict';
|
39 |
| - var $timeout, $compile, src, savedHtml; |
| 39 | + var $timeout, $compile, src, savedHtml = [], elements = []; |
40 | 40 |
|
41 | 41 | var preLinkFunc = function(scope, element, attrs) {
|
42 | 42 | var mapsUrl = attrs.mapLazyLoadParams || attrs.mapLazyLoad;
|
43 | 43 |
|
44 |
| - window.lazyLoadCallback = function() { |
45 |
| - console.log('Google maps script loaded:', mapsUrl); |
46 |
| - $timeout(function() { /* give some time to load */ |
47 |
| - element.html(savedHtml); |
48 |
| - $compile(element.contents())(scope); |
49 |
| - }, 100); |
50 |
| - }; |
51 |
| - |
52 | 44 | if(window.google === undefined || window.google.maps === undefined) {
|
| 45 | + elements.push({ |
| 46 | + scope: scope, |
| 47 | + element: element, |
| 48 | + savedHtml: savedHtml[elements.length], |
| 49 | + }); |
| 50 | + |
| 51 | + window.lazyLoadCallback = function() { |
| 52 | + console.log('Google maps script loaded:', mapsUrl); |
| 53 | + $timeout(function() { /* give some time to load */ |
| 54 | + elements.forEach(function(elm) { |
| 55 | + elm.element.html(elm.savedHtml); |
| 56 | + $compile(elm.element.contents())(elm.scope); |
| 57 | + }); |
| 58 | + }, 100); |
| 59 | + }; |
| 60 | + |
53 | 61 | var scriptEl = document.createElement('script');
|
54 | 62 | console.log('Prelinking script loaded,' + src);
|
55 | 63 |
|
|
69 | 77 | var compileFunc = function(tElement, tAttrs) {
|
70 | 78 |
|
71 | 79 | (!tAttrs.mapLazyLoad) && console.error('requires src with map-lazy-load');
|
72 |
| - savedHtml = tElement.html(); |
| 80 | + savedHtml.push(tElement.html()); |
73 | 81 | src = tAttrs.mapLazyLoad;
|
74 | 82 |
|
75 | 83 | /**
|
|
0 commit comments