Changeset 2771982
- Timestamp:
- 08/18/2022 08:34:04 AM (4 years ago)
- Location:
- wp-lozad/trunk
- Files:
-
- 3 edited
-
js/initLozad.js (modified) (9 diffs)
-
lozad.php (modified) (1 diff)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wp-lozad/trunk/js/initLozad.js
r2760300 r2771982 1 1 class InitLozad { 2 2 // verify the existence of the file 3 useIfFileExists = false; // todo handle 4 5 init = () => { 6 this.__handle(); 3 constructor() { 4 this.useIfFileExists = false; // todo handle 7 5 } 8 6 9 __handle = () => { 7 init() { 8 this.handle(); 9 } 10 11 handle() { 10 12 if (typeof lozad !== 'function') { 11 this. __image2x();13 this.image2x(); 12 14 return; 13 15 } 14 16 15 this. __initLazyload();17 this.initLazyload(); 16 18 } 17 19 18 __initLazyload = () =>{20 initLazyload() { 19 21 lozad('.lazyload', { 20 22 loaded: (el) => { … … 23 25 }).observe(); 24 26 25 this. __image2x();27 this.image2x(); 26 28 27 window.load = () =>{29 window.load = function() { 28 30 window.scrollTo(window.scrollX, window.scrollY); 29 31 }; 30 32 } 31 33 32 __urlExists = (url) =>{34 urlExists(url) { 33 35 const http = new XMLHttpRequest(); 34 36 http.open('HEAD', url, false); … … 37 39 } 38 40 39 __replaceImgTo2Img = (currentString) =>{41 replaceImgTo2Img(currentString) { 40 42 if (!currentString) { 41 43 return ''; … … 47 49 } 48 50 49 __handleBgImageTo2xBg = () =>{51 handleBgImageTo2xBg() { 50 52 let o = this; 51 53 52 54 const replaceBgImageTo2xBg = (element) => { 53 element.setAttribute('data-background-image', o. __replaceImgTo2Img(element.getAttribute('data-background-image')));55 element.setAttribute('data-background-image', o.replaceImgTo2Img(element.getAttribute('data-background-image'))); 54 56 }; 55 57 … … 58 60 59 61 if (o.useIfFileExists) { 60 if (o. __urlExists(o.__replaceImgTo2Img(dataBackgroundImage.substring(5, (dataBackgroundImage.length - 2))))) {62 if (o.urlExists(o.replaceImgTo2Img(dataBackgroundImage.substring(5, (dataBackgroundImage.length - 2))))) { 61 63 replaceBgImageTo2xBg(element); 62 64 } … … 68 70 } 69 71 70 __image2x = () =>{72 image2x() { 71 73 const replaceSiblingsSourceElements = (currentElement) => { 72 74 currentElement.parentNode.childNodes.forEach((item) => { … … 77 79 return; 78 80 } 79 item.setAttribute('srcset', this. __replaceImgTo2Img(item.getAttribute('srcset')))81 item.setAttribute('srcset', this.replaceImgTo2Img(item.getAttribute('srcset'))) 80 82 }); 81 83 }; … … 84 86 85 87 if (pixelRatio > 1) { 86 this. __handleBgImageTo2xBg();88 this.handleBgImageTo2xBg(); 87 89 88 90 const els = document.querySelectorAll('img.image2x'); … … 93 95 replaceSiblingsSourceElements(currentElement); 94 96 95 const src = this. __replaceImgTo2Img(currentElement.getAttribute('src'));96 if (this.useIfFileExists && !this. __urlExists(src)) {97 const src = this.replaceImgTo2Img(currentElement.getAttribute('src')); 98 if (this.useIfFileExists && !this.urlExists(src)) { 97 99 return; 98 100 } 99 101 100 102 currentElement.setAttribute('src', src); 101 currentElement.setAttribute('srcset', this. __replaceImgTo2Img(currentElement.getAttribute('srcset')));102 currentElement.setAttribute('data-srcset', this. __replaceImgTo2Img(currentElement.getAttribute('data-srcset')));103 currentElement.setAttribute('data-src', this. __replaceImgTo2Img(currentElement.getAttribute('data-src')));103 currentElement.setAttribute('srcset', this.replaceImgTo2Img(currentElement.getAttribute('srcset'))); 104 currentElement.setAttribute('data-srcset', this.replaceImgTo2Img(currentElement.getAttribute('data-srcset'))); 105 currentElement.setAttribute('data-src', this.replaceImgTo2Img(currentElement.getAttribute('data-src'))); 104 106 } 105 107 } -
wp-lozad/trunk/lozad.php
r2760300 r2771982 4 4 Description: lazy loading of images by baroda algorithm 5 5 Author: Evgeniy Kozenok 6 Version: 1.6. 16 Version: 1.6.2 7 7 */ 8 8 -
wp-lozad/trunk/readme.txt
r2760300 r2771982 4 4 Requires at least: 5.0 5 5 Tested up to: 6.0 6 Stable tag: 1.6. 16 Stable tag: 1.6.2 7 7 License: GPL2 8 8 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 24 24 25 25 == Changelog == 26 = 1.6.2 = 27 * 2022-08-18: JS ios < 14 28 26 29 = 1.6.1 = 27 30 * 2022-07-22: fix js private identifier in cache
Note: See TracChangeset
for help on using the changeset viewer.