Index: trunk/extensions/SemanticForms/libs/SemanticForms.js |
— | — | @@ -11,6 +11,94 @@ |
12 | 12 | * @author Eugene Mednikov |
13 | 13 | */ |
14 | 14 | |
| 15 | +/** |
| 16 | + * combobox() |
| 17 | + */ |
| 18 | +(function(jQuery) { |
| 19 | + jQuery.widget("ui.combobox", { |
| 20 | + _create: function() { |
| 21 | + var self = this; |
| 22 | + var select = this.element.hide(); |
| 23 | + var name= select[0].name; |
| 24 | + var id = select[0].id; |
| 25 | + var curval = select[0].options[0].value; |
| 26 | + curval = curval.replace('"', '"' ); |
| 27 | + var input = jQuery("<input id=\"" + id + "\" type=\"text\" name=\"" + name + "\" value=\"" + curval + "\">") |
| 28 | + .insertAfter(select) |
| 29 | + .attr("tabIndex", select.attr("tabIndex")) |
| 30 | + .attr("autocompletesettings", select.attr("autocompletesettings")) |
| 31 | + .css("width", select.attr("comboboxwidth")) |
| 32 | + .autocomplete({ |
| 33 | + source: function(request, response) { |
| 34 | + if ( sfgAutocompleteOnAllChars ) { |
| 35 | + var matcher = new RegExp(request.term, "i"); |
| 36 | + } else { |
| 37 | + var matcher = new RegExp("\\b" + request.term, "i"); |
| 38 | + } |
| 39 | + response(select.children("option").map(function() { |
| 40 | + var text = jQuery(this).text(); |
| 41 | + if (this.value && (!request.term || matcher.test(text))) { |
| 42 | + return { |
| 43 | + id: this.value, |
| 44 | + label: text, |
| 45 | + value: text |
| 46 | + }; |
| 47 | + } |
| 48 | + })); |
| 49 | + }, |
| 50 | + delay: 0, |
| 51 | + change: function(event, ui) { |
| 52 | + if (!ui.item) { |
| 53 | + if (select.attr("existingvaluesonly") == 'true') { |
| 54 | + // remove invalid value, as it didn't match anything |
| 55 | + jQuery(this).val(""); |
| 56 | + } |
| 57 | + return false; |
| 58 | + } |
| 59 | + select.val(ui.item.id); |
| 60 | + self._trigger("selected", event, { |
| 61 | + item: select.find("[value='" + ui.item.id.replace("'", "\\'") + "']") |
| 62 | + }); |
| 63 | + |
| 64 | + }, |
| 65 | + minLength: 0 |
| 66 | + }) |
| 67 | + .addClass("ui-widget ui-widget-content ui-corner-left sfComboBoxActual"); |
| 68 | + input.attr("origname", select.attr("origname")); |
| 69 | + jQuery('<button type="button"> </button>') |
| 70 | + .attr("tabIndex", -1) |
| 71 | + .attr("title", "Show All Items") |
| 72 | + .insertAfter(input) |
| 73 | + .button({ |
| 74 | + icons: { |
| 75 | + primary: "ui-icon-triangle-1-s" |
| 76 | + }, |
| 77 | + text: false |
| 78 | + }).removeClass("ui-corner-all") |
| 79 | + .addClass("ui-corner-right ui-button-icon sfComboBoxActual") |
| 80 | + // Add some inline CSS, to override CSS set by the |
| 81 | + // jquery.ui.tabs module - this is necessary if form is |
| 82 | + // used in conjunction with the Header Tabs extension. |
| 83 | + // 'cssText' attribute is needed because the normal |
| 84 | + // .css() calls don't allow for setting "!important", |
| 85 | + // which is needed to counteract "!important" coming |
| 86 | + // from the jquery.ui.tabs CSS. |
| 87 | + .css('cssText', 'padding: 0 !important; margin: 0 !important; -moz-border-radius: 0; -webkit-border-radius: 0; width: 1.7em;') |
| 88 | + .click(function() { |
| 89 | + // close if already visible |
| 90 | + if (input.autocomplete("widget").is(":visible")) { |
| 91 | + input.autocomplete("close"); |
| 92 | + return; |
| 93 | + } |
| 94 | + // pass empty string as value to search for, displaying all results |
| 95 | + input.autocomplete("search", ""); |
| 96 | + input.focus(); |
| 97 | + }); |
| 98 | + } |
| 99 | + }); |
| 100 | + |
| 101 | +})(jQuery); |
| 102 | + |
15 | 103 | // Activate autocomplete functionality for the specified field |
16 | 104 | (function(jQuery) { |
17 | 105 | |
— | — | @@ -959,90 +1047,3 @@ |
960 | 1048 | // If the form is submitted, validate everything! |
961 | 1049 | jQuery('#sfForm').submit( function() {return validateAll();} ); |
962 | 1050 | }); |
963 | | - |
964 | | -/* extending jquery functions */ |
965 | | - |
966 | | -(function(jQuery) { |
967 | | - jQuery.widget("ui.combobox", { |
968 | | - _create: function() { |
969 | | - var self = this; |
970 | | - var select = this.element.hide(); |
971 | | - var name= select[0].name; |
972 | | - var id = select[0].id; |
973 | | - var curval = select[0].options[0].value; |
974 | | - curval = curval.replace('"', '"' ); |
975 | | - var input = jQuery("<input id=\"" + id + "\" type=\"text\" name=\"" + name + "\" value=\"" + curval + "\">") |
976 | | - .insertAfter(select) |
977 | | - .attr("tabIndex", select.attr("tabIndex")) |
978 | | - .attr("autocompletesettings", select.attr("autocompletesettings")) |
979 | | - .css("width", select.attr("comboboxwidth")) |
980 | | - .autocomplete({ |
981 | | - source: function(request, response) { |
982 | | - if ( sfgAutocompleteOnAllChars ) { |
983 | | - var matcher = new RegExp(request.term, "i"); |
984 | | - } else { |
985 | | - var matcher = new RegExp("\\b" + request.term, "i"); |
986 | | - } |
987 | | - response(select.children("option").map(function() { |
988 | | - var text = jQuery(this).text(); |
989 | | - if (this.value && (!request.term || matcher.test(text))) { |
990 | | - return { |
991 | | - id: this.value, |
992 | | - label: text, |
993 | | - value: text |
994 | | - }; |
995 | | - } |
996 | | - })); |
997 | | - }, |
998 | | - delay: 0, |
999 | | - change: function(event, ui) { |
1000 | | - if (!ui.item) { |
1001 | | - if (select.attr("existingvaluesonly") == 'true') { |
1002 | | - // remove invalid value, as it didn't match anything |
1003 | | - jQuery(this).val(""); |
1004 | | - } |
1005 | | - return false; |
1006 | | - } |
1007 | | - select.val(ui.item.id); |
1008 | | - self._trigger("selected", event, { |
1009 | | - item: select.find("[value='" + ui.item.id.replace("'", "\\'") + "']") |
1010 | | - }); |
1011 | | - |
1012 | | - }, |
1013 | | - minLength: 0 |
1014 | | - }) |
1015 | | - .addClass("ui-widget ui-widget-content ui-corner-left sfComboBoxActual"); |
1016 | | - input.attr("origname", select.attr("origname")); |
1017 | | - jQuery('<button type="button"> </button>') |
1018 | | - .attr("tabIndex", -1) |
1019 | | - .attr("title", "Show All Items") |
1020 | | - .insertAfter(input) |
1021 | | - .button({ |
1022 | | - icons: { |
1023 | | - primary: "ui-icon-triangle-1-s" |
1024 | | - }, |
1025 | | - text: false |
1026 | | - }).removeClass("ui-corner-all") |
1027 | | - .addClass("ui-corner-right ui-button-icon sfComboBoxActual") |
1028 | | - // Add some inline CSS, to override CSS set by the |
1029 | | - // jquery.ui.tabs module - this is necessary if form is |
1030 | | - // used in conjunction with the Header Tabs extension. |
1031 | | - // 'cssText' attribute is needed because the normal |
1032 | | - // .css() calls don't allow for setting "!important", |
1033 | | - // which is needed to counteract "!important" coming |
1034 | | - // from the jquery.ui.tabs CSS. |
1035 | | - .css('cssText', 'padding: 0 !important; margin: 0 !important; -moz-border-radius: 0; -webkit-border-radius: 0; width: 1.7em;') |
1036 | | - .click(function() { |
1037 | | - // close if already visible |
1038 | | - if (input.autocomplete("widget").is(":visible")) { |
1039 | | - input.autocomplete("close"); |
1040 | | - return; |
1041 | | - } |
1042 | | - // pass empty string as value to search for, displaying all results |
1043 | | - input.autocomplete("search", ""); |
1044 | | - input.focus(); |
1045 | | - }); |
1046 | | - } |
1047 | | - }); |
1048 | | - |
1049 | | -})(jQuery); |