JQuery Stateful Plugin

Creating a JQuery plugin (https://github.com/mikebski/demano) for filtering objects on a page, I needed a way to create a stateful JQuery plugin.

This is done by attaching all of the configuration for the plugin to the actual DOM element we create the plugin on. This allows multiple separate “instances” of the plugin on the page. The only catch is that each must be on a separate DOM entity.

Here’s the example code, here it is on JSFiddle: https://jsfiddle.net/mbaranski/q2rarzfn/ and here is the github plugin: https://github.com/mikebski/demano/:

Note that we proxy the click listener so that “this” in the callback function points to the DOM element that the configuration is attached to.

Here’s a practical example -> https://github.com/mikebski/demano

Leave a Reply

Your email address will not be published. Required fields are marked *