a3rev / a3-lazy-load

Speed up your site and enhance frontend user's visual experience in PC's, Tablets and mobile with a3 Lazy Load.
GNU General Public License v3.0
18 stars 11 forks source link

Allow `.*` to be used in the skipped class list as a wildcard #20

Closed KZeni closed 6 years ago

KZeni commented 6 years ago

This still performs preg_quote, but it selectively allows .* to be used in the skipped class list as a wildcard.

As an aside, I've posted about this on the WP.org support forum at: https://wordpress.org/support/topic/proposed-patch-allow-to-be-used-in-the-skipped-class-list-as-a-wildcard/

KZeni commented 6 years ago

This only applies to images for now. I had to remove the iframe/video wildcard implementation as those weren't behaving properly, and I didn't have availability at the time to address this.

Ideally, the wildcard should be able to work for both... just need to implement it.

alextuan commented 6 years ago

Hi KZeni

Actual that wildcard is automatically add to skipped Classes feature, for example your image has class like this size-thumbnail , and then if you add this class to Skip Classes list like this thumbnail, then it still works , I mean the image has class size-thumbnail will be not apply lazyload

It's same for Video, Iframe

Just small bug appear if you enter to Skip Classes with a wildcard like .*thumbnail, it will not work so that plugin will automatically convert it to like this .*.*thumbnail, and it's wrong.

So i have tweak bit on this so that the Skip Classes work for both way use this thumbnail or .*thumbnail . That also will apply for Image and Iframe, Video, ...

Will not pull your request but THANKS for your suggestion so that i have look on plugin code again and solve that small bug.

alextuan commented 6 years ago

Hi KZeni

You can look some tweaks i just commit at https://github.com/a3rev/a3-lazy-load/commit/1095d9dc2d0e3b05383c4718a314c1b074af41d7

alextuan commented 6 years ago

So i will close this pull request , thanks

KZeni commented 6 years ago

Understood. I appreciate the info & follow up adjustments! đź‘Ť

KZeni commented 5 years ago

This isn't anything actionable on a3 Lazy Load's end. I want to follow up on my https://wordpress.org/support/topic/excluding-metaslider-image-class/ comment of:

I’m using msDefaultImage,slide-. as my skipped image classes with https://github.com/a3rev/a3-lazy-load/pull/20 applied so that . works as a wildcard (since metaslider gives classes with unique ids making them not readily selectable with a static class). The images load right away after doing so for myself.

Keep in mind that this isn’t an official patch/version update as of yet. So updating the code yourself & managing the updates afterwards is something you’ll need to take into account. That being said, I’ve requested that this be officially implemented in a future version of the plugin.

Since it's not totally fleshed out (doesn't account for Flexslider carousels using MetaSlider), that topic's otherwise closed due to inactivity, and I've come across something that could be helpful for others.

I want to add...

Implement the following in the theme's functions.php file to make it so MetaSlider applies a consistent image class name to all images regardless of being a slider (where the slide-* option worked) or a carousel (where MetaSlider wasn't adding any image classes to work with previously):

// Apply an always-consistent class to the Flexslider images in MetaSlider (applies to sliders & carousels). This is helpful for being able to exclude these via a3 Lazy Load's class exceptions.
function metaslider_change_image_attributes($attributes, $slide, $slider_id) {
    $attributes['class'].= ' slide-img';
    return $attributes;
}
add_filter('metaslider_flex_slider_image_attributes', 'metaslider_change_image_attributes', 10, 3);

This adds slide-img as a class to all Flexslider image elements while keeping any of the exisitng ones it might otherwise have. This then makes it so they're all easily targetable via the class exceptions in a3 Lazy Load. As an aside, you can swap out flex in the filter's name for the slider type being used by MetaSlider as needed (per: https://www.metaslider.com/documentation/metaslider_type_slider_image_attributes/)