Changeset 2080571
- Timestamp:
- 05/04/2019 06:09:49 PM (7 years ago)
- Location:
- ng-lazyload
- Files:
-
- 3 deleted
- 3 edited
-
assets (deleted)
-
branches (deleted)
-
tags (deleted)
-
trunk/NG-Lazyload.php (modified) (10 diffs)
-
trunk/plugin.js (modified) (2 diffs)
-
trunk/readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
ng-lazyload/trunk/NG-Lazyload.php
r2079208 r2080571 5 5 Description: Implements lazyload for thumbnails and content images 6 6 Author: Nikita Menshutin 7 Version: 1. 17 Version: 1.2 8 8 Author URI: http://nikita.global 9 9 … … 37 37 { 38 38 $this->prefix = 'nglazyload'; 39 $this->version = '1. 1';39 $this->version = '1.2'; 40 40 add_action('wp_enqueue_scripts', array($this, 'scripts')); 41 41 add_filter( … … 43 43 array( 44 44 $this, 45 'filterContent ',45 'filterContentTags', 46 46 ) 47 47 ); … … 55 55 3 56 56 ); 57 add_filter('the_content', array($this, 'filterContent')); 57 add_filter('the_content', array($this, 'filterContentTags')); 58 add_filter('the_content', array($this, 'filterContentBackgroundImages')); 58 59 } 59 60 … … 75 76 76 77 /** 78 * Replacing all background images in styles with 79 * lazy-load attributes 80 * 81 * @param string $content html content 82 * 83 * @return string updated images if any 84 */ 85 public function filterContentBackgroundImages($content) 86 { 87 $match = '#<[^>]*background\-image[^url]*url[^(]*\(([^\)]*)\)[^>]*>#'; 88 return preg_replace_callback( 89 $match, 90 function ($matches) { 91 $newtag = $matches[0]; 92 $url = $matches[1]; 93 $newtag = str_replace($url, NGLL::dataImg(), $newtag); 94 $newtag = str_replace( 95 '>', 96 NGLL::dataAttrValue($url, true) . 97 '>', 98 $newtag 99 ); 100 return $newtag; 101 }, 102 $content 103 ); 104 } 105 106 /** 77 107 * Replacing all images with 78 108 * lazy-load attributes … … 82 112 * @return string updated images if any 83 113 */ 84 public function filterContent ($content)114 public function filterContentTags($content) 85 115 { 86 116 $xmlprefix = '<?xml encoding="utf-8" ?>'; … … 88 118 $doc->loadHTML( 89 119 $xmlprefix . $content //, 90 // LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD120 // LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD 91 121 ); 92 122 $images = $doc->getElementsByTagName('img'); … … 104 134 '', 105 135 preg_replace( 106 '~<(?:!DOCTYPE|/?(?:html|head|body))[^>]*>\s*~i', 107 '', 136 '~<(?:!DOCTYPE|/?(?:html|head|body))[^>]*>\s*~i', 137 '', 108 138 $doc->saveHTML() 109 139 ) … … 113 143 114 144 /** 115 * En gueue plugin.js145 * Enqueue plugin.js 116 146 * 117 147 * @return void … … 163 193 * Generate data html tag attribute for real image 164 194 * 165 * @param string $src string with link 195 * @param string $src string with link 196 * @param bool $background if tag for background image 166 197 * 167 198 * @return void 168 199 */ 169 public static function dataAttrValue($src) 170 { 171 return ' ' . self::dataAttr . '="' . $src . '" '; 200 public static function dataAttrValue($src, $background = false) 201 { 202 $suffix = ''; 203 if ($background) { 204 $suffix = 'b'; 205 } 206 return ' ' . self::dataAttr() . $suffix . '="' . $src . '"'; 172 207 } 173 208 -
ng-lazyload/trunk/plugin.js
r2079194 r2080571 1 $(document).ready(function (){1 $(document).ready(function () { 2 2 nglazyLoad(); 3 3 setInterval(function () { … … 6 6 $(window).scroll(function () { 7 7 nglazyLoad(); 8 });9 $(window).resize(function () {10 nglazyLoad();11 });8 }); 9 $(window).resize(function () { 10 nglazyLoad(); 11 }); 12 12 }); 13 13 14 14 function nglazyLoad() { 15 $('[data-ngll-srcB]').each(function () { 16 if ($(this).isInViewport()) { 17 $(this).css( 18 'background-image', 'url(' + $(this).data('ngll-srcb') + ')' 19 ); 20 $(this).removeAttr('data-ngll-srcB'); 21 } 22 }) 15 23 $('img[data-ngll-src]').each(function () { 16 24 if ($(this).isInViewport()) { -
ng-lazyload/trunk/readme.txt
r2079208 r2080571 3 3 Plugin Name: NG-Lazyload 4 4 Tags: images, lazy load, lazyload, thumbnail, optimize content 5 Plugin URI: https://perishablepress.com/press/2009/12/22/protect-wordpress-against-malicious-url-requests/6 Tags: wp, protect, php, eval, malicious, url7 5 Author URI: https://nikita.global 8 6 Author: Nikita Menshutin … … 24 22 25 23 NG-Lazyload plugin replaces all the thumbails and images in the content with the smallest image possible (1 pixel gif) and then shows the full image only when it is in viewport. 24 The only plugin which also works with background images in style tag 26 25 27 26 == Installation == … … 36 35 == Changelog == 37 36 37 = 1.2 (2019-05-04) 38 * Now modifies style tags which have background-images. Useful when you have sliders like slick or owl caroussel. 39 38 40 = 1.0 (2019-05-02) = 39 41 * The First Upload, but was tested before at several sites
Note: See TracChangeset
for help on using the changeset viewer.