Skip to content

Commit e0da9b9

Browse files
committed
update: editable parts of the jquery boilerplate
1 parent df190bf commit e0da9b9

File tree

2 files changed

+60
-48
lines changed

2 files changed

+60
-48
lines changed

snippets/js/jquery/zothers/README.md

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,19 @@
33
### [jqb] jQuery Boilerplate
44

55
```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 ) {
915

1016
"use strict";
1117

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
1319
// mutable (ie. it can be changed by someone else). undefined isn't really being
1420
// passed in so we can ensure the value of it is truly undefined. In ES5, undefined
1521
// can no longer be modified.
@@ -18,48 +24,48 @@
1824
// as this (slightly) quickens the resolution process and can be more efficiently
1925
// minified (especially when both are regularly referenced in your plugin).
2026

21-
// Create the defaults once
22-
var pluginName = "defaultPluginName",
27+
// Create the defaults once}
28+
var pluginName = "${13:defaultPluginName}",
2329
defaults = {
2430
propertyName: "value"
2531
};
2632

27-
// The actual plugin constructor
33+
${7:// The actual plugin constructor}
2834
function Plugin ( element, options ) {
2935
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
3137
// more objects, storing the result in the first object. The first object
3238
// 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 );
3541
this._defaults = defaults;
3642
this._name = pluginName;
3743
this.init();
3844
}
3945

40-
// Avoid Plugin.prototype conflicts
41-
$.extend(Plugin.prototype, {
46+
${9:// Avoid Plugin.prototype conflicts}
47+
\$.extend(Plugin.prototype, {
4248
init: function () {
43-
// Place initialization logic here
49+
${10:// Place initialization logic here
4450
// You already have access to the DOM element and
4551
// the options via the instance, e.g. this.element
4652
// and this.settings
4753
// 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");}
5056
},
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+
\}}
5561
});
5662

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 ) {
6066
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 ) );
6369
}
6470
});
6571
};

snippets/js/jquery/zothers/jq-boilerplate.sublime-snippet

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
<snippet>
22
<content><![CDATA[
3-
// the semi-colon before function invocation is a safety net against concatenated
4-
// scripts and/or other plugins which may not be closed properly.
5-
;(function ( $, window, document, undefined ) {
3+
/**
4+
* Plugin: ${1}
5+
* Description: ${2}
6+
* Author: ${3}
7+
* License: ${4}
8+
*/
9+
${5:// the semi-colon before function invocation is a safety net against concatenated
10+
// scripts and/or other plugins which may not be closed properly.}
11+
;(function ( \$, window, document, undefined ) {
612
713
"use strict";
814
9-
// undefined is used here as the undefined global variable in ECMAScript 3 is
15+
${6:// undefined is used here as the undefined global variable in ECMAScript 3 is
1016
// mutable (ie. it can be changed by someone else). undefined isn't really being
1117
// passed in so we can ensure the value of it is truly undefined. In ES5, undefined
1218
// can no longer be modified.
@@ -15,48 +21,48 @@
1521
// as this (slightly) quickens the resolution process and can be more efficiently
1622
// minified (especially when both are regularly referenced in your plugin).
1723
18-
// Create the defaults once
19-
var pluginName = "defaultPluginName",
24+
// Create the defaults once}
25+
var pluginName = "${13:defaultPluginName}",
2026
defaults = {
2127
propertyName: "value"
2228
};
2329
24-
// The actual plugin constructor
30+
${7:// The actual plugin constructor}
2531
function Plugin ( element, options ) {
2632
this.element = element;
27-
// jQuery has an extend method which merges the contents of two or
33+
${8:// jQuery has an extend method which merges the contents of two or
2834
// more objects, storing the result in the first object. The first object
2935
// is generally empty as we don't want to alter the default options for
30-
// future instances of the plugin
31-
this.settings = $.extend( {}, defaults, options );
36+
// future instances of the plugin}
37+
this.settings = \$.extend( {}, defaults, options );
3238
this._defaults = defaults;
3339
this._name = pluginName;
3440
this.init();
3541
}
3642
37-
// Avoid Plugin.prototype conflicts
38-
$.extend(Plugin.prototype, {
43+
${9:// Avoid Plugin.prototype conflicts}
44+
\$.extend(Plugin.prototype, {
3945
init: function () {
40-
// Place initialization logic here
46+
${10:// Place initialization logic here
4147
// You already have access to the DOM element and
4248
// the options via the instance, e.g. this.element
4349
// and this.settings
4450
// you can add more functions like the one below and
45-
// call them like the example bellow
46-
this.yourOtherFunction("jQuery Boilerplate");
51+
// call them like the example bellow}
52+
${15:this.yourOtherFunction("jQuery Boilerplate");}
4753
},
48-
yourOtherFunction: function (text) {
49-
// some logic
50-
$(this.element).text(text);
51-
}
54+
${14:yourOtherFunction: function (text) \{
55+
${11:// some logic}
56+
\$(this.element).text(text);
57+
\}}
5258
});
5359
54-
// A really lightweight plugin wrapper around the constructor,
55-
// preventing against multiple instantiations
56-
$.fn[ pluginName ] = function ( options ) {
60+
${12:// A really lightweight plugin wrapper around the constructor,
61+
// preventing against multiple instantiations}
62+
\$.fn[ pluginName ] = function ( options ) {
5763
return this.each(function() {
58-
if ( !$.data( this, "plugin_" + pluginName ) ) {
59-
$.data( this, "plugin_" + pluginName, new Plugin( this, options ) );
64+
if ( !\$.data( this, "plugin_" + pluginName ) ) {
65+
\$.data( this, "plugin_" + pluginName, new Plugin( this, options ) );
6066
}
6167
});
6268
};

0 commit comments

Comments
 (0)