Index: trunk/extensions/SemanticForms/libs/SemanticForms.js |
— | — | @@ -22,24 +22,37 @@ |
23 | 23 | jQuery.noConflict(); |
24 | 24 | |
25 | 25 | /* extending jquery functions for custom highlighting */ |
26 | | - jQuery.ui.autocomplete.prototype._renderItem = function( ul, item) { |
| 26 | + jQuery.ui.autocomplete.prototype._renderItem = function( ul, item) { |
27 | 27 | |
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); |
32 | 32 | } else { |
33 | 33 | var t = item.label; |
34 | 34 | } |
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 | + }; |
40 | 40 | |
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) { |
44 | 57 | if ( autocompleteOnAllChars ) { |
45 | 58 | var matcher = new RegExp(jQuery.ui.autocomplete.escapeRegex(term), "i" ); |
46 | 59 | } else { |
— | — | @@ -48,26 +61,14 @@ |
49 | 62 | return jQuery.grep( array, function(value) { |
50 | 63 | return matcher.test( value.label || value.value || value ); |
51 | 64 | }); |
52 | | - } |
53 | | - }); |
| 65 | + } |
| 66 | + }); |
54 | 67 | |
55 | | - |
56 | 68 | if (values != null) { |
57 | 69 | |
58 | 70 | /* delimiter != '' means multiple autocomplete */ |
59 | 71 | |
60 | 72 | 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 | | - |
72 | 73 | jQuery(document).ready(function(){ |
73 | 74 | function split(val) { |
74 | 75 | return val.split(delimiter); |
— | — | @@ -126,50 +127,50 @@ |
127 | 128 | |
128 | 129 | jQuery(document).ready(function(){ |
129 | 130 | function split(val) { |
130 | | - return val.split(delimiter + " "); |
| 131 | + return val.split(delimiter); |
131 | 132 | } |
132 | 133 | function extractLast(term) { |
133 | 134 | return split(term).pop(); |
134 | 135 | } |
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 | + })) |
145 | 146 | |
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) { |
157 | 153 | 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; |
169 | 154 | } |
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 | + }); |
171 | 172 | |
172 | 173 | |
173 | | - } ); |
| 174 | + } ); |
174 | 175 | } else { |
175 | 176 | jQuery(document).ready(function(){ |
176 | 177 | jQuery("#" + input_name).autocomplete({ |
— | — | @@ -205,7 +206,7 @@ |
206 | 207 | }; |
207 | 208 | |
208 | 209 | /* |
209 | | - * Functions for handling 'show on select' and 'show on check' |
| 210 | + * Functions for handling 'show on select' |
210 | 211 | */ |
211 | 212 | |
212 | 213 | // show the relevant div if any one of the relevant options are passed in |
— | — | @@ -222,6 +223,7 @@ |
223 | 224 | the_div.style.display = 'none'; |
224 | 225 | } |
225 | 226 | |
| 227 | +// Like showIfSelected(), but only for list boxes |
226 | 228 | function showIfSelectedInListBox(input_id, options_array, div_id) { |
227 | 229 | the_input = document.getElementById(input_id); |
228 | 230 | the_div = document.getElementById(div_id); |
— | — | @@ -257,6 +259,8 @@ |
258 | 260 | the_div.style.display = 'none'; |
259 | 261 | } |
260 | 262 | |
| 263 | +// Evaluate an array of passed-in JS calls - this is a hack, but I can't |
| 264 | +// think of a better solution |
261 | 265 | for (var i = 0; i < sfgShowOnSelectCalls.length; i++ ) { |
262 | 266 | eval(sfgShowOnSelectCalls[i]); |
263 | 267 | } |
— | — | @@ -281,7 +285,7 @@ |
282 | 286 | } |
283 | 287 | } |
284 | 288 | |
285 | | -// special handling for radiobuttons, because what's being checked |
| 289 | +// Special handling for radiobuttons, because what's being checked |
286 | 290 | // is the first radiobutton, which has value of "None" |
287 | 291 | function validate_mandatory_radiobutton(none_button_id, info_id) { |
288 | 292 | none_button = document.getElementById(none_button_id); |
— | — | @@ -414,7 +418,7 @@ |
415 | 419 | } |
416 | 420 | } |
417 | 421 | |
418 | | -// same as validate_multiple_mandatory_fields(), but for type validation |
| 422 | +// Same as validate_multiple_mandatory_fields(), but for type validation |
419 | 423 | function validate_type_of_multiple_fields(field_num, type) { |
420 | 424 | var num_errors = 0; |
421 | 425 | elems = document.getElementsByTagName("*"); |
— | — | @@ -439,6 +443,8 @@ |
440 | 444 | function validate_all() { |
441 | 445 | var num_errors = 0; |
442 | 446 | |
| 447 | + // evaluate all the passed-in JS validation calls - as with the |
| 448 | + // "show on select" calls, this is a hack. |
443 | 449 | for (var i = 0; i < sfgJSValidationCalls.length; i++ ) { |
444 | 450 | if (! eval(sfgJSValidationCalls[i]) ) num_errors += 1; |
445 | 451 | } |
— | — | @@ -566,7 +572,7 @@ |
567 | 573 | }; |
568 | 574 | } |
569 | 575 | |
570 | | -//Activate autocomplete functionality for every field on the document |
| 576 | +// Activate autocomplete functionality for every field on the document |
571 | 577 | function attachAutocompleteToAllDocumentFields() |
572 | 578 | { |
573 | 579 | var forms = document.getElementsByTagName("form"); |
— | — | @@ -578,7 +584,8 @@ |
579 | 585 | } |
580 | 586 | } |
581 | 587 | |
582 | | -//Activate autocomplete functionality for every field under the specified element |
| 588 | +// Activate autocomplete functionality for every field under the specified |
| 589 | +// element |
583 | 590 | function attachAutocompleteToAllFields(base) |
584 | 591 | { |
585 | 592 | var inputs = base.getElementsByTagName("input"); |
— | — | @@ -593,15 +600,15 @@ |
594 | 601 | } |
595 | 602 | } |
596 | 603 | |
597 | | -//Activate autocomplete functionality for the specified field |
| 604 | +// Activate autocomplete functionality for the specified field |
598 | 605 | function attachAutocompleteToField(input_id) |
599 | 606 | { |
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 |
601 | 608 | if (input_id.substr(0,6) == 'input_') |
602 | 609 | { |
603 | | - //Extract the field ID number from the input field |
| 610 | + // Extract the field ID number from the input field |
604 | 611 | 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. |
606 | 613 | var field_string = sfgAutocompleteMappings[field_num]; |
607 | 614 | if (field_string) { |
608 | 615 | var div_id = input_id.replace(/input_/g, 'div_'); |
— | — | @@ -713,4 +720,3 @@ |
714 | 721 | }); |
715 | 722 | |
716 | 723 | })(jQuery); |
717 | | - |