r99146 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r99145‎ | r99146 | r99147 >
Date:21:41, 6 October 2011
Author:ashley
Status:deferred
Tags:
Comment:
CreateAPage: follow-up to r98701 -- fix an annoying JS bug caused by my YUI -> jQuery rewrite. Now only one createplate at a time in the "choose a page type" listing has the templateFrameSelected class. This fix is pretty ugly and somehow passing this.id as the elementId to switchTemplate() didn't work, yet passing this as an additional parameter and then accessing this.id works...
Modified paths:
  • /trunk/extensions/CreateAPage/js/CreateAPage.js (modified) (history)

Diff [purge]

Index: trunk/extensions/CreateAPage/js/CreateAPage.js
@@ -1101,7 +1101,7 @@
11021102
11031103 for ( var i = 0; i < wgCreateAPageElementsForJavaScript.length; i++ ) {
11041104 jQuery( '#' + wgCreateAPageElementsForJavaScript[i] ).click( function( e ) {
1105 - CreateAPage.switchTemplate( e, wgCreateAPageElementsForJavaScript[i] );
 1105+ CreateAPage.switchTemplate( e, wgCreateAPageElementsForJavaScript[i], this );
11061106 });
11071107 }
11081108
@@ -1119,10 +1119,12 @@
11201120 *
11211121 * @param e Event
11221122 * @param elementId String: name of the createplate template (i.e.
1123 - * cp-template-Name)
 1123+ * cp-template-Name) -- actually doesn't seem to work, which is why we pass
 1124+ * fullElement into this function and use it to get the ID instead
 1125+ * @param fullElement
11241126 */
1125 - switchTemplate: function( e, elementId ) {
1126 - CreateAPage.myId = elementId;
 1127+ switchTemplate: function( e, elementId, fullElement ) {
 1128+ CreateAPage.myId = fullElement.id;
11271129 e.preventDefault();
11281130
11291131 document.getElementById( 'cp-multiedit' ).innerHTML =
@@ -1137,7 +1139,7 @@
11381140 data: {
11391141 action: 'ajax',
11401142 rs: 'axMultiEditParse',
1141 - template: elementId.replace( 'cp-template-', '' )
 1143+ template: fullElement.id.replace( 'cp-template-', '' )
11421144 },
11431145 success: function( data, textStatus, jqXHR ) {
11441146 document.getElementById( 'cp-multiedit' ).innerHTML = '';
@@ -1150,24 +1152,15 @@
11511153 document.getElementById( 'cp-multiedit' ).innerHTML = res;
11521154 }
11531155
1154 - // @todo FIXME: need to add some code to remove the
1155 - // 'templateFrameSelected' class from other templates except
1156 - // the currently selected one
1157 - //
1158 - // I tried this above the addClass( 'templateFrameSelected' )
1159 - // stuff, but it didn't work (when you would select the 2nd
1160 - // template, the class would be given to the 3rd template
1161 - // instead...lol wut):
1162 - //
1163 - // jQuery( '.templateFrameSelected' ).each( function( index ) {
1164 - // jQuery( this ).removeClass( 'templateFrameSelected' );
1165 - // });
11661156 var elements = wgCreateAPageElementsForJavaScript;
11671157 for ( var i in elements ) {
11681158 jQuery( '#' + elements[i] ).addClass( 'templateFrame' );
 1159+ if ( jQuery( '#' + elements[i] ).hasClass( 'templateFrameSelected' ) ) {
 1160+ jQuery( '#' + elements[i] ).removeClass( 'templateFrameSelected' );
 1161+ }
11691162 }
11701163
1171 - // ...and make the recently selected createplate active!
 1164+ // Make the recently selected createplate active!
11721165 jQuery( '#' + CreateAPage.myId ).addClass( 'templateFrameSelected' );
11731166
11741167 var infoboxToggle = jQuery( '#cp-infobox-toggle' );

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r98701CreateAPage: initial changes to make this more compatible with 1.18 (committi...ashley18:42, 2 October 2011

Status & tagging log