Update chosen to v0.9.5

This commit is contained in:
Bart Visscher 2011-11-24 21:04:34 +01:00
parent fab70cb590
commit cea6561632
5 changed files with 180 additions and 81 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 742 B

After

Width:  |  Height:  |  Size: 3.9 KiB

View File

@ -1,9 +1,4 @@
/* @group Base */
select.chzn-select {
visibility: hidden;
height: 28px !important;
min-height: 28px !important;
}
.chzn-container {
font-size: 13px;
position: relative;
@ -60,9 +55,21 @@ select.chzn-select {
white-space: nowrap;
-o-text-overflow: ellipsis;
-ms-text-overflow: ellipsis;
-moz-binding: url('/xml/ellipsis.xml#ellipsis');
text-overflow: ellipsis;
}
.chzn-container-single .chzn-single abbr {
display: block;
position: absolute;
right: 26px;
top: 8px;
width: 12px;
height: 13px;
font-size: 1px;
background: url(chosen-sprite.png) right top no-repeat;
}
.chzn-container-single .chzn-single abbr:hover {
background-position: right -11px;
}
.chzn-container-single .chzn-single div {
-webkit-border-radius: 0 4px 4px 0;
-moz-border-radius : 0 4px 4px 0;
@ -94,18 +101,19 @@ select.chzn-select {
}
.chzn-container-single .chzn-search {
padding: 3px 4px;
position: relative;
margin: 0;
white-space: nowrap;
}
.chzn-container-single .chzn-search input {
background: #fff url('chosen-sprite.png') no-repeat 100% -20px;
background: url('chosen-sprite.png') no-repeat 100% -20px, -webkit-gradient(linear, left bottom, left top, color-stop(0.85, white), color-stop(0.99, #eeeeee));
background: url('chosen-sprite.png') no-repeat 100% -20px, -webkit-linear-gradient(center bottom, white 85%, #eeeeee 99%);
background: url('chosen-sprite.png') no-repeat 100% -20px, -moz-linear-gradient(center bottom, white 85%, #eeeeee 99%);
background: url('chosen-sprite.png') no-repeat 100% -20px, -o-linear-gradient(bottom, white 85%, #eeeeee 99%);
background: url('chosen-sprite.png') no-repeat 100% -20px, -ms-linear-gradient(top, #ffffff 85%,#eeeeee 99%);
background: url('chosen-sprite.png') no-repeat 100% -20px, -ms-linear-gradient(top, #ffffff 85%,#eeeeee 99%);
background: url('chosen-sprite.png') no-repeat 100% -20px, linear-gradient(top, #ffffff 85%,#eeeeee 99%);
background: #fff url('chosen-sprite.png') no-repeat 100% -22px;
background: url('chosen-sprite.png') no-repeat 100% -22px, -webkit-gradient(linear, left bottom, left top, color-stop(0.85, white), color-stop(0.99, #eeeeee));
background: url('chosen-sprite.png') no-repeat 100% -22px, -webkit-linear-gradient(center bottom, white 85%, #eeeeee 99%);
background: url('chosen-sprite.png') no-repeat 100% -22px, -moz-linear-gradient(center bottom, white 85%, #eeeeee 99%);
background: url('chosen-sprite.png') no-repeat 100% -22px, -o-linear-gradient(bottom, white 85%, #eeeeee 99%);
background: url('chosen-sprite.png') no-repeat 100% -22px, -ms-linear-gradient(top, #ffffff 85%,#eeeeee 99%);
background: url('chosen-sprite.png') no-repeat 100% -22px, -ms-linear-gradient(top, #ffffff 85%,#eeeeee 99%);
background: url('chosen-sprite.png') no-repeat 100% -22px, linear-gradient(top, #ffffff 85%,#eeeeee 99%);
margin: 1px 0;
padding: 4px 20px 4px 5px;
outline: 0;
@ -123,6 +131,11 @@ select.chzn-select {
}
/* @end */
.chzn-container-single-nosearch .chzn-search input {
position: absolute;
left: -9000px;
}
/* @group Multi Chosen */
.chzn-container-multi .chzn-choices {
background-color: #fff;
@ -197,18 +210,18 @@ select.chzn-select {
.chzn-container-multi .chzn-choices .search-choice .search-choice-close {
display: block;
position: absolute;
right: 5px;
top: 6px;
width: 8px;
height: 9px;
right: 3px;
top: 4px;
width: 12px;
height: 13px;
font-size: 1px;
background: url(chosen-sprite.png) right top no-repeat;
}
.chzn-container-multi .chzn-choices .search-choice .search-choice-close:hover {
background-position: right -9px;
background-position: right -11px;
}
.chzn-container-multi .chzn-choices .search-choice-focus .search-choice-close {
background-position: right -9px;
background-position: right -11px;
}
/* @end */
@ -226,6 +239,7 @@ select.chzn-select {
padding: 0;
}
.chzn-container .chzn-results li {
display: none;
line-height: 80%;
padding: 7px 7px 8px;
margin: 0;
@ -233,6 +247,7 @@ select.chzn-select {
}
.chzn-container .chzn-results .active-result {
cursor: pointer;
display: list-item;
}
.chzn-container .chzn-results .highlighted {
background: #3875d7;
@ -247,6 +262,7 @@ select.chzn-select {
}
.chzn-container .chzn-results .no-results {
background: #f4f4f4;
display: list-item;
}
.chzn-container .chzn-results .group-result {
cursor: default;
@ -309,6 +325,18 @@ select.chzn-select {
}
/* @end */
/* @group Disabled Support */
.chzn-disabled {
cursor: default;
opacity:0.5 !important;
}
.chzn-disabled .chzn-single {
cursor: default;
}
.chzn-disabled .chzn-choices .search-choice .search-choice-close {
cursor: default;
}
/* @group Right to Left */
.chzn-rtl { direction:rtl;text-align: right; }
.chzn-rtl .chzn-single { padding-left: 0; padding-right: 8px; }
@ -327,14 +355,14 @@ select.chzn-select {
.chzn-rtl .chzn-results .group-option { padding-left: 0; padding-right: 20px; }
.chzn-rtl.chzn-container-active .chzn-single-with-drop div { border-right: none; }
.chzn-rtl .chzn-search input {
background: url('chosen-sprite.png') no-repeat -38px -20px, #ffffff;
background: url('chosen-sprite.png') no-repeat -38px -20px, -webkit-gradient(linear, left bottom, left top, color-stop(0.85, white), color-stop(0.99, #eeeeee));
background: url('chosen-sprite.png') no-repeat -38px -20px, -webkit-linear-gradient(center bottom, white 85%, #eeeeee 99%);
background: url('chosen-sprite.png') no-repeat -38px -20px, -moz-linear-gradient(center bottom, white 85%, #eeeeee 99%);
background: url('chosen-sprite.png') no-repeat -38px -20px, -o-linear-gradient(bottom, white 85%, #eeeeee 99%);
background: url('chosen-sprite.png') no-repeat -38px -20px, -ms-linear-gradient(top, #ffffff 85%,#eeeeee 99%);
background: url('chosen-sprite.png') no-repeat -38px -20px, -ms-linear-gradient(top, #ffffff 85%,#eeeeee 99%);
background: url('chosen-sprite.png') no-repeat -38px -20px, linear-gradient(top, #ffffff 85%,#eeeeee 99%);
background: url('chosen-sprite.png') no-repeat -38px -22px, #ffffff;
background: url('chosen-sprite.png') no-repeat -38px -22px, -webkit-gradient(linear, left bottom, left top, color-stop(0.85, white), color-stop(0.99, #eeeeee));
background: url('chosen-sprite.png') no-repeat -38px -22px, -webkit-linear-gradient(center bottom, white 85%, #eeeeee 99%);
background: url('chosen-sprite.png') no-repeat -38px -22px, -moz-linear-gradient(center bottom, white 85%, #eeeeee 99%);
background: url('chosen-sprite.png') no-repeat -38px -22px, -o-linear-gradient(bottom, white 85%, #eeeeee 99%);
background: url('chosen-sprite.png') no-repeat -38px -22px, -ms-linear-gradient(top, #ffffff 85%,#eeeeee 99%);
background: url('chosen-sprite.png') no-repeat -38px -22px, -ms-linear-gradient(top, #ffffff 85%,#eeeeee 99%);
background: url('chosen-sprite.png') no-repeat -38px -22px, linear-gradient(top, #ffffff 85%,#eeeeee 99%);
padding: 4px 5px 4px 20px;
}
/* @end */

View File

@ -1 +1 @@
0.9.1
0.9.5

View File

@ -1,7 +1,7 @@
// Chosen, a Select Box Enhancer for jQuery and Protoype
// by Patrick Filler for Harvest, http://getharvest.com
//
// Version 0.9
// Version 0.9.5
// Full source at https://github.com/harvesthq/chosen
// Copyright (c) 2011 Harvest http://getharvest.com
@ -16,18 +16,22 @@
root = this;
$ = jQuery;
$.fn.extend({
chosen: function(data, options) {
chosen: function(options) {
if ($.browser === "msie" && ($.browser.version === "6.0" || $.browser.version === "7.0")) {
return this;
}
return $(this).each(function(input_field) {
if (!($(this)).hasClass("chzn-done")) {
return new Chosen(this, data, options);
return new Chosen(this, options);
}
});
}
});
Chosen = (function() {
function Chosen(elmn) {
function Chosen(form_field, options) {
this.form_field = form_field;
this.options = options != null ? options : {};
this.set_default_values();
this.form_field = elmn;
this.form_field_jq = $(this.form_field);
this.is_multiple = this.form_field.multiple;
this.is_rtl = this.form_field_jq.hasClass("chzn-rtl");
@ -40,22 +44,28 @@
this.click_test_action = __bind(function(evt) {
return this.test_active_click(evt);
}, this);
this.activate_action = __bind(function(evt) {
return this.activate_field(evt);
}, this);
this.active_field = false;
this.mouse_on_container = false;
this.results_showing = false;
this.result_highlighted = null;
this.result_single_selected = null;
return this.choices = 0;
this.allow_single_deselect = (this.options.allow_single_deselect != null) && this.form_field.options[0].text === "" ? this.options.allow_single_deselect : false;
this.disable_search_threshold = this.options.disable_search_threshold || 0;
this.choices = 0;
return this.results_none_found = this.options.no_results_text || "No results match";
};
Chosen.prototype.set_up_html = function() {
var container_div, dd_top, dd_width, sf_width;
this.container_id = this.form_field.id.length ? this.form_field.id.replace(/(:|\.)/g, '_') : this.generate_field_id();
this.container_id += "_chzn";
this.f_width = this.form_field_jq.width();
this.f_width = this.form_field_jq.outerWidth();
this.default_text = this.form_field_jq.data('placeholder') ? this.form_field_jq.data('placeholder') : this.default_text_default;
container_div = $("<div />", {
id: this.container_id,
"class": "chzn-container " + (this.is_rtl ? ' chzn-rtl' : void 0),
"class": "chzn-container" + (this.is_rtl ? ' chzn-rtl' : ''),
style: 'width: ' + this.f_width + 'px;'
});
if (this.is_multiple) {
@ -66,6 +76,9 @@
this.form_field_jq.hide().after(container_div);
this.container = $('#' + this.container_id);
this.container.addClass("chzn-container-" + (this.is_multiple ? "multi" : "single"));
if (!this.is_multiple && this.form_field.options.length <= this.disable_search_threshold) {
this.container.addClass("chzn-container-single-nosearch");
}
this.dropdown = this.container.find('div.chzn-drop').first();
dd_top = this.container.height();
dd_width = this.f_width - get_side_border_padding(this.dropdown);
@ -92,8 +105,11 @@
return this.set_tab_index();
};
Chosen.prototype.register_observers = function() {
this.container.click(__bind(function(evt) {
return this.container_click(evt);
this.container.mousedown(__bind(function(evt) {
return this.container_mousedown(evt);
}, this));
this.container.mouseup(__bind(function(evt) {
return this.container_mouseup(evt);
}, this));
this.container.mouseenter(__bind(function(evt) {
return this.mouse_enter(evt);
@ -101,8 +117,8 @@
this.container.mouseleave(__bind(function(evt) {
return this.mouse_leave(evt);
}, this));
this.search_results.click(__bind(function(evt) {
return this.search_results_click(evt);
this.search_results.mouseup(__bind(function(evt) {
return this.search_results_mouseup(evt);
}, this));
this.search_results.mouseover(__bind(function(evt) {
return this.search_results_mouseover(evt);
@ -129,30 +145,52 @@
return this.search_field.focus(__bind(function(evt) {
return this.input_focus(evt);
}, this));
} else {
return this.selected_item.focus(__bind(function(evt) {
return this.activate_field(evt);
}, this));
}
};
Chosen.prototype.container_click = function(evt) {
if (evt && evt.type === "click") {
evt.stopPropagation();
}
if (!this.pending_destroy_click) {
if (!this.active_field) {
if (this.is_multiple) {
this.search_field.val("");
}
$(document).click(this.click_test_action);
this.results_show();
} else if (!this.is_multiple && evt && ($(evt.target) === this.selected_item || $(evt.target).parents("a.chzn-single").length)) {
evt.preventDefault();
this.results_toggle();
Chosen.prototype.search_field_disabled = function() {
this.is_disabled = this.form_field_jq.attr('disabled');
if (this.is_disabled) {
this.container.addClass('chzn-disabled');
this.search_field.attr('disabled', true);
if (!this.is_multiple) {
this.selected_item.unbind("focus", this.activate_action);
}
return this.activate_field();
return this.close_field();
} else {
return this.pending_destroy_click = false;
this.container.removeClass('chzn-disabled');
this.search_field.attr('disabled', false);
if (!this.is_multiple) {
return this.selected_item.bind("focus", this.activate_action);
}
}
};
Chosen.prototype.container_mousedown = function(evt) {
var target_closelink;
if (!this.is_disabled) {
target_closelink = evt != null ? ($(evt.target)).hasClass("search-choice-close") : false;
if (evt && evt.type === "mousedown") {
evt.stopPropagation();
}
if (!this.pending_destroy_click && !target_closelink) {
if (!this.active_field) {
if (this.is_multiple) {
this.search_field.val("");
}
$(document).click(this.click_test_action);
this.results_show();
} else if (!this.is_multiple && evt && ($(evt.target) === this.selected_item || $(evt.target).parents("a.chzn-single").length)) {
evt.preventDefault();
this.results_toggle();
}
return this.activate_field();
} else {
return this.pending_destroy_click = false;
}
}
};
Chosen.prototype.container_mouseup = function(evt) {
if (evt.target.nodeName === "ABBR") {
return this.results_reset(evt);
}
};
Chosen.prototype.mouse_enter = function() {
@ -164,7 +202,7 @@
Chosen.prototype.input_focus = function(evt) {
if (!this.active_field) {
return setTimeout((__bind(function() {
return this.container_click();
return this.container_mousedown();
}, this)), 50);
}
};
@ -235,9 +273,13 @@
this.choice_build(data);
} else if (data.selected && !this.is_multiple) {
this.selected_item.find("span").text(data.text);
if (this.allow_single_deselect) {
this.selected_item.find("span").first().after("<abbr class=\"search-choice-close\"></abbr>");
}
}
}
}
this.search_field_disabled();
this.show_search_field_default();
this.search_field_scale();
this.search_results.html(content);
@ -252,7 +294,7 @@
}
};
Chosen.prototype.result_add_option = function(option) {
var classes;
var classes, style;
if (!option.disabled) {
option.dom_id = this.container_id + "_o_" + option.array_index;
classes = option.selected && this.is_multiple ? [] : ["active-result"];
@ -262,7 +304,11 @@
if (option.group_array_index != null) {
classes.push("group-option");
}
return '<li id="' + option.dom_id + '" class="' + classes.join(' ') + '">' + option.html + '</li>';
if (option.classes !== "") {
classes.push(option.classes);
}
style = option.style.cssText !== "" ? " style=\"" + option.style + "\"" : "";
return '<li id="' + option.dom_id + '" class="' + classes.join(' ') + '"' + style + '>' + option.html + '</li>';
} else {
return "";
}
@ -353,12 +399,12 @@
return this.search_field.removeClass("default");
}
};
Chosen.prototype.search_results_click = function(evt) {
Chosen.prototype.search_results_mouseup = function(evt) {
var target;
target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first();
if (target.length) {
this.result_highlight = target;
return this.result_select();
return this.result_select(evt);
}
};
Chosen.prototype.search_results_mouseover = function(evt) {
@ -391,8 +437,12 @@
};
Chosen.prototype.choice_destroy_link_click = function(evt) {
evt.preventDefault();
this.pending_destroy_click = true;
return this.choice_destroy($(evt.target));
if (!this.is_disabled) {
this.pending_destroy_click = true;
return this.choice_destroy($(evt.target));
} else {
return evt.stopPropagation;
}
};
Chosen.prototype.choice_destroy = function(link) {
this.choices -= 1;
@ -403,18 +453,29 @@
this.result_deselect(link.attr("rel"));
return link.parents('li').first().remove();
};
Chosen.prototype.result_select = function() {
Chosen.prototype.results_reset = function(evt) {
this.form_field.options[0].selected = true;
this.selected_item.find("span").text(this.default_text);
this.show_search_field_default();
$(evt.target).remove();
this.form_field_jq.trigger("change");
if (this.active_field) {
return this.results_hide();
}
};
Chosen.prototype.result_select = function(evt) {
var high, high_id, item, position;
if (this.result_highlight) {
high = this.result_highlight;
high_id = high.attr("id");
this.result_clear_highlight();
high.addClass("result-selected");
if (this.is_multiple) {
this.result_deactivate(high);
} else {
this.search_results.find(".result-selected").removeClass("result-selected");
this.result_single_selected = high;
}
high.addClass("result-selected");
position = high_id.substr(high_id.lastIndexOf("_") + 1);
item = this.results_data[position];
item.selected = true;
@ -423,18 +484,23 @@
this.choice_build(item);
} else {
this.selected_item.find("span").first().text(item.text);
if (this.allow_single_deselect) {
this.selected_item.find("span").first().after("<abbr class=\"search-choice-close\"></abbr>");
}
}
if (!(evt.metaKey && this.is_multiple)) {
this.results_hide();
}
this.results_hide();
this.search_field.val("");
this.form_field_jq.trigger("change");
return this.search_field_scale();
}
};
Chosen.prototype.result_activate = function(el) {
return el.addClass("active-result").show();
return el.addClass("active-result");
};
Chosen.prototype.result_deactivate = function(el) {
return el.removeClass("active-result").hide();
return el.removeClass("active-result");
};
Chosen.prototype.result_deselect = function(pos) {
var result, result_data;
@ -530,17 +596,18 @@
return _results;
};
Chosen.prototype.winnow_results_set_highlight = function() {
var do_high;
var do_high, selected_results;
if (!this.result_highlight) {
do_high = this.search_results.find(".active-result").first();
if (do_high) {
selected_results = !this.is_multiple ? this.search_results.find(".result-selected.active-result") : [];
do_high = selected_results.length ? selected_results.first() : this.search_results.find(".active-result").first();
if (do_high != null) {
return this.result_do_highlight(do_high);
}
}
};
Chosen.prototype.no_results = function(terms) {
var no_results_html;
no_results_html = $('<li class="no-results">No results match "<span></span>"</li>');
no_results_html = $('<li class="no-results">' + this.results_none_found + ' "<span></span>"</li>');
no_results_html.find("span").first().html(terms);
return this.search_results.append(no_results_html);
};
@ -611,7 +678,7 @@
case 13:
evt.preventDefault();
if (this.results_showing) {
return this.result_select();
return this.result_select(evt);
}
break;
case 27:
@ -623,6 +690,8 @@
case 38:
case 40:
case 16:
case 91:
case 17:
break;
default:
return this.results_search();
@ -758,7 +827,9 @@
html: option.innerHTML,
selected: option.selected,
disabled: group_disabled === true ? group_disabled : option.disabled,
group_array_index: group_position
group_array_index: group_position,
classes: option.className,
style: option.style.cssText
});
} else {
this.parsed.push({

File diff suppressed because one or more lines are too long