(bug 30499) Create jQuery replacements for injectSpinner and removeSpinner
authorJohn Du Hart <johnduhart@users.mediawiki.org>
Wed, 24 Aug 2011 21:08:39 +0000 (21:08 +0000)
committerJohn Du Hart <johnduhart@users.mediawiki.org>
Wed, 24 Aug 2011 21:08:39 +0000 (21:08 +0000)
resources/Resources.php
resources/jquery/images/spinner.gif [new file with mode: 0644]
resources/jquery/jquery.spinner.css [new file with mode: 0644]
resources/jquery/jquery.spinner.js [new file with mode: 0644]

index 898d241..4d4b8f5 100644 (file)
@@ -156,6 +156,10 @@ return array(
        'jquery.qunit.completenessTest' => array(
                'scripts' => 'resources/jquery/jquery.qunit.completenessTest.js',
        ),
+       'jquery.spinner' => array(
+               'scripts' => 'resources/jquery/jquery.spinner.js',
+               'styles' => 'resources/jquery/jquery.spinner.css',
+       ),
        'jquery.suggestions' => array(
                'scripts' => 'resources/jquery/jquery.suggestions.js',
                'styles' => 'resources/jquery/jquery.suggestions.css',
diff --git a/resources/jquery/images/spinner.gif b/resources/jquery/images/spinner.gif
new file mode 100644 (file)
index 0000000..d0bce15
Binary files /dev/null and b/resources/jquery/images/spinner.gif differ
diff --git a/resources/jquery/jquery.spinner.css b/resources/jquery/jquery.spinner.css
new file mode 100644 (file)
index 0000000..d3dd093
--- /dev/null
@@ -0,0 +1,8 @@
+.loading-spinner {
+       /* @embed */
+       background: transparent url('images/spinner.gif');
+       height: 16px;
+       width: 16px;
+       display: inline-block;
+       vertical-align: middle;
+}
\ No newline at end of file
diff --git a/resources/jquery/jquery.spinner.js b/resources/jquery/jquery.spinner.js
new file mode 100644 (file)
index 0000000..5536ecc
--- /dev/null
@@ -0,0 +1,42 @@
+/**
+ * Functions to replace injectSpinner which makes img tags with spinners
+ */
+( function( $ ) {
+
+$.extend( {
+       /**
+        * Creates a spinner element
+        *
+        * @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: '...'
+                       });
+       },
+
+       /**
+        * Removes a spinner element
+        *
+        * @param id
+        */
+       removeSpinner: function( id ) {
+               $( '#mw-spinner-' + id ).remove();
+       }
+} );
+
+/**
+ * Injects a spinner after the given objects
+ *
+ * @param id String id of the spinner
+ */
+$.fn.injectSpinner = function( id ) {
+       return this.after( $.createSpinner( id ) );
+};
+
+} )( jQuery );
\ No newline at end of file