]+?)src=[\'"]?([^\'"\s>]+)[\'"]?([^>]*)>#',
array( __CLASS__ , 'replace_callback' ),
$content
);
}
/**
* Replace callback
*
* @param array $matches The matches value from content.
* @return string The content
*/
/**
* [replace_callback description]
*
* @param array $matches [description]
*
* @return string [description]
*/
static function replace_callback( $matches ) {
$placeholder_image = self::get_placeholder();
$content = '';
/**
* Replace srcset, sizes and src attributes
*/
$content = str_replace(
array( 'srcset', 'sizes' ),
array( 'data-srcset', 'data-sizes' ),
sprintf(
'
',
$matches[1],
$placeholder_image,
$matches[2],
$matches[3]
)
);
/**
* Add noscript fallback plus microdata
* The meta tag works only if there is Schema.org markup
*/
$content .= sprintf(
'',
$matches[1],
$matches[2],
$matches[3]
);
return $content;
}
/**
* Get the placeholder
*
* @return string THe placeholder
*/
private static function get_placeholder() {
/**
* In case you want to change the placeholder image use filter
* ItalyStrapLazyload_placeholder_image
* Gif link
*
* @link http://clubmate.fi/base64-encoded-1px-gifs-black-gray-and-transparent/
* Gif nera
* data:image/gif;base64,R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs=
* Gif grigia
* data:image/gif;base64,R0lGODlhAQABAIAAAMLCwgAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==
* Gif trasparente
* data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
* @var string
*/
$placeholder_image = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7';
if ( ! empty( self::$options['lazyload-custom-placeholder'] ) ) {
$placeholder_image = self::$options['lazyload-custom-placeholder'];
}
return apply_filters( 'italystrap_lazy_load_placeholder_image', $placeholder_image );
}
/**
* Read and return unveil.js
*
* @link https://tommcfarlin.com/reading-files-with-php/
* @param file $filename The file for lazyloading.
* @return string [description]
*/
static function get_unveil( $filename ) {
$content = '';
$content = \ItalyStrap\Core\get_file_content( $filename );
/**
* Add script for img opacity
*
* @var string Js Code.
*/
// $output = 'jQuery(document).ready(function($){$("img").unveil(200, function(){$("img").load(function(){this.style.opacity = 1;});$(this).parent("img").css( "opacity","1");});});';
//Da testare
// $output = 'jQuery(document).ready(function($){$("img").unveil(200, function(){$(this).load(function(){$(this).css( "opacity","1");});});});';
$content .= 'jQuery(document).ready(function($){$("img").unveil(200, function(){$("img").load(function(){this.style.opacity = 1;});});});';
return $content;
}
/**
* Add css to opacize img first are append to src
*
* @return string Add opacity and transition to img
*/
static function custom_css() {
$custom_css = 'img{opacity:0;transition:opacity .3s ease-in;}';
/**
* return $custom_css;
*/
return null;
}
}