forked from adamovsky/jQuery-Plugin-Pattern
-
Notifications
You must be signed in to change notification settings - Fork 0
aniculescu/jQuery-Plugin-Pattern
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
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
About
This project provides a plugin pattern that is backwards compatible with jQuery's official plugin pattern but extends it with namespaces and the ability to use OOP.
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published