r79496 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r79495‎ | r79496 | r79497 >
Date:18:36, 2 January 2011
Author:foxtrott
Status:deferred
Tags:
Comment:
fixed timepicker, menuselect, mandatory inputs

* timepicker and menuselect work in multiple forms now
* parameter 'mandatory' works again (all inputs)
Modified paths:
  • /trunk/extensions/SemanticFormsInputs/SFI_Inputs.php (modified) (history)
  • /trunk/extensions/SemanticFormsInputs/SemanticFormsInputs.php (modified) (history)
  • /trunk/extensions/SemanticFormsInputs/libs/menuselect.js (modified) (history)
  • /trunk/extensions/SemanticFormsInputs/libs/timepicker.js (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticFormsInputs/SemanticFormsInputs.php
@@ -33,7 +33,7 @@
3434 $dir = dirname( __FILE__ );
3535
3636 // load user settings
37 -require_once( $dir. '/SFI_Settings.php' );
 37+require_once( $dir . '/SFI_Settings.php' );
3838
3939 $wgExtensionMessagesFiles['SemanticFormsInputs'] = $dir . '/SemanticFormsInputs.i18n.php';
4040 $wgExtensionFunctions[] = "wfSFISetup";
Index: trunk/extensions/SemanticFormsInputs/SFI_Inputs.php
@@ -39,7 +39,7 @@
4040 // array of attributes to pass to the input field
4141 $attribs = array(
4242 "name" => $input_name,
43 - "cssclass" => $class,
 43+ "class" => $class,
4444 "value" => $cur_value,
4545 "type" => "text"
4646 );
@@ -56,12 +56,12 @@
5757
5858 // modify class attribute for mandatory form fields
5959 if ( $is_mandatory ) {
60 - $attribs["cssclass"] .= ' mandatory';
 60+ $attribs["class"] .= ' mandatoryField';
6161 }
6262
6363 // add user class(es) to class attribute of input field
6464 if ( array_key_exists( 'class', $other_args ) ) {
65 - $attribs["cssclass"] .= ' ' . $other_args['class'];
 65+ $attribs["class"] .= ' ' . $other_args['class'];
6666 }
6767
6868 // set readonly attrib
@@ -892,8 +892,8 @@
893893
894894 }
895895
896 - // add span for error messages (e.g. used for mandatory inputs)
897 - $html .= Xml::element( "span", array( "id" => "info_$sfgFieldNum", "class" => "errorMessage" ) );
 896+ // wrap in span (e.g. used for mandatory inputs)
 897+ $html = '<span class="inputSpan' . ($is_mandatory ? ' mandatoryFieldSpan' : '') . '">' .$html . '</span>';
898898
899899 // insert the code of the JS init function into the pages code
900900 $wgOut->addScript( '<script type="text/javascript">' . $jstext . '</script>' );
@@ -1032,7 +1032,7 @@
10331033 . Xml::expandAttributes ( array(
10341034 'type' => 'button',
10351035 'class' => 'createboxInput ' . $userClasses,
1036 - 'id' => "input_{$sfgFieldNum}_button",
 1036+ 'name' => "button",
10371037 ) )
10381038 . "onclick=\"document.getElementById(this.id.replace('_button','_show')).focus();\""
10391039 . ">"
@@ -1074,7 +1074,7 @@
10751075 . Xml::expandAttributes ( array(
10761076 'type' => 'button',
10771077 'class' => 'createboxInput ' . $userClasses,
1078 - 'id' => "input_{$sfgFieldNum}_resetbutton",
 1078+ 'name' => "resetbutton",
10791079 ) )
10801080 . "onclick=\"document.getElementById(this.id.replace('_resetbutton','')).value='';"
10811081 . "document.getElementById(this.id.replace('_resetbutton','_show')).value='';\""
@@ -1090,20 +1090,14 @@
10911091 }
10921092 }
10931093
1094 - // append span for error messages (e.g. fore mandatory fields)
1095 - $html .= Xml::element( "span", array( "id" => "info_$sfgFieldNum", "class" => "errorMessage" ) );
 1094+ // wrap in span (e.g. used for mandatory inputs)
 1095+ $html = '<span class="inputSpan' . ($is_mandatory ? ' mandatoryFieldSpan' : '') . '">' .$html . '</span>';
10961096
10971097 // third: if the timepicker is not disabled set up JS attributes ans assemble JS call
10981098 if ( !$is_disabled ) {
10991099
11001100 self::timepickerSetup();
11011101
1102 -// if ( array_key_exists( 'delimiter', $other_args ) ) {
1103 -// $delimiter = $other_args[ 'delimiter' ];
1104 -// } else {
1105 -// $delimiter = ' ';
1106 -// }
1107 -//
11081102 // set min time if valid, else use default
11091103 if ( array_key_exists( 'mintime', $other_args )
11101104 && ( preg_match( '/^\d+:\d\d$/', trim( $other_args['mintime'] ) ) == 1 ) ) {
@@ -1128,8 +1122,16 @@
11291123 $interval = '15';
11301124 }
11311125
 1126+ // build JS code from attributes array
 1127+ $jstext = Xml::encodeJsVar( array(
 1128+ "minTime" => $minTime,
 1129+ "maxTime" => $maxTime,
 1130+ "interval" => $interval,
 1131+ "format" => "hh:mm"
 1132+ ) );
 1133+
11321134 $jstext = <<<JAVASCRIPT
1133 - addOnloadHook(function(){SFI_TP_init ( "input_$sfgFieldNum", "$minTime", "$maxTime", "$interval", "" );});
 1135+jQuery(function(){ jQuery('#input_$sfgFieldNum').registerInitialisation(SFI_TP_init, $jstext ); });
11341136 JAVASCRIPT;
11351137
11361138 // write JS code directly to the page's code
@@ -1199,7 +1201,7 @@
12001202 ) );
12011203
12021204
1203 - $html .= "<span class='SFI_menuselect' id='input_{$sfgFieldNum}_tree'>";
 1205+ $html .= "<span class='SFI_menuselect' id='span_{$sfgFieldNum}_tree'>";
12041206
12051207
12061208 // if ( array_key_exists( 'delimiter', $other_args ) ) $delimiter = $other_args[ 'delimiter' ];
@@ -1224,12 +1226,16 @@
12251227
12261228 $html .= "</span>";
12271229
1228 - $jstext = <<<JAVASCRIPT
1229 - addOnloadHook(function(){SFI_MS_init("input_$sfgFieldNum");});
 1230+ // wrap in span (e.g. used for mandatory inputs)
 1231+ $html = '<span class="inputSpan' . ($is_mandatory ? ' mandatoryFieldSpan' : '') . '">' .$html . '</span>';
 1232+
 1233+ $jstext = <<<JAVASCRIPT
 1234+jQuery(function(){ jQuery('#input_$sfgFieldNum').registerInitialisation(SFI_MS_init, null ); });
12301235 JAVASCRIPT;
12311236
12321237 // write JS code directly to the page's code
1233 - $wgOut->addScript( '<script type="text/javascript">' . $jstext . '</script>' );
 1238+ $wgOut->addScript( '<script type="text/javascript">' . $jstext . '</script>' );
 1239+
12341240 return array( $html, "", "SFI_MS_init" );
12351241
12361242 }
Index: trunk/extensions/SemanticFormsInputs/libs/menuselect.js
@@ -11,13 +11,15 @@
1212 *
1313 * @param inputID ( String ) the id of the input to initialize
1414 */
15 -function SFI_MS_init( inputID ) {
 15+function SFI_MS_init( inputID, params ) {
1616
17 - jQuery("#" + inputID + "_tree").css("visibility","hidden");
 17+ var treeid = "#" + inputID.replace(/input/,"span") + "_tree"
1818
 19+ jQuery(treeid).css("visibility","hidden");
 20+
1921 // wrap content in span to separate content from sub-menus,
2022 // wrap content in div to support animating the list item width later
21 - jQuery( "#" + inputID + "_tree li" ).each(
 23+ jQuery( treeid + " li" ).each(
2224 function() {
2325
2426 jQuery( this ).contents().not( "ul" )
@@ -39,13 +41,13 @@
4042 // ensure labels of list item have constant width regardless of width of list item
4143 // prevents layout changes when list item width is changed
4244 // set position static ( was set to fixed to calculate text width )
43 - jQuery( "#" + inputID + "_tree li>span>div.cont" ).each( function() {
 45+ jQuery( treeid + " li>span>div.cont" ).each( function() {
4446 jQuery( this ).width( jQuery( this ).outerWidth(true) + jQuery( this ).siblings("div.arrow").outerWidth(true) + 5);
4547 jQuery( this ).css( "position", "static" );
4648 } );
4749
4850 // add class for default state and fix dimensions
49 - jQuery( "#" + inputID + "_tree li" )
 51+ jQuery( treeid + " li" )
5052 .addClass( "ui-state-default" )
5153 .each(
5254 function() {
@@ -58,18 +60,18 @@
5961 );
6062
6163 // initially hide everything
62 - jQuery( "#" + inputID + "_tree ul" )
 64+ jQuery( treeid + " ul" )
6365 .css({"z-index":1})
6466 .hide()
6567 .fadeTo(0, 0 );
6668
6769 // some crap "browsers" need special treatment
6870 if ( jQuery.browser.msie ) {
69 - jQuery( "#" + inputID + "_tree ul" ).css({ "position":"relative" });
 71+ jQuery( treeid + " ul" ).css({ "position":"relative" });
7072 }
7173
7274 // sanitize links
73 - jQuery( "#" + inputID + "_tree" ).find( "a" )
 75+ jQuery( treeid ).find( "a" )
7476 .each(
7577 function() {
7678
@@ -100,7 +102,7 @@
101103 // attach event handlers
102104
103105 // mouse entered list item
104 - jQuery( "#" + inputID + "_tree li" )
 106+ jQuery( treeid + " li" )
105107 .mouseenter( function( evt ) {
106108
107109 // switch classes to change display style
@@ -163,7 +165,7 @@
164166 } );
165167
166168 // mouse left list item
167 - jQuery( "#" + inputID + "_tree li" )
 169+ jQuery( treeid + " li" )
168170 .mouseleave( function( evt ) {
169171
170172 // switch classes to change display style
@@ -216,7 +218,7 @@
217219 } );
218220
219221 // clicked list item
220 - jQuery( "#" + inputID + "_tree li" )
 222+ jQuery( treeid + " li" )
221223 .mousedown( function() {
222224
223225 // set visible value and leave input
@@ -245,19 +247,19 @@
246248 // show top menu when input gets focus
247249 jQuery( "#" + inputID + "_show" )
248250 .focus( function() {
249 - jQuery( "#" + inputID + "_tree>ul" ).css( "display", "inline" ).fadeTo( 400, 1 );
 251+ jQuery( treeid + ">ul" ).css( "display", "inline" ).fadeTo( 400, 1 );
250252 } );
251253
252254 // hide all menus when input loses focus
253255 jQuery( "#" + inputID + "_show" )
254256 .blur( function() {
255257
256 - jQuery( "#" + inputID + "_tree ul" ).fadeTo( 400, 0,
 258+ jQuery( treeid + " ul" ).fadeTo( 400, 0,
257259 function() {
258260 jQuery( this ).css( "display", "none" );
259261 } );
260262 } );
261263
262 - jQuery("#" + inputID + "_tree").css("visibility","visible");
 264+ jQuery( treeid ).css("visibility","visible");
263265
264266 }
\ No newline at end of file
Index: trunk/extensions/SemanticFormsInputs/libs/timepicker.js
@@ -10,68 +10,66 @@
1111 * Initializes a timepicker input
1212 *
1313 * @param inputID (String) the id of the input to initialize
14 - * @param minTime (String) the minimum time to be shown (format hh:mm)
15 - * @param maxTime (String) the maximum time to be shown (format hh:mm)
16 - * @param interval (String) the interval between selectable times in minutes
17 - * @param format (String) a format string (unused) (do we even need it?)
 14+ * @param params (Object) the parameter object for the timepicker, contains
 15+ * minTime: (String) the minimum time to be shown (format hh:mm)
 16+ * maxTime: (String) the maximum time to be shown (format hh:mm)
 17+ * interval: (String) the interval between selectable times in minutes
 18+ * format: (String) a format string (unused) (do we even need it?)
1819 *
1920 */
20 -function SFI_TP_init( inputID, minTime, maxTime, interval, format ) {
 21+function SFI_TP_init( inputID, params ) { // minTime, maxTime, interval, format
2122
2223 // sanitize inputs
23 - re = /^\d+:\d\d$/;
 24+ var re = /^\d+:\d\d$/;
 25+ var minh = 0;
 26+ var minm = 0;
2427
25 - if ( re.test( minTime ) ) {
 28+ var maxh = 23;
 29+ var maxm = 59;
2630
27 - min = minTime.split( ':', 2 );
 31+if ( re.test( params.minTime ) ) {
 32+
 33+ var min = params.minTime.split( ':', 2 );
2834 minh = Number( min[0] );
2935 minm = Number( min[1] );
3036
3137 if ( minm > 59 ) minm = 59;
32 -
33 - } else {
34 - minh = 0;
35 - minm = 0;
3638 }
3739
38 - if ( re.test( maxTime ) ) {
 40+ if ( re.test( params.maxTime ) ) {
3941
40 - max = maxTime.split( ':', 2 );
 42+ var max = params.maxTime.split( ':', 2 );
4143 maxh = Number( max[0] );
4244 maxm = Number( max[1] );
4345
4446 if ( maxm > 59 ) maxm = 59;
45 -
46 - } else {
47 - maxh = 23;
48 - maxm = 59;
4947 }
5048
51 - interv = Number( interval );
 49+ var interv = Number( params.interval );
5250
5351 if ( interv < 1 ) interv = 1;
5452 else if ( interv > 60 ) interv = 60;
5553
5654 // build html structure
57 - sp = jQuery( "<span class='SFI_timepicker' id='" + inputID + "_tree' ></span>" ).insertAfter( "#" + inputID );
 55+ var sp = jQuery( "<span class='SFI_timepicker' id='" + inputID + "_tree' ></span>" ).insertAfter( "#" + inputID );
5856
59 - ulh = jQuery( "<ul>" ).appendTo( sp );
 57+ var ulh = jQuery( "<ul>" ).appendTo( sp );
6058
6159
62 - for ( h = minh; h <= maxh; ++h ) {
 60+ for ( var h = minh; h <= maxh; ++h ) {
6361
64 - lih = jQuery( "<li class='ui-state-default'>" + ( ( h < 10 ) ? "0" : "" ) + h + "</li>" ).appendTo( ulh );
 62+ var lih = jQuery( "<li class='ui-state-default'>" + ( ( h < 10 ) ? "0" : "" ) + h + "</li>" ).appendTo( ulh );
6563
6664 //TODO: Replace value for "show" by formatted string
6765 lih
6866 .data( "value", ( ( h < 10 ) ? "0" : "" ) + h + ":00" )
6967 .data( "show", ( ( h < 10 ) ?"0" : "" ) + h + ":00" );
7068
71 - ulm = jQuery( "<ul>" ).appendTo( lih );
 69+ var ulm = jQuery( "<ul>" ).appendTo( lih );
7270
73 - for ( m = ( (h == minh) ? minm : 0 ) ; m <= ( (h == maxh) ? maxm : 59 ); m += interv ) {
 71+ for ( var m = ( (h == minh) ? minm : 0 ) ; m <= ( (h == maxh) ? maxm : 59 ); m += interv ) {
7472
75 - lim = jQuery( "<li class='ui-state-default'>" + ( ( m < 10 ) ? "0" : "" ) + m + "</li>" ).appendTo( ulm );
 73+ var lim = jQuery( "<li class='ui-state-default'>" + ( ( m < 10 ) ? "0" : "" ) + m + "</li>" ).appendTo( ulm );
7674
7775 //TODO: Replace value for "show" by formatted string
7876 lim
@@ -151,4 +149,15 @@
152150 jQuery("#" + inputID ).attr("value", jQuery(this).attr("value"));
153151 });
154152
 153+ jQuery("#" + inputID + '~ button[name="button"]' )
 154+ .attr("id", inputID + "_button")
 155+ .click(function() {
 156+ jQuery("#" + inputID + "_show" ).focus();
 157+ });
 158+
 159+ jQuery("#" + inputID + '~ button[name="resetbutton"]' )
 160+ .attr("id", inputID + "_resetbutton")
 161+ .click(function() {
 162+ jQuery("#" + inputID + "_show" ).attr("value", "");
 163+ });
155164 }
\ No newline at end of file

Status & tagging log