forked from adamovsky/jQuery-Plugin-Pattern
-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
36 lines (22 loc) · 2.12 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
jQuery Plugin Pattern
by Milan Adamovsky
Goals
=====
The goal of this project is to provide a way to code jQuery plugin that allow traditional object oriented programming paradigms (dot notation, inheritance, etc) while remaining backwards compatible with the official jQuery plugin authoring pattern.
The target audience for this pattern are jQuery plugin authors and companies who want to create reusable widgets using one common pattern. Large enterprise who do use jQuery and want to modularize their widgets and want a more sophisticated pattern than that offered by jQuery will greatly benefit from this pattern as well as it opens up new opportunities for more sophisticated widgets.
Since jQuery doesn't have the notion of an object, this pattern addresses that by making each selected set of elements be a new reusable object that in turn permits to save state across multiple instances.
The gist of it is that we are marrying OOP with jQuery with a focus on plugin development purposes.
Syntax
======
The idea is to be able to choose which syntax you would like to offer with your plugin. Here are a few syntax that should be possible with this plugin pattern:
$(selector).plugin(opts);
$(selector).plugin(opts).method(opts);
$(selector).plugin.method(opts);
$(selector).plugin.some.inherited.class.method(opts);
$(selector).plugin.method(opts).jquery(opts);
$(selector).plugin(opts).jquery(opts);
The jquery(opts) suggests a chainable jQuery object - or in other words, the way jQuery is architected to work.
The main change here is the ability to return an instantiated class object rather than a jquery object. This effectively allows you to namespace your code.
The other goal is to make sure that you can run multiple instances of your plugin side-by-side without effecting each other. For example, if you have two carousels on one page, you do not want both of them to scroll if you click the navigation buttons on one of them. In other words, they have to be atomic.
Let your imagination run wild now how you want your users to interface with your plugin !
Make sure to visit my blog at http://milan.adamovsky.com