https://github.com/grassator/jquery-declarative-init
Provides a way to initialize jquery plugins from the elements they are linked to.
https://github.com/grassator/jquery-declarative-init
Last synced: 10 months ago
JSON representation
Provides a way to initialize jquery plugins from the elements they are linked to.
- Host: GitHub
- URL: https://github.com/grassator/jquery-declarative-init
- Owner: grassator
- Created: 2012-10-27T13:54:26.000Z (about 13 years ago)
- Default Branch: master
- Last Pushed: 2013-08-29T15:02:24.000Z (over 12 years ago)
- Last Synced: 2023-04-09T14:49:36.075Z (almost 3 years ago)
- Language: JavaScript
- Homepage: http://kubyshkin.ru/posts/declarative-initialization-of-jquery-plugins.html
- Size: 105 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# jQuery Declarative Init Plugin
Provides a way to initialize jquery plugins from the elements they are linked to.
It works with both jQuery and Zepto.
## Basic Usage
First of all we need some plain old jQuery plugin. I will use [lightweight-datepicker](http://maximzhukov.com/demos/lw-datepicker/) for this example since it's really nice and has configuration options which is what we need. Let's say we have a field like this that needs a date picker:
Now we need a way to specify that this fields needs some query plugins applied to it, so we add a class:
Next thing we need is a way to specify which plugins we need so we add configuration as an `onclick` attribute:
In options we use a hash where key is plugin name and value is a hash of options for the plugin. All that's left is to run this jquery plugin:
$('.jquery-declarative-init').declarativeInit();
## Configuration
- `pluginDefaults` - (default: `{}`) - A hash of default options for plugins that will be merged with the ones provided in DOM element.
- `pluginGetter` - (default is function to get plugins from `onclick`) - this is an advanced option that let's you change a way plugins are specified. You can for example use html5 `data-*` attributes.
## Demo
Live demo available [here](http://kubyshkin.ru/samples/jquery-declarative-init.html).