Index: trunk/extensions/ApiSandbox/ext.apiSandbox.js |
— | — | @@ -21,18 +21,25 @@ |
22 | 22 | * Creates inputs and places them into container |
23 | 23 | */ |
24 | 24 | 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; |
29 | 26 | |
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 ); |
34 | 42 | } |
35 | | - s += '\n</tbody>\n</table>\n'; |
36 | | - this.$container.html( s ); |
| 43 | + this.$container.html( $table ); |
37 | 44 | }, |
38 | 45 | |
39 | 46 | /** |
— | — | @@ -86,24 +93,28 @@ |
87 | 94 | }, |
88 | 95 | |
89 | 96 | select: function( values, attributes, selected ) { |
| 97 | + var s = '', i, length, value, face, attrs; |
| 98 | + |
90 | 99 | attributes['class'] = 'api-sandbox-input'; |
91 | 100 | if ( isset( attributes.multiple ) ) { |
92 | 101 | attributes['size'] = Math.min( values.length, 10 ); |
93 | 102 | } |
94 | | - var s = ''; |
95 | 103 | if ( typeof selected != 'array' ) { |
96 | 104 | if ( selected ) { |
97 | 105 | s += mw.html.element( 'option', { value: '', selected: 'selected' }, mw.msg( 'apisb-select-value' ) ); |
98 | 106 | } |
99 | 107 | selected = []; |
100 | 108 | } |
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 | + |
105 | 115 | if ( $.inArray( value, selected ) >= 0 ) { |
106 | 116 | attrs.selected = 'selected'; |
107 | 117 | } |
| 118 | + |
108 | 119 | s += '\n' + mw.html.element( 'option', attrs, face ); |
109 | 120 | } |
110 | 121 | s = mw.html.element( 'select', attributes, new mw.html.Raw( s ) ); |
— | — | @@ -111,11 +122,11 @@ |
112 | 123 | }, |
113 | 124 | |
114 | 125 | 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 ); |
120 | 131 | if ( param.type == 'boolean' ) { |
121 | 132 | if ( $node.is( ':checked' ) ) { |
122 | 133 | params += '&' + name; |