1515
1616; ( function ( $ , window , document , undefined ) {
1717
18- $ . fn . pluginName = function ( options ) {
18+ $ . fn . pluginName = function ( options ) {
1919
20- // Here's a best practice for overriding 'defaults'
21- // with specified options. Note how, rather than a
22- // regular options object being passed as the second
23- // parameter, we instead refer to $.fn.pluginName.defaults
24- // explicitly, merging it with the options passed to the
25- // plugin. This allows us to override defaults both
26- // globally and on a per-call level.
20+ // Here's a best practice for overriding 'defaults'
21+ // with specified options. Note how, rather than a
22+ // regular defaults object being passed as the second
23+ // parameter, we instead refer to $.fn.pluginName.options
24+ // explicitly, merging it with the options passed directly
25+ // to the plugin. This allows us to override options both
26+ // globally and on a per-call level.
2727
28- settings = $ . extend ( { } , $ . fn . pluginName . defaults , options ) ;
28+ options = $ . extend ( { } , $ . fn . pluginName . options , options ) ;
2929
30- return this . each ( function ( ) {
30+ return this . each ( function ( ) {
3131
32- var elem = $ ( this ) ;
32+ var elem = $ ( this ) ;
3333
34- } ) ;
35- } ;
34+ } ) ;
35+ } ;
3636
37- // Globally overriding options
38- // Here are the publicly accessible defaults
39- // in case the user doesn't pass-in any or all
40- // possible options. The user is given a default
41- // experience but can optionally override the values
42- // as required.
43- // eg. $fn.pluginName.key ='otherval'
37+ // Globally overriding options
38+ // Here are our publicly accessible default plugin options
39+ // that are available in case the user doesn't pass in all
40+ // of the values expected. The user is given a default
41+ // experience but can also override the values as necessary.
42+ // eg. $fn.pluginName.key ='otherval'
4443
45- $ . fn . pluginName . defaults = {
44+ $ . fn . pluginName . options = {
4645
47- key : "value" ,
48- myMethod : function ( elem , param ) {
46+ key : "value" ,
47+ myMethod : function ( elem , param ) {
4948
50- // to do: implement myMethod() here
51-
52- }
53- } ;
49+ }
50+ } ;
5451
5552} ) ( jQuery , window , document ) ;
5653
5754
5855// References
59- // http://coding.smashingmagazine.com/2011/10/11/essential-jquery-plugin-patterns/
56+ /*
57+ jQuery Pluginization and the accompanying gist (by Ben Alman) - http://goo.gl/1VwfP http://goo.gl/bg63
58+ Essential jQuery Plugin Patterns (by Addy Osmani) - http://goo.gl/oE0ge
59+ */
6060</ script >
6161</ body >
6262</ html >
0 commit comments