jquery-flipster icon indicating copy to clipboard operation
jquery-flipster copied to clipboard

How do you find if it's already initialized without re-initializing?

Open ItsDanielHarris opened this issue 8 years ago • 2 comments

How would I find if it's already initialized without re-initializing it again? Here's what I tried, but it always initializes it in the if condition without the parameters.

            function init_flipster() {
                    if ($(window).width() <= 614 && !($('.flipster').flipster())) {
                            $('.flipster').flipster({
                                    style: 'carousel',
                                    spacing: -0.5,
                                    buttons: true,
                                    loop: true,
                                    touch: true
                            });                                       
                    }
            }

ItsDanielHarris avatar Nov 17 '17 18:11 ItsDanielHarris

You could check if container has class flipster--active

 if ($(window).width() <= 614 && !($('.flipster').hasClass('flipster--active'))) {
                            $('.flipster').flipster({
                                    style: 'carousel',
                                    spacing: -0.5,
                                    buttons: true,
                                    loop: true,
                                    touch: true
                            });                                       
                    }
```

brnosouza avatar May 16 '18 14:05 brnosouza

You could also just keep track of it yourself:

(function() {
    "use strict";

    is_flipster_initialized = false;

    function init_flipster() {
        if(is_flipster_initialized) {
            return;
        }

        // init flipster here
        
        is_flipster_initialized = true;
    }
}());

rmilesson avatar Aug 08 '18 09:08 rmilesson

This repository is going into very-low-maintenance mode and declaring backlog bankruptcy

drien avatar Jan 18 '24 00:01 drien