Review and clean up of jquery.tablesorter.js + applying code conventions
authorKrinkle <krinkle@users.mediawiki.org>
Sun, 26 Jun 2011 04:36:02 +0000 (04:36 +0000)
committerKrinkle <krinkle@users.mediawiki.org>
Sun, 26 Jun 2011 04:36:02 +0000 (04:36 +0000)
commit65c2c5cd6cb9cf95159ccd5d4e3b73354bceda4e
tree86dbfa0f0d75073cbd438410470ae990992ed5fb
parentc78fa7d720d5e30e1386708d475b5fece1378431
Review and clean up of jquery.tablesorter.js + applying code conventions

* Dropping redundant "new function(){}" construction, instead using the closure we already have for the local scope.
* Adding more function documentation
* Whitespace contentions
* Passing jQuery object to the $.tablesorter.construct and creating jQuery plugin function in $.fn.tablesorter (per jQuery convention, this allows $.tablesorter.construct to be used directly without having to use .apply() to get the this-context right).
* Making use of the arguments that jQuery.fn.each passes by default in $.tablesorter.construct (this/that => table)
* Renaming a few single-letter variables to something more descriptive (c => $row, r => regex etc.)
* Changed order of local functions in order of calling and dependancy (fixed JSHint potential implied globals). Also makes reading/understanding them easier.
* Removed commented out code
* Added more line breaks to separate blocks
* Merge var-statements together
* Declare 'ts' shortcut on top of the local scope, define 'ts' shortcut directly after definition of $.tablesorter
* Adding public member placeholders, populated by private functions, to the initial object instead of inside the functions. This way the members can be seen centrally (dateRegex, monthNames)

* Syntax/JSHint fixes (Passes 100% now; Globals: mw, jQuery)
- 'list' used out of scope. In function buildParserCache: "var list" was defined under an if-condition, but returned outside of it, this fails in the 'else' case. Moved var list outside the if-condition
- Strict === comparison to 0, null, undefined, false, true, '' etc.
- Require curly braces around all blocks

* Performance improvements (see also http://www.mediawiki.org/wiki/JSPERF)
- Using dot notation (obj.member = {}), instead of $.extend(obj, { member: .. }) for single additions. No need for $.extend
- Object literal {foo}, instead of new function(){ this.foo }
- Strict/fast comparison to undefined, without typeof and/or string evaluation
- cacheRegexs() is uselses if if re-creates the cache every time. Using static cache instead (which was likely the intention)
resources/jquery/jquery.tablesorter.js