font-size: 13px;
position: relative;
display: inline-block;
+ vertical-align: middle;
zoom: 1;
*display: inline;
}
border: 1px solid #aaa;
border-top: 0;
position: absolute;
- top: 29px;
- left: 0;
+ top: 100%;
+ left: -9999px;
-webkit-box-shadow: 0 4px 5px rgba(0,0,0,.15);
-moz-box-shadow : 0 4px 5px rgba(0,0,0,.15);
box-shadow : 0 4px 5px rgba(0,0,0,.15);
z-index: 1010;
+ width: 100%;
+ -moz-box-sizing : border-box;
+ -ms-box-sizing : border-box;
+ -webkit-box-sizing: border-box;
+ -khtml-box-sizing : border-box;
+ box-sizing : border-box;
+}
+
+.chzn-container.chzn-with-drop .chzn-drop {
+ left: 0;
}
+
/* @end */
/* @group Single Chosen */
border: 1px solid #aaa;
font-family: sans-serif;
font-size: 1em;
+ width: 100%;
+ -moz-box-sizing : border-box;
+ -ms-box-sizing : border-box;
+ -webkit-box-sizing: border-box;
+ -khtml-box-sizing : border-box;
+ box-sizing : border-box;
}
.chzn-container-single .chzn-drop {
+ margin-top: -1px;
-webkit-border-radius: 0 0 4px 4px;
-moz-border-radius : 0 0 4px 4px;
border-radius : 0 0 4px 4px;
-webkit-background-clip: padding-box;
background-clip : padding-box;
}
-/* @end */
-
-.chzn-container-single-nosearch .chzn-search input {
+.chzn-container-single-nosearch .chzn-search {
position: absolute;
- left: -9000px;
+ left: -9999px;
}
+/* @end */
/* @group Multi Chosen */
.chzn-container-multi .chzn-choices {
height: auto !important;
height: 1%;
position: relative;
+ width: 100%;
+ -moz-box-sizing : border-box;
+ -ms-box-sizing : border-box;
+ -webkit-box-sizing: border-box;
+ -khtml-box-sizing : border-box;
+ box-sizing : border-box;
}
.chzn-container-multi .chzn-choices li {
float: left;
-webkit-overflow-scrolling: touch;
}
.chzn-container-multi .chzn-results {
- margin: -1px 0 0;
+ margin: 0;
padding: 0;
}
.chzn-container .chzn-results li {
box-shadow : 0 0 5px rgba(0,0,0,.3);
border: 1px solid #5897fb;
}
-.chzn-container-active .chzn-single-with-drop {
+.chzn-container-active.chzn-with-drop .chzn-single {
border: 1px solid #aaa;
-webkit-box-shadow: 0 1px 0 #fff inset;
-moz-box-shadow : 0 1px 0 #fff inset;
border-bottom-left-radius : 0;
border-bottom-right-radius: 0;
}
-.chzn-container-active .chzn-single-with-drop div {
+.chzn-container-active.chzn-with-drop .chzn-single div {
background: transparent;
border-left: none;
}
-.chzn-container-active .chzn-single-with-drop div b {
+.chzn-container-active.chzn-with-drop .chzn-single div b {
background-position: -18px 2px;
}
.chzn-container-active .chzn-choices {
.chzn-rtl .chzn-choices li { float: right; }
.chzn-rtl .chzn-choices .search-choice { padding: 3px 5px 3px 19px; margin: 3px 5px 3px 0; }
.chzn-rtl .chzn-choices .search-choice .search-choice-close { left: 4px; right: auto; }
+.chzn-rtl .chzn-search { left: 9999px; }
+.chzn-rtl.chzn-with-drop .chzn-search { left: 0px; }
+.chzn-rtl .chzn-drop { left: 9999px; }
.chzn-rtl.chzn-container-single .chzn-results { margin: 0 0 4px 4px; padding: 0 4px 0 0; }
.chzn-rtl .chzn-results .group-option { padding-left: 0; padding-right: 15px; }
-.chzn-rtl.chzn-container-active .chzn-single-with-drop div { border-right: none; }
+.chzn-rtl.chzn-container-active.chzn-with-drop .chzn-single div { border-right: none; }
.chzn-rtl .chzn-search input {
background: #fff url('chosen-sprite.png') no-repeat -30px -20px;
background: url('chosen-sprite.png') no-repeat -30px -20px, -webkit-gradient(linear, 0 0, 0 100%, color-stop(1%, #eeeeee), color-stop(15%, #ffffff));
.chzn-container-single.chzn-rtl .chzn-single div b {
background-position: 6px 2px;
}
-.chzn-container-single.chzn-rtl .chzn-single-with-drop div b {
+.chzn-container-single.chzn-rtl.chzn-with-drop .chzn-single div b {
background-position: -12px 2px;
}
/* @end */
// Chosen, a Select Box Enhancer for jQuery and Protoype
// by Patrick Filler for Harvest, http://getharvest.com
//
-// Version 0.9.12
+// Version 0.9.14
// Full source at https://github.com/harvesthq/chosen
// Copyright (c) 2011 Harvest http://getharvest.com
function AbstractChosen(form_field, options) {
this.form_field = form_field;
this.options = options != null ? options : {};
+ if (!AbstractChosen.browser_is_supported()) {
+ return;
+ }
this.is_multiple = this.form_field.multiple;
this.set_default_text();
this.set_default_values();
if (this.form_field.getAttribute("data-placeholder")) {
this.default_text = this.form_field.getAttribute("data-placeholder");
} else if (this.is_multiple) {
- this.default_text = this.options.placeholder_text_multiple || this.options.placeholder_text || "Select Some Options";
+ this.default_text = this.options.placeholder_text_multiple || this.options.placeholder_text || AbstractChosen.default_multiple_text;
} else {
- this.default_text = this.options.placeholder_text_single || this.options.placeholder_text || "Select an Option";
+ this.default_text = this.options.placeholder_text_single || this.options.placeholder_text || AbstractChosen.default_single_text;
}
- return this.results_none_found = this.form_field.getAttribute("data-no_results_text") || this.options.no_results_text || "No results match";
+ return this.results_none_found = this.form_field.getAttribute("data-no_results_text") || this.options.no_results_text || AbstractChosen.default_no_result_text;
};
AbstractChosen.prototype.mouse_enter = function() {
}
};
+ AbstractChosen.prototype.choices_click = function(evt) {
+ evt.preventDefault();
+ if (!this.results_showing) {
+ return this.results_show();
+ }
+ };
+
AbstractChosen.prototype.keyup_checker = function(evt) {
var stroke, _ref;
stroke = (_ref = evt.which) != null ? _ref : evt.keyCode;
return newchar = chars.substring(rand, rand + 1);
};
+ AbstractChosen.prototype.container_width = function() {
+ var width;
+ if (this.options.width != null) {
+ return this.options.width;
+ }
+ width = window.getComputedStyle != null ? parseFloat(window.getComputedStyle(this.form_field).getPropertyValue('width')) : (typeof jQuery !== "undefined" && jQuery !== null) && (this.form_field_jq != null) ? this.form_field_jq.outerWidth() : this.form_field.getWidth();
+ return width + "px";
+ };
+
+ AbstractChosen.browser_is_supported = function() {
+ var _ref;
+ if (window.navigator.appName === "Microsoft Internet Explorer") {
+ return (null !== (_ref = document.documentMode) && _ref >= 8);
+ }
+ return true;
+ };
+
+ AbstractChosen.default_multiple_text = "Select Some Options";
+
+ AbstractChosen.default_single_text = "Select an Option";
+
+ AbstractChosen.default_no_result_text = "No results match";
+
return AbstractChosen;
})();
(function() {
- var $, Chosen, get_side_border_padding, root,
+ var $, Chosen, root,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
$.fn.extend({
chosen: function(options) {
- var browser, match, ua;
- ua = navigator.userAgent.toLowerCase();
- match = /(msie) ([\w.]+)/.exec(ua) || [];
- browser = {
- name: match[1] || "",
- version: match[2] || "0"
- };
- if (browser.name === "msie" && (browser.version === "6.0" || (browser.version === "7.0" && document.documentMode === 7))) {
+ if (!AbstractChosen.browser_is_supported()) {
return this;
}
return this.each(function(input_field) {
Chosen.prototype.setup = function() {
this.form_field_jq = $(this.form_field);
- this.current_value = this.form_field_jq.val();
+ this.current_selectedIndex = this.form_field.selectedIndex;
return this.is_rtl = this.form_field_jq.hasClass("chzn-rtl");
};
};
Chosen.prototype.set_up_html = function() {
- var container_classes, container_div, container_props, dd_top, dd_width, sf_width;
+ var container_classes, container_props;
this.container_id = this.form_field.id.length ? this.form_field.id.replace(/[^\w]/g, '_') : this.generate_field_id();
this.container_id += "_chzn";
container_classes = ["chzn-container"];
if (this.is_rtl) {
container_classes.push("chzn-rtl");
}
- this.f_width = this.form_field_jq.outerWidth();
container_props = {
- id: this.container_id,
- "class": container_classes.join(' '),
- style: 'width: ' + this.f_width + 'px;',
- title: this.form_field.title
+ 'id': this.container_id,
+ 'class': container_classes.join(' '),
+ 'style': "width: " + (this.container_width()) + ";",
+ 'title': this.form_field.title
};
- container_div = $("<div />", container_props);
+ this.container = $("<div />", container_props);
if (this.is_multiple) {
- container_div.html('<ul class="chzn-choices"><li class="search-field"><input type="text" value="' + this.default_text + '" class="default" autocomplete="off" style="width:25px;" /></li></ul><div class="chzn-drop" style="left:-9000px;"><ul class="chzn-results"></ul></div>');
+ this.container.html('<ul class="chzn-choices"><li class="search-field"><input type="text" value="' + this.default_text + '" class="default" autocomplete="off" style="width:25px;" /></li></ul><div class="chzn-drop"><ul class="chzn-results"></ul></div>');
} else {
- container_div.html('<a href="javascript:void(0)" class="chzn-single chzn-default" tabindex="-1"><span>' + this.default_text + '</span><div><b></b></div></a><div class="chzn-drop" style="left:-9000px;"><div class="chzn-search"><input type="text" autocomplete="off" /></div><ul class="chzn-results"></ul></div>');
+ this.container.html('<a href="javascript:void(0)" class="chzn-single chzn-default" tabindex="-1"><span>' + this.default_text + '</span><div><b></b></div></a><div class="chzn-drop"><div class="chzn-search"><input type="text" autocomplete="off" /></div><ul class="chzn-results"></ul></div>');
}
- this.form_field_jq.hide().after(container_div);
- this.container = $('#' + this.container_id);
+ this.form_field_jq.hide().after(this.container);
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);
- this.dropdown.css({
- "width": dd_width + "px",
- "top": dd_top + "px"
- });
this.search_field = this.container.find('input').first();
this.search_results = this.container.find('ul.chzn-results').first();
this.search_field_scale();
} else {
this.search_container = this.container.find('div.chzn-search').first();
this.selected_item = this.container.find('.chzn-single').first();
- sf_width = dd_width - get_side_border_padding(this.search_container) - get_side_border_padding(this.search_field);
- this.search_field.css({
- "width": sf_width + "px"
- });
}
this.results_build();
this.set_tab_index();
+ this.set_label_behavior();
return this.form_field_jq.trigger("liszt:ready", {
chosen: this
});
this.search_results.mouseout(function(evt) {
_this.search_results_mouseout(evt);
});
+ this.search_results.bind('mousewheel DOMMouseScroll', function(evt) {
+ _this.search_results_mousewheel(evt);
+ });
this.form_field_jq.bind("liszt:updated", function(evt) {
_this.results_update_field(evt);
});
};
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" && !this.results_showing) {
evt.preventDefault();
}
- if (!this.pending_destroy_click && !target_closelink) {
+ if (!((evt != null) && ($(evt.target)).hasClass("search-choice-close"))) {
if (!this.active_field) {
if (this.is_multiple) {
this.search_field.val("");
this.results_toggle();
}
return this.activate_field();
- } else {
- return this.pending_destroy_click = false;
}
}
};
}
};
+ Chosen.prototype.search_results_mousewheel = function(evt) {
+ var delta, _ref, _ref1;
+ delta = -((_ref = evt.originalEvent) != null ? _ref.wheelDelta : void 0) || ((_ref1 = evt.originialEvent) != null ? _ref1.detail : void 0);
+ if (delta != null) {
+ evt.preventDefault();
+ if (evt.type === 'DOMMouseScroll') {
+ delta = delta * 40;
+ }
+ return this.search_results.scrollTop(delta + this.search_results.scrollTop());
+ }
+ };
+
Chosen.prototype.blur_test = function(evt) {
if (!this.active_field && this.container.hasClass("chzn-container-active")) {
return this.close_field();
};
Chosen.prototype.results_show = function() {
- var dd_top;
- if (!this.is_multiple) {
- this.selected_item.addClass("chzn-single-with-drop");
- if (this.result_single_selected) {
- this.result_do_highlight(this.result_single_selected);
- }
- } else if (this.max_selected_options <= this.choices) {
+ if (this.result_single_selected != null) {
+ this.result_do_highlight(this.result_single_selected);
+ } else if (this.is_multiple && this.max_selected_options <= this.choices) {
this.form_field_jq.trigger("liszt:maxselected", {
chosen: this
});
return false;
}
- dd_top = this.is_multiple ? this.container.height() : this.container.height() - 1;
+ this.container.addClass("chzn-with-drop");
this.form_field_jq.trigger("liszt:showing_dropdown", {
chosen: this
});
- this.dropdown.css({
- "top": dd_top + "px",
- "left": 0
- });
this.results_showing = true;
this.search_field.focus();
this.search_field.val(this.search_field.val());
};
Chosen.prototype.results_hide = function() {
- if (!this.is_multiple) {
- this.selected_item.removeClass("chzn-single-with-drop");
- }
this.result_clear_highlight();
+ this.container.removeClass("chzn-with-drop");
this.form_field_jq.trigger("liszt:hiding_dropdown", {
chosen: this
});
- this.dropdown.css({
- "left": "-9000px"
- });
return this.results_showing = false;
};
}
};
+ Chosen.prototype.set_label_behavior = function() {
+ var _this = this;
+ this.form_field_label = this.form_field_jq.parents("label");
+ if (!this.form_field_label.length && this.form_field.id.length) {
+ this.form_field_label = $("label[for=" + this.form_field.id + "]");
+ }
+ if (this.form_field_label.length > 0) {
+ return this.form_field_label.click(function(evt) {
+ if (_this.is_multiple) {
+ return _this.container_mousedown(evt);
+ } else {
+ return _this.activate_field();
+ }
+ });
+ }
+ };
+
Chosen.prototype.show_search_field_default = function() {
if (this.is_multiple && this.choices < 1 && !this.active_field) {
this.search_field.val(this.default_text);
}
};
- Chosen.prototype.choices_click = function(evt) {
- evt.preventDefault();
- if (this.active_field && !($(evt.target).hasClass("search-choice" || $(evt.target).parents('.search-choice').first)) && !this.results_showing) {
- return this.results_show();
- }
- };
-
Chosen.prototype.choice_build = function(item) {
var choice_id, html, link,
_this = this;
Chosen.prototype.choice_destroy_link_click = function(evt) {
evt.preventDefault();
+ evt.stopPropagation();
if (!this.is_disabled) {
- this.pending_destroy_click = true;
return this.choice_destroy($(evt.target));
- } else {
- return evt.stopPropagation;
}
};
};
Chosen.prototype.results_reset_cleanup = function() {
- this.current_value = this.form_field_jq.val();
+ this.current_selectedIndex = this.form_field.selectedIndex;
return this.selected_item.find("abbr").remove();
};
this.results_hide();
}
this.search_field.val("");
- if (this.is_multiple || this.form_field_jq.val() !== this.current_value) {
+ if (this.is_multiple || this.form_field.selectedIndex !== this.current_selectedIndex) {
this.form_field_jq.trigger("change", {
'selected': this.form_field.options[item.options_index].value
});
}
- this.current_value = this.form_field_jq.val();
+ this.current_selectedIndex = this.form_field.selectedIndex;
return this.search_field_scale();
}
};
};
Chosen.prototype.search_field_scale = function() {
- var dd_top, div, h, style, style_block, styles, w, _i, _len;
+ var div, h, style, style_block, styles, w, _i, _len;
if (this.is_multiple) {
h = 0;
w = 0;
$('body').append(div);
w = div.width() + 25;
div.remove();
+ if (!this.f_width) {
+ this.f_width = this.container.outerWidth();
+ }
if (w > this.f_width - 10) {
w = this.f_width - 10;
}
- this.search_field.css({
+ return this.search_field.css({
'width': w + 'px'
});
- dd_top = this.container.height();
- return this.dropdown.css({
- "top": dd_top + "px"
- });
}
};
root.Chosen = Chosen;
- get_side_border_padding = function(elmt) {
- var side_border_padding;
- return side_border_padding = elmt.outerWidth() - elmt.width();
- };
-
- root.get_side_border_padding = get_side_border_padding;
-
}).call(this);