|
37 | 37 | } |
38 | 38 |
|
39 | 39 | .media-holder.media-holder-icon.hasImg { |
| 40 | + display: flex; |
| 41 | + align-items: center; |
40 | 42 | position: relative; |
41 | 43 | overflow: hidden; |
42 | 44 | height:100%; |
|
51 | 53 | } |
52 | 54 |
|
53 | 55 | .media-holder.media-holder-icon img.reveal-img { |
54 | | - position: absolute; |
55 | 56 | left: 0; |
56 | 57 | top: 0; |
57 | | - will-change: opacity; |
58 | | - animation: reveal 0.1s ease-out; |
59 | | - } |
60 | | - |
61 | | - @keyframes reveal { |
62 | | - 0% { |
63 | | - opacity: 0; |
64 | | - } |
65 | | - 50% { |
66 | | - opacity: 0.5; |
67 | | - } |
68 | | - 100% { |
69 | | - opacity: 1; |
70 | | - } |
71 | 58 | } |
72 | 59 |
|
73 | 60 | #light-folder-body { |
|
124 | 111 | <div id="txt" class="text-left folder-plugin-text clearfix hide-empty"></div> |
125 | 112 | <div id="pluginsContainer"></div> |
126 | 113 | <script> |
| 114 | + var carouselContainer = document.getElementById("carousel"); |
| 115 | + var txt = document.getElementById("txt"); |
| 116 | + var pluginsContainer = document.getElementById("pluginsContainer"); |
| 117 | + |
127 | 118 | var plugins = []; |
| 119 | + var compressImages = false; |
128 | 120 |
|
129 | 121 | var lazyLoad = { |
130 | 122 | loadImage: function (item) { |
131 | | - var _failAttempts = 0; |
132 | | - |
133 | 123 | // load image |
134 | 124 | var img = new Image(); |
135 | 125 |
|
|
139 | 129 | } |
140 | 130 |
|
141 | 131 | function _initImg(item) { |
142 | | - img.src = item.getAttribute('data-src'); |
| 132 | + var src = item.getAttribute('data-src'); |
| 133 | + |
| 134 | + var options = {}; |
| 135 | + options.size = item.getAttribute('data-crop-size'); |
| 136 | + options.aspect = item.getAttribute('data-crop-aspect'); |
| 137 | + options.compression = compressImages ? 80 : false; |
| 138 | + // fallbacks |
| 139 | + options.width = item.getAttribute('data-crop-width'); |
| 140 | + options.height = item.getAttribute('data-crop-height'); |
| 141 | + // enable for cache |
| 142 | + // buildfire.imageLib.cropImage(src, options, img); |
| 143 | + img.src = buildfire.imageLib.cropImage(src, options); |
| 144 | + |
143 | 145 | img.className = 'reveal-img'; |
| 146 | + |
144 | 147 | if (img.complete) _addImg(); |
145 | 148 | else img.onload = _addImg; |
146 | | - |
147 | | - img.onerror=function (e) { |
148 | | - if(_failAttempts >= 1){ |
149 | | - return; |
150 | | - } |
151 | | - |
152 | | - _failAttempts++; |
153 | | - |
154 | | - /* |
155 | | - * Sometimes Image IO doesn't crop image with certain width & height |
156 | | - * So this for changes the dimensions and try to do another crop using image IO |
157 | | - * to avoid showing only the blurred image |
158 | | - * */ |
159 | | - |
160 | | - img = new Image(); |
161 | | - var originalImg = item.getAttribute('data-original-img'); |
162 | | - var cropWidth = parseInt(item.getAttribute('data-crop-width')); |
163 | | - cropWidth +=1; |
164 | | - var cropHeight = parseInt(item.getAttribute('data-crop-height')); |
165 | | - cropHeight+=1; |
166 | | - |
167 | | - item.setAttribute('data-crop-width',cropWidth); |
168 | | - item.setAttribute('data-crop-height',cropHeight); |
169 | | - |
170 | | - var _newCroppedImg = buildfire.imageLib.cropImage(originalImg, {width:cropWidth,height: cropHeight}); |
171 | | - item.setAttribute('data-src',_newCroppedImg); |
172 | | - |
173 | | - _initImg(item); |
174 | | - }; |
175 | 149 | } |
176 | 150 |
|
177 | 151 | // replace image |
|
180 | 154 | item.addEventListener('click', function (e) { |
181 | 155 | e.preventDefault(); |
182 | 156 | }, false); |
183 | | - |
184 | | - item.appendChild(img).addEventListener('animationend', function (e) { |
185 | | - // remove preview image |
186 | | - var pImg = item.querySelector && item.querySelector('.placeholder'); |
187 | | - |
188 | | - if (pImg) { |
189 | | - e.target.alt = pImg.alt || ''; |
190 | | - e.target.classList.remove('reveal-img'); |
191 | | - pImg.style.display = 'none'; |
192 | | - pImg.removeAttribute('src'); |
193 | | - } |
194 | | - item.removeAttribute('data-src'); |
195 | | - }); |
196 | 157 |
|
| 158 | + item.appendChild(img); |
197 | 159 | } |
198 | 160 | }, |
199 | 161 | isInViewport: function (element) { |
|
232 | 194 | }); |
233 | 195 |
|
234 | 196 | function loadData(err, obj) { |
235 | | - if (err) return; |
| 197 | + if (err || !obj || !obj.data) return; |
236 | 198 | if (!obj.data.design) return; |
237 | | - layout = obj.data.design.selectedLayout; |
238 | 199 |
|
239 | | - var compressImages = obj.data.design.compressImages; |
| 200 | + layout = obj.data.design.selectedLayout; |
| 201 | + compressImages = obj.data.design.compressImages; |
240 | 202 |
|
241 | 203 | if(!obj.data.design.securedFeaturesOption) |
242 | 204 | obj.data.design.securedFeaturesOption="Enable"; |
243 | 205 |
|
244 | 206 | if(obj.data.content && obj.data.content.carouselImages && obj.data.content.carouselImages.length > 0){ |
245 | | - var carouselContainer = document.getElementById("carousel"); |
246 | 207 | carouselContainer.classList.remove('hide'); |
247 | 208 | } |
248 | 209 |
|
249 | | - var txt = document.getElementById("txt"); |
250 | 210 | txt.innerHTML = ''; |
251 | 211 | if (layout != 12) { |
252 | 212 | if (obj.data.content.text) |
|
260 | 220 |
|
261 | 221 | setIphonePadding(obj.data.content.carouselImages, obj.data.content.text, layout); |
262 | 222 |
|
263 | | - var pluginsContainer = document.getElementById("pluginsContainer"); |
264 | 223 | pluginsContainer.className = "layout" + layout; |
265 | 224 | pluginsContainer.innerHTML = ''; |
266 | 225 |
|
| 226 | + initStyle(obj, layout); |
267 | 227 | getPlugins(obj, function (result) { |
268 | 228 | plugins = result; |
269 | 229 | pluginsContainer.innerHTML = ''; |
270 | 230 |
|
271 | | - var options = calcImgOptions(layout, compressImages); |
| 231 | + var options = calcImgOptions(layout); |
272 | 232 |
|
273 | 233 | if (layout == 12) { |
274 | 234 | var pluginItemFrame = document.createElement('div'); |
|
310 | 270 |
|
311 | 271 | if (p.iconUrl || p.iconClassName) { |
312 | 272 | if (p.iconUrl) { |
313 | | - var _croppedImg = buildfire.imageLib.cropImage(p.iconUrl, options); |
314 | 273 | divImg.classList.add("hasImg"); |
315 | | - divImg.setAttribute("data-src", _croppedImg); |
| 274 | + divImg.setAttribute("data-src", p.iconUrl); |
316 | 275 | divImg.setAttribute("data-original-img", p.iconUrl); |
| 276 | + divImg.setAttribute("data-crop-size", options.size); |
| 277 | + divImg.setAttribute("data-crop-aspect", options.aspect); |
317 | 278 | divImg.setAttribute("data-crop-width", options.width); |
318 | 279 | divImg.setAttribute("data-crop-height", options.height); |
319 | 280 | divImg.classList.add('lazy-img'); |
320 | | - |
321 | | - var placeholder = document.createElement('img'); |
322 | | - var baseUrl = '../../../styles/media/holder-'; |
323 | | - |
324 | | - placeholder.src = getPlaceholderImage(layout); |
325 | | - placeholder.classList.add("placeholder"); |
326 | | - placeholder.setAttribute('width', options.width); |
327 | | - placeholder.setAttribute('height', options.height); |
328 | | - placeholder.style.height = options.height + "px !important"; |
329 | | - placeholder.style.width = options.width + "px !important"; |
330 | | - |
331 | | - divImg.appendChild(placeholder); |
332 | 281 | } |
333 | 282 | else { |
334 | 283 | divImg.classList.add("hasIcon"); |
|
427 | 376 | //load image in first render |
428 | 377 | lazyLoad.processLazyImages(); |
429 | 378 | }); |
430 | | - initStyle(obj, layout); |
431 | 379 |
|
432 | 380 | if (layout != 12) { |
433 | 381 | //Render Carousel |
|
550 | 498 | width: window.innerWidth, |
551 | 499 | height: window.innerHeight |
552 | 500 | }) + "') !Important; background-size: cover !important; } "; |
| 501 | + // enable for imageCache |
| 502 | + // style.innerHTML += "body { background-size: cover !important; } "; |
| 503 | + // buildfire.imageLib.cropImage(bgImage, { width: window.innerWidth, height: window.innerHeight }, document.body); |
553 | 504 | } |
554 | 505 |
|
555 | 506 | if (obj.data.design.hideText) |
|
574 | 525 | document.body.classList.add('no-carousel'); |
575 | 526 | } |
576 | 527 | } |
| 528 | + |
577 | 529 | buildfire.datastore.getWithDynamicData(loadData); |
578 | 530 |
|
579 | 531 | buildfire.datastore.onUpdate(function (obj) { |
|
602 | 554 | } |
603 | 555 | }; |
604 | 556 |
|
605 | | - function getPlaceholderImage(layout) { |
606 | | - var baseUrl = '../../../styles/media/holder-'; |
607 | | - var placeholderSrc = ''; |
608 | | - |
609 | | - if (layout === 10) { |
610 | | - placeholderSrc = baseUrl + '4x1.gif'; |
611 | | - } |
612 | | - |
613 | | - else if (layout === 7) { |
614 | | - placeholderSrc = baseUrl + '16x9.gif'; |
615 | | - } |
616 | | - |
617 | | - else if ([2, 3, 4, 9].indexOf(layout) > -1) { |
618 | | - placeholderSrc = baseUrl + '2x1.gif'; |
619 | | - } |
620 | | - |
621 | | - else { |
622 | | - placeholderSrc = baseUrl + '1x1.gif'; |
623 | | - } |
624 | | - |
625 | | - return placeholderSrc; |
626 | | - } |
627 | | - |
628 | 557 | function calcFontSize(options, layout) { |
629 | 558 | var fontSize = 0; |
630 | 559 | if ([6].indexOf(layout) >= 0) { |
|
639 | 568 | return fontSize; |
640 | 569 | } |
641 | 570 |
|
642 | | - function calcImgOptions(layout, compress) { |
| 571 | + function calcImgOptions(layout) { |
643 | 572 | var option = {}; |
644 | | - if (compress) { |
645 | | - option.compression = 80; |
646 | | - } |
| 573 | + |
647 | 574 | if ([3, 4, 9].indexOf(layout) >= 0) { |
| 575 | + option.size = 'full_width'; |
| 576 | + option.aspect = '16:9'; |
648 | 577 | option.width = window.innerWidth; |
649 | 578 | option.height = option.width * 9 / 16; |
650 | 579 | } |
651 | 580 | else if ([1, 8].indexOf(layout) >= 0) { |
| 581 | + option.size = 'sixth_width'; |
| 582 | + option.aspect = '1:1'; |
652 | 583 | option.width = window.innerWidth * (0.15); |
653 | 584 | option.height = option.width; |
654 | 585 | } |
655 | 586 | else if (layout == 2) { |
| 587 | + option.size = 'third_width'; |
| 588 | + option.aspect = '16:9'; |
656 | 589 | option.width = window.innerWidth * (0.32); |
657 | 590 | option.height = window.innerWidth * (0.18); |
658 | 591 | } |
659 | 592 | else if ([5, 11].indexOf(layout) >= 0) { |
| 593 | + option.size = 'half_width'; |
| 594 | + option.aspect = '1:1'; |
660 | 595 | option.width = Math.round(window.innerWidth / 2); |
661 | 596 | option.height = option.width; |
662 | 597 | } |
663 | 598 | else if (layout == 6) { |
| 599 | + option.size = 'half_width'; |
| 600 | + option.aspect = '1:1'; |
664 | 601 | option.width = Math.round(window.innerWidth / 2.4); |
665 | 602 | option.height = option.width; |
666 | 603 | } |
667 | 604 | else if (layout == 7) { |
| 605 | + option.size = 'full_width'; |
| 606 | + option.aspect = '16:9'; |
668 | 607 | option.width = window.innerWidth; |
669 | 608 | option.height = Math.round(window.innerWidth / 2.2); |
670 | 609 | } |
671 | 610 | else if (layout == 10) { |
| 611 | + option.size = 'full_width'; |
| 612 | + option.aspect = '2.39:1'; |
672 | 613 | option.width = window.innerWidth; |
673 | 614 | option.height = Math.round(window.innerWidth * 0.23); |
674 | 615 | } |
|
690 | 631 |
|
691 | 632 | function renderCarousel(carouselImages, layout) { |
692 | 633 | if (layout != 12) { |
693 | | - var carouselContainer = document.getElementById("carousel"); |
694 | 634 | if (carouselImages && carouselImages.length > 0) { |
695 | 635 | /* |
696 | 636 | if more than one image add carousel else add image directly to the carousel container |
|
0 commit comments