presence/vendor/assets/javascripts/jquery.flexselect.js in social_stream-0.21.0 vs presence/vendor/assets/javascripts/jquery.flexselect.js in social_stream-0.21.1

- old
+ new

@@ -19,10 +19,11 @@ $.extend($.flexselect.prototype, { settings: { allowMismatch: false, selectedClass: "flexselect_selected", dropdownClass: "flexselect_dropdown", + defaultmessage: "No results", inputIdTransform: function(id) { return id + "_flexselect"; }, inputNameTransform: function(name) { return; }, dropdownIdTransform: function(id) { return id + "_flexselect_dropdown"; } }, select: null, @@ -44,13 +45,19 @@ this.preloadCache(); this.renderControls(); this.wire(); }, - preloadCache: function() { + //preloadCache: function() { + // this.cache = this.select.children("option").map(function() { + // return { name: $.trim($(this).text()), value: $(this).val(), score: 0.0 }; + // }); + //}, + + preloadCache: function() { this.cache = this.select.children("option").map(function() { - return { name: $.trim($(this).text()), value: $(this).val(), score: 0.0 }; + return { name: ($(this).html()), value: $(this).val(), score: 0.0 }; }); }, renderControls: function() { var selected = this.select.children("option:selected"); @@ -63,10 +70,11 @@ this.input = $("<input type='text' autocomplete='off' />").attr({ id: this.settings.inputIdTransform(this.select.attr("id")), name: this.settings.inputNameTransform(this.select.attr("name")), accesskey: this.select.attr("accesskey"), tabindex: this.select.attr("tabindex"), + placeholder: this.select.attr("placeholder"), style: this.select.attr("style") }).addClass(this.select.attr("class")).val($.trim(selected.text())); this.dropdown = $("<div></div>").attr({ id: this.settings.dropdownIdTransform(this.select.attr("id")) @@ -82,21 +90,22 @@ var self = this; this.input.click(function() { self.lastAbbreviation = null; self.focus(); + if (!self.picked) self.filterResults(); }); this.input.mouseup(function(event) { // This is so Safari selection actually occurs. event.preventDefault(); }); this.input.focus(function() { self.abbreviationBeforeFocus = self.input.val(); self.input.select(); - if (!self.picked) self.filterResults(); + //if (!self.picked) self.filterResults(); }); this.input.blur(function() { if (!self.dropdownMouseover) { self.hide(); @@ -183,12 +192,17 @@ var results = []; $.each(this.cache, function() { this.score = LiquidMetal.score(this.name, abbreviation); if (this.score > 0.0) results.push(this); }); + + if (results.length==0){ + var defaultOption = { name: this.settings.defaultmessage, value: "ZERO_CONTACTS", score: 9.9 }; + results.push(defaultOption); + } + this.results = results; - this.sortResults(); this.renderDropdown(); this.markFirst(); this.lastAbbreviation = abbreviation; this.picked = false; @@ -206,14 +220,17 @@ top: (inputOffset.top + this.input.outerHeight()) + "px", left: inputOffset.left + "px" }); var list = this.dropdownList.html(""); - $.each(this.results, function() { - // list.append($("<li/>").html(this.name + " <small>[" + Math.round(this.score*100)/100 + "]</small>")); - list.append($("<li/>").html(this.name)); - }); + + if (this.results.length > 0) { + $.each(this.results, function() { + list.append($("<li/>").html(this.name)); + }); + } + this.dropdown.show(); }, markSelected: function(n) { if (n > this.results.length) return; @@ -228,19 +245,19 @@ pickSelected: function() { var selected = this.results[this.selectedIndex]; if (selected) { //this.input.val(selected.name); //this.picked = true; + this.hidden.val(selected.value); + this.input.val(""); if(typeof changeSelectContactValue == "function"){ - changeSelectContactValue(selected.name,selected.value); + return changeSelectContactValue(selected.name,selected.value); } - this.hidden.val(selected.value); } else if (this.settings.allowMismatch) { this.hidden.val(""); } else { this.reset(); } - this.input.val(""); }, hide: function() { this.dropdown.hide(); this.lastAbbreviation = null;