diff --git a/deployed/tmlazyload/plugins/system/tmlazyload/blank.gif b/deployed/tmlazyload/plugins/system/tmlazyload/blank.gif new file mode 100644 index 00000000..35d42e80 Binary files /dev/null and b/deployed/tmlazyload/plugins/system/tmlazyload/blank.gif differ diff --git a/deployed/tmlazyload/plugins/system/tmlazyload/index.html b/deployed/tmlazyload/plugins/system/tmlazyload/index.html new file mode 100644 index 00000000..e69de29b diff --git a/deployed/tmlazyload/plugins/system/tmlazyload/tmlazyload.js b/deployed/tmlazyload/plugins/system/tmlazyload/tmlazyload.js new file mode 100644 index 00000000..29172eae --- /dev/null +++ b/deployed/tmlazyload/plugins/system/tmlazyload/tmlazyload.js @@ -0,0 +1,14 @@ +/*! + * jQuery Lazy - min - v0.3.8 + * http://jquery.eisbehr.de/lazy/ + * http://eisbehr.de/ + * + * Copyright 2014, Daniel 'Eisbehr' Kern + * + * Dual licensed under the MIT and GPL-2.0 licenses: + * http://www.opensource.org/licenses/mit-license.php + * http://www.gnu.org/licenses/gpl-2.0.html + * + * jQuery("img.lazy").lazy(); + */ +(function(e,t,n,r){e.fn.lazy=function(i){"use strict";function d(){l=t.devicePixelRatio>1;if(s.defaultImage!==null||s.placeholder!==null)for(var n=0;n=0)setTimeout(function(){v(true)},s.delay);if(s.delay<0||s.combined){v(false);T(function(){e(s.appendScroll).bind("scroll",w(s.throttle,function(){T(function(){v(false)},this,true)}))},this);T(function(){e(s.appendScroll).bind("resize",w(s.throttle,function(){a=f=-1;T(function(){v(false)},this,true)}))},this)}}function v(t){if(!o.length)return;var n=false;for(var r=0;rr.top&&-s.thresholdr.left&&-s.threshold=0)return a;a=t.innerWidth||n.documentElement.clientWidth||n.body.clientWidth||n.body.offsetWidth||s.fallbackWidth;return a}function b(){if(f>=0)return f;f=t.innerHeight||n.documentElement.clientHeight||n.body.clientHeight||n.body.offsetHeight||s.fallbackHeight;return f}function w(e,t){function o(){function u(){i=+(new Date);t.apply(r)}var o=+(new Date)-i;n&&clearTimeout(n);if(o>e||!s.enableThrottle)u();else n=setTimeout(u,e-o)}var n,i=0;return o}function E(){--u;if(!o.size()&&!u)S(s.onFinishedAll,null)}function S(e,t){if(e){if(t)T(function(){e(t)},this);else T(e,this)}}function x(){c=setTimeout(function(){T();if(h.length)x()},2)}function T(e,n,r){if(e){if(!s.enableQueueing){e.call(n||t);return}if(!r||r&&!p){h.push([e,n,r]);if(r)p=true}if(h.length==1)x();return}var i=h.shift();if(!i)return;if(i[2])p=false;i[0].call(i[1]||t)}var s={bind:"load",threshold:500,fallbackWidth:2e3,fallbackHeight:2e3,visibleOnly:false,appendScroll:t,scrollDirection:"both",defaultImage:"data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==",placeholder:null,delay:-1,combined:false,attribute:"data-src",retinaAttribute:"data-retina",removeAttribute:true,handledName:"handled",effect:"show",effectTime:0,enableThrottle:false,throttle:250,enableQueueing:true,beforeLoad:null,onLoad:null,afterLoad:null,onError:null,onFinishedAll:null},o=this,u=0,a=-1,f=-1,l=false,c=null,h=[],p=false;(function(){if(i)e.extend(s,i);if(s.onError)o.each(function(){var t=this;T(function(){e(t).bind("error",function(){S(s.onError,e(this))})},t)});if(s.bind=="load")e(t).load(d);else if(s.bind=="event")d()})();return this};e.fn.Lazy=e.fn.lazy})(jQuery,window,document); \ No newline at end of file diff --git a/deployed/tmlazyload/plugins/system/tmlazyload/tmlazyload.php b/deployed/tmlazyload/plugins/system/tmlazyload/tmlazyload.php new file mode 100644 index 00000000..ecd86d87 --- /dev/null +++ b/deployed/tmlazyload/plugins/system/tmlazyload/tmlazyload.php @@ -0,0 +1,381 @@ +. + */ +defined('_JEXEC') or die('Restricted access'); + +class PlgSystemTmLazyLoad extends JPlugin +{ + protected $_execute; + + function __construct(&$subject, $config) + { + // First check whether version requirements are met for this specific version + if($this->checkVersionRequirements(false, '3.2', 'TM Lazy Load', 'plg_system_tmlazyload', JPATH_ADMINISTRATOR)) + { + parent::__construct($subject, $config); + $this->loadLanguage('', JPATH_ADMINISTRATOR); + $this->_execute = true; + } + } + + /** + * Do all checks whether the plugin has to be loaded and load needed JavaScript instructions + */ + public function onBeforeCompileHead() + { + if($this->params->get('exclude_editor')) + { + if(class_exists('JEditor', false)) + { + $this->_execute = false; + } + } + + if($this->params->get('exclude_bots') AND $this->_execute == true) + { + $this->excludeBots(); + } + + if($this->params->get('exclude_components') AND $this->_execute == true) + { + $this->excludeComponents(); + } + + if($this->params->get('exclude_urls') AND $this->_execute == true) + { + $this->excludeUrls(); + } + + if($this->_execute == true) + { + JHtml::_('jquery.framework'); + + $doc = JFactory::getDocument(); + $document =& $doc; + + $document->addScript(JURI::base() . 'plugins/system/tmlazyload/tmlazyload.js'); + $document->addScriptDeclaration(' + jQuery(function($) { + $("img.lazy").lazy({ + threshold: 200, + visibleOnly: false, + effect: "fadeIn", + effectTime: 500, + throttle: 500, + afterLoad: function(element) { + if(typeof $.fn.BlackAndWhite_init == "function"){ + jQuery(element).parent("a").BlackAndWhite_init(); + } + setTimeout(function(){ + element.addClass("lazyloaded"); + },500) + } + }); + }); + '); + } + } + + /** + * Trigger onAfterRender executes the main plugin procedure + */ + public function onAfterRender() + { + + if(JFactory::getApplication()->input->getWord('view')=='image'){ + $this->_execute = false; + } + if($this->_execute == true) + { + $exclude_image_names = array_map('trim', explode("\n", $this->params->get('exclude_imagenames'))); + $exclude_imagenames_toggle = $this->params->get('exclude_imagenames_toggle'); + $dom = new DOMDocument(); + libxml_use_internal_errors(true); + $dom->loadHTML(JFactory::getApplication()->getBody(false)); + + foreach($dom->getElementsByTagName('img') as $img) + { + $src = $img->getAttribute('src'); + $img_name = parse_url($src); + $img_name = $img_name['path']; + $img_name = explode('/', $img_name); + $img_name = end($img_name); + if(count($exclude_image_names)){ + $continue = false; + if($exclude_imagenames_toggle == 0){ + foreach($exclude_image_names as $exclude_image_name){ + if($exclude_image_name != '' && strpos($img_name, $exclude_image_name)===0){ + $continue = true; + } + } + } + else{ + $continue = true; + foreach($exclude_image_names as $exclude_image_name){ + if($exclude_image_name != '' && strpos($img_name, $exclude_image_name)===0){ + $continue = false; + } + } + } + if ($continue === true){ + continue; + } + } + if(!array_key_exists('host',parse_url($src))){ + $src = JURI::base().str_replace(JURI::base(true).'/', '', $src); + } + $size = @getimagesize($src); + $width = $size[0]; + $height = $size[1]; + $attributes = array(); + foreach($img->attributes as $attribute_name => $attribute_node) + { + $attributes[$attribute_name] = $attribute_node->nodeValue; + } + if(!array_key_exists('width',$attributes) || $attributes['width']==0 || $attributes['width']==''){ + $img->setAttribute('width',''.$width); + } + if(!array_key_exists('height',$attributes) || $attributes['height']==0 || $attributes['height']==''){ + $img->setAttribute('height',''.$height); + } + if(array_key_exists('class',$attributes)){ + $img->setAttribute('class', $attributes['class'].' lazy'); + } + else{ + $img->setAttribute('class','lazy'); + } + $img->setAttribute('data-src',''.$src); + $img->setAttribute('src', JURI::base().'plugins/system/tmlazyload/blank.gif'); + } + JFactory::getApplication()->setBody($dom->saveHTML()); + + $pattern = '/&[lg]t;/'; + $body = JFactory::getApplication()->getBody(false); + preg_match_all($pattern, $body, $matches); + + if(!empty($matches)) + { + foreach($matches[0] as $match) + { + $arg_1 = array('&lt;','&gt;'); + $arg_2 = array('<','>'); + + $matchlazy = str_replace($arg_1, $arg_2, $match); + $body = str_replace($match, $matchlazy, $body); + } + + JFactory::getApplication()->setBody($body); + } + + $pattern = '/&#160;/'; + preg_match_all($pattern, $body, $matches); + + if(!empty($matches)) + { + foreach($matches[0] as $match) + { + $arg_1 = '&#160;'; + $arg_2 = ' '; + + $matchlazy = str_replace($arg_1, $arg_2, $match); + $body = str_replace($match, $matchlazy, $body); + } + + JFactory::getApplication()->setBody($body); + } + + /*$pattern = "@]*src=[\"\']([^\"\']*)[\"\'][^>]*>@"; + preg_match_all($pattern, $body, $matches); + + if($this->params->get('exclude_imagenames') AND !empty($matches)) + { + $this->excludeImageNames($matches); + } + */ + } + } + + /** + * Excludes the execution in specified components if option is selected + */ + private function excludeComponents() + { + $option = JFactory::getApplication()->input->getWord('option'); + $exclude_components = array_map('trim', explode("\n", $this->params->get('exclude_components'))); + $hit = false; + + foreach($exclude_components as $exclude_component) + { + if($option == $exclude_component) + { + $hit = true; + break; + } + } + + if($this->params->get('exclude_components_toggle')) + { + if($hit == false) + { + $this->_execute = false; + } + } + else + { + if($hit == true) + { + $this->_execute = false; + } + } + } + + /** + * Excludes the execution in specified URLs if option is selected + */ + private function excludeUrls() + { + $url = JUri::getInstance()->toString(); + $exclude_urls = array_map('trim', explode("\n", $this->params->get('exclude_urls'))); + $hit = false; + + foreach($exclude_urls as $exclude_url) + { + if($url == $exclude_url) + { + $hit = true; + break; + } + } + + if($this->params->get('exclude_urls_toggle')) + { + if($hit == false) + { + $this->_execute = false; + } + } + else + { + if($hit == true) + { + $this->_execute = false; + } + } + } + + /** + * Excludes the execution in specified image names if option is selected + * + * @param $matches + */ + private function excludeImageNames(&$matches) + { + $exclude_image_names = array_map('trim', explode("\n", $this->params->get('exclude_imagenames'))); + $exclude_imagenames_toggle = $this->params->get('exclude_imagenames_toggle'); + $matches_temp = array(); + + foreach($exclude_image_names as $exclude_image_name) + { + $count = 0; + + foreach($matches[1] as $match) + { + if(preg_match('@'.preg_quote($exclude_image_name).'@', $match)) + { + if(empty($exclude_imagenames_toggle)) + { + unset($matches[0][$count]); + } + else + { + $matches_temp[] = $matches[0][$count]; + } + } + + $count++; + } + } + + if($exclude_imagenames_toggle) + { + unset($matches[0]); + $matches[0] = $matches_temp; + } + } + + /** + * Excludes the execution for specified bots if option is selected + */ + private function excludeBots() + { + $exclude_bots = array_map('trim', explode(",", $this->params->get('botslist'))); + $agent = $_SERVER['HTTP_USER_AGENT']; + + foreach($exclude_bots as $exclude_bot) + { + if(preg_match('@'.$exclude_bot.'@i', $agent)) + { + $this->_execute = false; + break; + } + } + } + + /** + * Checks whether all requirements are met for the execution + * + * @param $admin Allow backend execution - true or false + * @param $version_min Minimum required Joomla! version - e.g. 3.2 + * @param $extension_name Name of the extension of the warning message + * @param $extension_system_name System name of the extension for the language file loading - e.g. plg_system_xxx + * @param $jpath Path of the language file - JPATH_ADMINISTRATOR or JPATH_SITE + * + * @return bool + */ + private function checkVersionRequirements($admin, $version_min, $extension_name, $extension_system_name, $jpath) + { + $execution = true; + $version = new JVersion(); + + if(!$version->isCompatible($version_min)) + { + $execution = false; + $backend_message = true; + } + + if(empty($admin)) + { + if(JFactory::getApplication()->isAdmin()) + { + $execution = false; + + if(!empty($backend_message)) + { + $this->loadLanguage($extension_system_name, $jpath); + JFactory::getApplication()->enqueueMessage(JText::sprintf('KR_JOOMLA_VERSION_REQUIREMENTS_NOT_MET', $extension_name, $version_min), 'warning'); + } + } + } + + return $execution; + } +} diff --git a/deployed/tmlazyload/plugins/system/tmlazyload/tmlazyload.xml b/deployed/tmlazyload/plugins/system/tmlazyload/tmlazyload.xml new file mode 100644 index 00000000..b8c3f366 --- /dev/null +++ b/deployed/tmlazyload/plugins/system/tmlazyload/tmlazyload.xml @@ -0,0 +1,52 @@ + + + TM Lazy Load + 1.2.1 + 2014-07-04 + http://www.gnu.org/licenses/gpl-3.0 + Copyright 2014 Template Monster. All rights reserved. + Template Monster + + + PLG_TMLAZYLOAD_XML_DESCRIPTION + + tmlazyload.php + tmlazyload.js + blank.gif + index.html + + + en-GB/en-GB.plg_system_tmlazyload.ini + en-GB/en-GB.plg_system_tmlazyload.sys.ini + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
\ No newline at end of file