Applying conventions and some JSLint good practices in core modules.
authorKrinkle <krinkle@users.mediawiki.org>
Mon, 31 Jan 2011 22:02:58 +0000 (22:02 +0000)
committerKrinkle <krinkle@users.mediawiki.org>
Mon, 31 Jan 2011 22:02:58 +0000 (22:02 +0000)
resources/jquery/jquery.async.js
resources/jquery/jquery.autoEllipsis.js
resources/jquery/jquery.client.js

index 61493f7..2161f6b 100644 (file)
 // opts.test : (default true) function to test in the while test part
 // opts.loop : (default empty) function to call in the while loop part
 // opts.end : (default empty) function to call at the end of the while loop
-$.whileAsync = function(opts)
-{
+$.whileAsync = function(opts) {
        var delay = Math.abs(opts.delay) || 10,
                bulk = isNaN(opts.bulk) ? 500 : Math.abs(opts.bulk),
                test = opts.test || function(){ return true; },
                loop = opts.loop || function(){},
-               end  = opts.end  || function(){};
+               end = opts.end || function(){};
        
        (function(){
 
                var t = false,
                        begin = new Date();
                        
-               while( t = test() )
-               {
+               while( t = test() ) {
                        loop();
-                       if( bulk === 0 || (new Date() - begin) > bulk )
-                       {
+                       if( bulk === 0 || (new Date() - begin) > bulk ) {
                                break;
                        }
                }
-               if( t )
-               {
+               if( t ) {
                        setTimeout(arguments.callee, delay);
                }
-               else
-               {
+               else {
                        end();
                }
                
@@ -50,17 +45,15 @@ $.whileAsync = function(opts)
 // opts.bulk : (default 500) delay during which the loop can continue synchronously without yielding the CPU
 // opts.loop : (default empty) function to call in the each loop part, signature: function(index, value) this = value
 // opts.end : (default empty) function to call at the end of the each loop
-$.eachAsync = function(array, opts)
-{
-       var i = 0,
+$.eachAsync = function(array, opts) {
+       var     i = 0,
                l = array.length,
                loop = opts.loop || function(){};
        
        $.whileAsync(
                $.extend(opts, {
-                       test: function(){ return i < l; },
-                       loop: function()
-                       {
+                       test: function() { return i < l; },
+                       loop: function() {
                                var val = array[i];
                                return loop.call(val, i++, val);
                        }
@@ -68,11 +61,9 @@ $.eachAsync = function(array, opts)
        );
 };
 
-$.fn.eachAsync = function(opts)
-{
+$.fn.eachAsync = function(opts) {
        $.eachAsync(this, opts);
        return this;
 }
 
-})(jQuery);
-
+})(jQuery);
\ No newline at end of file
index 4993118..0ec1ad3 100644 (file)
@@ -17,29 +17,29 @@ $.fn.autoEllipsis = function( options ) {
                'matchText': null
        }, options );
        $(this).each( function() {
-               var $this = $(this);
+               var $el = $(this);
                if ( options.restoreText ) {
-                       if ( ! $this.data( 'autoEllipsis.originalText' ) ) {
-                               $this.data( 'autoEllipsis.originalText', $this.text() );
+                       if ( !$el.data( 'autoEllipsis.originalText' ) ) {
+                               $el.data( 'autoEllipsis.originalText', $el.text() );
                        } else {
-                               $this.text( $this.data( 'autoEllipsis.originalText' ) );
+                               $el.text( $el.data( 'autoEllipsis.originalText' ) );
                        }
                }
                
                // container element - used for measuring against
-               var $container = $this;
+               var $container = $el;
                // trimmable text element - only the text within this element will be trimmed
                var $trimmableText = null;
                // protected text element - the width of this element is counted, but next is never trimmed from it
                var $protectedText = null;
 
                if ( options.hasSpan ) {
-                       $trimmableText = $this.children( options.selector );
+                       $trimmableText = $el.children( options.selector );
                } else {
                        $trimmableText = $( '<span />' )
                                .css( 'whiteSpace', 'nowrap' )
-                               .text( $this.text() );
-                       $this
+                               .text( $el.text() );
+                       $el
                                .empty()
                                .append( $trimmableText );
                }
@@ -60,14 +60,16 @@ $.fn.autoEllipsis = function( options ) {
                }
                if ( !options.matchText && w in cache[text] ) {
                        $container.html( cache[text][w] );
-                       if ( options.tooltip )
+                       if ( options.tooltip ) {
                                $container.attr( 'title', text );
+                       }
                        return;
                }
                if( options.matchText && options.matchText in matchTextCache[text] && w in matchTextCache[text][options.matchText] ) {
                        $container.html( matchTextCache[text][options.matchText][w] );
-                       if ( options.tooltip )
+                       if ( options.tooltip ) {
                                $container.attr( 'title', text );
+                       }
                        return;
                }
                if ( $trimmableText.width() + pw > w ) {
@@ -94,7 +96,7 @@ $.fn.autoEllipsis = function( options ) {
                                        while ( $trimmableText.outerWidth() + pw > w  && i[0] > 0 ) {
                                                $trimmableText.text( trimmableText.substr( 0, i[0] ) + '...' + trimmableText.substr( i[1] ) );
                                                // Alternate between trimming the end and begining
-                                               if ( side == 0 ) {
+                                               if ( side === 0 ) {
                                                        // Make the begining shorter
                                                        i[0]--;
                                                        side = 1;
index 93c05bb..95407c9 100644 (file)
@@ -1,7 +1,6 @@
 /**
  * User-agent detection
  */
- */
 ( function( $ ) {
 $.client = new ( function() {
 
@@ -15,15 +14,15 @@ $.client = new ( function() {
         * Returns an object containing information about the browser
         *
         * The resulting client object will be in the following format:
-        *      {
-        *              'name': 'firefox',
-        *              'layout': 'gecko',
-        *              'layoutVersion': '20101026',
-        *              'platform': 'linux'
-        *              'version': '3.5.1',
-        *              'versionBase': '3',
-        *              'versionNumber': 3.5,
-        *      }
+        *  {
+        *   'name': 'firefox',
+        *   'layout': 'gecko',
+        *   'layoutVersion': '20101026',
+        *   'platform': 'linux'
+        *   'version': '3.5.1',
+        *   'versionBase': '3',
+        *   'versionNumber': 3.5,
+        *  }
         */
        this.profile = function() {
                // Use the cached version if possible
@@ -50,7 +49,7 @@ $.client = new ( function() {
                                // This helps keep differnt versions consistent
                                ['Navigator', 'Netscape'],
                                // This prevents version extraction issues, otherwise translation would happen later
-                               ['PLAYSTATION 3', 'PS3'],
+                               ['PLAYSTATION 3', 'PS3']
                        ];
                        // Strings which precede a version number in a user agent string - combined and used as match 1 in
                        // version detectection
@@ -62,8 +61,8 @@ $.client = new ( function() {
                        var versionSuffix = '(\\/|\\;?\\s|)([a-z0-9\\.\\+]*?)(\\;|dev|rel|\\)|\\s|$)';
                        // Names of known browsers
                        var names = [
-                               'camino', 'chrome', 'firefox', 'netscape', 'konqueror', 'lynx', 'msie', 'opera', 'safari', 'ipod',
-                               'iphone', 'blackberry', 'ps3'
+                               'camino', 'chrome', 'firefox', 'netscape', 'konqueror', 'lynx', 'msie', 'opera', 'safari', 'ipod',
+                               'iphone', 'blackberry', 'ps3'
                        ];
                        // Tanslations for conforming browser names
                        var nameTranslations = [];
@@ -81,7 +80,7 @@ $.client = new ( function() {
                        /* Methods */
 
                        // Performs multiple replacements on a string
-                       function translate( source, translations ) {
+                       var translate = function( source, translations ) {
                                for ( var i = 0; i < translations.length; i++ ) {
                                        source = source.replace( translations[i][0], translations[i][1] );
                                }
@@ -107,7 +106,7 @@ $.client = new ( function() {
                                layout = translate( match[1], layoutTranslations );
                        }
                        if ( match = new RegExp( '(' + layoutVersions.join( '|' ) + ')\\\/(\\d+)').exec( navigator.userAgent.toLowerCase() ) ) {
-                               layoutversion = parseInt(match[2]);
+                               layoutversion = parseInt( match[2], 10 );
                        }
                        if ( match = new RegExp( '(' + platforms.join( '|' ) + ')' ).exec( navigator.platform.toLowerCase() ) ) {
                                platform = translate( match[1], platformTranslations );
@@ -148,20 +147,20 @@ $.client = new ( function() {
         * element is classified as either "ltr" or "rtl". If neither is set, "ltr" is assumed.
         *
         * A browser map is in the following format:
-        *      {
-        *              'ltr': {
-        *                      // Multiple rules with configurable operators
-        *                      'msie': [['>=', 7], ['!=', 9]],
-        *                      // Blocked entirely
-        *                      'iphone': false
-        *              },
-        *              'rtl': {
-        *                      // Test against a string
-        *                      'msie': [['!==', '8.1.2.3']],
-        *                      // RTL rules do not fall through to LTR rules, you must explicity set each of them
-        *                      'iphone': false
-        *              }
-        *      }
+        * {
+        *   'ltr': {
+        *     // Multiple rules with configurable operators
+        *     'msie': [['>=', 7], ['!=', 9]],
+        *      // Blocked entirely
+        *     'iphone': false
+        *   },
+        *   'rtl': {
+        *     // Test against a string
+        *     'msie': [['!==', '8.1.2.3']],
+        *     // RTL rules do not fall through to LTR rules, you must explicity set each of them
+        *     'iphone': false
+        *   }
+        * }
         *
         * @param map Object of browser support map
         *