Index: trunk/extensions/SemanticForms/includes/SF_FormInputs.php |
— | — | @@ -14,7 +14,7 @@ |
15 | 15 | * Creates an array of values that match the specified source name and type, |
16 | 16 | * for use by both Javascript autocompletion and comboboxes. |
17 | 17 | */ |
18 | | - static function createAutocompleteValuesArray( $source_name, $source_type ) { |
| 18 | + static function getAutocompleteValues( $source_name, $source_type ) { |
19 | 19 | $names_array = array(); |
20 | 20 | // the query depends on whether this is a property, category, concept |
21 | 21 | // or namespace |
— | — | @@ -33,22 +33,6 @@ |
34 | 34 | return $names_array; |
35 | 35 | } |
36 | 36 | |
37 | | - |
38 | | - /** |
39 | | - * Creates a comma-delimited string of values that match the specified |
40 | | - * source name and type, for use by Javascript autocompletion. |
41 | | - */ |
42 | | - static function createAutocompleteValuesString( $source_name, $source_type ) { |
43 | | - $names_array = self::createAutocompleteValuesArray( $source_name, $source_type ); |
44 | | - // escape quotes, to avoid Javascript errors |
45 | | - $names_array = array_map( 'addslashes', $names_array ); |
46 | | - $autocomplete_string = "['" . implode( "', '", $names_array ) . "']"; |
47 | | - // replace any newlines in the string, just to avoid breaking the Javascript |
48 | | - $autocomplete_string = str_replace( "\n", ' ', $autocomplete_string ); |
49 | | - $autocomplete_string = str_replace( "\r", ' ', $autocomplete_string ); |
50 | | - return $autocomplete_string; |
51 | | - } |
52 | | - |
53 | 37 | static function uploadLinkHTML( $input_id, $delimiter = null, $default_filename = null ) { |
54 | 38 | global $wgOut, $sfgScriptPath, $sfgFancyBoxIncluded; |
55 | 39 | |
— | — | @@ -69,6 +53,7 @@ |
70 | 54 | |
71 | 55 | if ( !$sfgFancyBoxIncluded ) { |
72 | 56 | $sfgFancyBoxIncluded = true; |
| 57 | + global $wgOut; |
73 | 58 | $wgOut->addScriptFile( "$sfgScriptPath/libs/jquery.fancybox-1.3.1.js" ); |
74 | 59 | } |
75 | 60 | |
— | — | @@ -178,7 +163,7 @@ |
179 | 164 | } |
180 | 165 | |
181 | 166 | static function dropdownHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) { |
182 | | - global $sfgTabIndex, $sfgFieldNum; |
| 167 | + global $sfgTabIndex, $sfgFieldNum, $sfgShowOnSelectCalls; |
183 | 168 | |
184 | 169 | $className = ( $is_mandatory ) ? "mandatoryField" : "createboxInput"; |
185 | 170 | if ( array_key_exists( 'class', $other_args ) ) |
— | — | @@ -186,20 +171,16 @@ |
187 | 172 | $input_id = "input_$sfgFieldNum"; |
188 | 173 | $info_id = "info_$sfgFieldNum"; |
189 | 174 | $disabled_text = ( $is_disabled ) ? "disabled" : ""; |
190 | | - $javascript_text = ''; |
191 | | - $return_js_text = ''; |
192 | 175 | if ( array_key_exists( 'show on select', $other_args ) ) { |
193 | | - $javascript_text = 'onChange="'; |
194 | 176 | foreach ( $other_args['show on select'] as $div_id => $options ) { |
195 | 177 | $options_str = implode( "', '", $options ); |
196 | | - $this_js_text = "showIfSelected('$input_id', ['$options_str'], '$div_id'); "; |
197 | | - $javascript_text .= $this_js_text; |
198 | | - $return_js_text .= $this_js_text . "\n"; |
| 178 | + $js_text = "showIfSelected('$input_id', ['$options_str'], '$div_id'); "; |
| 179 | + $sfgShowOnSelectCalls[] = "$('#$input_id').change( function() { $js_text } );"; |
| 180 | + $sfgShowOnSelectCalls[] = $js_text; |
199 | 181 | } |
200 | | - $javascript_text .= '"'; |
201 | 182 | } |
202 | 183 | $text = <<<END |
203 | | - <select id="$input_id" tabindex="$sfgTabIndex" name="$input_name" class="$className" $disabled_text $javascript_text> |
| 184 | + <select id="$input_id" tabindex="$sfgTabIndex" name="$input_name" class="$className" $disabled_text> |
204 | 185 | |
205 | 186 | END; |
206 | 187 | // add a blank value at the beginning, unless this is a mandatory field |
— | — | @@ -225,7 +206,7 @@ |
226 | 207 | <span id="$info_id" class="errorMessage"></span> |
227 | 208 | |
228 | 209 | END; |
229 | | - return array( $text, $return_js_text ); |
| 210 | + return array( $text, null ); |
230 | 211 | } |
231 | 212 | |
232 | 213 | /** |
— | — | @@ -242,7 +223,7 @@ |
243 | 224 | } |
244 | 225 | |
245 | 226 | static function listboxHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) { |
246 | | - global $sfgTabIndex, $sfgFieldNum; |
| 227 | + global $sfgTabIndex, $sfgFieldNum, $sfgShowOnSelectCalls; |
247 | 228 | |
248 | 229 | $className = ( $is_mandatory ) ? "mandatoryField" : "createboxInput"; |
249 | 230 | if ( array_key_exists( 'class', $other_args ) ) |
— | — | @@ -264,26 +245,17 @@ |
265 | 246 | } |
266 | 247 | $cur_values = self::getValuesArray( $cur_value, $delimiter ); |
267 | 248 | |
268 | | - $javascript_text = ''; |
269 | | - $return_js_text = ''; |
270 | | - if ( array_key_exists( 'show on select', $other_args ) ) { |
271 | | - $javascript_text = 'onChange="'; |
272 | | - foreach ( $other_args['show on select'] as $div_id => $options ) { |
273 | | - $options_str = implode( "', '", $options ); |
274 | | - $this_js_text = "showIfSelected('$input_id', ['$options_str'], '$div_id'); "; |
275 | | - $javascript_text .= $this_js_text; |
276 | | - $return_js_text .= $this_js_text . "\n"; |
277 | | - } |
278 | | - $javascript_text .= '"'; |
279 | | - } |
280 | | - |
281 | 249 | $text = <<<END |
282 | | - <select id="$input_id" tabindex="$sfgTabIndex" name="$input_name" class="$className" multiple $size_text $disabled_text $javascript_text> |
| 250 | + <select id="$input_id" tabindex="$sfgTabIndex" name="$input_name" class="$className" multiple $size_text $disabled_text> |
283 | 251 | |
284 | 252 | END; |
285 | 253 | if ( ( $possible_values = $other_args['possible_values'] ) == null ) |
286 | 254 | $possible_values = array(); |
| 255 | + $enum_input_ids = array(); |
287 | 256 | foreach ( $possible_values as $possible_value ) { |
| 257 | + // create array $enum_input_ids to associate values with their input IDs, |
| 258 | + // for use in creating the 'show on select' Javascript later |
| 259 | + $enum_input_ids[$possible_value] = $input_id; |
288 | 260 | $text .= " <option value=\"$possible_value\""; |
289 | 261 | if ( in_array( $possible_value, $cur_values ) ) { $text .= " selected"; } |
290 | 262 | $text .= ">"; |
— | — | @@ -299,11 +271,32 @@ |
300 | 272 | <input type="hidden" name="$hidden_input_name" value="1" /> |
301 | 273 | |
302 | 274 | END; |
303 | | - return array( $text, $return_js_text ); |
| 275 | + |
| 276 | + if ( array_key_exists( 'show on select', $other_args ) ) { |
| 277 | + foreach ( $other_args['show on select'] as $div_id => $options ) { |
| 278 | + $cur_input_ids = array(); |
| 279 | + foreach ( $options as $option ) { |
| 280 | + if ( array_key_exists( $option, $enum_input_ids ) ) { |
| 281 | + $cur_input_ids[] = $enum_input_ids[$option]; |
| 282 | + } |
| 283 | + } |
| 284 | + $options_str = "['" . implode( "', '", $options ) . "']"; |
| 285 | + $js_text = "showIfSelectedInListBox('$input_id', $options_str, '$div_id'); "; |
| 286 | + $sfgShowOnSelectCalls[] = $js_text; |
| 287 | + foreach ( $possible_values as $key => $possible_value ) { |
| 288 | + $cur_input_id = $enum_input_ids[$possible_value]; |
| 289 | + if ( in_array( $possible_value, $options ) ) { |
| 290 | + $sfgShowOnSelectCalls[] = "$('#$cur_input_id').click( function() { $js_text } );"; |
| 291 | + } |
| 292 | + } |
| 293 | + } |
| 294 | + } |
| 295 | + |
| 296 | + return array( $text, null ); |
304 | 297 | } |
305 | 298 | |
306 | 299 | static function checkboxesHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) { |
307 | | - global $sfgTabIndex, $sfgFieldNum; |
| 300 | + global $sfgTabIndex, $sfgFieldNum, $sfgShowOnSelectCalls; |
308 | 301 | |
309 | 302 | $checkbox_class = ( $is_mandatory ) ? "mandatoryField" : "createboxInput"; |
310 | 303 | $span_class = "checkboxSpan"; |
— | — | @@ -322,7 +315,6 @@ |
323 | 316 | if ( ( $possible_values = $other_args['possible_values'] ) == null ) |
324 | 317 | $possible_values = array(); |
325 | 318 | $text = ""; |
326 | | - $return_js_text = ""; |
327 | 319 | $enum_input_ids = array(); |
328 | 320 | foreach ( $possible_values as $key => $possible_value ) { |
329 | 321 | // create array $enum_input_ids to associate values with their input IDs, |
— | — | @@ -374,7 +366,6 @@ |
375 | 367 | |
376 | 368 | END; |
377 | 369 | |
378 | | - $return_js_text = ''; |
379 | 370 | if ( array_key_exists( 'show on select', $other_args ) ) { |
380 | 371 | foreach ( $other_args['show on select'] as $div_id => $options ) { |
381 | 372 | $cur_input_ids = array(); |
— | — | @@ -384,35 +375,22 @@ |
385 | 376 | } |
386 | 377 | } |
387 | 378 | $options_str = "['" . implode( "', '", $cur_input_ids ) . "']"; |
388 | | - $cur_js_text = "showIfChecked($options_str, '$div_id'); "; |
389 | | - $return_js_text .= $cur_js_text . "\n"; |
| 379 | + $js_text = "showIfChecked($options_str, '$div_id'); "; |
| 380 | + $sfgShowOnSelectCalls[] = $js_text; |
390 | 381 | foreach ( $possible_values as $key => $possible_value ) { |
391 | 382 | $cur_input_id = $enum_input_ids[$possible_value]; |
392 | | - // we use addClickHandler(), instead of adding the Javascript via |
393 | | - // onClick="", because MediaWiki's wikibits.js does its own handling |
394 | | - // of checkboxes, which impacts their behavior in IE |
395 | 383 | if ( in_array( $possible_value, $options ) ) { |
396 | | - $return_js_text .= <<<END |
397 | | -addClickHandler( |
398 | | - document.getElementById('$cur_input_id'), |
399 | | - function() { $cur_js_text } |
400 | | -); |
401 | | - |
402 | | -END; |
| 384 | + $sfgShowOnSelectCalls[] = "$('#$cur_input_id').click( function() { $js_text } );"; |
403 | 385 | } |
404 | 386 | } |
405 | 387 | } |
406 | 388 | } |
407 | 389 | |
408 | | - // do the replacements |
409 | | - foreach ( $enum_input_ids as $enum_val => $input_id ) { |
410 | | - $return_js_text = str_replace( "<<$enum_val>>", "'$input_id'", $return_js_text ); |
411 | | - } |
412 | | - return array( $text, $return_js_text ); |
| 390 | + return array( $text, null ); |
413 | 391 | } |
414 | 392 | |
415 | 393 | static function comboboxHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) { |
416 | | - if ( array_key_exists( 'no autocomplete', $other_args ) && |
| 394 | + if ( array_key_exists( 'no autocomplete', $other_args ) && |
417 | 395 | $other_args['no autocomplete'] == true ) { |
418 | 396 | unset( $other_args['autocompletion source'] ); |
419 | 397 | return SFFormInputs::textEntryHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ); |
— | — | @@ -421,7 +399,9 @@ |
422 | 400 | if ( array_key_exists( 'possible_values', $other_args ) && $other_args['possible_values'] != null ) |
423 | 401 | return SFFormInputs::dropdownHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ); |
424 | 402 | |
425 | | - global $sfgTabIndex, $sfgFieldNum,$wgOut, $sfgScriptPath,$wgJsMimeType, $smwgScriptPath,$smwgJqUIAutoIncluded; |
| 403 | + global $sfgTabIndex, $sfgFieldNum, $wgOut, $sfgScriptPath, $wgJsMimeType; |
| 404 | + global $smwgScriptPath, $smwgJqUIAutoIncluded; |
| 405 | + global $sfgAutocompleteMappings, $sfgComboBoxInputs, $sfgAutogrowInputs; |
426 | 406 | |
427 | 407 | $autocomplete_field_type = ""; |
428 | 408 | $autocompletion_source = ""; |
— | — | @@ -448,11 +428,9 @@ |
449 | 429 | $div_name = "div_" . $sfgFieldNum; |
450 | 430 | |
451 | 431 | $options_str_key = str_replace( "'", "\'", $autocompletion_source ); |
452 | | - $javascript_text = "autocompletemappings[$sfgFieldNum] = '$options_str_key';\n"; |
| 432 | + $sfgAutocompleteMappings[$sfgFieldNum] = $options_str_key; |
453 | 433 | |
454 | | - $values = array(); |
455 | | - $values = self::createAutocompleteValuesArray($autocompletion_source, $autocomplete_field_type ); |
456 | | - |
| 434 | + $values = self::getAutocompleteValues($autocompletion_source, $autocomplete_field_type ); |
457 | 435 | |
458 | 436 | /*adding code for displaying dropdown of autocomplete values*/ |
459 | 437 | |
— | — | @@ -469,10 +447,8 @@ |
470 | 448 | </select> |
471 | 449 | <span id="$info_id" class="errorMessage"></span> |
472 | 450 | </div> |
473 | | -<script type="text/javascript" > |
474 | | -jQuery(function() {jQuery("#input_$sfgFieldNum").combobox();}); |
475 | | -</script> |
476 | 451 | END; |
| 452 | + $sfgComboBoxInputs[] = $sfgFieldNum; |
477 | 453 | // there's no direct correspondence between the 'size=' attribute for |
478 | 454 | // text inputs and the number of pixels, but multiplying by 6 seems to |
479 | 455 | // be about right for the major browsers |
— | — | @@ -483,7 +459,7 @@ |
484 | 460 | </style> |
485 | 461 | END; |
486 | 462 | $wgOut->addScript($combobox_css); |
487 | | - return array( $text, $javascript_text ); |
| 463 | + return array( $text, null ); |
488 | 464 | } |
489 | 465 | |
490 | 466 | static function textInputWithAutocompleteHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) { |
— | — | @@ -497,12 +473,12 @@ |
498 | 474 | if ( array_key_exists( 'possible_values', $other_args ) && $other_args['possible_values'] != null ) |
499 | 475 | return SFFormInputs::dropdownHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ); |
500 | 476 | |
501 | | - global $sfgTabIndex, $sfgFieldNum, $wgOut, $sfgScriptPath,$wgJsMimeType, $smwgScriptPath,$smwgJqUIAutoIncluded; |
| 477 | + global $sfgTabIndex, $sfgFieldNum, $sfgScriptPath, $wgJsMimeType, $smwgScriptPath, $smwgJqUIAutoIncluded; |
| 478 | + global $sfgAutogrowInputs, $sfgAutocompleteMappings, $sfgAutocompleteDataTypes, $sfgAutocompleteValues; |
502 | 479 | |
503 | 480 | $className = ( $is_mandatory ) ? "autocompleteInput mandatoryField" : "autocompleteInput createboxInput"; |
504 | 481 | if ( array_key_exists( 'class', $other_args ) ) |
505 | 482 | $className .= " " . $other_args['class']; |
506 | | - $disabled_text = ( $is_disabled ) ? "disabled" : ""; |
507 | 483 | if ( array_key_exists( 'autocomplete field type', $other_args ) ) { |
508 | 484 | $autocomplete_field_type = $other_args['autocomplete field type']; |
509 | 485 | $autocompletion_source = $other_args['autocompletion source']; |
— | — | @@ -518,32 +494,37 @@ |
519 | 495 | |
520 | 496 | $rows = $other_args['rows']; |
521 | 497 | $cols = $other_args['cols']; |
| 498 | + $text = ""; |
| 499 | + if ( array_key_exists( 'autogrow', $other_args ) ) { |
| 500 | + $sfgAutogrowInputs[] = $input_id; |
| 501 | + $className .= ' autoGrow'; |
| 502 | + if ( ! method_exists( 'OutputPage', 'addModules' ) ) { |
| 503 | + global $wgOut; |
| 504 | + $wgOut->addScriptFile( "$sfgScriptPath/libs/SF_autogrow.js" ); |
| 505 | + } |
| 506 | + } |
| 507 | + |
| 508 | + $textarea_attrs = array( |
| 509 | + 'tabindex' => $sfgTabIndex, |
| 510 | + 'id' => $input_id, |
| 511 | + 'name' => $input_name, |
| 512 | + 'rows' => $rows, |
| 513 | + 'cols' => $cols, |
| 514 | + 'class' => $className, |
| 515 | + ); |
| 516 | + if ( $is_disabled ) { |
| 517 | + $textarea_attrs['disabled'] = 'disabled'; |
| 518 | + } |
522 | 519 | if ( array_key_exists( 'maxlength', $other_args ) ) { |
523 | 520 | $maxlength = $other_args['maxlength']; |
524 | 521 | // is this an unnecessary performance load? Get the substring of the |
525 | 522 | // text on every key press or release, regardless of the current length |
526 | 523 | // of the text |
527 | | - $js_call = " onKeyDown=\"this.value = this.value.substring(0, $maxlength);\" onKeyUp=\"this.value = this.value.substring(0, $maxlength);\""; |
528 | | - } else { |
529 | | - $js_call = ""; |
| 524 | + $textarea_attrs['onKeyDown'] = "this.value = this.value.substring(0, $maxlength);"; |
| 525 | + $textarea_attrs['onKeyUp'] = "this.value = this.value.substring(0, $maxlength);"; |
530 | 526 | } |
531 | | - $text = ""; |
532 | | - if ( array_key_exists( 'autogrow', $other_args ) ) { |
533 | | - $text .= <<<END |
534 | | -<script type="text/javascript"> |
535 | | - jQuery.noConflict(); |
536 | | - jQuery(document).ready(function() { |
537 | | - jQuery("#$input_id").autoGrow(); |
538 | | - }); |
539 | | -</script> |
540 | | - |
541 | | -END; |
542 | | - $className .= ' autoGrow'; |
543 | | - } |
544 | | - |
545 | | - $text .= <<<END |
546 | | - <textarea tabindex="$sfgTabIndex" id="$input_id" name="$input_name" rows="$rows" cols="$cols" class="$className" $disabled_text $js_call></textarea> |
547 | | -END; |
| 527 | + $textarea_input = Xml::element('textarea', $textarea_attrs, '', false); |
| 528 | + $text .= $textarea_input; |
548 | 529 | } else { |
549 | 530 | if ( array_key_exists( 'size', $other_args ) ) |
550 | 531 | $size = $other_args['size']; |
— | — | @@ -593,14 +574,13 @@ |
594 | 575 | $options_str_key .= "," . $delimiter; |
595 | 576 | } |
596 | 577 | } |
597 | | - $options_str_key = str_replace( "'", "\'", $options_str_key ); |
598 | | - $javascript_text = "autocompletemappings[$sfgFieldNum] = '$options_str_key';\n"; |
| 578 | + $sfgAutocompleteMappings[$sfgFieldNum] = $options_str_key; |
599 | 579 | if ( array_key_exists( 'remote autocompletion', $other_args ) && |
600 | 580 | $other_args['remote autocompletion'] == true ) { |
601 | | - $javascript_text .= "autocompletedatatypes['$options_str_key'] = '$autocomplete_field_type';\n"; |
| 581 | + $sfgAutocompleteDataTypes[$options_str_key] = $autocomplete_field_type; |
602 | 582 | } elseif ( $autocompletion_source != '' ) { |
603 | | - $autocomplete_string = self::createAutocompleteValuesString( $autocompletion_source, $autocomplete_field_type ); |
604 | | - $javascript_text .= "autocompletestrings['$options_str_key'] = $autocomplete_string;\n"; |
| 583 | + $autocomplete_values = self::getAutocompleteValues( $autocompletion_source, $autocomplete_field_type ); |
| 584 | + $sfgAutocompleteValues[$options_str_key] = $autocomplete_values; |
605 | 585 | } |
606 | 586 | if ( $cur_value ) { |
607 | 587 | // replace various values to not break the Javascript |
— | — | @@ -610,7 +590,7 @@ |
611 | 591 | $text .= "document.getElementById('$input_id').value = \"$cur_value\"\n"; |
612 | 592 | } |
613 | 593 | $text .= '/* ]]> */</script>'; |
614 | | - return array( $text, $javascript_text ); |
| 594 | + return array( $text, null ); |
615 | 595 | } |
616 | 596 | |
617 | 597 | static function textAreaHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) { |
— | — | @@ -627,7 +607,7 @@ |
628 | 608 | return SFFormInputs::textInputWithAutocompleteHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ); |
629 | 609 | } |
630 | 610 | |
631 | | - global $sfgTabIndex, $sfgFieldNum, $smwgScriptPath, $sfgScriptPath,$wgOut; |
| 611 | + global $sfgTabIndex, $sfgFieldNum, $smwgScriptPath, $sfgScriptPath, $sfgAutogrowInputs; |
632 | 612 | |
633 | 613 | $className = ( $is_mandatory ) ? "mandatoryField" : "createboxInput"; |
634 | 614 | if ( array_key_exists( 'class', $other_args ) ) |
— | — | @@ -635,39 +615,43 @@ |
636 | 616 | $info_id = "info_$sfgFieldNum"; |
637 | 617 | // use a special ID for the free text field, for FCK's needs |
638 | 618 | $input_id = $input_name == "free_text" ? "free_text" : "input_$sfgFieldNum"; |
639 | | - $disabled_text = ( $is_disabled ) ? "disabled" : ""; |
640 | 619 | |
641 | 620 | $rows = $other_args['rows']; |
642 | 621 | $cols = $other_args['cols']; |
643 | | - if ( array_key_exists( 'maxlength', $other_args ) ) { |
644 | | - $maxlength = $other_args['maxlength']; |
645 | | - // is this an unnecessary performance load? Get the substring of the |
646 | | - // text on every key press or release, regardless of the current length |
647 | | - // of the text |
648 | | - $js_call = " onKeyDown=\"this.value = this.value.substring(0, $maxlength);\" onKeyUp=\"this.value = this.value.substring(0, $maxlength);\""; |
649 | | - } else { |
650 | | - $js_call = ""; |
651 | | - } |
652 | 622 | |
653 | 623 | $cur_value = htmlspecialchars( $cur_value ); |
654 | 624 | $text = ""; |
655 | 625 | if ( array_key_exists( 'autogrow', $other_args ) ) { |
656 | | - $wgOut->addScriptFile( "$sfgScriptPath/libs/SF_autogrow.js" ); |
657 | | - $text .= <<<END |
658 | | -<script type="text/javascript"> |
659 | | - jQuery.noConflict(); |
660 | | - jQuery(document).ready(function(){ |
661 | | - jQuery("#$input_id").autoGrow(); |
662 | | - }); |
663 | | -</script> |
664 | | - |
665 | | -END; |
| 626 | + $sfgAutogrowInputs[] = $input_id; |
666 | 627 | $className .= ' autoGrow'; |
| 628 | + if ( ! method_exists( 'OutputPage', 'addModules' ) ) { |
| 629 | + global $wgOut; |
| 630 | + $wgOut->addScriptFile( "$sfgScriptPath/libs/SF_autogrow.js" ); |
| 631 | + } |
667 | 632 | } |
668 | 633 | |
| 634 | + $textarea_attrs = array( |
| 635 | + 'tabindex' => $sfgTabIndex, |
| 636 | + 'id' => $input_id, |
| 637 | + 'name' => $input_name, |
| 638 | + 'rows' => $rows, |
| 639 | + 'cols' => $cols, |
| 640 | + 'class' => $className, |
| 641 | + ); |
| 642 | + if ( $is_disabled ) { |
| 643 | + $textarea_attrs['disabled'] = 'disabled'; |
| 644 | + } |
| 645 | + if ( array_key_exists( 'maxlength', $other_args ) ) { |
| 646 | + $maxlength = $other_args['maxlength']; |
| 647 | + // is this an unnecessary performance load? Get the substring of the |
| 648 | + // text on every key press or release, regardless of the current length |
| 649 | + // of the text |
| 650 | + $textarea_attrs['onKeyDown'] = "this.value = this.value.substring(0, $maxlength);"; |
| 651 | + $textarea_attrs['onKeyUp'] = "this.value = this.value.substring(0, $maxlength);"; |
| 652 | + } |
| 653 | + $textarea_input = Xml::element( 'textarea', $textarea_attrs, '', false ); |
669 | 654 | $text .= <<<END |
670 | | - |
671 | | - <textarea tabindex="$sfgTabIndex" id="$input_id" name="$input_name" rows="$rows" cols="$cols" class="$className" $disabled_text $js_call>$cur_value</textarea> |
| 655 | + $textarea_input |
672 | 656 | <span id="$info_id" class="errorMessage"></span> |
673 | 657 | |
674 | 658 | END; |
— | — | @@ -808,11 +792,11 @@ |
809 | 793 | $text .= ' <input tabindex="' . $sfgTabIndex . '" name="' . $input_name . '[timezone]" type="text" value="' . $timezone . '" size="2"/ ' . $disabled_text . '>' . "\n"; |
810 | 794 | } |
811 | 795 | |
812 | | - return array( $text, $javascript_text ); |
| 796 | + return array( $text, null ); |
813 | 797 | } |
814 | 798 | |
815 | 799 | static function radioButtonHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) { |
816 | | - global $sfgTabIndex, $sfgFieldNum; |
| 800 | + global $sfgTabIndex, $sfgFieldNum, $sfgShowOnSelectCalls; |
817 | 801 | |
818 | 802 | $span_class = "checkboxSpan"; |
819 | 803 | if ( array_key_exists( 'class', $other_args ) ) |
— | — | @@ -905,7 +889,6 @@ |
906 | 890 | END; |
907 | 891 | |
908 | 892 | // Finally, we do the 'show on select' handling. |
909 | | - $return_js_text = ''; |
910 | 893 | if ( array_key_exists( 'show on select', $other_args ) ) { |
911 | 894 | foreach ( $other_args['show on select'] as $div_id => $options ) { |
912 | 895 | $cur_input_ids = array(); |
— | — | @@ -919,32 +902,23 @@ |
920 | 903 | continue; |
921 | 904 | } |
922 | 905 | $options_str = "['" . implode( "', '", $cur_input_ids ) . "']"; |
923 | | - $cur_js_text = "showIfChecked($options_str, '$div_id'); "; |
924 | | - $return_js_text .= $cur_js_text . "\n"; |
| 906 | + $js_text = "showIfChecked($options_str, '$div_id');"; |
| 907 | + $sfgShowOnSelectCalls[] = $js_text; |
925 | 908 | foreach ( $possible_values as $key => $possible_value ) { |
926 | 909 | // We need to add each click handler to each radiobutton, |
927 | 910 | // because there doesn't seem to be any way for a radiobutton |
928 | 911 | // to know that it was unchecked - rather, the newly-checked |
929 | 912 | // radiobutton has to handle the change. |
930 | 913 | foreach ( $enum_input_ids as $cur_input_id ) { |
931 | | - // we use addClickHandler(), instead of adding the Javascript via |
932 | | - // onClick="", because MediaWiki's wikibits.js does its own handling |
933 | | - // of checkboxes, which impacts their behavior in IE |
934 | 914 | if ( in_array( $possible_value, $options ) ) { |
935 | | - $return_js_text .= <<<END |
936 | | -addClickHandler( |
937 | | - document.getElementById('$cur_input_id'), |
938 | | - function() { $cur_js_text } |
939 | | -); |
940 | | - |
941 | | -END; |
| 915 | + $sfgShowOnSelectCalls[] = "$('#$cur_input_id').click( function() { $js_text } );"; |
942 | 916 | } |
943 | 917 | } |
944 | 918 | } |
945 | 919 | } |
946 | 920 | } |
947 | 921 | |
948 | | - return array( $text, $return_js_text ); |
| 922 | + return array( $text, null ); |
949 | 923 | } |
950 | 924 | |
951 | 925 | static function checkboxHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) { |
— | — | @@ -956,21 +930,10 @@ |
957 | 931 | $info_id = "info_$sfgFieldNum"; |
958 | 932 | $input_id = "input_$sfgFieldNum"; |
959 | 933 | $disabled_text = ( $is_disabled ) ? "disabled" : ""; |
960 | | - $return_js_text = ''; |
961 | 934 | if ( array_key_exists( 'show on select', $other_args ) ) { |
962 | 935 | $div_id = key( $other_args['show on select'] ); |
963 | | - $this_js_text = "showIfChecked(['$input_id'], '$div_id');"; |
964 | | - // we use addClickHandler(), instead of adding the Javascript via |
965 | | - // onClick="", because MediaWiki's wikibits.js does its own handling |
966 | | - // of checkboxes, which impacts their behavior in IE |
967 | | - $return_js_text = <<<END |
968 | | -$this_js_text; |
969 | | -addClickHandler( |
970 | | - document.getElementById("$input_id"), |
971 | | - function() { $this_js_text } |
972 | | -); |
973 | | - |
974 | | -END; |
| 936 | + $js_text = "showIfChecked(['$input_id'], '$div_id');"; |
| 937 | + $sfgShowOnSelectCalls[] = "$('#$input_id').click( function() { $js_text } );"; |
975 | 938 | } |
976 | 939 | |
977 | 940 | // can show up here either as an array or a string, depending on |
— | — | @@ -994,7 +957,7 @@ |
995 | 958 | <span id="$info_id" class="errorMessage"></span> |
996 | 959 | |
997 | 960 | END; |
998 | | - return array( $text, $return_js_text ); |
| 961 | + return array( $text, null ); |
999 | 962 | } |
1000 | 963 | |
1001 | 964 | static function categoryHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) { |