npm.io
1.0.4 • Published 8 years ago

jquery-pluginify

Licence
MIT
Version
1.0.4
Deps
0
Size
8 kB
Vulns
0
Weekly
0

jQuery Pluginify

Convert plugin class into a jQuery plugin

Installation

npm i jquery-pluginify --save

Requires

ES6 Support

Options
Name Type Description
name string Plugin name reference
classname object Class reference
iterate bool Defaults to true.
True - Defines a class for every instance of the elements found.
False - Defines the class just once, and passes all element instances through to the class.
shorthand bool Defaults to false. Generate a shorthand as $.name
ignoreWarning bool Defaults to false. Set to true if you want to ignore the fact the jQuery isn't found at the time of calling this function.
Example
class myClass {
  constructor(elements, ...settings) {
    // console.log(elements, settings);
  }
}

Define default settings to apply to all instances of the class

myClass.settings = {};

Define settings like this:

pluginify('myPlugin', myClass, false, true);

Or like this (in any order):

pluginify({
  name      : 'myPlugin',
  classname : myClass,
  shorthand : false,
  iterate   : true,
});

How it might be used

$('nav ul li').myPlugin({...})
Credit

monkeymonk benjasHu