Utilizing numerous copies of a single plugin

I recently integrated a plugin called flip-carousel.js into my website and here is an example of how it looks on the site.

Check out the sample implementation

Now, I encountered an issue when trying to use multiple instances of the same plugin. When initializing the plugin, the code looks like this:

$('article').flipcarousel({
    pagination: false,
    loader: true,
    itemsperpage: 3,
    randomizer: 0.7
});

To have multiple instances, I opted to use classes instead of elements. The plugin works by taking a list of elements and transforming them with injected elements along with the content in the HTML tags. Below is the code for implementing multiple instances:

var roomTypes = hotelData.getSelectedRoomTypeIds();
roomTypes.forEach(function(e){
    if($('.flip_article_' + e.toString()).length > 0){
        $('.flip_article_' + e.toString()).flipcarousel({
            pagination: false,
            loader: true,
            itemsperpage: 3,
            randomizer: 0.7
        });
    }
})

In this setup, I first created a series of elements with specific class names (e.g., flip_article_1210). I then loop through these elements to initialize the plugin. However, the problem arises when setting up the second carousel instance - it gets initialized but does not display any element items. I tried delving into the plugin code for modifications, but hit a dead end.

One idea I had was that the plugin relies on a parent class named flip-carousel where everything is appended to. If each carousel could have a unique parent class, perhaps it would work better. But, unfortunately, other methods are dependent on this structure.

If anyone can provide assistance or insights on this issue, I've included the source link to the plugin below. Your help would be greatly appreciated.

Here is the plugin source

Answer №1

After making some adjustments to the plugin, it is now functioning perfectly.

If you go to line number 73 in this file

Instead of $card = $('.card');, change it to

$card = $container.parent().find('.card');

You can preview the changes in this fiddle

UPDATE

To properly initialize the plugin, use the following code:

$('#flip1 article').flipcarousel({
    pagination: true,
    loader: true,
    itemsperpage: 3,
    randomizer: 0.7
});

$('#flip2 article').flipcarousel({
    pagination: true,
    loader: true,
    itemsperpage: 3,
    randomizer: 0.7
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Basic jQuery template design

Currently, I am developing a user interface that allows users to add or delete items with a similar layout. The process starts with one item and by clicking 'add', more items can be added. These items come in several different types. My current ...

Exploring and extracting values from nested arrays of objects in JavaScript and React

Hey there, I am having trouble getting the data from the backend server to display on a chart library. Can you please take a look at my code and help me out? const data = [ { id: "americano", data: [{x: "10",y: 10,}, {x: &quo ...

Looking for a specific search term within the middle of strings in an array

Is there a way to improve the autocomplete feature of my input field so that it shows suggestions based on any part of the word typed in? I currently have it set up to only show suggestions if the input matches the start of a word in the array. How can I m ...

Incorporating Angular into the script code of the extension content

I am looking to customize text fields on a website using a chrome-extension. However, the website is built with Angular, so I need to modify the text fields using Angular code. To incorporate Angular in my extension's scope, I am attempting to declar ...

Tips for extracting data from arrays with multiple dimensions - (JavaScript)

I am looking to extract string values from a multi-dimensional array and store them in a new array as the answer. For Example : var dimStr = [ "First-one", ["Double-one", "Double-two", "Double-three", ["Triple-one", "Triple-two"] ], "First-two" ] ; The ...

Is there a way to run /_next/static/xxx.js using a script tag?

I have customized my next.config file (webpack) to generate a static JavaScript file (.next/static/loader.js). The original loader.js is an Immediately Invoked Function Expression (IIFE): (function stickerLoader(){ alert('Hello'); // ... so ...

Reorganizing the layout of grid items

Currently, I am working on a task involving GRID CSS. The main objective of the task is to utilize GRID specifically, rather than other methods like flex. I have successfully set up two columns in my GRID, each with its own divs. However, what I am struggl ...

Struggling to traverse through intricate layers of nested objects in React and showcasing them without going crazy

Dealing with an API that returns data structured in deeply nested objects has been a challenging task. The goal is to extract specific data from these nested objects and then display them within a React project. Despite numerous attempts, finding a simple ...

Detecting when the page is done loading in CasperJS with the help of $.ajaxStop()

During my CasperJS tests, I've relied on waitForSelector() to check if a page has finished loading, including all asynchronous AJAX requests. However, I'm interested in finding a more standard approach for waiting for page load. Is it possible to ...

Deliver PDF through ajax call and display in a new tab

I am utilizing an ajax request to a specific API URL in order to retrieve a PDF file. My goal is to then display this file in a new window. $("#pdfurl").click(function (e) { var Pdfurl = $(this).attr('data-href'); $.ajax({ url: " ...

How can one determine the dimensions of the browser window using a property?

Can someone please clarify how to find the width and height of the browser window specifically? Thanks in advance! ...

What could be causing my LESS files not to compile properly in grunt?

I've successfully installed npm and ran npm init. Additionally, I've installed the following packages using npm: grunt grunt-contrib-less grunt-contrib-watch jit-grunt --save-dev My Gruntfile.js configuration looks like this: module.exports = f ...

Error: Unable to set attribute because the property is undefined in the onLoad function

Can anyone help troubleshoot this error? List of included files: <link rel="stylesheet" href="../../node_modules/semantic-ui/dist/semantic.min.css"> <link rel="stylesheet" href="../../node_modules/font-awesome/css/font-awesome.min.css"> <l ...

How can you restrict a textbox input to accept only numerical values and decimals using ng-pattern?

I'm working on a code that needs to accept both decimals and integers. How can I verify this using the ng-pattern? An example of the code: Some test cases include: 1) 22 = Should pass, 2) 22.5 = Should pass, 3) 2a = Should fail, 4) @#@ = Should ...

Sending an array through an AJAX request to a Java class using Struts2

Issue with Javascript-AJAX Call function assignTask(){ var formdata = "xyz"; var taskList = []; $.each($("input[name='taskname']:checked"), function(){ taskList.push($(this).val()); }); $.ajax({ type: "post", data: {taskList:taskList ...

Implementing Sass mixin transition to specifically add transition-delay - a comprehensive guide

As I continue to enhance my front-end development skills and practice Sass to optimize my CSS code, I encountered a roadblock. After exploring resources and tutorials online, I created a global mixin in Sass named 'transition'. Here is the code: ...

What steps do I need to take in order to create a web-based file uploader that supports simultaneous uploads of multiple files

Is there a way to create the ability for users to upload multiple files at once on a Django/Python/jquery website, similar to the Gmail file selection feature? I am looking to allow users to select multiple files from their browser file selector and uplo ...

The componentWillUnmount method is not being called

I'm currently working on a Backbone application and I'm in the process of integrating React components. The React component is being mounted using the following code: ReactDOM.render( <WrappedComponent />, node ); where "node" represents ...

What is the simplest way to shift an icon to the right in the header of an Expansion panel using Vuetify

After implementing the template from this example: https://vuetifyjs.com/en/components/expansion-panels/#usage I am facing an issue where the header icon is stuck to the title Even applying "float: right;" does not seem to resolve it Has anyone els ...

Transferring callback variables from an Express GET request to a forked process in Node.js

I encountered an issue while trying to transfer the callback variables from app.get() to a forked process. The error message I received was: TypeError: Converting circular structure to JSON The primary goal behind this endeavor is to enable a main node w ...