Printing the images loaded by Lazy Load for Joomla

9 years 8 months ago - 9 years 8 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
The topic has been locked.
9 years 8 months ago #9327 by Viktor
Please log in to see the response. Attention: You need a valid subscription to activate an account.

Kubik-Rubik Joomla! Extensions
The topic has been locked.
9 years 8 months ago #9333 by Viktor
Please log in to see the response. Attention: You need a valid subscription to activate an account.

Kubik-Rubik Joomla! Extensions
The following user(s) said Thank You: sfg85
The topic has been locked.
9 years 8 months ago #9334 by sfg85
Please log in to see the response. Attention: You need a valid subscription to activate an account.
The topic has been locked.
9 years 8 months ago #9337 by Viktor
Please log in to see the response. Attention: You need a valid subscription to activate an account.

Kubik-Rubik Joomla! Extensions
The topic has been locked.
Time to create page: 0.198 seconds