r75197 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r75196‎ | r75197 | r75198 >
Date:15:54, 22 October 2010
Author:yaron
Status:deferred
Tags:
Comment:
Streamlined handling of Javascript, especially for multiple-instance templates
Modified paths:
  • /trunk/extensions/SemanticForms/includes/SF_FormPrinter.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/includes/SF_FormPrinter.php
@@ -149,6 +149,7 @@
150150 global $sfgTabIndex; // used to represent the current tab index in the form
151151 global $sfgFieldNum; // used for setting various HTML IDs
152152 global $sfgJSValidationCalls; // array of Javascript calls to determine if page can be saved
 153+ global $sfgAdderButtons, $sfgRemoverButtons;
153154
154155 // initialize some variables
155156 $sfgTabIndex = 1;
@@ -232,7 +233,6 @@
233234 }
234235 }
235236 $javascript_text = "";
236 - $sfgJSValidationCalls = array();
237237 $fields_javascript_text = "";
238238
239239 // Remove <noinclude> sections and <includeonly> tags from form definition
@@ -1136,14 +1136,17 @@
11371137 // in the form, to differentiate the inputs the form starts out
11381138 // with from any inputs added by the Javascript
11391139 $section = str_replace( '[num]', "[{$instance_num}a]", $section );
 1140+ $wrapperID = "wrapper_$sfgFieldNum";
 1141+ $removerID = "remover_$sfgFieldNum";
11401142 $remove_text = wfMsg( 'sf_formedit_remove' );
11411143 $form_text .= <<<END
1142 - <div id="wrapper_$sfgFieldNum" class="multipleTemplate">
 1144+ <div id="$wrapperID" class="multipleTemplate">
11431145 $section
1144 - <input type="button" onclick="removeInstance('wrapper_$sfgFieldNum');" value="$remove_text" tabindex="$sfgTabIndex" class="remove" />
 1146+ <input type="button" id="$removerID" value="$remove_text" tabindex="$sfgTabIndex" class="remove" />
11451147 </div>
11461148
11471149 END;
 1150+ $sfgRemoverButtons[] = "$removerID,$wrapperID";
11481151 // this will cause the section to be re-parsed on the next go
11491152 $section_num--;
11501153 } else {
@@ -1157,11 +1160,13 @@
11581161
11591162 END;
11601163 $add_another = wfMsg( 'sf_formedit_addanother' );
 1164+ $adderID = "adder_$sfgFieldNum";
11611165 $form_text .= <<<END
11621166 <p style="margin-left:10px;">
1163 - <p><input type="button" onclick="addInstance('starter_$query_template_name', 'main_$query_template_name', '$sfgFieldNum');" value="$add_another" tabindex="$sfgTabIndex" class="addAnother" /></p>
 1167+ <p><input type="button" id="$adderID" value="$add_another" tabindex="$sfgTabIndex" class="addAnother" /></p>
11641168
11651169 END;
 1170+ $sfgAdderButtons[] = "$adderID,$query_template_name,$sfgFieldNum";
11661171 }
11671172 } else {
11681173 $form_text .= $section;
@@ -1255,9 +1260,6 @@
12561261 END;
12571262
12581263 // add Javascript code for form-wide use
1259 - $javascript_text .= SFFormUtils::validationJavascript();
1260 - $javascript_text .= SFFormUtils::instancesJavascript();
1261 - $javascript_text .= SFFormUtils::autocompletionJavascript();
12621264 if ( $free_text_was_included && $showFCKEditor > 0 ) {
12631265 $javascript_text .= SFFormUtils::mainFCKJavascript( $showFCKEditor );
12641266 if ( $showFCKEditor & ( RTE_TOGGLE_LINK | RTE_POPUP ) ) {
@@ -1285,7 +1287,7 @@
12861288 $javascript_text = '';
12871289 }
12881290
1289 - return array( $form_text, "/*<![CDATA[*/ $javascript_text /*]]>*/",
 1291+ return array( $form_text, $javascript_text,
12901292 $data_text, $new_text, $generated_page_name );
12911293 }
12921294

Status & tagging log