1/* 2 Plugin Name: Zedna WP Image Lazy Load 3 Plugin URI: https://profiles.wordpress.org/zedna#content-plugins 4 Text Domain: wp-image-lazy-load 5 Domain Path: /languages 6 Description: Image lazy load plugin to boost page load time and save bandwidth by removing all the images, background-images, responsive images, iframes and videos. Elements will load just when reach visible part of screen. Lazy loading can be also applied on themes. 7 Version: 1.6.3.3 8 Author: Radek Mezulanik 9 Author URI: https://cz.linkedin.com/in/radekmezulanik 10 License: GPL3 11*/ 12 13(function ($) { 14 //get options from DB 15 var skipIframe = wpimagelazyload_settings.wpimagelazyloadsetting_skipiframe; //true=skip iframe, false=apply the code 16 var skipParent = wpimagelazyload_settings.wpimagelazyloadsetting_skipparent; 17 var skipAllParent = wpimagelazyload_settings.wpimagelazyloadsetting_skipallparent.split(";"); 18 var skipVideo = wpimagelazyload_settings.wpimagelazyloadsetting_skipvideo; 19 var loadonposition = parseInt(wpimagelazyload_settings.wpimagelazyloadsetting_loadonposition); 20 var importantVC = wpimagelazyload_settings.wpimagelazyloadsetting_importantvc; 21 22 //Check if element has some class that should be skipped 23 function myClasses(element, skipClasses) { 24 if (skipAllParent.length > 0 && $(element).parents().hasClass(skipAllParent)) { 25 return false; 26 } 27 if (element instanceof SVGElement === false) { 28 var myClasses = element.className.split(' '); 29 if (myClasses.some(function (v) { return skipClasses.indexOf(v) >= 0; })) { 30 return false; 31 } else { 32 return true; 33 } 34 } 35 } 36 37 $('document').ready(function () { 38 39 //set visible part of screen 40 var scrollBottom = $(window).scrollTop() + window.innerHeight; 41 42 /* 43 -remove & backup source from images 44 -remove & backup source set from responsive images 45 -give back source of visible images 46 -for some browsers, `bgbak` is undefined; for others, `bgbak` is false -> check both like: if (typeof srcsetbak !== typeof undefined && srcsetbak !== false) 47 */ 48 $('img').each(function () { 49 if (myClasses(this, skipAllParent)) { 50 this.setAttribute('src-backup', this.src); 51 var elements = $(this); 52 var elementsoffset = elements.offset(); 53 var isvisibleOriginal = parseInt(elementsoffset.top); 54 var isvisible = isvisibleOriginal + loadonposition; 55 var srcsetbak = $(this).attr('srcset'); 56 if (srcsetbak) { 57 $(this).attr("srcset-backup", srcsetbak); 58 } 59 if (scrollBottom < isvisible) { 60 this.style.opacity = "0"; 61 this.setAttribute('src', ''); 62 this.setAttribute('srcset', ''); 63 } 64 } 65 }); 66 67 /* 68 remove & backup source from videos 69 give back source of visible videos 70 */ 71 if (skipVideo === "false") { 72 $('video').each(function () { 73 if (myClasses(this, skipAllParent)) { 74 this.setAttribute('src-backup', this.src); 75 var elements = $(this); 76 var elementsoffset = elements.offset(); 77 var isvisibleOriginal = parseInt(elementsoffset.top); 78 var isvisible = isvisibleOriginal + loadonposition; 79 var source = elements.find("source"); 80 if (scrollBottom < isvisible) { 81 this.style.opacity = "0"; 82 this.setAttribute('src', ''); 83 for (i = 0; i < source.length; i++) { 84 source[i].setAttribute('src-backup', source[i].src); 85 source[i].setAttribute('src', ''); 86 } 87 } 88 } 89 }); 90 } 91 92 /* 93 remove & backup source from iframes 94 give back source of visible iframes 95 */ 96 if (skipIframe === "false") { 97 $('iframe').each(function () { 98 if (myClasses(this, skipParent)) { 99 this.setAttribute('src-backup', this.src); 100 var elements = $(this); 101 var elementsoffset = elements.offset(); 102 var isvisibleOriginal = parseInt(elementsoffset.top); 103 var isvisible = isvisibleOriginal + loadonposition; 104 if (skipParent.length !== 0) { 105 //skip this iframe 106 } else { 107 if (scrollBottom < isvisible) { 108 this.setAttribute('src', ''); 109 this.style.opacity = "0"; 110 } else { 111 this.style.opacity = "1"; 112 } 113 } 114 } 115 }); 116 } 117 118 $("*").each(function () { 119 if (myClasses(this, skipAllParent)) { 120 //remove & backup background-image from all elements 121 if ($(this).css('background-image').indexOf('url') > -1) { 122 var bg = $(this).css('background-image'); 123 $(this).attr("background-image-backup", bg); 124 if (importantVC) { 125 $(this).css('cssText', 'background-image: none !important'); 126 } else { 127 $(this).css('background-image', 'none'); 128 } 129 } 130 //give back background-image of all visible elements 131 var bgbak = $(this).attr("background-image-backup"); 132 if (bgbak) { 133 var elements = $(this); 134 var elementsoffset = elements.offset(); 135 var isvisibleOriginal = parseInt(elementsoffset.top); 136 var isvisible = isvisibleOriginal + loadonposition; 137 if (scrollBottom >= isvisible) { 138 if (importantVC) { 139 $(this).css('cssText', "background-image: " + bgbak + " !important"); 140 } else { 141 $(this).css("background-image", bgbak); 142 } 143 } 144 } 145 } 146 }); 147 }); 148 149 //Detect if user scrolled to the image 150 $(window).scroll(function () { 151 152 //set visible part of screen 153 var scrollBottom = $(window).scrollTop() + window.innerHeight; 154 155 //give back source of visible images 156 $('img').each(function () { 157 if (myClasses(this, skipAllParent)) { 158 var isLoaded = $(this).attr("src"); 159 var isLoaded2 = $(this).attr("srcset"); 160 var hasBackup = $(this).attr("srcset-backup"); 161 var elements = $(this); 162 var elementsoffset = elements.offset(); 163 var isvisibleOriginal = parseInt(elementsoffset.top); 164 var isvisible = isvisibleOriginal + loadonposition; 165 if (scrollBottom >= isvisible) { 166 if (!isLoaded) { //check if source is not set 167 this.src = this.getAttribute('src-backup'); 168 this.className += " fadein"; 169 this.style.opacity = "1"; 170 } 171 if (!isLoaded2) { //check if source is not set 172 if (hasBackup) { 173 $(this).attr("srcset", hasBackup); 174 } 175 } 176 } 177 } 178 }); 179 180 //give back source of visible videos
181 if (skipVideo === "false") { 182 $('video').each(function () { 183 if (myClasses(this, skipAllParent)) { 184 var isLoaded = $(this).attr("src"); 185 var isLoaded2 = $(this).attr("srcset"); 186 var hasBackup = $(this).attr("srcset-backup"); 187 var elements = $(this); 188 var elementsoffset = elements.offset(); 189 var isvisibleOriginal = parseInt(elementsoffset.top); 190 var isvisible = isvisibleOriginal + loadonposition; 191 var source = elements.find("source"); 192 if (scrollBottom >= isvisible) { 193 if (!isLoaded) { //check if source is not set 194 this.src = this.getAttribute('src-backup'); 195 if (this.classList.contains("fadein") === false) { 196 this.className += " fadein"; 197 } 198 this.style.opacity = "1"; 199 200 for (i = 0; i < source.length; i++) { 201 source[i].src = source[i].getAttribute('src-backup'); 202 } 203 } 204 if (!isLoaded2) { //check if source is not set 205 if (hasBackup) { 206 $(this).attr("srcset", hasBackup); 207 } 208 } 209 } 210 } 211 }); 212 } 213 214 //give back source of visible iframes 215 if (skipIframe === "false") { 216 $('iframe').each(function () { 217 if (myClasses(this, skipParent)) { 218 var isLoaded = $(this).attr("src"); 219 var elements = $(this); 220 var elementsoffset = elements.offset(); 221 var isvisibleOriginal = parseInt(elementsoffset.top); 222 var isvisible = isvisibleOriginal + loadonposition; 223 var hasBackup = $(this).attr("src-backup"); //check if iframe has backup source 224 var found; 225 if (skipParent.length !== 0) { 226 found = $(this).parents().hasClass(skipParent); //look for ignored parent 227 } 228 if (scrollBottom >= isvisible) { 229 if (!isLoaded) { //check if source is not set 230 if (found && skipParent.length !== 0) { 231 //ignored parent was found, so leave it as it is 232 } else { 233 this.src = this.getAttribute('src-backup'); 234 this.className += " fadein"; 235 this.style.opacity = "1"; 236 237 } 238 } 239 } 240 } 241 }); 242 } 243 244 //give back background-image of all visible elements 245 $("*").each(function () { 246 if (myClasses(this, skipAllParent)) { 247 var bgbak = $(this).attr("background-image-backup"); 248 if (bgbak) { 249 var elements = $(this); 250 var elementsoffset = elements.offset(); 251 var isvisibleOriginal = parseInt(elementsoffset.top); 252 var isvisible = isvisibleOriginal + loadonposition; 253 if (scrollBottom >= isvisible) { 254 if ($(this).css('background-image').indexOf('url') === -1) { //check if source is not set 255 if (importantVC) { 256 $(this).css('cssText', "background-image: " + bgbak + " !important"); 257 } else { 258 $(this).css("background-image", bgbak); 259 } 260 } 261 } 262 } 263 } 264 }); 265 }); 266})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.