r108170 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r108169‎ | r108170 | r108171 >
Date:19:33, 5 January 2012
Author:johnduhart
Status:ok
Tags:
Comment:
Followup r99891, clean up javascript
Modified paths:
  • /trunk/extensions/ApiSandbox/ext.apiSandbox.js (modified) (history)

Diff [purge]

Index: trunk/extensions/ApiSandbox/ext.apiSandbox.js
@@ -21,18 +21,25 @@
2222 * Creates inputs and places them into container
2323 */
2424 createInputs: function() {
25 - var s = '<table class="api-sandbox-options">\n<tbody>';
26 - for ( var i = 0; i < this.params.length; i++ ) {
27 - var param = this.params[i],
28 - name = this.prefix + param.name;
 25+ var $table, i, length, param, name;
2926
30 - s += '<tr><td class="api-sandbox-label">'
31 - + mw.html.element( 'label', { 'for': 'param-' + name }, name + '=' )
32 - + '</td><td class="api-sandbox-value">' + this.input( param, name )
33 - + '</td><td>' + smartEscape( param.description ) + '</td></tr>';
 27+ $table = $( '<table class="api-sandbox-options">' );
 28+ for ( i = 0, length = this.params.length; i < length; i += 1 ) {
 29+ param = this.params[i];
 30+ name = this.prefix + param.name;
 31+
 32+ $( '<tr>' )
 33+ .append(
 34+ $( '<td class="api-sandbox-label">' )
 35+ .html( mw.html.element( 'label',
 36+ { 'for': 'param-' + name }, name + '=' )
 37+ )
 38+ )
 39+ .append( $( '<td class="api-sandbox-value">' ).html( this.input( param, name ) ) )
 40+ .append( $( '<td>' ).html( smartEscape( param.description ) ) )
 41+ .appendTo( $table );
3442 }
35 - s += '\n</tbody>\n</table>\n';
36 - this.$container.html( s );
 43+ this.$container.html( $table );
3744 },
3845
3946 /**
@@ -86,24 +93,28 @@
8794 },
8895
8996 select: function( values, attributes, selected ) {
 97+ var s = '', i, length, value, face, attrs;
 98+
9099 attributes['class'] = 'api-sandbox-input';
91100 if ( isset( attributes.multiple ) ) {
92101 attributes['size'] = Math.min( values.length, 10 );
93102 }
94 - var s = '';
95103 if ( typeof selected != 'array' ) {
96104 if ( selected ) {
97105 s += mw.html.element( 'option', { value: '', selected: 'selected' }, mw.msg( 'apisb-select-value' ) );
98106 }
99107 selected = [];
100108 }
101 - for ( var i = 0; i < values.length; i++ ) {
102 - var value = typeof values[i] == 'object' ? values[i].key : values[i],
103 - face = typeof values[i] == 'object' ? values[i].value : values[i],
104 - attrs = { 'value': value };
 109+
 110+ for ( i = 0, length = values.length; i < length; i += 1 ) {
 111+ value = typeof values[i] == 'object' ? values[i].key : values[i];
 112+ face = typeof values[i] == 'object' ? values[i].value : values[i];
 113+ attrs = { 'value': value };
 114+
105115 if ( $.inArray( value, selected ) >= 0 ) {
106116 attrs.selected = 'selected';
107117 }
 118+
108119 s += '\n' + mw.html.element( 'option', attrs, face );
109120 }
110121 s = mw.html.element( 'select', attributes, new mw.html.Raw( s ) );
@@ -111,11 +122,11 @@
112123 },
113124
114125 getRequestData: function() {
115 - var params = '';
116 - for ( var i = 0; i < this.params.length; i++ ) {
117 - var param = this.params[i],
118 - name = this.prefix + param.name,
119 - $node = $( '#param-' + name );
 126+ var params = '', i, length, param, name, $node;
 127+ for ( i = 0, length = this.params.length; i < length; i += 1 ) {
 128+ param = this.params[i];
 129+ name = this.prefix + param.name;
 130+ $node = $( '#param-' + name );
120131 if ( param.type == 'boolean' ) {
121132 if ( $node.is( ':checked' ) ) {
122133 params += '&' + name;

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r99891Major rewrite, added support for generators, pageset and other tasty stufmaxsem17:05, 15 October 2011

Status & tagging log