WordPress.org

Support

Support » Plugins and Hacks » [Plugin: Easy FancyBox] Modify img selectors

[Plugin: Easy FancyBox] Modify img selectors

  • I’m trying to alter the jQuery selectors for images which the plugin uses, and the way I’ve figured out to do it is:

    function easy_fancybox_mod() {
    	global $easy_fancybox_array;
    	$easy_fancybox_array['IMG']['options']['autoAttribute']['selector'] = "href*=";
    }
    
    add_action('wp_head','easy_fancybox_mod',998);

    Is there a better/easier way to do this? Does the Easy Fancybox plugin provide a filter for this?

    The reason for the change is that the W3 Total Cache plugin appends query strings to the image link href value, which prevents the existing jQuery selectors $a[href$="jpg"] from recognizing the links because the “jpg” is no longer at the end of the URL.

    http://wordpress.org/extend/plugins/easy-fancybox/

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author RavanH

    @ravanh

    Hmmm, I see the reason you would want this… And I see no easier way since there is no hook in my plugin that allows this.

    The problem is that for the following versions I cannot guarantee the array will remain like it is.

    Does W3TC always append the same query string or does it change in time or is different per image? if it’s always the same, you could simply append the query string to the file extensions as defined on your Settings > Media page in the Auto-detect field.

    Or you could munually add the class “fancybox” to each image link and switch off auto-detection…

    Thanks @ravanh. The query string varies. The point of it is that it allows the plugin to change the link when the cache settings have changed, thereby forcing the browser cache to reload the image/link.

    And adding the class manually is not really an option, because then I’d have to explain it to my clients, and well, some of them are not as technically proficient as I might prefer.

    Any chance you could be talked into adding a hook for this in a future version? Or a hidden option in the admin or something?

    Plugin Author RavanH

    @ravanh

    OK, you’re working with clients… I understand 😉

    Any chance you could be talked into adding a hook for this in a future version? Or a hidden option in the admin or something?

    Not a chance, sorry. Because you’ve got me thinking about it already :p

    Making this an option (even a hidden one) will take more time than I have right now but… The thing is that I need to be sure that simply making href*= the default instead of href$= will not cause problems for others after upgrading.

    Can you imagine any situation where “.jpg” or “.png” or any other image file extension could be present in any link URL without being a link to an actual image, causing trouble by getting the FancyBox function attached to it?

    Well, I think that changing the selector to href*= might mean that it would be better to add in the dot: $a[href*=".jpg"]. At least then it’s looking explicitly for a dot extension and wouldn’t find something like myjpg.doc. The only instance I can think of where it fails would be something like notanimage.jpg.php or http://mysite.com/page.php?param=image.jpg, but I’m hard pressed to think of an actual case for this becoming a problem or breaking existing functionality, primarily because WordPress’ default image link behavior is so simple.

    That said, I am not a jQuery expert, so if anyone else cares to weigh in on this, that would be great. There is a parallel conversation going on about the jQuery selector here: http://stackoverflow.com/questions/9501929/jquery-selector-for-links-to-images-which-tolerates-query-strings#comment12060207_9501929

    Plugin Author RavanH

    @ravanh

    Well, I think that changing the selector to href*= might mean that it would be better to add in the dot: $a[href*=”.jpg”].

    The dot is already in the source code script, just not on the options page (yet) …

    The only instance I can think of where it fails would be something like notanimage.jpg.php or page.php?param=image.jpg

    That last example link already gets fancybox bound to it (unless the .jpg is followed by other query parameters), but indeed that first case would be treated the same with $a[href*=".jpg"] … Like you, I do not see that kind of links often.

    For those rare cases, there is always the class ‘nofancybox’ available to exclude the link manually.

    So I’ve changed it in the dev version. Changes should be available soon on http://downloads.wordpress.org/plugin/easy-fancybox.zip so if you’d like to test, be my guest… Feedback appreciated 🙂

    It works perfectly now on my test site with W3 Total Cache appending the query string. I’ll let you know if I see anything wonky.

    There is nothing I love better than responsive, friendly developers in forums. OK, maybe really good hand-churned ice cream. But other than that, nothing! 🙂

    Logged in to say thanks so much for this – I was having the same problem & downloading the zip file above and uploading the new easy-fancybox files fixed the issue instantly!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘[Plugin: Easy FancyBox] Modify img selectors’ is closed to new replies.