Expanding images in Help Center articles | Community
Skip to main content

Expanding images in Help Center articles

  • September 23, 2018
  • 67 replies
  • 0 views

Show first post

67 replies

Joshua25
  • Author
  • February 6, 2020

Eric,

Do you have the class name on the image you want to expand?

<img class="fancybox" src="image.png" alt="alt text">


  • February 6, 2020

Hi Joshua,

Thanks for the prompt response. No, I don't have the class name on the image. That must be it. How do I put a class name on an image? Do I change the file name? Or do these images need to be added via CSS; not the image uploader in articles? Thanks again.


  • February 6, 2020

UPDATE: I used the source code button in the WYSIWYG editor to add the class name to each image, however, it didn't do anything. Thoughts?


Joshua25
  • Author
  • February 6, 2020

Eric,

After you load the image with the uploader in the article, click on the Source Code button on the right side of the editor.

In the Code pop-up, add the class name to the image tag, as you see above. You don't need to do anything else. 

Good luck!

Joshua


  • February 6, 2020

Hi Josh,

I did this, but it didn't do anything. Any other ideas?


Joshua25
  • Author
  • February 6, 2020

Can you load a screenshot of what you did?


  • February 6, 2020

Here's the code with the class added...


Joshua25
  • Author
  • February 6, 2020

Did you try doing a hard refresh of the article in your browser (not the editing page, the customer-facing page)? Hold down CTRL and press F5. 

You might also use the Code Inspector to make sure the class name is actually showing up where it should and the CSS and JS links you added in the header are being applied. If not, make sure you added those to the right template. 


  • February 12, 2020

I have implemented this for on of my articles which worked. After updating the article with a new image, I noticed it no longer expands. Double checked that the class was added but still no go.

We did add an extra class to images for another reason. So I removed the additional class to rule it out - still no go.

Also tried adding the additional class to the script but there I just made things worse in other articles.

Did something change in the fancybox code perhaps?

Its only one article where I require this function so not stressing too much. To get around this I'm linking the image to itself so that it opens a larger view in a new window.


Joshua25
  • Author
  • February 12, 2020

@Jacques van Rensburg Did you double check that the header is still in place and the JS is correct? 


  • February 12, 2020

Yes, all appeared to be correct at the time.
I'll try setting up again when I have a moment


  • February 12, 2020

@Joshua Tallent, that's what I did. I think the code on this may need to be updated. See the code that @Marco van der Valk included in his screenshot above. It's not the code you reference in your article. He used different coding on script.js to get it to work. Not sure if you saw that. Thoughts?


  • February 13, 2020

Hi @Joshua Tallent

Some feedback:
I've removed and copied the links back into document_head.hbs
In script.js I checked everything is correct, but removed and copied everything back in again.
Added class="fancybox" to the <img> element.

Viewing the elements, the image is shown as img.fancybox.
Under sources I see fancybox/3.2.5 under cdnjs.cloudfare.com

I also tried Marco's solution.
Got it to work once, I think, to add the attribute and zoom. The problem is I only need to apply it to one image, so tried to select only the image with the alt="roadmap". Subsequent loads did not add the additional attributes so think I made a typo somewhere and did not look further.

The buttons in his code did not work for me. I did notice that I was getting a '.fancybox is not a function' in the console.
Quick Google search and found plenty questions out there with similar issues. Some saying they started seeing this issue from Dec 2019 for jquery 3.x

Afraid that is how far I got - need to get onto other work now, so I'm going back to the image opening in an alternative window for now.

Thx, Jacques


Joshua25
  • Author
  • February 13, 2020

@Eric Haley What Marco did is completely different than the original design. If that works for you, then by all means feel free to use it.

The code I posted originally works perfectly in my knowledge base, and should in any other. If it does not, then there's something else getting in the way, probably a code issue. You might want to paste your JS into a validator to make sure you don't have any other issues keeping that piece of code from working properly. Beyond that, I don't know what to tell you. 


  • February 13, 2020

Hi @Joshua Tallent, I never touched the javascript until I added the code from this article. So if there are any issues, they would have come that way out-of-the-box. Perhaps it's a systemic issue that's getting in the way and Zendesk should take accountability for it instead of putting it on their customers. I don't know how to use a javascript validator as I'm not a coder. So, I'm giving up on this solution. Three people have posted issues with the instructions in the article. Just pointing out the obvious. You do what you wish. Thank you anyway for your time and effort. 


Joshua25
  • Author
  • February 13, 2020

As I said, the code I posted seems to work fine from what I can tell. I'm sorry you were not able to get it to work in your case. I agree that Zendesk should just make this a standard function that does not require special work. 


  • March 23, 2020

Hi - we are in the process of going live with our Help Centre and were successfully using your fancy box functionality in our draft Theme.

Our stylesheet developer has just upgraded us the Guide templating API V 2 which came out a few weeks ago - and now the fancy box no longer works.  He suggested loading the latest jquery library as the new framework no  longer loads it automatically, but this has not resolved the issue.  Do you have any thoughts on how to make it work ?  here is what we have tried in document_head.hbs. 

<script
src="https://code.jquery.com/jquery-3.4.1.min.js"
integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
crossorigin="anonymous"></script>

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.2.5/jquery.fancybox.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.2.5/jquery.fancybox.min.js"></script>




Joshua25
  • Author
  • March 23, 2020

@Kate Rowe You might try using the Inspector tool on Chrome or Firefox to see if the CSS is being applied correctly or being overwritten somehow. 

Also, @Jessie Schutz might be able to ask the dev team to look into whether the latest update broke support for this workaround.

As I have said since the beginning, it would be better if ZenDesk would just offer this feature natively instead of relying on workarounds that are so finicky. Maybe some day they will actually spend some time adding new features to Guide instead of only working on other parts of the ZD system. 


  • March 24, 2020

Thanks for the quick response @Joshua Tallent! We have tried that, but no luck.  Agree that would be much preferable if we had this capability in the platform.


  • April 3, 2020

HI
I am getting no reaction from the code. Could you please take a look.

Here is my set up.

document_head i added these two lines

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.2.5/jquery.fancybox.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.2.5/jquery.fancybox.min.js"></script>

scripts.js I added code below the //fancybox and before the closing });

// Communities active class
$('.my-activities-nav.nav-bordered li, .my-activities-sub-nav.nav-spaced li').each(function(id, it) {
if(typeof $(it).find('a').get(0) == 'undefined') {
$(it).addClass('active');
}
});

// Bootstrap table class on article body
$('.article-body').find('table').wrap('<div class="table-responsive"></div>');

$('.community-enabled .search-results-column').addClass('col-sm-6');

// Function of set year
var x = new Date();
var y = x.getFullYear();
$('#year').html(y);

//Fancybox
$('.article-body img.fancybox').on('click', function() {
$.fancybox.open([
{
src : $(this).attr("src"),
opts : {},
},
]);
});

});

 

My HTML looks like this

<p>
<a class="fancybox" href="https://source.unsplash.com/0JYgd2QuMfw/1500x1000" data-caption="This image has a simple caption"> <img src="https://support.fleetcomplete.eu/hc/article_attachments/115002059411/mceclip1.png"> </a>
</p>

 

The image is just opening i a new tab.

I am getting no errors in the console.?

I hope you can see what is wrong.


  • April 3, 2020

Hi

Just wanted to let you know I am having better luck with the option from. 

http://fancyapps.com/fancybox/3/docs/#introduction

That provided approach is working for me. Thanks

 


Joshua25
  • Author
  • April 3, 2020

@Robert Holm, thanks for the info! I have updated the post to point people to that location if they are having trouble. 


  • January 20, 2021

I'm revisiting this solution and the original still does not work.
Tried the one from @Robert Holm and still no go.
However, I found this article from zenplates and they noted that 'Display unsafe html' must be enabled when using data attributes.
With that enabled it works great but company rules does not allow that. I looked through the options and samples but I suck at java so not sure how it can be implemented with the unsafe html option disabled.
Any suggestions?


Brett13
  • Community Manager
  • January 21, 2021

Hey Jacques,

As far as I know, any time your using custom code in your Guide theme (including Java) you'd need to have Display Unsafe Content enabled in your settings. Hopefully others can jump in here if they were able to find an alternative solution for you.


Joshua16
  • July 28, 2021

The installation as it stands requires jQuery to work. I went to the developers' website and found a different way to implement the lightbox.

  1. Add the following CSS link to the "document_head.hbs" file.
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.css"/>
  2. Add the following JS to the top of "article_page.hbs".
    <script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.js"></script>
    - You could add this to the head as well. I moved it to the article page to appear in the <body> for better performance.
  3. Add the following JavaScript to the bottom of the "scripts.js" file.
    function addFancyBox() {
    var images = document.querySelectorAll('.article-body img');
    images.forEach(function(el) {
    el.setAttribute('data-fancybox','');
    })
    }
    addFancyBox();
    - This adds the required data attribute to all images inside the article body. Modify this code if you want to be more specific. You can also forego this step if you want to add the data attribute manually.

  4. Add the following CSS to "style.css."
    img[data-fancybox] {
    cursor: pointer
    }

    - This makes the cursor turn into a hand when you mouse over an image, so the user knows they can click it.