http://www.mediawiki.org/wiki/Special:Code/MediaWiki/93801

Revision: 93801
Author:   nad
Date:     2011-08-03 07:02:04 +0000 (Wed, 03 Aug 2011)
Log Message:
-----------
make JS loading work witj 1.17 addModules but maintain backward campatibility 
with pre 1.17

Modified Paths:
--------------
    trunk/extensions/RecordAdmin/RecordAdmin.php
    trunk/extensions/RecordAdmin/RecordAdmin_body.php

Added Paths:
-----------
    trunk/extensions/RecordAdmin/recordadmin.js

Modified: trunk/extensions/RecordAdmin/RecordAdmin.php
===================================================================
--- trunk/extensions/RecordAdmin/RecordAdmin.php        2011-08-03 06:42:41 UTC 
(rev 93800)
+++ trunk/extensions/RecordAdmin/RecordAdmin.php        2011-08-03 07:02:04 UTC 
(rev 93801)
@@ -10,8 +10,10 @@
  * @author Siebrand Mazeland
  * @licence GNU General Public Licence 2.0 or later
  */
-define( 'RECORDADMIN_VERSION', '1.2.10, 2011-08-01' );
+define( 'RECORDADMIN_VERSION', '1.3.0, 2011-08-03' );
 
+$wgRecordAdminExtPath = preg_replace( "|^.*(/extensions/.*$)|", 
"$wgScriptPath$1", dirname( __FILE__ ) );
+
 $dir = dirname( __FILE__ ) . '/';
 $wgExtensionMessagesFiles['RecordAdmin'] = $dir . 'RecordAdmin.i18n.php';
 $wgExtensionAliasesFiles['RecordAdmin']  = $dir . 'RecordAdmin.alias.php';
@@ -35,7 +37,16 @@
 
 $wgExtensionFunctions[] = 'wfSetupRecordAdmin';
 function wfSetupRecordAdmin() {
-       global $wgRecordAdmin;
+       global $wgRecordAdmin, $wgResourceModules, $wgRecordAdminExtPath;
+
+       $wgResourceModules['ext.recordadmin'] = array(
+               'scripts' => array( 'recordadmin.js' ),
+               'styles' => array(),
+               'dependencies' => array( 'jquery' ),
+               'localBasePath' => dirname( __FILE__ ),
+               'remoteExtPath' => $wgRecordAdminExtPath
+       );
+
        $wgRecordAdmin = new RecordAdmin();
 }
 

Modified: trunk/extensions/RecordAdmin/RecordAdmin_body.php
===================================================================
--- trunk/extensions/RecordAdmin/RecordAdmin_body.php   2011-08-03 06:42:41 UTC 
(rev 93800)
+++ trunk/extensions/RecordAdmin/RecordAdmin_body.php   2011-08-03 07:02:04 UTC 
(rev 93801)
@@ -108,36 +108,20 @@
                        $editPage->editFormTextTop = $tabset;
 
                        # JS to add an onSubmit method that adds the record 
forms contents to hidden values in the edit form
-                       $wgOut->addScript( "<script type='$wgJsMimeType'>
-                               function raRecordForms() {
-                                       var forms = [ $jsFormsList ];
-                                       for( i = 0; i < forms.length; i++ ) {
-                                               var type = forms[i];
-                                               var form = 
document.getElementById( type + '-form' );
-                                               var tags = [ 'input', 'select', 
'textarea' ];
-                                               for( j = 0; j < tags.length; 
j++ ) {
-                                                       var inputs = 
form.getElementsByTagName( tags[j] );
-                                                       for( k = 0; k < 
inputs.length; k++ ) {
-                                                               var input = 
jQuery( inputs[k] );
-                                                               if( 
input.attr('type') != 'checkbox' || input.attr('checked') ) {
-                                                                       var 
multi = input.val();
-                                                                       if( 
typeof( multi ) == 'object' ) multi = multi.join('\\n');
-                                                                       var key 
= type + ':' + inputs[k].getAttribute('name');
-                                                                       var 
hidden = jQuery( document.createElement( 'input' ) );
-                                                                       
hidden.attr( 'name', key );
-                                                                       
hidden.attr( 'type', 'hidden' );
-                                                                       
hidden.val( multi );
-                                                                       jQuery( 
'#editform' ).append( hidden );
-                                                               }
-                                                       }
-                                               }
+                       if( is_callable( array( $wgOut, 'addModules' ) ) ) {
+                               $wgOut->addModules( 'ext.recordadmin' );
+                       } else {
+                               global $wgRecordAdminExtPath;
+                               $wgOut->addScript( "<script 
type=\"$wgJsMimeType\" src=\"$wgRecordAdminExtPath/recordadmin.js\"></script>" 
);
+                               $wgOut->addScript( "<script 
type=\"$wgJsMimeType\">
+                                       function raAddRecordFormSubmit() {
+                                               jQuery( '#editform' ).attr( 
'onsubmit', 'raRecordForms()' );
                                        }
-                               }
-                               function raAddToSubmit() {
-                                       jQuery( '#editform' ).attr( 'onsubmit', 
'raRecordForms()' );
-                               }
-                               addOnloadHook( raAddToSubmit );
-                       </script>" );
+                                       addOnloadHook( raAddRecordFormSubmit 
);</script>"
+                               );
+                       }
+                       $wgOut->addScript( "<script type=\"$wgJsMimeType\">var 
forms = [ $jsFormsList ];</script>" );
+
                }
 
 

Added: trunk/extensions/RecordAdmin/recordadmin.js
===================================================================
--- trunk/extensions/RecordAdmin/recordadmin.js                         (rev 0)
+++ trunk/extensions/RecordAdmin/recordadmin.js 2011-08-03 07:02:04 UTC (rev 
93801)
@@ -0,0 +1,25 @@
+window.raRecordForms = function () {
+       for( i = 0; i < window.forms.length; i++ ) {
+               var type = forms[i];
+               var form = document.getElementById( type + '-form' );
+               var tags = [ 'input', 'select', 'textarea' ];
+               for( j = 0; j < tags.length; j++ ) {
+                       var inputs = form.getElementsByTagName( tags[j] );
+                       for( k = 0; k < inputs.length; k++ ) {
+                               var input = jQuery( inputs[k] );
+                               if( input.attr('type') != 'checkbox' || 
input.attr('checked') ) {
+                                       var multi = input.val();
+                                       if( typeof( multi ) == 'object' ) multi 
= multi.join('\\n');
+                                       var key = type + ':' + 
inputs[k].getAttribute('name');
+                                       var hidden = jQuery( 
document.createElement( 'input' ) );
+                                       hidden.attr( 'name', key );
+                                       hidden.attr( 'type', 'hidden' );
+                                       hidden.val( multi );
+                                       jQuery( '#editform' ).append( hidden );
+                               }
+                       }
+               }
+       }
+};
+
+jQuery( '#editform' ).attr( 'onsubmit', 'raRecordForms()' );


_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to