Index: trunk/extensions/SemanticForms/specials/SF_CreateForm.php |
— | — | @@ -360,7 +360,8 @@ |
361 | 361 | |
362 | 362 | $params = method_exists( $inputTypeClass, 'getParameters' ) ? call_user_func( array( $inputTypeClass, 'getParameters' ) ) : array(); |
363 | 363 | |
364 | | - foreach ( $params as $i => $param ) { |
| 364 | + $i = 0; |
| 365 | + foreach ( $params as $param ) { |
365 | 366 | $paramName = $param['name']; |
366 | 367 | $type = $param['type']; |
367 | 368 | $desc = $wgParser->parse( $param['description'], new Title(), new ParserOptions() )->getText(); |
— | — | @@ -387,6 +388,7 @@ |
388 | 389 | if ( $i % 3 == 2 || $i == count( $params ) - 1 ) { |
389 | 390 | $text .= "<div style=\"clear: both\";></div></div>\n"; |
390 | 391 | } |
| 392 | + ++$i; |
391 | 393 | } |
392 | 394 | return $text; |
393 | 395 | } |
Index: trunk/extensions/SemanticForms/includes/forminputs/SF_FormInput.php |
— | — | @@ -87,27 +87,27 @@ |
88 | 88 | */ |
89 | 89 | public static function getParameters() { |
90 | 90 | $params = array(); |
91 | | - $params[] = array( |
| 91 | + $params['mandatory'] = array( |
92 | 92 | 'name' => 'mandatory', |
93 | 93 | 'type' => 'boolean', |
94 | 94 | 'description' => wfMsg( 'sf_forminputs_mandatory' ) |
95 | 95 | ); |
96 | | - $params[] = array( |
| 96 | + $params['restricted'] = array( |
97 | 97 | 'name' => 'restricted', |
98 | 98 | 'type' => 'boolean', |
99 | 99 | 'description' => wfMsg( 'sf_forminputs_restricted' ) |
100 | 100 | ); |
101 | | - $params[] = array( |
| 101 | + $params['class'] = array( |
102 | 102 | 'name' => 'class', |
103 | 103 | 'type' => 'string', |
104 | 104 | 'description' => wfMsg( 'sf_forminputs_class' ) |
105 | 105 | ); |
106 | | - $params[] = array( |
| 106 | + $params['property'] = array( |
107 | 107 | 'name' => 'property', |
108 | 108 | 'type' => 'string', |
109 | 109 | 'description' => wfMsg( 'sf_forminputs_property' ) |
110 | 110 | ); |
111 | | - $params[] = array( |
| 111 | + $params['default'] = array( |
112 | 112 | 'name' => 'default', |
113 | 113 | 'type' => 'string', |
114 | 114 | 'description' => wfMsg( 'sf_forminputs_default' ) |
— | — | @@ -165,6 +165,19 @@ |
166 | 166 | public function getJsValidationFunctionData() { |
167 | 167 | return $this->mJsValidationFunctionData; |
168 | 168 | } |
| 169 | + |
| 170 | + |
| 171 | + /** |
| 172 | + * Returns the names of the resource modules this input type uses. |
| 173 | + * |
| 174 | + * Returns the names of the modules as an array or - if there is only one |
| 175 | + * module - as a string. |
| 176 | + * |
| 177 | + * @return null|string|array |
| 178 | + */ |
| 179 | + public function getResourceModuleNames() { |
| 180 | + return null; |
| 181 | + } |
169 | 182 | |
170 | 183 | /** |
171 | 184 | * For each input type one or more JavaScript initialization functions may |
— | — | @@ -294,27 +307,38 @@ |
295 | 308 | |
296 | 309 | $input = new $calledClass ( $sfgFieldNum, $cur_value, $input_name, $is_disabled, $other_args ); |
297 | 310 | |
| 311 | + $modules = $input->getResourceModuleNames(); |
| 312 | + |
| 313 | + // register modules for the input |
| 314 | + if ( $modules !== null ) { |
| 315 | + $wgOut->addModuleStyles( $modules ); |
| 316 | + $wgOut->addModuleScripts( $modules ); |
| 317 | + } |
| 318 | + |
298 | 319 | // create calls to JS initialization and validation |
299 | 320 | // TODO: This data should be transferred as a JSON blob and then be evaluated from a dedicated JS file |
300 | | - $jstext = ''; |
| 321 | + if ( $input->getJsInitFunctionData() || $input->getJsValidationFunctionData() ) { |
301 | 322 | |
302 | | - foreach ( $input->getJsInitFunctionData() as $jsInitFunctionData ) { |
| 323 | + $jstext = ''; |
303 | 324 | |
304 | | - $jstext .= <<<JAVASCRIPT |
305 | | -jQuery(function(){ jQuery('#input_$sfgFieldNum').SemanticForms_registerInputInit({$jsInitFunctionData['name']}, {$jsInitFunctionData['param']} ); }); |
306 | | -JAVASCRIPT; |
307 | | - } |
| 325 | + foreach ( $input->getJsInitFunctionData() as $jsInitFunctionData ) { |
| 326 | + $jstext .= "jQuery('#input_$sfgFieldNum').SemanticForms_registerInputInit({$jsInitFunctionData['name']}, {$jsInitFunctionData['param']} );"; |
| 327 | + } |
308 | 328 | |
309 | | - foreach ( $input->getJsValidationFunctionData() as $jsValidationFunctionData ) { |
| 329 | + foreach ( $input->getJsValidationFunctionData() as $jsValidationFunctionData ) { |
| 330 | + $jstext .= "jQuery('#input_$sfgFieldNum').SemanticForms_registerInputValidation( {$jsValidationFunctionData['name']}, {$jsValidationFunctionData['param']});"; |
| 331 | + } |
310 | 332 | |
311 | | - $jstext .= <<<JAVASCRIPT |
312 | | -jQuery(function(){ jQuery('#input_$sfgFieldNum').SemanticForms_registerInputValidation( {$jsValidationFunctionData['name']}, {$jsValidationFunctionData['param']}); }); |
313 | | -JAVASCRIPT; |
| 333 | + if ( $modules !== null ) { |
| 334 | + $jstext = 'mw.loader.using(' . json_encode( $modules ) . ', function(){' . $jstext . '});'; |
| 335 | + } |
| 336 | + |
| 337 | + $jstext = 'jQuery(function(){' . $jstext . '});'; |
| 338 | + |
| 339 | + // write JS code directly to the page's code |
| 340 | + $wgOut->addScript( Html::inlineScript( $jstext ) ); |
314 | 341 | } |
315 | 342 | |
316 | | - // write JS code directly to the page's code |
317 | | - $wgOut->addScript( Html::inlineScript( $jstext ) ); |
318 | | - |
319 | 343 | return $input->getHtmlText(); |
320 | 344 | } |
321 | 345 | |