get( 'Version' );
wp_enqueue_script(
'flatsome-lazy',
$extensions_uri . '/flatsome-lazy-load/flatsome-lazy-load.js',
array( 'flatsome-js' ),
$version,
true
);
}
static function add_image_placeholders( $content ) {
if ( ! self::is_enabled() )
return $content;
// Don't lazyload for feeds, previews, mobile
if ( is_feed() || is_preview() )
return $content;
$matches = array();
preg_match_all( '/
/is', $content, $matches );
$search = array();
$replace = array();
$i = 0;
foreach ( $matches[0] as $imgHTML ) {
// don't do the replacement if the image is a data-uri
if ( ! preg_match( "/src=['\"]data:image/is", $imgHTML ) ) {
$i++;
// generate a base64 image string
$src = self::create_base64_string( $imgHTML );
// replace the src and add the data-src attribute
$replaceHTML = '';
if ( false === strpos( $imgHTML, 'data-src' ) ) {
$replaceHTML = preg_replace( '/
$attr ) {
$value = intval( $matches[2][ $key ] );
if ( $attr === 'width' ) $size[0] = $value;
if ( $attr === 'height' ) $size[1] = $value;
}
return $size;
}
static function create_base64_string( $imgHTML ) {
list( $width, $height ) = self::get_image_size( $imgHTML );
$svg = '