question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Working with Photoswipe in meteor init() function not working properly

See original GitHub issue

I keep getting an error that states “spectrum_photoswipe.js:63 Uncaught TypeError: Cannot read property ‘className’ of undefined” It’s refrencing this block of code:

 removeClass: function(el, className) { var reg = new RegExp('(\\s|^)' + className + '(\\s|$)');
  el.className = el.className.replace(reg, ' ').replace(/^\s\s*/, '').replace(/\s\s*$/, '');  }

My code is passing items and options correctly like so:

    var listingId = template.data.listingId,
    imgs = ListingCollection.findOne({_id: listingId}).images;
    var items = [];
    for(var i =0; i < imgs.length; i++) {
        var tempImg = new Image();
        tempImg.src = imgs[i];
        var itemObject = {"src": "", "w": "", "h": ""};
            itemObject.src = imgs[i];
            itemObject.w = tempImg.width;
            itemObject.h = tempImg.height;
        items[i] = itemObject;
    }
    var options = {
        index: 0,
        history: false,
        focus: false,
        showAnimationDuration: 0,
        hideAnimationDuration: 0
    };

    var gallery = new PhotoSwipe( pswpElement, PhotoSwipeUI_Default, items, options);
    gallery.init();

And I’ve checked to make sure that the pswp element is in the DOM. I’m not really sure what’s going on here. Any help would be greatly appreciated

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
chesiocommented, May 27, 2016

Well, I’m not the plugin author 😃 Btw. in #1128 someone already mentioned issues with -- in comment. Glad you got it working!

0reactions
sylverfystcommented, May 27, 2016

Thank you! That was the issue, one of the commented out sections in the pswp uses – in the comment:

<!-- element will get class pswp__preloader--active when preloader is running -->

and that commented out the pswp__preloader class. You might want to consider changing that comment in the documentation. Thanks for the help!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting Started - PhotoSwipe
PhotoSwipe requires predefined image dimensions, you must define the width and height of each image. PhotoSwipe is not designed to display very large...
Read more >
Very low meteor performance in production
I see that your site has large images that can slow down, on the other hand does not use the rendering server, however...
Read more >
How to allow the user to click on a link while ... - Stack Overflow
EDIT: This is how I initialize the photoswipe gallery. function showSoftwareGallery(sections, index){ var pswpElement = document.
Read more >
Dogfalo/materialize - Gitter
The material_select() call is being executed I guess because of the added HTML to the ... its working and more issues are appearing,...
Read more >
Rocket.Chat - HISTORY.md - OW2 Gitlab
Creation of Omnichannel rooms not working correctly through the Apps ... the Template events() call, once in the reactions init.js and the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found