jquery.spinner: Fix small issues
authorKrinkle <krinkle@users.mediawiki.org>
Wed, 24 Aug 2011 21:37:59 +0000 (21:37 +0000)
committerKrinkle <krinkle@users.mediawiki.org>
Wed, 24 Aug 2011 21:37:59 +0000 (21:37 +0000)
(Follows-up r95445)
* Using the same spinner as before, preserving svn history (20px vs. 16px)
* Adding a line-break at the end of file and changing indentation per our conventions
* Adjusting doc to reflect the plugin itself instead of what it replaces.
* Using shorthand utility in jQuery (no / and using the attr-object as second argument)
* Adding @return comment to $.fn.injectSpinner
* Adding return statement to $.removerSpinner (returning a jQuery object of the element). Could be useful, but better than not having a return value at all.

JSHint:
* Adding parentheses around the class object property, otherwise it may be interpreted as a class operator which breaks the object.

resources/jquery/images/spinner.gif
resources/jquery/jquery.spinner.css
resources/jquery/jquery.spinner.js

index d0bce15..37d3a43 100644 (file)
Binary files a/resources/jquery/images/spinner.gif and b/resources/jquery/images/spinner.gif differ
index d3dd093..4f33bb4 100644 (file)
@@ -1,8 +1,8 @@
-.loading-spinner {
+.mw-spinner {
        /* @embed */
-       background: transparent url('images/spinner.gif');
-       height: 16px;
-       width: 16px;
+       background: transparent url(images/spinner.gif);
+       height: 20px;
+       width: 20px;
        display: inline-block;
        vertical-align: middle;
 }
\ No newline at end of file
index 5536ecc..01fa8de 100644 (file)
@@ -1,42 +1,45 @@
 /**
- * Functions to replace injectSpinner which makes img tags with spinners
+ * jQuery spinner
+ *
+ * Simple jQuery plugin to create, inject and remove spinners.
  */
 ( function( $ ) {
 
 $.extend( {
        /**
-        * Creates a spinner element
+        * Creates a spinner element.
         *
-        * @param id String id of the spinner
-        * @return jQuery spinner
+        * @param id {String} id of the spinner
+        * @return {jQuery} spinner
         */
        createSpinner: function( id ) {
-               return $( '<div/>' )
-                       .attr({
-                               id: 'mw-spinner-' + id,
-                               class: 'loading-spinner',
-                               title: '...',
-                               alt: '...'
-                       });
+               return $( '<div>' ).attr( {
+                       id: 'mw-spinner-' + id,
+                       'class': 'mw-spinner',
+                       title: '...',
+                       alt: '...'
+               } );
        },
 
        /**
-        * Removes a spinner element
+        * Removes a spinner element.
         *
-        * @param id
+        * @param id {String}
+        * @return {jQuery} spinner
         */
        removeSpinner: function( id ) {
-               $( '#mw-spinner-' + id ).remove();
+               return $( '#mw-spinner-' + id ).remove();
        }
 } );
 
 /**
- * Injects a spinner after the given objects
+ * Injects a spinner after the elements in the jQuery collection.
  *
  * @param id String id of the spinner
+ * @return {jQuery}
  */
 $.fn.injectSpinner = function( id ) {
        return this.after( $.createSpinner( id ) );
 };
 
-} )( jQuery );
\ No newline at end of file
+} )( jQuery );