Lazy load tablesorter only when needed. Bug 28946
authorLeo Koppelkamm <diebuche@users.mediawiki.org>
Fri, 13 May 2011 15:28:42 +0000 (15:28 +0000)
committerLeo Koppelkamm <diebuche@users.mediawiki.org>
Fri, 13 May 2011 15:28:42 +0000 (15:28 +0000)
resources/Resources.php
resources/mediawiki.action/mediawiki.action.view.tablesorting.js [new file with mode: 0644]
resources/mediawiki.util/mediawiki.util.js

index 05265f0..cbbdb9c 100644 (file)
@@ -439,6 +439,9 @@ return array(
                'scripts' => 'resources/mediawiki.action/mediawiki.action.view.metadata.js',
                'messages' => array( 'metadata-expand', 'metadata-collapse' ),
        ),
+       'mediawiki.action.view.tablesorting' => array(
+               'scripts' => 'resources/mediawiki.action/mediawiki.action.view.tablesorting.js',
+       ),
        'mediawiki.action.watch.ajax' => array(
                'scripts' => 'resources/mediawiki.action/mediawiki.action.watch.ajax.js',
                'dependencies' => 'mediawiki.util',
diff --git a/resources/mediawiki.action/mediawiki.action.view.tablesorting.js b/resources/mediawiki.action/mediawiki.action.view.tablesorting.js
new file mode 100644 (file)
index 0000000..09aefc0
--- /dev/null
@@ -0,0 +1,9 @@
+// Lazy load jquery.tablesorter
+
+( function( $ ) {
+       if ( $( 'table.sortable' ).length ) {
+               mw.loader.using( 'jquery.tablesorter', function() {
+                       $( 'table.sortable' ).tablesorter(); 
+               } );
+       }
+} )( jQuery );
\ No newline at end of file
index 7e64225..67b7dde 100644 (file)
@@ -57,9 +57,6 @@
                                        /* Enable CheckboxShiftClick */
                                        $( 'input[type=checkbox]:not(.noshiftselect)' ).checkboxShiftClick();
 
-                                       /* Enable Tablesorting */
-                                       $( 'table.sortable' ).tablesorter(); 
-
                                        /* Emulate placeholder if not supported by browser */
                                        if ( !( 'placeholder' in document.createElement( 'input' ) ) ) {
                                                $( 'input[placeholder]' ).placeholder();