Skip to content

Commit

Permalink
Whitespace changes to better conform to jQuery coding standards, remo…
Browse files Browse the repository at this point in the history
…ved the mix of spaces and tabs, adjusted line spacing in these two files for consistency of conceptual segmentation, and made changes to pass jsHint

The JQuery Core Style Guidelines can be found here: http://docs.jquery.com/JQuery_Core_Style_Guidelines

Adjusted the in-code white-spacing for consistency -- prior to these changes there was no evident standard, or a standard had yet to be enforced.  Chose to adhere to jQuery Core Style Guidelines because students studying jQuery will come across many examples authored by core team members who, on balance, tend towards this standard.

Fixed one minor jsHint-discovered error, an unnecessary semicolon at the end of a function definition.

Stripped-away all trailing spaces on code and blank lines.

By the way, I like your use of the leading semicolon to guard against prior concatenated code.

Signed-off-by: Steven Black <steveb@stevenblack.com>
  • Loading branch information
StevenBlack committed Mar 27, 2012
1 parent e53a5be commit d34a297
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 62 deletions.
32 changes: 16 additions & 16 deletions jquery-plugin-patterns/extend.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,32 @@
As you'll notice below, we're making use of $.fn.extend to create our plugin rather
than opting for $.fn.pluginname. This type of structure may be useful if you need
to add a relatively large number of methods to your plugin. There are however alternatives
to this that may be better suited, including Alex Sexton's prototypal inheritence pattern
which is also included in this repo.
to this that may be better suited, including Alex Sexton's prototypal inheritence pattern
which is also included in this repo.
*/


//the semi colon before function invocation is a safety net against concatenated
//scripts and/or other plugins which may not be closed properly.
;(function($){
$.fn.extend({
pluginname: function( options ) {
// the semi colon before function invocation is a safety net against concatenated
// scripts and/or other plugins which may not be closed properly.
;( function( $ ){
$.fn.extend( {
pluginname: function( options ) {

this.defaultOptions = {};
this.defaultOptions = {};

var settings = $.extend({}, this.defaultOptions, options);
var settings = $.extend( {}, this.defaultOptions, options );

return this.each(function() {
return this.each( function() {

var $this = $(this);
var $this = $( this );

});
});

}

});
}

})(jQuery);
});

})( jQuery );


// References
Expand Down
92 changes: 46 additions & 46 deletions jquery-plugin-patterns/namespaced-starter.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,52 +14,52 @@
*/

;(function ( $ ) {
if (!$.myNamespace) {
$.myNamespace = {};
};

$.myNamespace.myPluginName = function ( el, myFunctionParam, options ) {
// To avoid scope issues, use 'base' instead of 'this'
// to reference this class from internal events and functions.
var base = this;

// Access to jQuery and DOM versions of element
base.$el = $(el);
base.el = el;

// Add a reverse reference to the DOM object
base.$el.data( "myNamespace.myPluginName" , base );

base.init = function () {
base.myFunctionParam = myFunctionParam;

base.options = $.extend({},
$.myNamespace.myPluginName.defaultOptions, options);

// Put your initialization code here
};

// Sample Function, Uncomment to use
// base.functionName = function( paramaters ){
//
// };
// Run initializer
base.init();
};

$.myNamespace.myPluginName.defaultOptions = {
myDefaultValue: ""
};

$.fn.mynamespace_myPluginName = function
( myFunctionParam, options ) {
return this.each(function () {
(new $.myNamespace.myPluginName(this,
myFunctionParam, options));
});
};

})( jQuery );
if ( ! $.myNamespace ) {
$.myNamespace = {};
}

$.myNamespace.myPluginName = function ( el, myFunctionParam, options ) {

// To avoid scope issues, use 'base' instead of 'this'
// to reference this class from internal events and functions.
var base = this;

// Access to jQuery and DOM versions of element
base.$el = $( el );
base.el = el;

// Add a reverse reference to the DOM object
base.$el.data( "myNamespace.myPluginName" , base );

base.init = function () {
base.myFunctionParam = myFunctionParam;

base.options = $.extend( {}, $.myNamespace.myPluginName.defaultOptions, options );

// Put your initialization code here

};

// Sample Function, Uncomment to use
// base.functionName = function( paramaters ){
//
// };

// Run initializer
base.init();
};

$.myNamespace.myPluginName.defaultOptions = {
myDefaultValue: ""
};

$.fn.mynamespace_myPluginName = function( myFunctionParam, options ) {
return this.each( function () {
( new $.myNamespace.myPluginName( this, myFunctionParam, options ) );
});
};

} )( jQuery );


// References
Expand Down

0 comments on commit d34a297

Please sign in to comment.