Updating chosen lib

skala
Julio Montoya 11 years ago
parent e1200f6532
commit 0b3991f2bc
  1. BIN
      main/inc/lib/javascript/chosen/chosen-sprite@2x.png
  2. 252
      main/inc/lib/javascript/chosen/chosen.css
  3. 395
      main/inc/lib/javascript/chosen/chosen.jquery.js
  4. 4
      main/inc/lib/javascript/chosen/chosen.jquery.min.js

Binary file not shown.

After

Width:  |  Height:  |  Size: 872 B

@ -1,13 +1,16 @@
/* @group Base */
.chzn-container {
.chosen-container {
position: relative;
display: inline-block;
vertical-align: middle;
font-size: 13px;
zoom: 1;
*display: inline;
-webkit-user-select: none;
-moz-user-select: none;
user-select: none;
}
.chzn-container .chzn-drop {
.chosen-container .chosen-drop {
position: absolute;
top: 100%;
left: -9999px;
@ -21,13 +24,16 @@
background: #fff;
box-shadow: 0 4px 5px rgba(0, 0, 0, 0.15);
}
.chzn-container.chzn-with-drop .chzn-drop {
.chosen-container.chosen-with-drop .chosen-drop {
left: 0;
}
.chosen-container a {
cursor: pointer;
}
/* @end */
/* @group Single Chosen */
.chzn-container-single .chzn-single {
.chosen-container-single .chosen-single {
position: relative;
display: block;
overflow: hidden;
@ -48,20 +54,20 @@
white-space: nowrap;
line-height: 24px;
}
.chzn-container-single .chzn-default {
.chosen-container-single .chosen-default {
color: #999;
}
.chzn-container-single .chzn-single span {
.chosen-container-single .chosen-single span {
display: block;
overflow: hidden;
margin-right: 26px;
text-overflow: ellipsis;
white-space: nowrap;
}
.chzn-container-single .chzn-single-with-deselect span {
.chosen-container-single .chosen-single-with-deselect span {
margin-right: 38px;
}
.chzn-container-single .chzn-single abbr {
.chosen-container-single .chosen-single abbr {
position: absolute;
top: 6px;
right: 26px;
@ -71,13 +77,13 @@
background: url('chosen-sprite.png') -42px 1px no-repeat;
font-size: 1px;
}
.chzn-container-single .chzn-single abbr:hover {
.chosen-container-single .chosen-single abbr:hover {
background-position: -42px -10px;
}
.chzn-container-single.chzn-disabled .chzn-single abbr:hover {
.chosen-container-single.chosen-disabled .chosen-single abbr:hover {
background-position: -42px -10px;
}
.chzn-container-single .chzn-single div {
.chosen-container-single .chosen-single div {
position: absolute;
top: 0;
right: 0;
@ -85,26 +91,27 @@
width: 18px;
height: 100%;
}
.chzn-container-single .chzn-single div b {
.chosen-container-single .chosen-single div b {
display: block;
width: 100%;
height: 100%;
background: url('chosen-sprite.png') no-repeat 0px 2px;
}
.chzn-container-single .chzn-search {
.chosen-container-single .chosen-search {
position: relative;
z-index: 1010;
margin: 0;
padding: 3px 4px;
white-space: nowrap;
}
.chzn-container-single .chzn-search input {
.chosen-container-single .chosen-search input[type="text"] {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
margin: 1px 0;
padding: 4px 20px 4px 5px;
width: 100%;
height: auto;
outline: 0;
border: 1px solid #aaa;
background: white url('chosen-sprite.png') no-repeat 100% -20px;
@ -115,20 +122,75 @@
background: url('chosen-sprite.png') no-repeat 100% -20px, linear-gradient(#eeeeee 1%, #ffffff 15%);
font-size: 1em;
font-family: sans-serif;
line-height: normal;
border-radius: 0;
}
.chzn-container-single .chzn-drop {
.chosen-container-single .chosen-drop {
margin-top: -1px;
border-radius: 0 0 4px 4px;
background-clip: padding-box;
}
.chzn-container-single.chzn-container-single-nosearch .chzn-search {
.chosen-container-single.chosen-container-single-nosearch .chosen-search {
position: absolute;
left: -9999px;
}
/* @end */
/* @group Results */
.chosen-container .chosen-results {
position: relative;
overflow-x: hidden;
overflow-y: auto;
margin: 0 4px 4px 0;
padding: 0 0 0 4px;
max-height: 240px;
-webkit-overflow-scrolling: touch;
}
.chosen-container .chosen-results li {
display: none;
margin: 0;
padding: 5px 6px;
list-style: none;
line-height: 15px;
}
.chosen-container .chosen-results li.active-result {
display: list-item;
cursor: pointer;
}
.chosen-container .chosen-results li.disabled-result {
display: list-item;
color: #ccc;
cursor: default;
}
.chosen-container .chosen-results li.highlighted {
background-color: #3875d7;
background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(20%, #3875d7), color-stop(90%, #2a62bc));
background-image: -webkit-linear-gradient(#3875d7 20%, #2a62bc 90%);
background-image: -moz-linear-gradient(#3875d7 20%, #2a62bc 90%);
background-image: -o-linear-gradient(#3875d7 20%, #2a62bc 90%);
background-image: linear-gradient(#3875d7 20%, #2a62bc 90%);
color: #fff;
}
.chosen-container .chosen-results li.no-results {
display: list-item;
background: #f4f4f4;
}
.chosen-container .chosen-results li.group-result {
display: list-item;
font-weight: bold;
cursor: default;
}
.chosen-container .chosen-results li.group-option {
padding-left: 15px;
}
.chosen-container .chosen-results li em {
font-style: normal;
text-decoration: underline;
}
/* @end */
/* @group Multi Chosen */
.chzn-container-multi .chzn-choices {
.chosen-container-multi .chosen-choices {
position: relative;
overflow: hidden;
-webkit-box-sizing: border-box;
@ -148,16 +210,16 @@
background-image: linear-gradient(#eeeeee 1%, #ffffff 15%);
cursor: text;
}
.chzn-container-multi .chzn-choices li {
.chosen-container-multi .chosen-choices li {
float: left;
list-style: none;
}
.chzn-container-multi .chzn-choices li.search-field {
.chosen-container-multi .chosen-choices li.search-field {
margin: 0;
padding: 0;
white-space: nowrap;
}
.chzn-container-multi .chzn-choices li.search-field input {
.chosen-container-multi .chosen-choices li.search-field input[type="text"] {
margin: 1px 0;
padding: 5px;
height: 15px;
@ -168,11 +230,13 @@
color: #666;
font-size: 100%;
font-family: sans-serif;
line-height: normal;
border-radius: 0;
}
.chzn-container-multi .chzn-choices li.search-field .default {
.chosen-container-multi .chosen-choices li.search-field .default {
color: #999;
}
.chzn-container-multi .chzn-choices li.search-choice {
.chosen-container-multi .chosen-choices li.search-choice {
position: relative;
margin: 3px 0 3px 5px;
padding: 3px 20px 3px 5px;
@ -190,7 +254,7 @@
line-height: 13px;
cursor: default;
}
.chzn-container-multi .chzn-choices li.search-choice .search-choice-close {
.chosen-container-multi .chosen-choices li.search-choice .search-choice-close {
position: absolute;
top: 4px;
right: 3px;
@ -200,10 +264,10 @@
background: url('chosen-sprite.png') -42px 1px no-repeat;
font-size: 1px;
}
.chzn-container-multi .chzn-choices li.search-choice .search-choice-close:hover {
.chosen-container-multi .chosen-choices li.search-choice .search-choice-close:hover {
background-position: -42px -10px;
}
.chzn-container-multi .chzn-choices li.search-choice-disabled {
.chosen-container-multi .chosen-choices li.search-choice-disabled {
padding-right: 5px;
border: 1px solid #ccc;
background-color: #e4e4e4;
@ -214,91 +278,29 @@
background-image: linear-gradient(top, #f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%);
color: #666;
}
.chzn-container-multi .chzn-choices li.search-choice-focus {
.chosen-container-multi .chosen-choices li.search-choice-focus {
background: #d4d4d4;
}
.chzn-container-multi .chzn-choices li.search-choice-focus .search-choice-close {
.chosen-container-multi .chosen-choices li.search-choice-focus .search-choice-close {
background-position: -42px -10px;
}
.chzn-container-multi .chzn-results {
.chosen-container-multi .chosen-results {
margin: 0;
padding: 0;
}
.chzn-container-multi .chzn-drop .result-selected {
display: list-item;
color: #ccc;
cursor: default;
}
.chzn-container-multi .chzn-drop .result-selected em {
background: transparent;
}
/* @end */
/* @group Results */
.chzn-container .chzn-results {
position: relative;
overflow-x: hidden;
overflow-y: auto;
margin: 0 4px 4px 0;
padding: 0 0 0 4px;
max-height: 240px;
-webkit-overflow-scrolling: touch;
}
.chzn-container .chzn-results li {
display: none;
margin: 0;
padding: 5px 6px;
list-style: none;
line-height: 15px;
}
.chzn-container .chzn-results li.active-result {
display: list-item;
cursor: pointer;
}
.chzn-container .chzn-results li.disabled-result {
.chosen-container-multi .chosen-drop .result-selected {
display: list-item;
color: #ccc;
cursor: default;
}
.chzn-container .chzn-results li.disabled-result em {
background: transparent;
}
.chzn-container .chzn-results li.highlighted {
background-color: #3875d7;
background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(20%, #3875d7), color-stop(90%, #2a62bc));
background-image: -webkit-linear-gradient(#3875d7 20%, #2a62bc 90%);
background-image: -moz-linear-gradient(#3875d7 20%, #2a62bc 90%);
background-image: -o-linear-gradient(#3875d7 20%, #2a62bc 90%);
background-image: linear-gradient(#3875d7 20%, #2a62bc 90%);
color: #fff;
}
.chzn-container .chzn-results li.highlighted em {
background: transparent;
}
.chzn-container .chzn-results li.no-results {
display: list-item;
background: #f4f4f4;
}
.chzn-container .chzn-results li.group-result {
color: #999;
font-weight: bold;
cursor: default;
}
.chzn-container .chzn-results li.group-option {
padding-left: 15px;
}
.chzn-container .chzn-results li em {
background: #feffde;
font-style: normal;
}
/* @end */
/* @group Active */
.chzn-container-active .chzn-single {
.chosen-container-active .chosen-single {
border: 1px solid #5897fb;
box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
}
.chzn-container-active.chzn-with-drop .chzn-single {
.chosen-container-active.chosen-with-drop .chosen-single {
border: 1px solid #aaa;
-moz-border-radius-bottomright: 0;
border-bottom-right-radius: 0;
@ -311,89 +313,89 @@
background-image: linear-gradient(#eeeeee 20%, #ffffff 80%);
box-shadow: 0 1px 0 #fff inset;
}
.chzn-container-active.chzn-with-drop .chzn-single div {
.chosen-container-active.chosen-with-drop .chosen-single div {
border-left: none;
background: transparent;
}
.chzn-container-active.chzn-with-drop .chzn-single div b {
.chosen-container-active.chosen-with-drop .chosen-single div b {
background-position: -18px 2px;
}
.chzn-container-active .chzn-choices {
.chosen-container-active .chosen-choices {
border: 1px solid #5897fb;
box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
}
.chzn-container-active .chzn-choices li.search-field input {
.chosen-container-active .chosen-choices li.search-field input[type="text"] {
color: #111 !important;
}
/* @end */
/* @group Disabled Support */
.chzn-disabled {
.chosen-disabled {
opacity: 0.5 !important;
cursor: default;
}
.chzn-disabled .chzn-single {
.chosen-disabled .chosen-single {
cursor: default;
}
.chzn-disabled .chzn-choices .search-choice .search-choice-close {
.chosen-disabled .chosen-choices .search-choice .search-choice-close {
cursor: default;
}
/* @end */
/* @group Right to Left */
.chzn-rtl {
.chosen-rtl {
text-align: right;
}
.chzn-rtl .chzn-single {
.chosen-rtl .chosen-single {
overflow: visible;
padding: 0 8px 0 0;
}
.chzn-rtl .chzn-single span {
.chosen-rtl .chosen-single span {
margin-right: 0;
margin-left: 26px;
direction: rtl;
}
.chzn-rtl .chzn-single-with-deselect span {
.chosen-rtl .chosen-single-with-deselect span {
margin-left: 38px;
}
.chzn-rtl .chzn-single div {
.chosen-rtl .chosen-single div {
right: auto;
left: 3px;
}
.chzn-rtl .chzn-single abbr {
.chosen-rtl .chosen-single abbr {
right: auto;
left: 26px;
}
.chzn-rtl .chzn-choices li {
.chosen-rtl .chosen-choices li {
float: right;
}
.chzn-rtl .chzn-choices li.search-field input {
.chosen-rtl .chosen-choices li.search-field input[type="text"] {
direction: rtl;
}
.chzn-rtl .chzn-choices li.search-choice {
.chosen-rtl .chosen-choices li.search-choice {
margin: 3px 5px 3px 0;
padding: 3px 5px 3px 19px;
}
.chzn-rtl .chzn-choices li.search-choice .search-choice-close {
.chosen-rtl .chosen-choices li.search-choice .search-choice-close {
right: auto;
left: 4px;
}
.chzn-rtl.chzn-container-single-nosearch .chzn-search,
.chzn-rtl .chzn-drop {
.chosen-rtl.chosen-container-single-nosearch .chosen-search,
.chosen-rtl .chosen-drop {
left: 9999px;
}
.chzn-rtl.chzn-container-single .chzn-results {
.chosen-rtl.chosen-container-single .chosen-results {
margin: 0 0 4px 4px;
padding: 0 4px 0 0;
}
.chzn-rtl .chzn-results li.group-option {
.chosen-rtl .chosen-results li.group-option {
padding-right: 15px;
padding-left: 0;
}
.chzn-rtl.chzn-container-active.chzn-with-drop .chzn-single div {
.chosen-rtl.chosen-container-active.chosen-with-drop .chosen-single div {
border-right: none;
}
.chzn-rtl .chzn-search input {
.chosen-rtl .chosen-search input[type="text"] {
padding: 4px 5px 4px 20px;
background: white url('chosen-sprite.png') no-repeat -30px -20px;
background: url('chosen-sprite.png') no-repeat -30px -20px, -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(1%, #eeeeee), color-stop(15%, #ffffff));
@ -403,23 +405,23 @@
background: url('chosen-sprite.png') no-repeat -30px -20px, linear-gradient(#eeeeee 1%, #ffffff 15%);
direction: rtl;
}
.chzn-rtl.chzn-container-single .chzn-single div b {
.chosen-rtl.chosen-container-single .chosen-single div b {
background-position: 6px 2px;
}
.chzn-rtl.chzn-container-single.chzn-with-drop .chzn-single div b {
.chosen-rtl.chosen-container-single.chosen-with-drop .chosen-single div b {
background-position: -12px 2px;
}
/* @end */
/* @group Retina compatibility */
@media only screen and (-webkit-min-device-pixel-ratio: 2), only screen and (min-resolution: 144dpi) {
.chzn-rtl .chzn-search input,
.chzn-container-single .chzn-single abbr,
.chzn-container-single .chzn-single div b,
.chzn-container-single .chzn-search input,
.chzn-container-multi .chzn-choices .search-choice .search-choice-close,
.chzn-container .chzn-results-scroll-down span,
.chzn-container .chzn-results-scroll-up span {
.chosen-rtl .chosen-search input[type="text"],
.chosen-container-single .chosen-single abbr,
.chosen-container-single .chosen-single div b,
.chosen-container-single .chosen-search input[type="text"],
.chosen-container-multi .chosen-choices .search-choice .search-choice-close,
.chosen-container .chosen-results-scroll-down span,
.chosen-container .chosen-results-scroll-up span {
background-image: url('chosen-sprite@2x.png') !important;
background-size: 52px 37px !important;
background-repeat: no-repeat !important;

@ -1,14 +1,16 @@
// Chosen, a Select Box Enhancer for jQuery and Prototype
// by Patrick Filler for Harvest, http://getharvest.com
//
// Version 0.12.1
// Version 1.0.0
// Full source at https://github.com/harvesthq/chosen
// Copyright (c) 2011 Harvest http://getharvest.com
// MIT License, https://github.com/harvesthq/chosen/blob/master/LICENSE.md
// This file is generated by `grunt build`, do not edit it by hand.
(function() {
var SelectParser;
var $, AbstractChosen, Chosen, SelectParser, _ref,
__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; };
SelectParser = (function() {
function SelectParser() {
@ -31,7 +33,7 @@
this.parsed.push({
array_index: group_position,
group: true,
label: group.label,
label: this.escapeExpression(group.label),
children: 0,
disabled: group.disabled
});
@ -73,6 +75,28 @@
}
};
SelectParser.prototype.escapeExpression = function(text) {
var map, unsafe_chars;
if ((text == null) || text === false) {
return "";
}
if (!/[\&\<\>\"\'\`]/.test(text)) {
return text;
}
map = {
"<": "&lt;",
">": "&gt;",
'"': "&quot;",
"'": "&#x27;",
"`": "&#x60;"
};
unsafe_chars = /&(?!\w+;)|[\<\>\"\'\`]/g;
return text.replace(unsafe_chars, function(chr) {
return map[chr] || "&amp;";
});
};
return SelectParser;
})();
@ -89,15 +113,6 @@
return parser.parsed;
};
this.SelectParser = SelectParser;
}).call(this);
(function() {
var AbstractChosen, root;
root = this;
AbstractChosen = (function() {
function AbstractChosen(form_field, options) {
this.form_field = form_field;
@ -111,7 +126,6 @@
this.setup();
this.set_up_html();
this.register_observers();
this.finish_setup();
}
AbstractChosen.prototype.set_default_values = function() {
@ -132,10 +146,13 @@
this.disable_search_threshold = this.options.disable_search_threshold || 0;
this.disable_search = this.options.disable_search || false;
this.enable_split_word_search = this.options.enable_split_word_search != null ? this.options.enable_split_word_search : true;
this.group_search = this.options.group_search != null ? this.options.group_search : true;
this.search_contains = this.options.search_contains || false;
this.single_backstroke_delete = this.options.single_backstroke_delete || false;
this.single_backstroke_delete = this.options.single_backstroke_delete != null ? this.options.single_backstroke_delete : true;
this.max_selected_options = this.options.max_selected_options || Infinity;
return this.inherit_select_classes = this.options.inherit_select_classes || false;
this.inherit_select_classes = this.options.inherit_select_classes || false;
this.display_selected_options = this.options.display_selected_options != null ? this.options.display_selected_options : true;
return this.display_disabled_options = this.options.display_disabled_options != null ? this.options.display_disabled_options : true;
};
AbstractChosen.prototype.set_default_text = function() {
@ -191,9 +208,9 @@
_ref = this.results_data;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
data = _ref[_i];
if (data.group && data.search_match) {
if (data.group) {
content += this.result_add_group(data);
} else if (!data.empty && data.search_match) {
} else {
content += this.result_add_option(data);
}
if (options != null ? options.first : void 0) {
@ -210,7 +227,12 @@
AbstractChosen.prototype.result_add_option = function(option) {
var classes, style;
option.dom_id = this.container_id + "_o_" + option.array_index;
if (!option.search_match) {
return '';
}
if (!this.include_option_in_results(option)) {
return '';
}
classes = [];
if (!option.disabled && !(option.selected && this.is_multiple)) {
classes.push("active-result");
@ -228,7 +250,17 @@
classes.push(option.classes);
}
style = option.style.cssText !== "" ? " style=\"" + option.style + "\"" : "";
return "<li id=\"" + option.dom_id + "\" class=\"" + (classes.join(' ')) + "\"" + style + ">" + option.search_text + "</li>";
return "<li class=\"" + (classes.join(' ')) + "\"" + style + " data-option-array-index=\"" + option.array_index + "\">" + option.search_text + "</li>";
};
AbstractChosen.prototype.result_add_group = function(group) {
if (!(group.search_match || group.group_match)) {
return '';
}
if (!(group.active_options > 0)) {
return '';
}
return "<li class=\"group-result\">" + group.search_text + "</li>";
};
AbstractChosen.prototype.results_update_field = function() {
@ -238,7 +270,10 @@
}
this.result_clear_highlight();
this.result_single_selected = null;
return this.results_build();
this.results_build();
if (this.results_showing) {
return this.winnow_results();
}
};
AbstractChosen.prototype.results_toggle = function() {
@ -258,53 +293,54 @@
};
AbstractChosen.prototype.winnow_results = function() {
var option, part, parts, regex, regexAnchor, results, searchText, startpos, text, zregex, _i, _j, _len, _len1, _ref;
var escapedSearchText, option, regex, regexAnchor, results, results_group, searchText, startpos, text, zregex, _i, _len, _ref;
this.no_results_clear();
results = 0;
searchText = this.get_search_text();
escapedSearchText = searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
regexAnchor = this.search_contains ? "" : "^";
regex = new RegExp(regexAnchor + searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i');
zregex = new RegExp(searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i');
regex = new RegExp(regexAnchor + escapedSearchText, 'i');
zregex = new RegExp(escapedSearchText, 'i');
_ref = this.results_data;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
option = _ref[_i];
if (!option.empty) {
option.search_match = false;
results_group = null;
if (this.include_option_in_results(option)) {
if (option.group) {
option.search_match = false;
} else {
option.search_match = false;
if (regex.test(option.html)) {
option.search_match = true;
option.group_match = false;
option.active_options = 0;
}
if ((option.group_array_index != null) && this.results_data[option.group_array_index]) {
results_group = this.results_data[option.group_array_index];
if (results_group.active_options === 0 && results_group.search_match) {
results += 1;
}
results_group.active_options += 1;
}
if (!(option.group && !this.group_search)) {
option.search_text = option.group ? option.label : option.html;
option.search_match = this.search_string_match(option.search_text, regex);
if (option.search_match && !option.group) {
results += 1;
} else if (this.enable_split_word_search && (option.html.indexOf(" ") >= 0 || option.html.indexOf("[") === 0)) {
parts = option.html.replace(/\[|\]/g, "").split(" ");
if (parts.length) {
for (_j = 0, _len1 = parts.length; _j < _len1; _j++) {
part = parts[_j];
if (regex.test(part)) {
option.search_match = true;
results += 1;
}
}
}
}
if (option.search_match) {
if (searchText.length) {
startpos = option.html.search(zregex);
text = option.html.substr(0, startpos + searchText.length) + '</em>' + option.html.substr(startpos + searchText.length);
text = text.substr(0, startpos) + '<em>' + text.substr(startpos);
} else {
text = option.html;
startpos = option.search_text.search(zregex);
text = option.search_text.substr(0, startpos + searchText.length) + '</em>' + option.search_text.substr(startpos + searchText.length);
option.search_text = text.substr(0, startpos) + '<em>' + text.substr(startpos);
}
option.search_text = text;
if (option.group_array_index != null) {
this.results_data[option.group_array_index].search_match = true;
if (results_group != null) {
results_group.group_match = true;
}
} else if ((option.group_array_index != null) && this.results_data[option.group_array_index].search_match) {
option.search_match = true;
}
}
}
}
this.result_clear_highlight();
if (results < 1 && searchText.length) {
this.update_results_content("");
return this.no_results(searchText);
@ -314,6 +350,24 @@
}
};
AbstractChosen.prototype.search_string_match = function(search_string, regex) {
var part, parts, _i, _len;
if (regex.test(search_string)) {
return true;
} else if (this.enable_split_word_search && (search_string.indexOf(" ") >= 0 || search_string.indexOf("[") === 0)) {
parts = search_string.replace(/\[|\]/g, "").split(" ");
if (parts.length) {
for (_i = 0, _len = parts.length; _i < _len; _i++) {
part = parts[_i];
if (regex.test(part)) {
return true;
}
}
}
}
};
AbstractChosen.prototype.choices_count = function() {
var option, _i, _len, _ref;
@ -375,22 +429,6 @@
}
};
AbstractChosen.prototype.generate_field_id = function() {
var new_id;
new_id = this.generate_random_id();
this.form_field.id = new_id;
return new_id;
};
AbstractChosen.prototype.generate_random_char = function() {
var chars, newchar, rand;
chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
rand = Math.floor(Math.random() * chars.length);
return newchar = chars.substring(rand, rand + 1);
};
AbstractChosen.prototype.container_width = function() {
if (this.options.width != null) {
return this.options.width;
@ -399,11 +437,30 @@
}
};
AbstractChosen.browser_is_supported = function() {
var _ref;
AbstractChosen.prototype.include_option_in_results = function(option) {
if (this.is_multiple && (!this.display_selected_options && option.selected)) {
return false;
}
if (!this.display_disabled_options && option.disabled) {
return false;
}
if (option.empty) {
return false;
}
return true;
};
AbstractChosen.browser_is_supported = function() {
if (window.navigator.appName === "Microsoft Internet Explorer") {
return (null !== (_ref = document.documentMode) && _ref >= 8);
return document.documentMode >= 8;
}
if (/iP(od|hone)/i.test(window.navigator.userAgent)) {
return false;
}
if (/Android/i.test(window.navigator.userAgent)) {
if (/Mobile/i.test(window.navigator.userAgent)) {
return false;
}
}
return true;
};
@ -418,17 +475,6 @@
})();
root.AbstractChosen = AbstractChosen;
}).call(this);
(function() {
var $, Chosen, root, _ref,
__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; };
root = this;
$ = jQuery;
$.fn.extend({
@ -437,11 +483,14 @@
return this;
}
return this.each(function(input_field) {
var $this;
var $this, chosen;
$this = $(this);
if (!$this.hasClass("chzn-done")) {
return $this.data('chosen', new Chosen(this, options));
chosen = $this.data('chosen');
if (options === 'destroy' && chosen) {
chosen.destroy();
} else if (!chosen) {
$this.data('chosen', new Chosen(this, options));
}
});
}
@ -458,55 +507,51 @@
Chosen.prototype.setup = function() {
this.form_field_jq = $(this.form_field);
this.current_selectedIndex = this.form_field.selectedIndex;
return this.is_rtl = this.form_field_jq.hasClass("chzn-rtl");
};
Chosen.prototype.finish_setup = function() {
return this.form_field_jq.addClass("chzn-done");
return this.is_rtl = this.form_field_jq.hasClass("chosen-rtl");
};
Chosen.prototype.set_up_html = function() {
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"];
container_classes.push("chzn-container-" + (this.is_multiple ? "multi" : "single"));
container_classes = ["chosen-container"];
container_classes.push("chosen-container-" + (this.is_multiple ? "multi" : "single"));
if (this.inherit_select_classes && this.form_field.className) {
container_classes.push(this.form_field.className);
}
if (this.is_rtl) {
container_classes.push("chzn-rtl");
container_classes.push("chosen-rtl");
}
container_props = {
'id': this.container_id,
'class': container_classes.join(' '),
'style': "width: " + (this.container_width()) + ";",
'title': this.form_field.title
};
if (this.form_field.id.length) {
container_props.id = this.form_field.id.replace(/[^\w]/g, '_') + "_chosen";
}
this.container = $("<div />", container_props);
if (this.is_multiple) {
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>');
this.container.html('<ul class="chosen-choices"><li class="search-field"><input type="text" value="' + this.default_text + '" class="default" autocomplete="off" style="width:25px;" /></li></ul><div class="chosen-drop"><ul class="chosen-results"></ul></div>');
} else {
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.container.html('<a class="chosen-single chosen-default" tabindex="-1"><span>' + this.default_text + '</span><div><b></b></div></a><div class="chosen-drop"><div class="chosen-search"><input type="text" autocomplete="off" /></div><ul class="chosen-results"></ul></div>');
}
this.form_field_jq.hide().after(this.container);
this.dropdown = this.container.find('div.chzn-drop').first();
this.dropdown = this.container.find('div.chosen-drop').first();
this.search_field = this.container.find('input').first();
this.search_results = this.container.find('ul.chzn-results').first();
this.search_results = this.container.find('ul.chosen-results').first();
this.search_field_scale();
this.search_no_results = this.container.find('li.no-results').first();
if (this.is_multiple) {
this.search_choices = this.container.find('ul.chzn-choices').first();
this.search_choices = this.container.find('ul.chosen-choices').first();
this.search_container = this.container.find('li.search-field').first();
} else {
this.search_container = this.container.find('div.chzn-search').first();
this.selected_item = this.container.find('.chzn-single').first();
this.search_container = this.container.find('div.chosen-search').first();
this.selected_item = this.container.find('.chosen-single').first();
}
this.results_build();
this.set_tab_index();
this.set_label_behavior();
return this.form_field_jq.trigger("liszt:ready", {
return this.form_field_jq.trigger("chosen:ready", {
chosen: this
});
};
@ -514,76 +559,86 @@
Chosen.prototype.register_observers = function() {
var _this = this;
this.container.mousedown(function(evt) {
this.container.bind('mousedown.chosen', function(evt) {
_this.container_mousedown(evt);
});
this.container.mouseup(function(evt) {
this.container.bind('mouseup.chosen', function(evt) {
_this.container_mouseup(evt);
});
this.container.mouseenter(function(evt) {
this.container.bind('mouseenter.chosen', function(evt) {
_this.mouse_enter(evt);
});
this.container.mouseleave(function(evt) {
this.container.bind('mouseleave.chosen', function(evt) {
_this.mouse_leave(evt);
});
this.search_results.mouseup(function(evt) {
this.search_results.bind('mouseup.chosen', function(evt) {
_this.search_results_mouseup(evt);
});
this.search_results.mouseover(function(evt) {
this.search_results.bind('mouseover.chosen', function(evt) {
_this.search_results_mouseover(evt);
});
this.search_results.mouseout(function(evt) {
this.search_results.bind('mouseout.chosen', function(evt) {
_this.search_results_mouseout(evt);
});
this.search_results.bind('mousewheel DOMMouseScroll', function(evt) {
this.search_results.bind('mousewheel.chosen DOMMouseScroll.chosen', function(evt) {
_this.search_results_mousewheel(evt);
});
this.form_field_jq.bind("liszt:updated", function(evt) {
this.form_field_jq.bind("chosen:updated.chosen", function(evt) {
_this.results_update_field(evt);
});
this.form_field_jq.bind("liszt:activate", function(evt) {
this.form_field_jq.bind("chosen:activate.chosen", function(evt) {
_this.activate_field(evt);
});
this.form_field_jq.bind("liszt:open", function(evt) {
this.form_field_jq.bind("chosen:open.chosen", function(evt) {
_this.container_mousedown(evt);
});
this.search_field.blur(function(evt) {
this.search_field.bind('blur.chosen', function(evt) {
_this.input_blur(evt);
});
this.search_field.keyup(function(evt) {
this.search_field.bind('keyup.chosen', function(evt) {
_this.keyup_checker(evt);
});
this.search_field.keydown(function(evt) {
this.search_field.bind('keydown.chosen', function(evt) {
_this.keydown_checker(evt);
});
this.search_field.focus(function(evt) {
this.search_field.bind('focus.chosen', function(evt) {
_this.input_focus(evt);
});
if (this.is_multiple) {
return this.search_choices.click(function(evt) {
return this.search_choices.bind('click.chosen', function(evt) {
_this.choices_click(evt);
});
} else {
return this.container.click(function(evt) {
return this.container.bind('click.chosen', function(evt) {
evt.preventDefault();
});
}
};
Chosen.prototype.destroy = function() {
$(document).unbind("click.chosen", this.click_test_action);
if (this.search_field[0].tabIndex) {
this.form_field_jq[0].tabIndex = this.search_field[0].tabIndex;
}
this.container.remove();
this.form_field_jq.removeData('chosen');
return this.form_field_jq.show();
};
Chosen.prototype.search_field_disabled = function() {
this.is_disabled = this.form_field_jq[0].disabled;
if (this.is_disabled) {
this.container.addClass('chzn-disabled');
this.container.addClass('chosen-disabled');
this.search_field[0].disabled = true;
if (!this.is_multiple) {
this.selected_item.unbind("focus", this.activate_action);
this.selected_item.unbind("focus.chosen", this.activate_action);
}
return this.close_field();
} else {
this.container.removeClass('chzn-disabled');
this.container.removeClass('chosen-disabled');
this.search_field[0].disabled = false;
if (!this.is_multiple) {
return this.selected_item.bind("focus", this.activate_action);
return this.selected_item.bind("focus.chosen", this.activate_action);
}
}
};
@ -598,9 +653,9 @@
if (this.is_multiple) {
this.search_field.val("");
}
$(document).click(this.click_test_action);
$(document).bind('click.chosen', this.click_test_action);
this.results_show();
} else if (!this.is_multiple && evt && (($(evt.target)[0] === this.selected_item[0]) || $(evt.target).parents("a.chzn-single").length)) {
} else if (!this.is_multiple && evt && (($(evt.target)[0] === this.selected_item[0]) || $(evt.target).parents("a.chosen-single").length)) {
evt.preventDefault();
this.results_toggle();
}
@ -629,30 +684,30 @@
};
Chosen.prototype.blur_test = function(evt) {
if (!this.active_field && this.container.hasClass("chzn-container-active")) {
if (!this.active_field && this.container.hasClass("chosen-container-active")) {
return this.close_field();
}
};
Chosen.prototype.close_field = function() {
$(document).unbind("click", this.click_test_action);
$(document).unbind("click.chosen", this.click_test_action);
this.active_field = false;
this.results_hide();
this.container.removeClass("chzn-container-active");
this.container.removeClass("chosen-container-active");
this.clear_backstroke();
this.show_search_field_default();
return this.search_field_scale();
};
Chosen.prototype.activate_field = function() {
this.container.addClass("chzn-container-active");
this.container.addClass("chosen-container-active");
this.active_field = true;
this.search_field.val(this.search_field.val());
return this.search_field.focus();
};
Chosen.prototype.test_active_click = function(evt) {
if ($(evt.target).parents('#' + this.container_id).length) {
if (this.container.is($(evt.target).closest('.chosen-container'))) {
return this.active_field = true;
} else {
return this.close_field();
@ -662,17 +717,17 @@
Chosen.prototype.results_build = function() {
this.parsing = true;
this.selected_option_count = null;
this.results_data = root.SelectParser.select_to_array(this.form_field);
this.results_data = SelectParser.select_to_array(this.form_field);
if (this.is_multiple) {
this.search_choices.find("li.search-choice").remove();
} else if (!this.is_multiple) {
this.single_set_selected_text();
if (this.disable_search || this.form_field.options.length <= this.disable_search_threshold) {
this.search_field[0].readOnly = true;
this.container.addClass("chzn-container-single-nosearch");
this.container.addClass("chosen-container-single-nosearch");
} else {
this.search_field[0].readOnly = false;
this.container.removeClass("chzn-container-single-nosearch");
this.container.removeClass("chosen-container-single-nosearch");
}
}
this.update_results_content(this.results_option_build({
@ -684,11 +739,6 @@
return this.parsing = false;
};
Chosen.prototype.result_add_group = function(group) {
group.dom_id = this.container_id + "_g_" + group.array_index;
return '<li id="' + group.dom_id + '" class="group-result">' + $("<div />").text(group.label).html() + '</li>';
};
Chosen.prototype.result_do_highlight = function(el) {
var high_bottom, high_top, maxHeight, visible_bottom, visible_top;
@ -718,13 +768,13 @@
Chosen.prototype.results_show = function() {
if (this.is_multiple && this.max_selected_options <= this.choices_count()) {
this.form_field_jq.trigger("liszt:maxselected", {
this.form_field_jq.trigger("chosen:maxselected", {
chosen: this
});
return false;
}
this.container.addClass("chzn-with-drop");
this.form_field_jq.trigger("liszt:showing_dropdown", {
this.container.addClass("chosen-with-drop");
this.form_field_jq.trigger("chosen:showing_dropdown", {
chosen: this
});
this.results_showing = true;
@ -740,8 +790,8 @@
Chosen.prototype.results_hide = function() {
if (this.results_showing) {
this.result_clear_highlight();
this.container.removeClass("chzn-with-drop");
this.form_field_jq.trigger("liszt:hiding_dropdown", {
this.container.removeClass("chosen-with-drop");
this.form_field_jq.trigger("chosen:hiding_dropdown", {
chosen: this
});
}
@ -751,10 +801,10 @@
Chosen.prototype.set_tab_index = function(el) {
var ti;
if (this.form_field_jq.attr("tabindex")) {
ti = this.form_field_jq.attr("tabindex");
this.form_field_jq.attr("tabindex", -1);
return this.search_field.attr("tabindex", ti);
if (this.form_field.tabIndex) {
ti = this.form_field.tabIndex;
this.form_field.tabIndex = -1;
return this.search_field[0].tabIndex = ti;
}
};
@ -766,7 +816,7 @@
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) {
return this.form_field_label.bind('click.chosen', function(evt) {
if (_this.is_multiple) {
return _this.container_mousedown(evt);
} else {
@ -823,11 +873,10 @@
choice.addClass('search-choice-disabled');
} else {
close_link = $('<a />', {
href: '#',
"class": 'search-choice-close',
rel: item.array_index
'data-option-array-index': item.array_index
});
close_link.click(function(evt) {
close_link.bind('click.chosen', function(evt) {
return _this.choice_destroy_link_click(evt);
});
choice.append(close_link);
@ -844,7 +893,7 @@
};
Chosen.prototype.choice_destroy = function(link) {
if (this.result_deselect(link.attr("rel"))) {
if (this.result_deselect(link[0].getAttribute("data-option-array-index"))) {
this.show_search_field_default();
if (this.is_multiple && this.choices_count() > 0 && this.search_field.val().length < 1) {
this.results_hide();
@ -872,14 +921,13 @@
};
Chosen.prototype.result_select = function(evt) {
var high, high_id, item, position;
var high, item, selected_index;
if (this.result_highlight) {
high = this.result_highlight;
high_id = high.attr("id");
this.result_clear_highlight();
if (this.is_multiple && this.max_selected_options <= this.choices_count()) {
this.form_field_jq.trigger("liszt:maxselected", {
this.form_field_jq.trigger("chosen:maxselected", {
chosen: this
});
return false;
@ -887,12 +935,15 @@
if (this.is_multiple) {
high.removeClass("active-result");
} else {
this.search_results.find(".result-selected").removeClass("result-selected");
if (this.result_single_selected) {
this.result_single_selected.removeClass("result-selected");
selected_index = this.result_single_selected[0].getAttribute('data-option-array-index');
this.results_data[selected_index].selected = false;
}
this.result_single_selected = high;
}
high.addClass("result-selected");
position = high_id.substr(high_id.lastIndexOf("_") + 1);
item = this.results_data[position];
item = this.results_data[high[0].getAttribute("data-option-array-index")];
item.selected = true;
this.form_field.options[item.options_index].selected = true;
this.selected_option_count = null;
@ -920,24 +971,22 @@
text = this.default_text;
}
if (text === this.default_text) {
this.selected_item.addClass("chzn-default");
this.selected_item.addClass("chosen-default");
} else {
this.single_deselect_control_build();
this.selected_item.removeClass("chzn-default");
this.selected_item.removeClass("chosen-default");
}
return this.selected_item.find("span").text(text);
};
Chosen.prototype.result_deselect = function(pos) {
var result, result_data;
var result_data;
result_data = this.results_data[pos];
if (!this.form_field.options[result_data.options_index].disabled) {
result_data.selected = false;
this.form_field.options[result_data.options_index].selected = false;
this.selected_option_count = null;
result = $("#" + this.container_id + "_o_" + pos);
result.removeClass("result-selected").addClass("active-result").show();
this.result_clear_highlight();
if (this.results_showing) {
this.winnow_results();
@ -959,7 +1008,7 @@
if (!this.selected_item.find("abbr").length) {
this.selected_item.find("span").first().after("<abbr class=\"search-choice-close\"></abbr>");
}
return this.selected_item.addClass("chzn-single-with-deselect");
return this.selected_item.addClass("chosen-single-with-deselect");
};
Chosen.prototype.get_search_text = function() {
@ -1082,7 +1131,7 @@
};
Chosen.prototype.search_field_scale = function() {
var div, h, style, style_block, styles, w, _i, _len;
var div, f_width, h, style, style_block, styles, w, _i, _len;
if (this.is_multiple) {
h = 0;
@ -1100,11 +1149,9 @@
$('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;
f_width = this.container.outerWidth();
if (w > f_width - 10) {
w = f_width - 10;
}
return this.search_field.css({
'width': w + 'px'
@ -1112,20 +1159,8 @@
}
};
Chosen.prototype.generate_random_id = function() {
var string;
string = "sel" + this.generate_random_char() + this.generate_random_char() + this.generate_random_char();
while ($("#" + string).length > 0) {
string += this.generate_random_char();
}
return string;
};
return Chosen;
})(AbstractChosen);
root.Chosen = Chosen;
}).call(this);

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save