Printing the images loaded by Lazy Load for Joomla

4 years 3 months ago - 4 years 3 months ago #9325 by sfg85
As you know, you cannot print the images with lazy loading. I think it would be useful to add an excluding option which will exclude a page /templates/your_template/COMPONENT.PHP, which was intended as a print version of a document. Unfortunately, there isn't an option for excluding such URLs, generated with this file (you may exclude only whole URL — but it is not convenient), so I had to recode lazyloadforjoomla.php, redefining the function onAfterRender():
public function onAfterRender()
    {
	
		$viewRel = explode('?', $_SERVER["REQUEST_URI"]); 
		$viewRel = $viewRel[1];
		
        if($this->_execute == true && $viewRel != 'tmpl=component&print=1')

        {
            $blankimage = JURI::base().'plugins/system/lazyloadforjoomla/blank.gif';
            $body = JFactory::getApplication()->getBody(false);

            $pattern = "@<img[^>]*src=[\"\']([^\"\']*)[\"\'][^>]*>@";
            preg_match_all($pattern, $body, $matches);

            if($this->params->get('exclude_imagenames') AND !empty($matches))
            {
                $this->excludeImageNames($matches);
            }

            if(!empty($matches))
            {
                foreach($matches[0] as $match)
                {
                    $matchlazy = str_replace('src=', 'src="'.$blankimage.'" data-src=', $match);
                    $body = str_replace($match, $matchlazy, $body);
                }

                JFactory::getApplication()->setBody($body);
            }
        }
    }

The result you may see here (there is a print button in the left corner of the article)

However, if I upgrade the version, I will need to change the code again. That's why I would like to ask you to make this option always availible without core editing.

Philip

4 years 3 months ago #9327 by Vitja
Please login to view the response. Attention: You need a valid subscription to activate an account.

Kubik-Rubik Joomla! Extensions

Please support my work with a review in the Joomla! Extensions Directory: extensions.joomla.org/profile/profile/details/61997
4 years 3 months ago #9333 by Vitja
Please login to view the response. Attention: You need a valid subscription to activate an account.

Kubik-Rubik Joomla! Extensions

Please support my work with a review in the Joomla! Extensions Directory: extensions.joomla.org/profile/profile/details/61997
The following user(s) said Thank You: sfg85
4 years 3 months ago #9334 by sfg85
Please login to view the response. Attention: You need a valid subscription to activate an account.
4 years 3 months ago #9337 by Vitja
Please login to view the response. Attention: You need a valid subscription to activate an account.

Kubik-Rubik Joomla! Extensions

Please support my work with a review in the Joomla! Extensions Directory: extensions.joomla.org/profile/profile/details/61997
Time to create page: 0.149 seconds