Index: trunk/extensions/SemanticForms/libs/SemanticForms.js |
— | — | @@ -10,8 +10,25 @@ |
11 | 11 | * @author Eugene Mednikov |
12 | 12 | */ |
13 | 13 | |
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"; |
16 | 33 | jQuery.noConflict(); |
17 | 34 | |
18 | 35 | /* extending jQuery functions for custom highlighting */ |
— | — | @@ -46,7 +63,7 @@ |
47 | 64 | /* extending jquery functions */ |
48 | 65 | jQuery.extend( jQuery.ui.autocomplete, { |
49 | 66 | filter: function(array, term) { |
50 | | - if ( autocompleteOnAllChars ) { |
| 67 | + if ( sfgAutocompleteOnAllChars ) { |
51 | 68 | var matcher = new RegExp(jQuery.ui.autocomplete.escapeRegex(term), "i" ); |
52 | 69 | } else { |
53 | 70 | var matcher = new RegExp("\\b" + jQuery.ui.autocomplete.escapeRegex(term), "i" ); |
— | — | @@ -57,6 +74,7 @@ |
58 | 75 | } |
59 | 76 | }); |
60 | 77 | |
| 78 | + values = sfgAutocompleteValues[field_string]; |
61 | 79 | if (values != null) { |
62 | 80 | // Local autocompletion |
63 | 81 | |
— | — | @@ -101,6 +119,7 @@ |
102 | 120 | } |
103 | 121 | } else { |
104 | 122 | // Remote autocompletion |
| 123 | + data_type = sfgAutocompleteDataTypes[field_string]; |
105 | 124 | if (data_type == 'property') |
106 | 125 | myServer += "?action=sfautocomplete&format=json&property=" + data_source; |
107 | 126 | else if (data_type == 'relation') |
— | — | @@ -185,7 +204,9 @@ |
186 | 205 | } ); |
187 | 206 | } |
188 | 207 | } |
189 | | -}; |
| 208 | + }); |
| 209 | + }; |
| 210 | +})( jQuery ); |
190 | 211 | |
191 | 212 | /* |
192 | 213 | * Functions for handling 'show on select' |
— | — | @@ -446,6 +467,10 @@ |
447 | 468 | } |
448 | 469 | } |
449 | 470 | |
| 471 | +/** |
| 472 | + * Functions for multiple-instance templates. |
| 473 | + */ |
| 474 | + |
450 | 475 | function addInstance(starter_div_id, main_div_id, tab_index) { |
451 | 476 | num_elements++; |
452 | 477 | |
— | — | @@ -517,35 +542,6 @@ |
518 | 543 | new_div.find('.autoGrow').autoGrow(); |
519 | 544 | } |
520 | 545 | |
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 | | - |
550 | 546 | var num_elements = 0; |
551 | 547 | |
552 | 548 | // Once the document has finished loading, set up everything! |
— | — | @@ -605,7 +601,6 @@ |
606 | 602 | /* extending jquery functions */ |
607 | 603 | |
608 | 604 | (function(jQuery) { |
609 | | - |
610 | 605 | jQuery.widget("ui.combobox", { |
611 | 606 | _create: function() { |
612 | 607 | var self = this; |
— | — | @@ -616,9 +611,10 @@ |
617 | 612 | var input = jQuery("<input id=\"" + id + "\" type=\"text\" name=\" " + name + " \" value=\"" + curval + "\">") |
618 | 613 | .insertAfter(select) |
619 | 614 | .attr("tabIndex", select.attr("tabIndex")) |
| 615 | + .attr("autocompletesettings", select.attr("autocompletesettings")) |
620 | 616 | .autocomplete({ |
621 | 617 | source: function(request, response) { |
622 | | - if ( autocompleteOnAllChars ) { |
| 618 | + if ( sfgAutocompleteOnAllChars ) { |
623 | 619 | var matcher = new RegExp(request.term, "i"); |
624 | 620 | } else { |
625 | 621 | var matcher = new RegExp("\\b" + request.term, "i"); |