Skip to content

[SOLVED] Fancybox doesn't work in chat

Bugs
  • For those of you using Fancybox, you’ve probably noticed that it doesn’t seem to work in Chat since the upgrade to v3. Looking at the function, it’s pretty obvious why

    if (top.location.pathname !== '/login') {
        $(document).ready(function() {
            $(window).on('action:ajaxify.end', function(data) {
                this.$('a').not('.forum-logo').not(".avatar").not(".emoji").not(".bmac-noanimate").each(function() {
                    $('a[href*=".jpg"], a[href*=".jpeg"], a[href*=".png"], a[href*=".gif"], a[href*=".webp"]').addClass("noanimate");
                    data.preventDefault()
                    // Strip out the images contained inside blockquotes as this looks nasty :)
                    $('blockquote img').remove();
                });
                Fancybox.bind(
                    'a[href*=".jpg"], a[href*=".jpeg"], a[href*=".png"], a[href*=".gif"], a[href*=".webp"]', {
                        groupAll: true,
                    }
                );
            });
        });
    }
    

    The function above targets a href where in fact, in the chat window, it doesn’t exist - it’s just an img tag

    6e601da6-93a0-44a0-b49f-d1a78e589804-image.png

    Not very helpful, so I will need to modify this function. I’ll advise as soon as I have it working in case you want to use on your own forums 🙂

  • Ok, this will work. Chats are now handled differently, so the two below functions need to be added to your custom js

    // Chat fancybox - fires when chat module loaded and AJAX calls new chat
    $(document).ready(function() {
        $(window).on('action:chat.loaded', function(data) {
                this.$('img').not('.forum-logo').not(".avatar").not(".emoji").not(".bmac-noanimate").each(function() {
                    var newHref = $(this).attr("src");
                    $(this).wrap("<a class='fancybox' href='" + newHref + "'/>");
                    $('a[href*=".jpg"], a[href*=".jpeg"], a[href*=".png"], a[href*=".gif"], a[href*=".webp"]').addClass("noanimate");
                    data.preventDefault();
                    // Strip out the images contained inside blockquotes as this looks nasty :)
                    $('blockquote img').remove();
                });
                Fancybox.bind(
                    'a[href*=".jpg"], a[href*=".jpeg"], a[href*=".png"], a[href*=".gif"], a[href*=".webp"]', {
                        groupAll: true,
                    }
                );
        });
    });
    
  • EDIT: Sorry all, I found a bug that causes Fancybox to be bound twice.

    Please remove the original functions I provided (the original post has been updated for anyone who did not use the original code and is new here) and replace with just this block

    // Chat fancybox - fires when chat module loaded and AJAX calls new chat
    $(document).ready(function() {
        $(window).on('action:chat.loaded', function(data) {
                this.$('img').not('.forum-logo').not(".avatar").not(".emoji").not(".bmac-noanimate").each(function() {
                    var newHref = $(this).attr("src");
                    $(this).wrap("<a class='fancybox' href='" + newHref + "'/>");
                    $('a[href*=".jpg"], a[href*=".jpeg"], a[href*=".png"], a[href*=".gif"], a[href*=".webp"]').addClass("noanimate");
                    data.preventDefault();
                    // Strip out the images contained inside blockquotes as this looks nasty :)
                    $('blockquote img').remove();
                });
                Fancybox.bind(
                    'a[href*=".jpg"], a[href*=".jpeg"], a[href*=".png"], a[href*=".gif"], a[href*=".webp"]', {
                        groupAll: true,
                    }
                );
        });
    });
    
  • phenomlabundefined phenomlab forked this topic on
  • DownPWundefined DownPW referenced this topic on

  • 6 Votes
    13 Posts
    123 Views

    @phenomlab yes, search page is fixed 🙂 thanks 👍

  • Loading Image Problem

    Bugs
    24
    6 Votes
    24 Posts
    1k Views

    Thank you Mark.

  • Is NTFY working properly on iOS?

    Bugs
    10
    5 Votes
    10 Posts
    427 Views

    @phenomlab thx, the same for us. It sees 1.7.3 as the last version although it is updated to 1.7.4… i will report this to @barisusakli

  • Bug Report

    Solved Bugs
    43
    21 Votes
    43 Posts
    976 Views

    @crazycells yep. I get it! Good point.

  • Nodebb 3.2.2

    Bugs
    27
    11 Votes
    27 Posts
    1k Views

    @crazycells yes, I’ve just seen that and modified the post. It seems to only happen if you have a space between the “greater than” symbol and the actual text.

    Clearly a markdown thing.

  • Nodebb 3.2.0

    Bugs
    20
    2 Votes
    20 Posts
    578 Views

    @crazycells yes, I’m aware of that. Need to fix

    EDIT- fixed. Caused by the same CSS that is used to absolutely position the “verified” group badge in the posts view. Amended this CSS so that is specifically targets the post stream as below

    li[component="post"] a[href*="/groups/verified"] { position: absolute !important; left: 8px; z-index: 2; margin-top: 1px; border-radius: 999px !important; line-height: 14px; display: block; height: 22px; margin-left: 0px !important; }
  • Permission issues

    Solved Bugs
    8
    2 Votes
    8 Posts
    245 Views

    @Panda I forked this topic out of the previous thread as it’s an issue in it’s own right. Having checked, I see the reason why

    06d082f0-6c7d-443b-98bc-94db5f3e5d0e-image.png

    As you can see from the screenshot, category “Announcements” does not permit editing. This specific category was originally read only, which I then changed to members could reply. Looks like I forgot to add the right to edit 😕

    Should be fixed now

    a533d8ff-23f1-432e-a4a6-3d10cb05a46d-image.png

  • 3 Votes
    6 Posts
    1k Views

    @phenomlab

    haha!!
    You are crazy. In a good way, of course 🙂

    It’s a way of saying you’re awesome !