r78333 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r78332‎ | r78333 | r78334 >
Date:22:13, 13 December 2010
Author:yaron
Status:deferred
Tags:
Comment:
Another fairly big change - 'attachAutocomplete' and 'sfAutocomplete' functions merged into one function, called 'attachAutocomplete', that now works correctly once again for multiple autocomplete inputs in the same form (i.e., a fix for a major bug). Also, sfgAutocompleteMappings global variable removed, replaced by attributes within the form inputs themselves.
Modified paths:
  • /trunk/extensions/SemanticForms/libs/SemanticForms.js (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/libs/SemanticForms.js
@@ -10,8 +10,25 @@
1111 * @author Eugene Mednikov
1212 */
1313
14 -jQuery.fn.sfAutocomplete = function(values, api_url, data_type, delimiter, data_source) {
15 - var myServer = api_url;
 14+// Activate autocomplete functionality for the specified field
 15+(function(jQuery) {
 16+ jQuery.fn.attachAutocomplete = function() {
 17+ return this.each(function() {
 18+ // Get all the necessary values from the input's "autocompletesettings"
 19+ // attribute. This should probably be done as three separate attributes,
 20+ // instead.
 21+ var field_string = jQuery(this).attr("autocompletesettings");
 22+ var field_values = field_string.split(',');
 23+ var delimiter = null;
 24+ var data_source = field_values[0];
 25+ if (field_values[1] == 'list') {
 26+ delimiter = ",";
 27+ if (field_values[2] != null) {
 28+ delimiter = field_values[2];
 29+ }
 30+ }
 31+
 32+ var myServer = wgScriptPath + "/api.php";
1633 jQuery.noConflict();
1734
1835 /* extending jQuery functions for custom highlighting */
@@ -46,7 +63,7 @@
4764 /* extending jquery functions */
4865 jQuery.extend( jQuery.ui.autocomplete, {
4966 filter: function(array, term) {
50 - if ( autocompleteOnAllChars ) {
 67+ if ( sfgAutocompleteOnAllChars ) {
5168 var matcher = new RegExp(jQuery.ui.autocomplete.escapeRegex(term), "i" );
5269 } else {
5370 var matcher = new RegExp("\\b" + jQuery.ui.autocomplete.escapeRegex(term), "i" );
@@ -57,6 +74,7 @@
5875 }
5976 });
6077
 78+ values = sfgAutocompleteValues[field_string];
6179 if (values != null) {
6280 // Local autocompletion
6381
@@ -101,6 +119,7 @@
102120 }
103121 } else {
104122 // Remote autocompletion
 123+ data_type = sfgAutocompleteDataTypes[field_string];
105124 if (data_type == 'property')
106125 myServer += "?action=sfautocomplete&format=json&property=" + data_source;
107126 else if (data_type == 'relation')
@@ -185,7 +204,9 @@
186205 } );
187206 }
188207 }
189 -};
 208+ });
 209+ };
 210+})( jQuery );
190211
191212 /*
192213 * Functions for handling 'show on select'
@@ -446,6 +467,10 @@
447468 }
448469 }
449470
 471+/**
 472+ * Functions for multiple-instance templates.
 473+ */
 474+
450475 function addInstance(starter_div_id, main_div_id, tab_index) {
451476 num_elements++;
452477
@@ -517,35 +542,6 @@
518543 new_div.find('.autoGrow').autoGrow();
519544 }
520545
521 -// Activate autocomplete functionality for the specified field
522 -jQuery.fn.attachAutocomplete = function() {
523 - input_id = this.attr("id");
524 - // For some reason, the find() call that calls this function will
525 - // still call it even if no elements are found - if that happens,
526 - // escape here to avoid an error.
527 - if (input_id == null) return;
528 - // Extract the field ID number from the input field
529 - var field_num = parseInt(input_id.substring(input_id.lastIndexOf('_') + 1, input_id.length),10);
530 - // Add the autocomplete string, if a mapping exists.
531 - var field_string = sfgAutocompleteMappings[field_num];
532 - if (field_string) {
533 - var field_values = field_string.split(',');
534 - var delimiter = null;
535 - var data_source = field_values[0];
536 - if (field_values[1] == 'list') {
537 - delimiter = ",";
538 - if (field_values[2] != null) {
539 - delimiter = field_values[2];
540 - }
541 - }
542 - if (sfgAutocompleteValues[field_string] != null) {
543 - this.sfAutocomplete(sfgAutocompleteValues[field_string], null, null, delimiter, data_source);
544 - } else {
545 - this.sfAutocomplete(null, wgScriptPath + "/api.php", sfgAutocompleteDataTypes[field_string], delimiter, data_source);
546 - }
547 - }
548 -}
549 -
550546 var num_elements = 0;
551547
552548 // Once the document has finished loading, set up everything!
@@ -605,7 +601,6 @@
606602 /* extending jquery functions */
607603
608604 (function(jQuery) {
609 -
610605 jQuery.widget("ui.combobox", {
611606 _create: function() {
612607 var self = this;
@@ -616,9 +611,10 @@
617612 var input = jQuery("<input id=\"" + id + "\" type=\"text\" name=\" " + name + " \" value=\"" + curval + "\">")
618613 .insertAfter(select)
619614 .attr("tabIndex", select.attr("tabIndex"))
 615+ .attr("autocompletesettings", select.attr("autocompletesettings"))
620616 .autocomplete({
621617 source: function(request, response) {
622 - if ( autocompleteOnAllChars ) {
 618+ if ( sfgAutocompleteOnAllChars ) {
623619 var matcher = new RegExp(request.term, "i");
624620 } else {
625621 var matcher = new RegExp("\\b" + request.term, "i");

Status & tagging log