chosen.jquery.js 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359
  1. /*!
  2. Chosen, a Select Box Enhancer for jQuery and Prototype
  3. by Patrick Filler for Harvest, http://getharvest.com
  4. Version 1.8.7
  5. Full source at https://github.com/harvesthq/chosen
  6. Copyright (c) 2011-2018 Harvest http://getharvest.com
  7. MIT License, https://github.com/harvesthq/chosen/blob/master/LICENSE.md
  8. This file is generated by `grunt build`, do not edit it by hand.
  9. */
  10. (function() {
  11. var $, AbstractChosen, Chosen, SelectParser,
  12. bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
  13. extend = 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; },
  14. hasProp = {}.hasOwnProperty;
  15. SelectParser = (function() {
  16. function SelectParser() {
  17. this.options_index = 0;
  18. this.parsed = [];
  19. }
  20. SelectParser.prototype.add_node = function(child) {
  21. if (child.nodeName.toUpperCase() === "OPTGROUP") {
  22. return this.add_group(child);
  23. } else {
  24. return this.add_option(child);
  25. }
  26. };
  27. SelectParser.prototype.add_group = function(group) {
  28. var group_position, i, len, option, ref, results1;
  29. group_position = this.parsed.length;
  30. this.parsed.push({
  31. array_index: group_position,
  32. group: true,
  33. label: group.label,
  34. title: group.title ? group.title : void 0,
  35. children: 0,
  36. disabled: group.disabled,
  37. classes: group.className
  38. });
  39. ref = group.childNodes;
  40. results1 = [];
  41. for (i = 0, len = ref.length; i < len; i++) {
  42. option = ref[i];
  43. results1.push(this.add_option(option, group_position, group.disabled));
  44. }
  45. return results1;
  46. };
  47. SelectParser.prototype.add_option = function(option, group_position, group_disabled) {
  48. if (option.nodeName.toUpperCase() === "OPTION") {
  49. if (option.text !== "") {
  50. if (group_position != null) {
  51. this.parsed[group_position].children += 1;
  52. }
  53. this.parsed.push({
  54. array_index: this.parsed.length,
  55. options_index: this.options_index,
  56. value: option.value,
  57. text: option.text,
  58. html: option.innerHTML,
  59. title: option.title ? option.title : void 0,
  60. selected: option.selected,
  61. disabled: group_disabled === true ? group_disabled : option.disabled,
  62. group_array_index: group_position,
  63. group_label: group_position != null ? this.parsed[group_position].label : null,
  64. classes: option.className,
  65. style: option.style.cssText
  66. });
  67. } else {
  68. this.parsed.push({
  69. array_index: this.parsed.length,
  70. options_index: this.options_index,
  71. empty: true
  72. });
  73. }
  74. return this.options_index += 1;
  75. }
  76. };
  77. return SelectParser;
  78. })();
  79. SelectParser.select_to_array = function(select) {
  80. var child, i, len, parser, ref;
  81. parser = new SelectParser();
  82. ref = select.childNodes;
  83. for (i = 0, len = ref.length; i < len; i++) {
  84. child = ref[i];
  85. parser.add_node(child);
  86. }
  87. return parser.parsed;
  88. };
  89. AbstractChosen = (function() {
  90. function AbstractChosen(form_field, options1) {
  91. this.form_field = form_field;
  92. this.options = options1 != null ? options1 : {};
  93. this.label_click_handler = bind(this.label_click_handler, this);
  94. if (!AbstractChosen.browser_is_supported()) {
  95. return;
  96. }
  97. this.is_multiple = this.form_field.multiple;
  98. this.set_default_text();
  99. this.set_default_values();
  100. this.setup();
  101. this.set_up_html();
  102. this.register_observers();
  103. this.on_ready();
  104. }
  105. AbstractChosen.prototype.set_default_values = function() {
  106. this.click_test_action = (function(_this) {
  107. return function(evt) {
  108. return _this.test_active_click(evt);
  109. };
  110. })(this);
  111. this.activate_action = (function(_this) {
  112. return function(evt) {
  113. return _this.activate_field(evt);
  114. };
  115. })(this);
  116. this.active_field = false;
  117. this.mouse_on_container = false;
  118. this.results_showing = false;
  119. this.result_highlighted = null;
  120. this.is_rtl = this.options.rtl || /\bchosen-rtl\b/.test(this.form_field.className);
  121. this.allow_single_deselect = (this.options.allow_single_deselect != null) && (this.form_field.options[0] != null) && this.form_field.options[0].text === "" ? this.options.allow_single_deselect : false;
  122. this.disable_search_threshold = this.options.disable_search_threshold || 0;
  123. this.disable_search = this.options.disable_search || false;
  124. this.enable_split_word_search = this.options.enable_split_word_search != null ? this.options.enable_split_word_search : true;
  125. this.group_search = this.options.group_search != null ? this.options.group_search : true;
  126. this.search_contains = this.options.search_contains || false;
  127. this.single_backstroke_delete = this.options.single_backstroke_delete != null ? this.options.single_backstroke_delete : true;
  128. this.max_selected_options = this.options.max_selected_options || Infinity;
  129. this.inherit_select_classes = this.options.inherit_select_classes || false;
  130. this.display_selected_options = this.options.display_selected_options != null ? this.options.display_selected_options : true;
  131. this.display_disabled_options = this.options.display_disabled_options != null ? this.options.display_disabled_options : true;
  132. this.include_group_label_in_selected = this.options.include_group_label_in_selected || false;
  133. this.max_shown_results = this.options.max_shown_results || Number.POSITIVE_INFINITY;
  134. this.case_sensitive_search = this.options.case_sensitive_search || false;
  135. return this.hide_results_on_select = this.options.hide_results_on_select != null ? this.options.hide_results_on_select : true;
  136. };
  137. AbstractChosen.prototype.set_default_text = function() {
  138. if (this.form_field.getAttribute("data-placeholder")) {
  139. this.default_text = this.form_field.getAttribute("data-placeholder");
  140. } else if (this.is_multiple) {
  141. this.default_text = this.options.placeholder_text_multiple || this.options.placeholder_text || AbstractChosen.default_multiple_text;
  142. } else {
  143. this.default_text = this.options.placeholder_text_single || this.options.placeholder_text || AbstractChosen.default_single_text;
  144. }
  145. this.default_text = this.escape_html(this.default_text);
  146. return this.results_none_found = this.form_field.getAttribute("data-no_results_text") || this.options.no_results_text || AbstractChosen.default_no_result_text;
  147. };
  148. AbstractChosen.prototype.choice_label = function(item) {
  149. if (this.include_group_label_in_selected && (item.group_label != null)) {
  150. return "<b class='group-name'>" + (this.escape_html(item.group_label)) + "</b>" + item.html;
  151. } else {
  152. return item.html;
  153. }
  154. };
  155. AbstractChosen.prototype.mouse_enter = function() {
  156. return this.mouse_on_container = true;
  157. };
  158. AbstractChosen.prototype.mouse_leave = function() {
  159. return this.mouse_on_container = false;
  160. };
  161. AbstractChosen.prototype.input_focus = function(evt) {
  162. if (this.is_multiple) {
  163. if (!this.active_field) {
  164. return setTimeout(((function(_this) {
  165. return function() {
  166. return _this.container_mousedown();
  167. };
  168. })(this)), 50);
  169. }
  170. } else {
  171. if (!this.active_field) {
  172. return this.activate_field();
  173. }
  174. }
  175. };
  176. AbstractChosen.prototype.input_blur = function(evt) {
  177. if (!this.mouse_on_container) {
  178. this.active_field = false;
  179. return setTimeout(((function(_this) {
  180. return function() {
  181. return _this.blur_test();
  182. };
  183. })(this)), 100);
  184. }
  185. };
  186. AbstractChosen.prototype.label_click_handler = function(evt) {
  187. if (this.is_multiple) {
  188. return this.container_mousedown(evt);
  189. } else {
  190. return this.activate_field();
  191. }
  192. };
  193. AbstractChosen.prototype.results_option_build = function(options) {
  194. var content, data, data_content, i, len, ref, shown_results;
  195. content = '';
  196. shown_results = 0;
  197. ref = this.results_data;
  198. for (i = 0, len = ref.length; i < len; i++) {
  199. data = ref[i];
  200. data_content = '';
  201. if (data.group) {
  202. data_content = this.result_add_group(data);
  203. } else {
  204. data_content = this.result_add_option(data);
  205. }
  206. if (data_content !== '') {
  207. shown_results++;
  208. content += data_content;
  209. }
  210. if (options != null ? options.first : void 0) {
  211. if (data.selected && this.is_multiple) {
  212. this.choice_build(data);
  213. } else if (data.selected && !this.is_multiple) {
  214. this.single_set_selected_text(this.choice_label(data));
  215. }
  216. }
  217. if (shown_results >= this.max_shown_results) {
  218. break;
  219. }
  220. }
  221. return content;
  222. };
  223. AbstractChosen.prototype.result_add_option = function(option) {
  224. var classes, option_el;
  225. if (!option.search_match) {
  226. return '';
  227. }
  228. if (!this.include_option_in_results(option)) {
  229. return '';
  230. }
  231. classes = [];
  232. if (!option.disabled && !(option.selected && this.is_multiple)) {
  233. classes.push("active-result");
  234. }
  235. if (option.disabled && !(option.selected && this.is_multiple)) {
  236. classes.push("disabled-result");
  237. }
  238. if (option.selected) {
  239. classes.push("result-selected");
  240. }
  241. if (option.group_array_index != null) {
  242. classes.push("group-option");
  243. }
  244. if (option.classes !== "") {
  245. classes.push(option.classes);
  246. }
  247. option_el = document.createElement("li");
  248. option_el.className = classes.join(" ");
  249. if (option.style) {
  250. option_el.style.cssText = option.style;
  251. }
  252. option_el.setAttribute("data-option-array-index", option.array_index);
  253. option_el.innerHTML = option.highlighted_html || option.html;
  254. if (option.title) {
  255. option_el.title = option.title;
  256. }
  257. return this.outerHTML(option_el);
  258. };
  259. AbstractChosen.prototype.result_add_group = function(group) {
  260. var classes, group_el;
  261. if (!(group.search_match || group.group_match)) {
  262. return '';
  263. }
  264. if (!(group.active_options > 0)) {
  265. return '';
  266. }
  267. classes = [];
  268. classes.push("group-result");
  269. if (group.classes) {
  270. classes.push(group.classes);
  271. }
  272. group_el = document.createElement("li");
  273. group_el.className = classes.join(" ");
  274. group_el.innerHTML = group.highlighted_html || this.escape_html(group.label);
  275. if (group.title) {
  276. group_el.title = group.title;
  277. }
  278. return this.outerHTML(group_el);
  279. };
  280. AbstractChosen.prototype.results_update_field = function() {
  281. this.set_default_text();
  282. if (!this.is_multiple) {
  283. this.results_reset_cleanup();
  284. }
  285. this.result_clear_highlight();
  286. this.results_build();
  287. if (this.results_showing) {
  288. return this.winnow_results();
  289. }
  290. };
  291. AbstractChosen.prototype.reset_single_select_options = function() {
  292. var i, len, ref, result, results1;
  293. ref = this.results_data;
  294. results1 = [];
  295. for (i = 0, len = ref.length; i < len; i++) {
  296. result = ref[i];
  297. if (result.selected) {
  298. results1.push(result.selected = false);
  299. } else {
  300. results1.push(void 0);
  301. }
  302. }
  303. return results1;
  304. };
  305. AbstractChosen.prototype.results_toggle = function() {
  306. if (this.results_showing) {
  307. return this.results_hide();
  308. } else {
  309. return this.results_show();
  310. }
  311. };
  312. AbstractChosen.prototype.results_search = function(evt) {
  313. if (this.results_showing) {
  314. return this.winnow_results();
  315. } else {
  316. return this.results_show();
  317. }
  318. };
  319. AbstractChosen.prototype.winnow_results = function(options) {
  320. var escapedQuery, fix, i, len, option, prefix, query, ref, regex, results, results_group, search_match, startpos, suffix, text;
  321. this.no_results_clear();
  322. results = 0;
  323. query = this.get_search_text();
  324. escapedQuery = query.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
  325. regex = this.get_search_regex(escapedQuery);
  326. ref = this.results_data;
  327. for (i = 0, len = ref.length; i < len; i++) {
  328. option = ref[i];
  329. option.search_match = false;
  330. results_group = null;
  331. search_match = null;
  332. option.highlighted_html = '';
  333. if (this.include_option_in_results(option)) {
  334. if (option.group) {
  335. option.group_match = false;
  336. option.active_options = 0;
  337. }
  338. if ((option.group_array_index != null) && this.results_data[option.group_array_index]) {
  339. results_group = this.results_data[option.group_array_index];
  340. if (results_group.active_options === 0 && results_group.search_match) {
  341. results += 1;
  342. }
  343. results_group.active_options += 1;
  344. }
  345. text = option.group ? option.label : option.text;
  346. if (!(option.group && !this.group_search)) {
  347. search_match = this.search_string_match(text, regex);
  348. option.search_match = search_match != null;
  349. if (option.search_match && !option.group) {
  350. results += 1;
  351. }
  352. if (option.search_match) {
  353. if (query.length) {
  354. startpos = search_match.index;
  355. prefix = text.slice(0, startpos);
  356. fix = text.slice(startpos, startpos + query.length);
  357. suffix = text.slice(startpos + query.length);
  358. option.highlighted_html = (this.escape_html(prefix)) + "<em>" + (this.escape_html(fix)) + "</em>" + (this.escape_html(suffix));
  359. }
  360. if (results_group != null) {
  361. results_group.group_match = true;
  362. }
  363. } else if ((option.group_array_index != null) && this.results_data[option.group_array_index].search_match) {
  364. option.search_match = true;
  365. }
  366. }
  367. }
  368. }
  369. this.result_clear_highlight();
  370. if (results < 1 && query.length) {
  371. this.update_results_content("");
  372. return this.no_results(query);
  373. } else {
  374. this.update_results_content(this.results_option_build());
  375. if (!(options != null ? options.skip_highlight : void 0)) {
  376. return this.winnow_results_set_highlight();
  377. }
  378. }
  379. };
  380. AbstractChosen.prototype.get_search_regex = function(escaped_search_string) {
  381. var regex_flag, regex_string;
  382. regex_string = this.search_contains ? escaped_search_string : "(^|\\s|\\b)" + escaped_search_string + "[^\\s]*";
  383. if (!(this.enable_split_word_search || this.search_contains)) {
  384. regex_string = "^" + regex_string;
  385. }
  386. regex_flag = this.case_sensitive_search ? "" : "i";
  387. return new RegExp(regex_string, regex_flag);
  388. };
  389. AbstractChosen.prototype.search_string_match = function(search_string, regex) {
  390. var match;
  391. match = regex.exec(search_string);
  392. if (!this.search_contains && (match != null ? match[1] : void 0)) {
  393. match.index += 1;
  394. }
  395. return match;
  396. };
  397. AbstractChosen.prototype.choices_count = function() {
  398. var i, len, option, ref;
  399. if (this.selected_option_count != null) {
  400. return this.selected_option_count;
  401. }
  402. this.selected_option_count = 0;
  403. ref = this.form_field.options;
  404. for (i = 0, len = ref.length; i < len; i++) {
  405. option = ref[i];
  406. if (option.selected) {
  407. this.selected_option_count += 1;
  408. }
  409. }
  410. return this.selected_option_count;
  411. };
  412. AbstractChosen.prototype.choices_click = function(evt) {
  413. evt.preventDefault();
  414. this.activate_field();
  415. if (!(this.results_showing || this.is_disabled)) {
  416. return this.results_show();
  417. }
  418. };
  419. AbstractChosen.prototype.keydown_checker = function(evt) {
  420. var ref, stroke;
  421. stroke = (ref = evt.which) != null ? ref : evt.keyCode;
  422. this.search_field_scale();
  423. if (stroke !== 8 && this.pending_backstroke) {
  424. this.clear_backstroke();
  425. }
  426. switch (stroke) {
  427. case 8:
  428. this.backstroke_length = this.get_search_field_value().length;
  429. break;
  430. case 9:
  431. if (this.results_showing && !this.is_multiple) {
  432. this.result_select(evt);
  433. }
  434. this.mouse_on_container = false;
  435. break;
  436. case 13:
  437. if (this.results_showing) {
  438. evt.preventDefault();
  439. }
  440. break;
  441. case 27:
  442. if (this.results_showing) {
  443. evt.preventDefault();
  444. }
  445. break;
  446. case 32:
  447. if (this.disable_search) {
  448. evt.preventDefault();
  449. }
  450. break;
  451. case 38:
  452. evt.preventDefault();
  453. this.keyup_arrow();
  454. break;
  455. case 40:
  456. evt.preventDefault();
  457. this.keydown_arrow();
  458. break;
  459. }
  460. };
  461. AbstractChosen.prototype.keyup_checker = function(evt) {
  462. var ref, stroke;
  463. stroke = (ref = evt.which) != null ? ref : evt.keyCode;
  464. this.search_field_scale();
  465. switch (stroke) {
  466. case 8:
  467. if (this.is_multiple && this.backstroke_length < 1 && this.choices_count() > 0) {
  468. this.keydown_backstroke();
  469. } else if (!this.pending_backstroke) {
  470. this.result_clear_highlight();
  471. this.results_search();
  472. }
  473. break;
  474. case 13:
  475. evt.preventDefault();
  476. if (this.results_showing) {
  477. this.result_select(evt);
  478. }
  479. break;
  480. case 27:
  481. if (this.results_showing) {
  482. this.results_hide();
  483. }
  484. break;
  485. case 9:
  486. case 16:
  487. case 17:
  488. case 18:
  489. case 38:
  490. case 40:
  491. case 91:
  492. break;
  493. default:
  494. this.results_search();
  495. break;
  496. }
  497. };
  498. AbstractChosen.prototype.clipboard_event_checker = function(evt) {
  499. if (this.is_disabled) {
  500. return;
  501. }
  502. return setTimeout(((function(_this) {
  503. return function() {
  504. return _this.results_search();
  505. };
  506. })(this)), 50);
  507. };
  508. AbstractChosen.prototype.container_width = function() {
  509. if (this.options.width != null) {
  510. return this.options.width;
  511. } else {
  512. return this.form_field.offsetWidth + "px";
  513. }
  514. };
  515. AbstractChosen.prototype.include_option_in_results = function(option) {
  516. if (this.is_multiple && (!this.display_selected_options && option.selected)) {
  517. return false;
  518. }
  519. if (!this.display_disabled_options && option.disabled) {
  520. return false;
  521. }
  522. if (option.empty) {
  523. return false;
  524. }
  525. return true;
  526. };
  527. AbstractChosen.prototype.search_results_touchstart = function(evt) {
  528. this.touch_started = true;
  529. return this.search_results_mouseover(evt);
  530. };
  531. AbstractChosen.prototype.search_results_touchmove = function(evt) {
  532. this.touch_started = false;
  533. return this.search_results_mouseout(evt);
  534. };
  535. AbstractChosen.prototype.search_results_touchend = function(evt) {
  536. if (this.touch_started) {
  537. return this.search_results_mouseup(evt);
  538. }
  539. };
  540. AbstractChosen.prototype.outerHTML = function(element) {
  541. var tmp;
  542. if (element.outerHTML) {
  543. return element.outerHTML;
  544. }
  545. tmp = document.createElement("div");
  546. tmp.appendChild(element);
  547. return tmp.innerHTML;
  548. };
  549. AbstractChosen.prototype.get_single_html = function() {
  550. return "<a class=\"chosen-single chosen-default\">\n <span>" + this.default_text + "</span>\n <div><b></b></div>\n</a>\n<div class=\"chosen-drop\">\n <div class=\"chosen-search\">\n <input class=\"chosen-search-input\" type=\"text\" autocomplete=\"off\" />\n </div>\n <ul class=\"chosen-results\"></ul>\n</div>";
  551. };
  552. AbstractChosen.prototype.get_multi_html = function() {
  553. return "<ul class=\"chosen-choices\">\n <li class=\"search-field\">\n <input class=\"chosen-search-input\" type=\"text\" autocomplete=\"off\" value=\"" + this.default_text + "\" />\n </li>\n</ul>\n<div class=\"chosen-drop\">\n <ul class=\"chosen-results\"></ul>\n</div>";
  554. };
  555. AbstractChosen.prototype.get_no_results_html = function(terms) {
  556. return "<li class=\"no-results\">\n " + this.results_none_found + " <span>" + (this.escape_html(terms)) + "</span>\n</li>";
  557. };
  558. AbstractChosen.browser_is_supported = function() {
  559. if ("Microsoft Internet Explorer" === window.navigator.appName) {
  560. return document.documentMode >= 8;
  561. }
  562. if (/iP(od|hone)/i.test(window.navigator.userAgent) || /IEMobile/i.test(window.navigator.userAgent) || /Windows Phone/i.test(window.navigator.userAgent) || /BlackBerry/i.test(window.navigator.userAgent) || /BB10/i.test(window.navigator.userAgent) || /Android.*Mobile/i.test(window.navigator.userAgent)) {
  563. return false;
  564. }
  565. return true;
  566. };
  567. AbstractChosen.default_multiple_text = "Select Some Options";
  568. AbstractChosen.default_single_text = "Select an Option";
  569. AbstractChosen.default_no_result_text = "No results match";
  570. return AbstractChosen;
  571. })();
  572. $ = jQuery;
  573. $.fn.extend({
  574. chosen: function(options) {
  575. if (!AbstractChosen.browser_is_supported()) {
  576. return this;
  577. }
  578. return this.each(function(input_field) {
  579. var $this, chosen;
  580. $this = $(this);
  581. chosen = $this.data('chosen');
  582. if (options === 'destroy') {
  583. if (chosen instanceof Chosen) {
  584. chosen.destroy();
  585. }
  586. return;
  587. }
  588. if (!(chosen instanceof Chosen)) {
  589. $this.data('chosen', new Chosen(this, options));
  590. }
  591. });
  592. }
  593. });
  594. Chosen = (function(superClass) {
  595. extend(Chosen, superClass);
  596. function Chosen() {
  597. return Chosen.__super__.constructor.apply(this, arguments);
  598. }
  599. Chosen.prototype.setup = function() {
  600. this.form_field_jq = $(this.form_field);
  601. return this.current_selectedIndex = this.form_field.selectedIndex;
  602. };
  603. Chosen.prototype.set_up_html = function() {
  604. var container_classes, container_props;
  605. container_classes = ["chosen-container"];
  606. container_classes.push("chosen-container-" + (this.is_multiple ? "multi" : "single"));
  607. if (this.inherit_select_classes && this.form_field.className) {
  608. container_classes.push(this.form_field.className);
  609. }
  610. if (this.is_rtl) {
  611. container_classes.push("chosen-rtl");
  612. }
  613. container_props = {
  614. 'class': container_classes.join(' '),
  615. 'title': this.form_field.title
  616. };
  617. if (this.form_field.id.length) {
  618. container_props.id = this.form_field.id.replace(/[^\w]/g, '_') + "_chosen";
  619. }
  620. this.container = $("<div />", container_props);
  621. this.container.width(this.container_width());
  622. if (this.is_multiple) {
  623. this.container.html(this.get_multi_html());
  624. } else {
  625. this.container.html(this.get_single_html());
  626. }
  627. this.form_field_jq.hide().after(this.container);
  628. this.dropdown = this.container.find('div.chosen-drop').first();
  629. this.search_field = this.container.find('input').first();
  630. this.search_results = this.container.find('ul.chosen-results').first();
  631. this.search_field_scale();
  632. this.search_no_results = this.container.find('li.no-results').first();
  633. if (this.is_multiple) {
  634. this.search_choices = this.container.find('ul.chosen-choices').first();
  635. this.search_container = this.container.find('li.search-field').first();
  636. } else {
  637. this.search_container = this.container.find('div.chosen-search').first();
  638. this.selected_item = this.container.find('.chosen-single').first();
  639. }
  640. this.results_build();
  641. this.set_tab_index();
  642. return this.set_label_behavior();
  643. };
  644. Chosen.prototype.on_ready = function() {
  645. return this.form_field_jq.trigger("chosen:ready", {
  646. chosen: this
  647. });
  648. };
  649. Chosen.prototype.register_observers = function() {
  650. this.container.on('touchstart.chosen', (function(_this) {
  651. return function(evt) {
  652. _this.container_mousedown(evt);
  653. };
  654. })(this));
  655. this.container.on('touchend.chosen', (function(_this) {
  656. return function(evt) {
  657. _this.container_mouseup(evt);
  658. };
  659. })(this));
  660. this.container.on('mousedown.chosen', (function(_this) {
  661. return function(evt) {
  662. _this.container_mousedown(evt);
  663. };
  664. })(this));
  665. this.container.on('mouseup.chosen', (function(_this) {
  666. return function(evt) {
  667. _this.container_mouseup(evt);
  668. };
  669. })(this));
  670. this.container.on('mouseenter.chosen', (function(_this) {
  671. return function(evt) {
  672. _this.mouse_enter(evt);
  673. };
  674. })(this));
  675. this.container.on('mouseleave.chosen', (function(_this) {
  676. return function(evt) {
  677. _this.mouse_leave(evt);
  678. };
  679. })(this));
  680. this.search_results.on('mouseup.chosen', (function(_this) {
  681. return function(evt) {
  682. _this.search_results_mouseup(evt);
  683. };
  684. })(this));
  685. this.search_results.on('mouseover.chosen', (function(_this) {
  686. return function(evt) {
  687. _this.search_results_mouseover(evt);
  688. };
  689. })(this));
  690. this.search_results.on('mouseout.chosen', (function(_this) {
  691. return function(evt) {
  692. _this.search_results_mouseout(evt);
  693. };
  694. })(this));
  695. this.search_results.on('mousewheel.chosen DOMMouseScroll.chosen', (function(_this) {
  696. return function(evt) {
  697. _this.search_results_mousewheel(evt);
  698. };
  699. })(this));
  700. this.search_results.on('touchstart.chosen', (function(_this) {
  701. return function(evt) {
  702. _this.search_results_touchstart(evt);
  703. };
  704. })(this));
  705. this.search_results.on('touchmove.chosen', (function(_this) {
  706. return function(evt) {
  707. _this.search_results_touchmove(evt);
  708. };
  709. })(this));
  710. this.search_results.on('touchend.chosen', (function(_this) {
  711. return function(evt) {
  712. _this.search_results_touchend(evt);
  713. };
  714. })(this));
  715. this.form_field_jq.on("chosen:updated.chosen", (function(_this) {
  716. return function(evt) {
  717. _this.results_update_field(evt);
  718. };
  719. })(this));
  720. this.form_field_jq.on("chosen:activate.chosen", (function(_this) {
  721. return function(evt) {
  722. _this.activate_field(evt);
  723. };
  724. })(this));
  725. this.form_field_jq.on("chosen:open.chosen", (function(_this) {
  726. return function(evt) {
  727. _this.container_mousedown(evt);
  728. };
  729. })(this));
  730. this.form_field_jq.on("chosen:close.chosen", (function(_this) {
  731. return function(evt) {
  732. _this.close_field(evt);
  733. };
  734. })(this));
  735. this.search_field.on('blur.chosen', (function(_this) {
  736. return function(evt) {
  737. _this.input_blur(evt);
  738. };
  739. })(this));
  740. this.search_field.on('keyup.chosen', (function(_this) {
  741. return function(evt) {
  742. _this.keyup_checker(evt);
  743. };
  744. })(this));
  745. this.search_field.on('keydown.chosen', (function(_this) {
  746. return function(evt) {
  747. _this.keydown_checker(evt);
  748. };
  749. })(this));
  750. this.search_field.on('focus.chosen', (function(_this) {
  751. return function(evt) {
  752. _this.input_focus(evt);
  753. };
  754. })(this));
  755. this.search_field.on('cut.chosen', (function(_this) {
  756. return function(evt) {
  757. _this.clipboard_event_checker(evt);
  758. };
  759. })(this));
  760. this.search_field.on('paste.chosen', (function(_this) {
  761. return function(evt) {
  762. _this.clipboard_event_checker(evt);
  763. };
  764. })(this));
  765. if (this.is_multiple) {
  766. return this.search_choices.on('click.chosen', (function(_this) {
  767. return function(evt) {
  768. _this.choices_click(evt);
  769. };
  770. })(this));
  771. } else {
  772. return this.container.on('click.chosen', function(evt) {
  773. evt.preventDefault();
  774. });
  775. }
  776. };
  777. Chosen.prototype.destroy = function() {
  778. $(this.container[0].ownerDocument).off('click.chosen', this.click_test_action);
  779. if (this.form_field_label.length > 0) {
  780. this.form_field_label.off('click.chosen');
  781. }
  782. if (this.search_field[0].tabIndex) {
  783. this.form_field_jq[0].tabIndex = this.search_field[0].tabIndex;
  784. }
  785. this.container.remove();
  786. this.form_field_jq.removeData('chosen');
  787. return this.form_field_jq.show();
  788. };
  789. Chosen.prototype.search_field_disabled = function() {
  790. this.is_disabled = this.form_field.disabled || this.form_field_jq.parents('fieldset').is(':disabled');
  791. this.container.toggleClass('chosen-disabled', this.is_disabled);
  792. this.search_field[0].disabled = this.is_disabled;
  793. if (!this.is_multiple) {
  794. this.selected_item.off('focus.chosen', this.activate_field);
  795. }
  796. if (this.is_disabled) {
  797. return this.close_field();
  798. } else if (!this.is_multiple) {
  799. return this.selected_item.on('focus.chosen', this.activate_field);
  800. }
  801. };
  802. Chosen.prototype.container_mousedown = function(evt) {
  803. var ref;
  804. if (this.is_disabled) {
  805. return;
  806. }
  807. if (evt && ((ref = evt.type) === 'mousedown' || ref === 'touchstart') && !this.results_showing) {
  808. evt.preventDefault();
  809. }
  810. if (!((evt != null) && ($(evt.target)).hasClass("search-choice-close"))) {
  811. if (!this.active_field) {
  812. if (this.is_multiple) {
  813. this.search_field.val("");
  814. }
  815. $(this.container[0].ownerDocument).on('click.chosen', this.click_test_action);
  816. this.results_show();
  817. } else if (!this.is_multiple && evt && (($(evt.target)[0] === this.selected_item[0]) || $(evt.target).parents("a.chosen-single").length)) {
  818. evt.preventDefault();
  819. this.results_toggle();
  820. }
  821. return this.activate_field();
  822. }
  823. };
  824. Chosen.prototype.container_mouseup = function(evt) {
  825. if (evt.target.nodeName === "ABBR" && !this.is_disabled) {
  826. return this.results_reset(evt);
  827. }
  828. };
  829. Chosen.prototype.search_results_mousewheel = function(evt) {
  830. var delta;
  831. if (evt.originalEvent) {
  832. delta = evt.originalEvent.deltaY || -evt.originalEvent.wheelDelta || evt.originalEvent.detail;
  833. }
  834. if (delta != null) {
  835. evt.preventDefault();
  836. if (evt.type === 'DOMMouseScroll') {
  837. delta = delta * 40;
  838. }
  839. return this.search_results.scrollTop(delta + this.search_results.scrollTop());
  840. }
  841. };
  842. Chosen.prototype.blur_test = function(evt) {
  843. if (!this.active_field && this.container.hasClass("chosen-container-active")) {
  844. return this.close_field();
  845. }
  846. };
  847. Chosen.prototype.close_field = function() {
  848. $(this.container[0].ownerDocument).off("click.chosen", this.click_test_action);
  849. this.active_field = false;
  850. this.results_hide();
  851. this.container.removeClass("chosen-container-active");
  852. this.clear_backstroke();
  853. this.show_search_field_default();
  854. this.search_field_scale();
  855. return this.search_field.blur();
  856. };
  857. Chosen.prototype.activate_field = function() {
  858. if (this.is_disabled) {
  859. return;
  860. }
  861. this.container.addClass("chosen-container-active");
  862. this.active_field = true;
  863. this.search_field.val(this.search_field.val());
  864. return this.search_field.focus();
  865. };
  866. Chosen.prototype.test_active_click = function(evt) {
  867. var active_container;
  868. active_container = $(evt.target).closest('.chosen-container');
  869. if (active_container.length && this.container[0] === active_container[0]) {
  870. return this.active_field = true;
  871. } else {
  872. return this.close_field();
  873. }
  874. };
  875. Chosen.prototype.results_build = function() {
  876. this.parsing = true;
  877. this.selected_option_count = null;
  878. this.results_data = SelectParser.select_to_array(this.form_field);
  879. if (this.is_multiple) {
  880. this.search_choices.find("li.search-choice").remove();
  881. } else {
  882. this.single_set_selected_text();
  883. if (this.disable_search || this.form_field.options.length <= this.disable_search_threshold) {
  884. this.search_field[0].readOnly = true;
  885. this.container.addClass("chosen-container-single-nosearch");
  886. } else {
  887. this.search_field[0].readOnly = false;
  888. this.container.removeClass("chosen-container-single-nosearch");
  889. }
  890. }
  891. this.update_results_content(this.results_option_build({
  892. first: true
  893. }));
  894. this.search_field_disabled();
  895. this.show_search_field_default();
  896. this.search_field_scale();
  897. return this.parsing = false;
  898. };
  899. Chosen.prototype.result_do_highlight = function(el) {
  900. var high_bottom, high_top, maxHeight, visible_bottom, visible_top;
  901. if (el.length) {
  902. this.result_clear_highlight();
  903. this.result_highlight = el;
  904. this.result_highlight.addClass("highlighted");
  905. maxHeight = parseInt(this.search_results.css("maxHeight"), 10);
  906. visible_top = this.search_results.scrollTop();
  907. visible_bottom = maxHeight + visible_top;
  908. high_top = this.result_highlight.position().top + this.search_results.scrollTop();
  909. high_bottom = high_top + this.result_highlight.outerHeight();
  910. if (high_bottom >= visible_bottom) {
  911. return this.search_results.scrollTop((high_bottom - maxHeight) > 0 ? high_bottom - maxHeight : 0);
  912. } else if (high_top < visible_top) {
  913. return this.search_results.scrollTop(high_top);
  914. }
  915. }
  916. };
  917. Chosen.prototype.result_clear_highlight = function() {
  918. if (this.result_highlight) {
  919. this.result_highlight.removeClass("highlighted");
  920. }
  921. return this.result_highlight = null;
  922. };
  923. Chosen.prototype.results_show = function() {
  924. if (this.is_multiple && this.max_selected_options <= this.choices_count()) {
  925. this.form_field_jq.trigger("chosen:maxselected", {
  926. chosen: this
  927. });
  928. return false;
  929. }
  930. this.container.addClass("chosen-with-drop");
  931. this.results_showing = true;
  932. this.search_field.focus();
  933. this.search_field.val(this.get_search_field_value());
  934. this.winnow_results();
  935. return this.form_field_jq.trigger("chosen:showing_dropdown", {
  936. chosen: this
  937. });
  938. };
  939. Chosen.prototype.update_results_content = function(content) {
  940. return this.search_results.html(content);
  941. };
  942. Chosen.prototype.results_hide = function() {
  943. if (this.results_showing) {
  944. this.result_clear_highlight();
  945. this.container.removeClass("chosen-with-drop");
  946. this.form_field_jq.trigger("chosen:hiding_dropdown", {
  947. chosen: this
  948. });
  949. }
  950. return this.results_showing = false;
  951. };
  952. Chosen.prototype.set_tab_index = function(el) {
  953. var ti;
  954. if (this.form_field.tabIndex) {
  955. ti = this.form_field.tabIndex;
  956. this.form_field.tabIndex = -1;
  957. return this.search_field[0].tabIndex = ti;
  958. }
  959. };
  960. Chosen.prototype.set_label_behavior = function() {
  961. this.form_field_label = this.form_field_jq.parents("label");
  962. if (!this.form_field_label.length && this.form_field.id.length) {
  963. this.form_field_label = $("label[for='" + this.form_field.id + "']");
  964. }
  965. if (this.form_field_label.length > 0) {
  966. return this.form_field_label.on('click.chosen', this.label_click_handler);
  967. }
  968. };
  969. Chosen.prototype.show_search_field_default = function() {
  970. if (this.is_multiple && this.choices_count() < 1 && !this.active_field) {
  971. this.search_field.val(this.default_text);
  972. return this.search_field.addClass("default");
  973. } else {
  974. this.search_field.val("");
  975. return this.search_field.removeClass("default");
  976. }
  977. };
  978. Chosen.prototype.search_results_mouseup = function(evt) {
  979. var target;
  980. target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first();
  981. if (target.length) {
  982. this.result_highlight = target;
  983. this.result_select(evt);
  984. return this.search_field.focus();
  985. }
  986. };
  987. Chosen.prototype.search_results_mouseover = function(evt) {
  988. var target;
  989. target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first();
  990. if (target) {
  991. return this.result_do_highlight(target);
  992. }
  993. };
  994. Chosen.prototype.search_results_mouseout = function(evt) {
  995. if ($(evt.target).hasClass("active-result") || $(evt.target).parents('.active-result').first()) {
  996. return this.result_clear_highlight();
  997. }
  998. };
  999. Chosen.prototype.choice_build = function(item) {
  1000. var choice, close_link;
  1001. choice = $('<li />', {
  1002. "class": "search-choice"
  1003. }).html("<span>" + (this.choice_label(item)) + "</span>");
  1004. if (item.disabled) {
  1005. choice.addClass('search-choice-disabled');
  1006. } else {
  1007. close_link = $('<a />', {
  1008. "class": 'search-choice-close',
  1009. 'data-option-array-index': item.array_index
  1010. });
  1011. close_link.on('click.chosen', (function(_this) {
  1012. return function(evt) {
  1013. return _this.choice_destroy_link_click(evt);
  1014. };
  1015. })(this));
  1016. choice.append(close_link);
  1017. }
  1018. return this.search_container.before(choice);
  1019. };
  1020. Chosen.prototype.choice_destroy_link_click = function(evt) {
  1021. evt.preventDefault();
  1022. evt.stopPropagation();
  1023. if (!this.is_disabled) {
  1024. return this.choice_destroy($(evt.target));
  1025. }
  1026. };
  1027. Chosen.prototype.choice_destroy = function(link) {
  1028. if (this.result_deselect(link[0].getAttribute("data-option-array-index"))) {
  1029. if (this.active_field) {
  1030. this.search_field.focus();
  1031. } else {
  1032. this.show_search_field_default();
  1033. }
  1034. if (this.is_multiple && this.choices_count() > 0 && this.get_search_field_value().length < 1) {
  1035. this.results_hide();
  1036. }
  1037. link.parents('li').first().remove();
  1038. return this.search_field_scale();
  1039. }
  1040. };
  1041. Chosen.prototype.results_reset = function() {
  1042. this.reset_single_select_options();
  1043. this.form_field.options[0].selected = true;
  1044. this.single_set_selected_text();
  1045. this.show_search_field_default();
  1046. this.results_reset_cleanup();
  1047. this.trigger_form_field_change();
  1048. if (this.active_field) {
  1049. return this.results_hide();
  1050. }
  1051. };
  1052. Chosen.prototype.results_reset_cleanup = function() {
  1053. this.current_selectedIndex = this.form_field.selectedIndex;
  1054. return this.selected_item.find("abbr").remove();
  1055. };
  1056. Chosen.prototype.result_select = function(evt) {
  1057. var high, item;
  1058. if (this.result_highlight) {
  1059. high = this.result_highlight;
  1060. this.result_clear_highlight();
  1061. if (this.is_multiple && this.max_selected_options <= this.choices_count()) {
  1062. this.form_field_jq.trigger("chosen:maxselected", {
  1063. chosen: this
  1064. });
  1065. return false;
  1066. }
  1067. if (this.is_multiple) {
  1068. high.removeClass("active-result");
  1069. } else {
  1070. this.reset_single_select_options();
  1071. }
  1072. high.addClass("result-selected");
  1073. item = this.results_data[high[0].getAttribute("data-option-array-index")];
  1074. item.selected = true;
  1075. this.form_field.options[item.options_index].selected = true;
  1076. this.selected_option_count = null;
  1077. if (this.is_multiple) {
  1078. this.choice_build(item);
  1079. } else {
  1080. this.single_set_selected_text(this.choice_label(item));
  1081. }
  1082. if (this.is_multiple && (!this.hide_results_on_select || (evt.metaKey || evt.ctrlKey))) {
  1083. if (evt.metaKey || evt.ctrlKey) {
  1084. this.winnow_results({
  1085. skip_highlight: true
  1086. });
  1087. } else {
  1088. this.search_field.val("");
  1089. this.winnow_results();
  1090. }
  1091. } else {
  1092. this.results_hide();
  1093. this.show_search_field_default();
  1094. }
  1095. if (this.is_multiple || this.form_field.selectedIndex !== this.current_selectedIndex) {
  1096. this.trigger_form_field_change({
  1097. selected: this.form_field.options[item.options_index].value
  1098. });
  1099. }
  1100. this.current_selectedIndex = this.form_field.selectedIndex;
  1101. evt.preventDefault();
  1102. return this.search_field_scale();
  1103. }
  1104. };
  1105. Chosen.prototype.single_set_selected_text = function(text) {
  1106. if (text == null) {
  1107. text = this.default_text;
  1108. }
  1109. if (text === this.default_text) {
  1110. this.selected_item.addClass("chosen-default");
  1111. } else {
  1112. this.single_deselect_control_build();
  1113. this.selected_item.removeClass("chosen-default");
  1114. }
  1115. return this.selected_item.find("span").html(text);
  1116. };
  1117. Chosen.prototype.result_deselect = function(pos) {
  1118. var result_data;
  1119. result_data = this.results_data[pos];
  1120. if (!this.form_field.options[result_data.options_index].disabled) {
  1121. result_data.selected = false;
  1122. this.form_field.options[result_data.options_index].selected = false;
  1123. this.selected_option_count = null;
  1124. this.result_clear_highlight();
  1125. if (this.results_showing) {
  1126. this.winnow_results();
  1127. }
  1128. this.trigger_form_field_change({
  1129. deselected: this.form_field.options[result_data.options_index].value
  1130. });
  1131. this.search_field_scale();
  1132. return true;
  1133. } else {
  1134. return false;
  1135. }
  1136. };
  1137. Chosen.prototype.single_deselect_control_build = function() {
  1138. if (!this.allow_single_deselect) {
  1139. return;
  1140. }
  1141. if (!this.selected_item.find("abbr").length) {
  1142. this.selected_item.find("span").first().after("<abbr class=\"search-choice-close\"></abbr>");
  1143. }
  1144. return this.selected_item.addClass("chosen-single-with-deselect");
  1145. };
  1146. Chosen.prototype.get_search_field_value = function() {
  1147. return this.search_field.val();
  1148. };
  1149. Chosen.prototype.get_search_text = function() {
  1150. return $.trim(this.get_search_field_value());
  1151. };
  1152. Chosen.prototype.escape_html = function(text) {
  1153. return $('<div/>').text(text).html();
  1154. };
  1155. Chosen.prototype.winnow_results_set_highlight = function() {
  1156. var do_high, selected_results;
  1157. selected_results = !this.is_multiple ? this.search_results.find(".result-selected.active-result") : [];
  1158. do_high = selected_results.length ? selected_results.first() : this.search_results.find(".active-result").first();
  1159. if (do_high != null) {
  1160. return this.result_do_highlight(do_high);
  1161. }
  1162. };
  1163. Chosen.prototype.no_results = function(terms) {
  1164. var no_results_html;
  1165. no_results_html = this.get_no_results_html(terms);
  1166. this.search_results.append(no_results_html);
  1167. return this.form_field_jq.trigger("chosen:no_results", {
  1168. chosen: this
  1169. });
  1170. };
  1171. Chosen.prototype.no_results_clear = function() {
  1172. return this.search_results.find(".no-results").remove();
  1173. };
  1174. Chosen.prototype.keydown_arrow = function() {
  1175. var next_sib;
  1176. if (this.results_showing && this.result_highlight) {
  1177. next_sib = this.result_highlight.nextAll("li.active-result").first();
  1178. if (next_sib) {
  1179. return this.result_do_highlight(next_sib);
  1180. }
  1181. } else {
  1182. return this.results_show();
  1183. }
  1184. };
  1185. Chosen.prototype.keyup_arrow = function() {
  1186. var prev_sibs;
  1187. if (!this.results_showing && !this.is_multiple) {
  1188. return this.results_show();
  1189. } else if (this.result_highlight) {
  1190. prev_sibs = this.result_highlight.prevAll("li.active-result");
  1191. if (prev_sibs.length) {
  1192. return this.result_do_highlight(prev_sibs.first());
  1193. } else {
  1194. if (this.choices_count() > 0) {
  1195. this.results_hide();
  1196. }
  1197. return this.result_clear_highlight();
  1198. }
  1199. }
  1200. };
  1201. Chosen.prototype.keydown_backstroke = function() {
  1202. var next_available_destroy;
  1203. if (this.pending_backstroke) {
  1204. this.choice_destroy(this.pending_backstroke.find("a").first());
  1205. return this.clear_backstroke();
  1206. } else {
  1207. next_available_destroy = this.search_container.siblings("li.search-choice").last();
  1208. if (next_available_destroy.length && !next_available_destroy.hasClass("search-choice-disabled")) {
  1209. this.pending_backstroke = next_available_destroy;
  1210. if (this.single_backstroke_delete) {
  1211. return this.keydown_backstroke();
  1212. } else {
  1213. return this.pending_backstroke.addClass("search-choice-focus");
  1214. }
  1215. }
  1216. }
  1217. };
  1218. Chosen.prototype.clear_backstroke = function() {
  1219. if (this.pending_backstroke) {
  1220. this.pending_backstroke.removeClass("search-choice-focus");
  1221. }
  1222. return this.pending_backstroke = null;
  1223. };
  1224. Chosen.prototype.search_field_scale = function() {
  1225. var div, i, len, style, style_block, styles, width;
  1226. if (!this.is_multiple) {
  1227. return;
  1228. }
  1229. style_block = {
  1230. position: 'absolute',
  1231. left: '-1000px',
  1232. top: '-1000px',
  1233. display: 'none',
  1234. whiteSpace: 'pre'
  1235. };
  1236. styles = ['fontSize', 'fontStyle', 'fontWeight', 'fontFamily', 'lineHeight', 'textTransform', 'letterSpacing'];
  1237. for (i = 0, len = styles.length; i < len; i++) {
  1238. style = styles[i];
  1239. style_block[style] = this.search_field.css(style);
  1240. }
  1241. div = $('<div />').css(style_block);
  1242. div.text(this.get_search_field_value());
  1243. $('body').append(div);
  1244. width = div.width() + 25;
  1245. div.remove();
  1246. if (this.container.is(':visible')) {
  1247. width = Math.min(this.container.outerWidth() - 10, width);
  1248. }
  1249. return this.search_field.width(width);
  1250. };
  1251. Chosen.prototype.trigger_form_field_change = function(extra) {
  1252. this.form_field_jq.trigger("input", extra);
  1253. return this.form_field_jq.trigger("change", extra);
  1254. };
  1255. return Chosen;
  1256. })(AbstractChosen);
  1257. }).call(this);