r75301 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r75300‎ | r75301 | r75302 >
Date:06:53, 24 October 2010
Author:yaron
Status:deferred
Tags:
Comment:
Fixed handling of "\n" delimiter for remote autocompletion as well; various improvements to Javascript tabbing and layout
Modified paths:
  • /trunk/extensions/SemanticForms/libs/SemanticForms.js (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/libs/SemanticForms.js
@@ -22,24 +22,37 @@
2323 jQuery.noConflict();
2424
2525 /* extending jquery functions for custom highlighting */
26 - jQuery.ui.autocomplete.prototype._renderItem = function( ul, item) {
 26+ jQuery.ui.autocomplete.prototype._renderItem = function( ul, item) {
2727
28 - var re = new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + this.term.replace(/([\^\$\(\)\[\]\{\}\*\.\+\?\|\\])/gi, "\\$1") + ")(?![^<>]*>)(?![^&;]+;)", "gi");
29 - var loc = item.label.search(re);
30 - if (loc >= 0) {
31 - var t = item.label.substr(0, loc) + '<strong>' + item.label.substr(loc, this.term.length) + '</strong>' + item.label.substr(loc + this.term.length);
 28+ var re = new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + this.term.replace(/([\^\$\(\)\[\]\{\}\*\.\+\?\|\\])/gi, "\\$1") + ")(?![^<>]*>)(?![^&;]+;)", "gi");
 29+ var loc = item.label.search(re);
 30+ if (loc >= 0) {
 31+ var t = item.label.substr(0, loc) + '<strong>' + item.label.substr(loc, this.term.length) + '</strong>' + item.label.substr(loc + this.term.length);
3232 } else {
3333 var t = item.label;
3434 }
35 - return jQuery( "<li></li>" )
36 - .data( "item.autocomplete", item )
37 - .append( " <a>" + t + "</a>" )
38 - .appendTo( ul );
39 - };
 35+ return jQuery( "<li></li>" )
 36+ .data( "item.autocomplete", item )
 37+ .append( " <a>" + t + "</a>" )
 38+ .appendTo( ul );
 39+ };
4040
41 -/* extending jquery functions */
42 - jQuery.extend( jQuery.ui.autocomplete, {
43 - filter: function(array, term) {
 41+ // Modify the delimiter. If it's "\n", change it to an actual
 42+ // newline - otherwise, add a space to the end.
 43+ // This doesn't cover the case of a delimiter that's a newline
 44+ // plus something else, like ".\n" or "\n\n", but as far as we
 45+ // know no one has yet needed that.
 46+ if ( delimiter != null ) {
 47+ if ( delimiter == "\\n" ) {
 48+ delimiter = "\n";
 49+ } else {
 50+ delimiter += " ";
 51+ }
 52+ }
 53+
 54+ /* extending jquery functions */
 55+ jQuery.extend( jQuery.ui.autocomplete, {
 56+ filter: function(array, term) {
4457 if ( autocompleteOnAllChars ) {
4558 var matcher = new RegExp(jQuery.ui.autocomplete.escapeRegex(term), "i" );
4659 } else {
@@ -48,26 +61,14 @@
4962 return jQuery.grep( array, function(value) {
5063 return matcher.test( value.label || value.value || value );
5164 });
52 - }
53 - });
 65+ }
 66+ });
5467
55 -
5668 if (values != null) {
5769
5870 /* delimiter != '' means multiple autocomplete */
5971
6072 if (delimiter != null) {
61 - // Special handling for "\n" - if it's that, change it to an
62 - // actual newline - otherwise, add a space to the end.
63 - // This doesn't cover the case of a delimiter that's a newline
64 - // plus something else, like ".\n" or "\n\n", but in our
65 - // experience no one has yet needed that.
66 - if ( delimiter == "\\n" ) {
67 - delimiter = "\n";
68 - } else {
69 - delimiter += " ";
70 - }
71 -
7273 jQuery(document).ready(function(){
7374 function split(val) {
7475 return val.split(delimiter);
@@ -126,50 +127,50 @@
127128
128129 jQuery(document).ready(function(){
129130 function split(val) {
130 - return val.split(delimiter + " ");
 131+ return val.split(delimiter);
131132 }
132133 function extractLast(term) {
133134 return split(term).pop();
134135 }
135 - jQuery("#" + input_name).autocomplete({
136 - source: function(request, response) {
137 - jQuery.getJSON(myServer, {
138 - substr: extractLast(request.term)
139 - }, function( data ) {
140 - response(jQuery.map(data.sfautocomplete, function(item) {
141 - return {
142 - value: item.title
143 - }
144 - }))
 136+ jQuery("#" + input_name).autocomplete({
 137+ source: function(request, response) {
 138+ jQuery.getJSON(myServer, {
 139+ substr: extractLast(request.term)
 140+ }, function( data ) {
 141+ response(jQuery.map(data.sfautocomplete, function(item) {
 142+ return {
 143+ value: item.title
 144+ }
 145+ }))
145146
146 - });
147 - },
148 - search: function() {
149 - // custom minLength
150 - var term = extractLast(this.value);
151 - if (term.length < 1) {
152 - return false;
153 - }
154 - },
155 - focus: function() {
156 - // prevent value inserted on focus
 147+ });
 148+ },
 149+ search: function() {
 150+ // custom minLength
 151+ var term = extractLast(this.value);
 152+ if (term.length < 1) {
157153 return false;
158 - },
159 - select: function(event, ui) {
160 - var terms = split( this.value );
161 - // remove the current input
162 - terms.pop();
163 - // add the selected item
164 - terms.push( ui.item.value );
165 - // add placeholder to get the comma-and-space at the end
166 - terms.push("");
167 - this.value = terms.join(delimiter+" ");
168 - return false;
169154 }
170 - });
 155+ },
 156+ focus: function() {
 157+ // prevent value inserted on focus
 158+ return false;
 159+ },
 160+ select: function(event, ui) {
 161+ var terms = split( this.value );
 162+ // remove the current input
 163+ terms.pop();
 164+ // add the selected item
 165+ terms.push( ui.item.value );
 166+ // add placeholder to get the comma-and-space at the end
 167+ terms.push("");
 168+ this.value = terms.join(delimiter);
 169+ return false;
 170+ }
 171+ });
171172
172173
173 - } );
 174+ } );
174175 } else {
175176 jQuery(document).ready(function(){
176177 jQuery("#" + input_name).autocomplete({
@@ -205,7 +206,7 @@
206207 };
207208
208209 /*
209 - * Functions for handling 'show on select' and 'show on check'
 210+ * Functions for handling 'show on select'
210211 */
211212
212213 // show the relevant div if any one of the relevant options are passed in
@@ -222,6 +223,7 @@
223224 the_div.style.display = 'none';
224225 }
225226
 227+// Like showIfSelected(), but only for list boxes
226228 function showIfSelectedInListBox(input_id, options_array, div_id) {
227229 the_input = document.getElementById(input_id);
228230 the_div = document.getElementById(div_id);
@@ -257,6 +259,8 @@
258260 the_div.style.display = 'none';
259261 }
260262
 263+// Evaluate an array of passed-in JS calls - this is a hack, but I can't
 264+// think of a better solution
261265 for (var i = 0; i < sfgShowOnSelectCalls.length; i++ ) {
262266 eval(sfgShowOnSelectCalls[i]);
263267 }
@@ -281,7 +285,7 @@
282286 }
283287 }
284288
285 -// special handling for radiobuttons, because what's being checked
 289+// Special handling for radiobuttons, because what's being checked
286290 // is the first radiobutton, which has value of "None"
287291 function validate_mandatory_radiobutton(none_button_id, info_id) {
288292 none_button = document.getElementById(none_button_id);
@@ -414,7 +418,7 @@
415419 }
416420 }
417421
418 -// same as validate_multiple_mandatory_fields(), but for type validation
 422+// Same as validate_multiple_mandatory_fields(), but for type validation
419423 function validate_type_of_multiple_fields(field_num, type) {
420424 var num_errors = 0;
421425 elems = document.getElementsByTagName("*");
@@ -439,6 +443,8 @@
440444 function validate_all() {
441445 var num_errors = 0;
442446
 447+ // evaluate all the passed-in JS validation calls - as with the
 448+ // "show on select" calls, this is a hack.
443449 for (var i = 0; i < sfgJSValidationCalls.length; i++ ) {
444450 if (! eval(sfgJSValidationCalls[i]) ) num_errors += 1;
445451 }
@@ -566,7 +572,7 @@
567573 };
568574 }
569575
570 -//Activate autocomplete functionality for every field on the document
 576+// Activate autocomplete functionality for every field on the document
571577 function attachAutocompleteToAllDocumentFields()
572578 {
573579 var forms = document.getElementsByTagName("form");
@@ -578,7 +584,8 @@
579585 }
580586 }
581587
582 -//Activate autocomplete functionality for every field under the specified element
 588+// Activate autocomplete functionality for every field under the specified
 589+// element
583590 function attachAutocompleteToAllFields(base)
584591 {
585592 var inputs = base.getElementsByTagName("input");
@@ -593,15 +600,15 @@
594601 }
595602 }
596603
597 -//Activate autocomplete functionality for the specified field
 604+// Activate autocomplete functionality for the specified field
598605 function attachAutocompleteToField(input_id)
599606 {
600 - //Check input id for the proper format, to ensure this is for SF
 607+ // Check input id for the proper format, to ensure this is for SF
601608 if (input_id.substr(0,6) == 'input_')
602609 {
603 - //Extract the field ID number from the input field
 610+ // Extract the field ID number from the input field
604611 var field_num = parseInt(input_id.substring(input_id.lastIndexOf('_') + 1, input_id.length),10);
605 - //Add the autocomplete string, if a mapping exists.
 612+ // Add the autocomplete string, if a mapping exists.
606613 var field_string = sfgAutocompleteMappings[field_num];
607614 if (field_string) {
608615 var div_id = input_id.replace(/input_/g, 'div_');
@@ -713,4 +720,3 @@
714721 });
715722
716723 })(jQuery);
717 -

Status & tagging log