1
+ /*
2
+ * Project:
3
+ * Description:
4
+ * Author:
5
+ * License:
6
+ */
7
+
8
+ // the semi-colon before function invocation is a safety net against concatenated
9
+ // scripts and/or other plugins which may not be closed properly.
10
+ ; ( function ( $ , window , undefined ) {
11
+
12
+ // undefined is used here as the undefined global variable in ECMAScript 3 is
13
+ // mutable (ie. it can be changed by someone else). undefined isn't really being
14
+ // passed in so we can ensure the value of it is truly undefined. In ES5, undefined
15
+ // can no longer be modified.
16
+
17
+ // window is passed through as local variable rather than global
18
+ // as this (slightly) quickens the resolution process and can be more efficiently
19
+ // minified (especially when both are regularly referenced in your plugin).
20
+
21
+ // Create the defaults once
22
+ var pluginName = 'defaultPluginName' ,
23
+ document = window . document ,
24
+ defaults = {
25
+ propertyName : "value"
26
+ } ;
27
+
28
+ // The actual plugin constructor
29
+ function Plugin ( element , options ) {
30
+ this . element = element ;
31
+
32
+ // jQuery has an extend method which merges the contents of two or
33
+ // more objects, storing the result in the first object. The first object
34
+ // is generally empty as we don't want to alter the default options for
35
+ // future instances of the plugin
36
+ this . options = $ . extend ( { } , defaults , options ) ;
37
+
38
+ this . _defaults = defaults ;
39
+ this . _name = pluginName ;
40
+
41
+ this . init ( ) ;
42
+ }
43
+
44
+ Plugin . prototype . init = function ( ) {
45
+ // Place initialization logic here
46
+ // You already have access to the DOM element and the options via the instance,
47
+ // e.g., this.element and this.options
48
+ } ;
49
+
50
+ // A really lightweight plugin wrapper around the constructor,
51
+ // preventing against multiple instantiations
52
+ $ . fn [ pluginName ] = function ( options ) {
53
+ return this . each ( function ( ) {
54
+ if ( ! $ . data ( this , 'plugin_' + pluginName ) ) {
55
+ $ . data ( this , 'plugin_' + pluginName , new Plugin ( this , options ) ) ;
56
+ }
57
+ } ) ;
58
+ } ;
59
+
60
+ } ( jQuery , window ) ) ;
0 commit comments