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