1// /*! 2// Chosen, a Select Box Enhancer for jQuery and Prototype 3// by Patrick Filler for Harvest, http://getharvest.com 4 5// Version 1.8.7 6// Full source at https://github.com/harvesthq/chosen 7// Copyright (c) 2011-2018 Harvest http://getharvest.com 8 9// MIT License, https://github.com/harvesthq/chosen/blob/master/LICENSE.md 10// This file is generated by `grunt build`, do not edit it by hand. 11// */ 12 13// (function() { 14// var $, AbstractChosen, Chosen, SelectParser, 15// bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, 16// 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; }, 17// hasProp = {}.hasOwnProperty; 18 19// SelectParser = (function() { 20// function SelectParser() { 21// this.options_index = 0; 22// this.parsed = []; 23// } 24 25// SelectParser.prototype.add_node = function(child) { 26// if (child.nodeName.toUpperCase() === "OPTGROUP") { 27// return this.add_group(child); 28// } else { 29// return this.add_option(child); 30// } 31// }; 32 33// SelectParser.prototype.add_group = function(group) { 34// var group_position, i, len, option, ref, results1; 35// group_position = this.parsed.length; 36// this.parsed.push({ 37// array_index: group_position, 38// group: true, 39// label: group.label, 40// title: group.title ? group.title : void 0, 41// children: 0, 42// disabled: group.disabled, 43// classes: group.className 44// }); 45// ref = group.childNodes; 46// results1 = []; 47// for (i = 0, len = ref.length; i < len; i++) { 48// option = ref[i]; 49// results1.push(this.add_option(option, group_position, group.disabled)); 50// } 51// return results1; 52// }; 53 54// SelectParser.prototype.add_option = function(option, group_position, group_disabled) { 55// if (option.nodeName.toUpperCase() === "OPTION") { 56// if (option.text !== "") { 57// if (group_position != null) { 58// this.parsed[group_position].children += 1; 59// } 60// this.parsed.push({ 61// array_index: this.parsed.length, 62// options_index: this.options_index, 63// value: option.value, 64// text: option.text, 65// html: option.innerHTML, 66// title: option.title ? option.title : void 0, 67// selected: option.selected, 68// disabled: group_disabled === true ? group_disabled : option.disabled, 69// group_array_index: group_position, 70// group_label: group_position != null ? this.parsed[group_position].label : null, 71// classes: option.className, 72// style: option.style.cssText 73// }); 74// } else { 75// this.parsed.push({ 76// array_index: this.parsed.length, 77// options_index: this.options_index, 78// empty: true 79// }); 80// } 81// return this.options_index += 1; 82// } 83// }; 84 85// return SelectParser; 86 87// })(); 88 89// SelectParser.select_to_array = function(select) { 90// var child, i, len, parser, ref; 91// parser = new SelectParser(); 92// ref = select.childNodes; 93// for (i = 0, len = ref.length; i < len; i++) { 94// child = ref[i]; 95// parser.add_node(child); 96// } 97// return parser.parsed; 98// }; 99 100// AbstractChosen = (function() { 101// function AbstractChosen(form_field, options1) { 102// this.form_field = form_field; 103// this.options = options1 != null ? options1 : {}; 104// this.label_click_handler = bind(this.label_click_handler, this); 105// // if (!AbstractChosen.browser_is_supported()) { 106// // return; 107// // } 108// this.is_multiple = this.form_field.multiple; 109// this.set_default_text(); 110// this.set_default_values(); 111// this.setup(); 112// this.set_up_html(); 113// this.register_observers(); 114// this.on_ready(); 115// } 116 117// AbstractChosen.prototype.set_default_values = function() { 118// this.click_test_action = (function(_this) { 119// return function(evt) { 120// return _this.test_active_click(evt); 121// }; 122// })(this); 123// this.activate_action = (function(_this) { 124// return function(evt) { 125// return _this.activate_field(evt); 126// }; 127// })(this); 128// this.active_field = false;
129// this.mouse_on_container = false; 130// this.results_showing = false; 131// this.result_highlighted = null; 132// this.is_rtl = this.options.rtl || /\bchosen-rtl\b/.test(this.form_field.className); 133// 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; 134// this.disable_search_threshold = this.options.disable_search_threshold || 0; 135// this.disable_search = this.options.disable_search || false; 136// this.enable_split_word_search = this.options.enable_split_word_search != null ? this.options.enable_split_word_search : true; 137// this.group_search = this.options.group_search != null ? this.options.group_search : true; 138// this.search_contains = this.options.search_contains || false; 139// this.single_backstroke_delete = this.options.single_backstroke_delete != null ? this.options.single_backstroke_delete : true; 140// this.max_selected_options = this.options.max_selected_options || Infinity; 141// this.inherit_select_classes = this.options.inherit_select_classes || false; 142// this.display_selected_options = this.options.display_selected_options != null ? this.options.display_selected_options : true; 143// this.display_disabled_options = this.options.display_disabled_options != null ? this.options.display_disabled_options : true; 144// this.include_group_label_in_selected = this.options.include_group_label_in_selected || false; 145// this.max_shown_results = this.options.max_shown_results || Number.POSITIVE_INFINITY; 146// this.case_sensitive_search = this.options.case_sensitive_search || false; 147// return this.hide_results_on_select = this.options.hide_results_on_select != null ? this.options.hide_results_on_select : true; 148// }; 149 150// AbstractChosen.prototype.set_default_text = function() { 151// if (this.form_field.getAttribute("data-placeholder")) { 152// this.default_text = this.form_field.getAttribute("data-placeholder"); 153// } else if (this.is_multiple) { 154// this.default_text = this.options.placeholder_text_multiple || this.options.placeholder_text || AbstractChosen.default_multiple_text; 155// } else { 156// this.default_text = this.options.placeholder_text_single || this.options.placeholder_text || AbstractChosen.default_single_text; 157// } 158// this.default_text = this.escape_html(this.default_text); 159// return this.results_none_found = this.form_field.getAttribute("data-no_results_text") || this.options.no_results_text || AbstractChosen.default_no_result_text; 160// }; 161 162// AbstractChosen.prototype.choice_label = function(item) { 163// if (this.include_group_label_in_selected && (item.group_label != null)) { 164// return "<b class='group-name'>" + (this.escape_html(item.group_label)) + "</b>" + item.html; 165// } else { 166// return item.html; 167// } 168// }; 169 170// AbstractChosen.prototype.mouse_enter = function() { 171// return this.mouse_on_container = true; 172// }; 173 174// AbstractChosen.prototype.mouse_leave = function() { 175// return this.mouse_on_container = false; 176// }; 177 178// AbstractChosen.prototype.input_focus = function(evt) { 179// if (this.is_multiple) { 180// if (!this.active_field) { 181// return setTimeout(((function(_this) { 182// return function() { 183// return _this.container_mousedown(); 184// }; 185// })(this)), 50); 186// } 187// } else { 188// if (!this.active_field) { 189// return this.activate_field(); 190// } 191// } 192// }; 193 194// AbstractChosen.prototype.input_blur = function(evt) { 195// if (!this.mouse_on_container) { 196// this.active_field = false; 197// return setTimeout(((function(_this) { 198// return function() { 199// return _this.blur_test(); 200// }; 201// })(this)), 100); 202// } 203// }; 204 205// AbstractChosen.prototype.label_click_handler = function(evt) { 206// if (this.is_multiple) { 207// return this.container_mousedown(evt); 208// } else { 209// return this.activate_field(); 210// } 211// }; 212 213// AbstractChosen.prototype.results_option_build = function(options) { 214// var content, data, data_content, i, len, ref, shown_results; 215// content = ''; 216// shown_results = 0; 217// ref = this.results_data; 218// for (i = 0, len = ref.length; i < len; i++) { 219// data = ref[i]; 220// data_content = ''; 221// if (data.group) { 222// data_content = this.result_add_group(data); 223// } else { 224// data_content = this.result_add_option(data); 225// } 226// if (data_content !== '') { 227// shown_results++; 228// content += data_content; 229// } 230// if (options != null ? options.first : void 0) { 231// if (data.selected && this.is_multiple) { 232// this.choice_build(data); 233// } else if (data.selected && !this.is_multiple) { 234// this.single_set_selected_text(this.choice_label(data)); 235// } 236// } 237// if (shown_results >= this.max_shown_results) { 238// break; 239// } 240// } 241// return content; 242// }; 243 244// AbstractChosen.prototype.result_add_option = function(option) { 245// var classes, option_el; 246// if (!option.search_match) { 247// return ''; 248// } 249// if (!this.include_option_in_results(option)) { 250// return ''; 251// } 252// classes = []; 253// if (!option.disabled && !(option.selected && this.is_multiple)) { 254// classes.push("active-result"); 255// } 256// if (option.disabled && !(option.selected && this.is_multiple)) { 257// classes.push("disabled-result"); 258// } 259// if (option.selected) { 260// classes.push("result-selected"); 261// } 262// if (option.group_array_index != null) { 263// classes.push("group-option"); 264// } 265// if (option.classes !== "") { 266// classes.push(option.classes); 267// } 268// option_el = document.createElement("li"); 269// option_el.className = classes.join(" "); 270// if (option.style) { 271// option_el.style.cssText = option.style; 272// } 273// option_el.setAttribute("data-option-array-index", option.array_index); 274// option_el.innerHTML = option.highlighted_html || option.html; 275// if (option.title) { 276// option_el.title = option.title; 277// } 278// return this.outerHTML(option_el); 279// }; 280 281// AbstractChosen.prototype.result_add_group = function(group) { 282// var classes, group_el; 283// if (!(group.search_match || group.group_match)) { 284// return ''; 285// } 286// if (!(group.active_options > 0)) { 287// return ''; 288// } 289// classes = []; 290// classes.push("group-result"); 291// if (group.classes) { 292// classes.push(group.classes); 293// } 294// group_el = document.createElement("li"); 295// group_el.className = classes.join(" "); 296// group_el.innerHTML = group.highlighted_html || this.escape_html(group.label); 297// if (group.title) { 298// group_el.title = group.title; 299// } 300// return this.outerHTML(group_el); 301// }; 302 303// AbstractChosen.prototype.results_update_field = function() { 304// this.set_default_text(); 305// if (!this.is_multiple) { 306// this.results_reset_cleanup(); 307// } 308// this.result_clear_highlight(); 309// this.results_build(); 310// if (this.results_showing) { 311// return this.winnow_results(); 312// } 313// }; 314 315// AbstractChosen.prototype.reset_single_select_options = function() { 316// var i, len, ref, result, results1; 317// ref = this.results_data; 318// results1 = []; 319// for (i = 0, len = ref.length; i < len; i++) { 320// result = ref[i]; 321// if (result.selected) { 322// results1.push(result.selected = false); 323// } else { 324// results1.push(void 0); 325// } 326// } 327// return results1; 328// }; 329 330// AbstractChosen.prototype.results_toggle = function() { 331// if (this.results_showing) { 332// return this.results_hide(); 333// } else { 334// return this.results_show(); 335// } 336// }; 337 338// AbstractChosen.prototype.results_search = function(evt) { 339// if (this.results_showing) { 340// return this.winnow_results(); 341// } else { 342// return this.results_show(); 343// } 344// }; 345 346// AbstractChosen.prototype.winnow_results = function(options) { 347// var escapedQuery, fix, i, len, option, prefix, query, ref, regex, results, results_group, search_match, startpos, suffix, text; 348// this.no_results_clear(); 349// results = 0; 350// query = this.get_search_text(); 351// escapedQuery = query.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"); 352// regex = this.get_search_regex(escapedQuery); 353// ref = this.results_data; 354// for (i = 0, len = ref.length; i < len; i++) { 355// option = ref[i]; 356// option.search_match = false;
357// results_group = null; 358// search_match = null; 359// option.highlighted_html = ''; 360// if (this.include_option_in_results(option)) { 361// if (option.group) { 362// option.group_match = false; 363// option.active_options = 0; 364// } 365// if ((option.group_array_index != null) && this.results_data[option.group_array_index]) { 366// results_group = this.results_data[option.group_array_index]; 367// if (results_group.active_options === 0 && results_group.search_match) { 368// results += 1; 369// } 370// results_group.active_options += 1; 371// } 372// text = option.group ? option.label : option.text; 373// if (!(option.group && !this.group_search)) { 374// search_match = this.search_string_match(text, regex); 375// option.search_match = search_match != null; 376// if (option.search_match && !option.group) { 377// results += 1; 378// } 379// if (option.search_match) { 380// if (query.length) { 381// startpos = search_match.index; 382// prefix = text.slice(0, startpos); 383// fix = text.slice(startpos, startpos + query.length); 384// suffix = text.slice(startpos + query.length); 385// option.highlighted_html = (this.escape_html(prefix)) + "<em>" + (this.escape_html(fix)) + "</em>" + (this.escape_html(suffix)); 386// } 387// if (results_group != null) { 388// results_group.group_match = true; 389// } 390// } else if ((option.group_array_index != null) && this.results_data[option.group_array_index].search_match) { 391// option.search_match = true; 392// } 393// } 394// } 395// } 396// this.result_clear_highlight(); 397// if (results < 1 && query.length) { 398// this.update_results_content(""); 399// return this.no_results(query); 400// } else { 401// this.update_results_content(this.results_option_build()); 402// if (!(options != null ? options.skip_highlight : void 0)) { 403// return this.winnow_results_set_highlight(); 404// } 405// } 406// }; 407 408// AbstractChosen.prototype.get_search_regex = function(escaped_search_string) { 409// var regex_flag, regex_string; 410// regex_string = this.search_contains ? escaped_search_string : "(^|\\s|\\b)" + escaped_search_string + "[^\\s]*"; 411// if (!(this.enable_split_word_search || this.search_contains)) { 412// regex_string = "^" + regex_string; 413// } 414// regex_flag = this.case_sensitive_search ? "" : "i"; 415// return new RegExp(regex_string, regex_flag); 416// }; 417 418// AbstractChosen.prototype.search_string_match = function(search_string, regex) { 419// var match; 420// match = regex.exec(search_string); 421// if (!this.search_contains && (match != null ? match[1] : void 0)) { 422// match.index += 1; 423// } 424// return match; 425// }; 426 427// AbstractChosen.prototype.choices_count = function() { 428// var i, len, option, ref; 429// if (this.selected_option_count != null) { 430// return this.selected_option_count; 431// } 432// this.selected_option_count = 0; 433// ref = this.form_field.options; 434// for (i = 0, len = ref.length; i < len; i++) { 435// option = ref[i]; 436// if (option.selected) { 437// this.selected_option_count += 1; 438// } 439// } 440// return this.selected_option_count; 441// }; 442 443// AbstractChosen.prototype.choices_click = function(evt) { 444// evt.preventDefault(); 445// this.activate_field(); 446// if (!(this.results_showing || this.is_disabled)) { 447// return this.results_show(); 448// } 449// }; 450 451// AbstractChosen.prototype.keydown_checker = function(evt) { 452// var ref, stroke; 453// stroke = (ref = evt.which) != null ? ref : evt.keyCode; 454// this.search_field_scale(); 455// if (stroke !== 8 && this.pending_backstroke) { 456// this.clear_backstroke(); 457// } 458// switch (stroke) { 459// case 8: 460// this.backstroke_length = this.get_search_field_value().length; 461// break; 462// case 9: 463// if (this.results_showing && !this.is_multiple) { 464// this.result_select(evt); 465// } 466// this.mouse_on_container = false;
467// break; 468// case 13: 469// if (this.results_showing) { 470// evt.preventDefault(); 471// } 472// break; 473// case 27: 474// if (this.results_showing) { 475// evt.preventDefault(); 476// } 477// break; 478// case 32: 479// if (this.disable_search) { 480// evt.preventDefault(); 481// } 482// break; 483// case 38: 484// evt.preventDefault(); 485// this.keyup_arrow(); 486// break; 487// case 40: 488// evt.preventDefault(); 489// this.keydown_arrow(); 490// break; 491// } 492// }; 493 494// AbstractChosen.prototype.keyup_checker = function(evt) { 495// var ref, stroke; 496// stroke = (ref = evt.which) != null ? ref : evt.keyCode; 497// this.search_field_scale(); 498// switch (stroke) { 499// case 8: 500// if (this.is_multiple && this.backstroke_length < 1 && this.choices_count() > 0) { 501// this.keydown_backstroke(); 502// } else if (!this.pending_backstroke) { 503// this.result_clear_highlight(); 504// this.results_search(); 505// } 506// break; 507// case 13: 508// evt.preventDefault(); 509// if (this.results_showing) { 510// this.result_select(evt); 511// } 512// break; 513// case 27: 514// if (this.results_showing) { 515// this.results_hide(); 516// } 517// break; 518// case 9: 519// case 16: 520// case 17: 521// case 18: 522// case 38: 523// case 40: 524// case 91: 525// break; 526// default: 527// this.results_search(); 528// break; 529// } 530// }; 531 532// AbstractChosen.prototype.clipboard_event_checker = function(evt) { 533// if (this.is_disabled) { 534// return; 535// } 536// return setTimeout(((function(_this) { 537// return function() { 538// return _this.results_search(); 539// }; 540// })(this)), 50); 541// }; 542 543// AbstractChosen.prototype.container_width = function() { 544// if (this.options.width != null) { 545// return this.options.width; 546// } else { 547// return this.form_field.offsetWidth + "px"; 548// } 549// }; 550 551// AbstractChosen.prototype.include_option_in_results = function(option) { 552// if (this.is_multiple && (!this.display_selected_options && option.selected)) { 553// return false; 554// } 555// if (!this.display_disabled_options && option.disabled) { 556// return false; 557// } 558// if (option.empty) { 559// return false; 560// } 561// return true; 562// }; 563 564// AbstractChosen.prototype.search_results_touchstart = function(evt) { 565// this.touch_started = true; 566// return this.search_results_mouseover(evt); 567// }; 568 569// AbstractChosen.prototype.search_results_touchmove = function(evt) { 570// this.touch_started = false; 571// return this.search_results_mouseout(evt); 572// }; 573 574// AbstractChosen.prototype.search_results_touchend = function(evt) { 575// if (this.touch_started) { 576// return this.search_results_mouseup(evt); 577// } 578// }; 579 580// AbstractChosen.prototype.outerHTML = function(element) { 581// var tmp; 582// if (element.outerHTML) { 583// return element.outerHTML; 584// } 585// tmp = document.createElement("div"); 586// tmp.appendChild(element); 587// return tmp.innerHTML; 588// }; 589 590// AbstractChosen.prototype.get_single_html = function() { 591// 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>"; 592// }; 593 594// AbstractChosen.prototype.get_multi_html = function() { 595// 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>"; 596// }; 597 598// AbstractChosen.prototype.get_no_results_html = function(terms) { 599// return "<li class=\"no-results\">\n " + this.results_none_found + " <span>" + (this.escape_html(terms)) + "</span>\n</li>"; 600// }; 601 602// AbstractChosen.browser_is_supported = function() { 603// if ("Microsoft Internet Explorer" === window.navigator.appName) { 604// return document.documentMode >= 8; 605// } 606// // 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)) { 607// // return false;
608// // } 609// return true; 610// }; 611 612// AbstractChosen.default_multiple_text = "Select Some Options"; 613 614// AbstractChosen.default_single_text = "Select an Option"; 615 616// AbstractChosen.default_no_result_text = "No results match"; 617 618// return AbstractChosen; 619 620// })(); 621 622// $ = jQuery; 623 624// $.fn.extend({ 625// chosen: function(options) { 626// if (!AbstractChosen.browser_is_supported()) { 627// return this; 628// } 629// return this.each(function(input_field) { 630// var $this, chosen; 631// $this = $(this); 632// chosen = $this.data('chosen'); 633// if (options === 'destroy') { 634// if (chosen instanceof Chosen) { 635// chosen.destroy(); 636// } 637// return; 638// } 639// if (!(chosen instanceof Chosen)) { 640// $this.data('chosen', new Chosen(this, options)); 641// } 642// }); 643// } 644// }); 645 646// Chosen = (function(superClass) { 647// extend(Chosen, superClass); 648 649// function Chosen() { 650// return Chosen.__super__.constructor.apply(this, arguments); 651// } 652 653// Chosen.prototype.setup = function() { 654// this.form_field_jq = $(this.form_field); 655// return this.current_selectedIndex = this.form_field.selectedIndex; 656// }; 657 658// Chosen.prototype.set_up_html = function() {
659// var container_classes, container_props; 660// container_classes = ["chosen-container"]; 661// container_classes.push("chosen-container-" + (this.is_multiple ? "multi" : "single")); 662// if (this.inherit_select_classes && this.form_field.className) { 663// container_classes.push(this.form_field.className); 664// } 665// if (this.is_rtl) { 666// container_classes.push("chosen-rtl"); 667// } 668// container_props = { 669// 'class': container_classes.join(' '), 670// 'title': this.form_field.title 671// }; 672// if (this.form_field.id.length) { 673// container_props.id = this.form_field.id.replace(/[^\w]/g, '_') + "_chosen"; 674// } 675// this.container = $("<div />", container_props); 676// this.container.width(this.container_width()); 677// if (this.is_multiple) { 678// this.container.html(this.get_multi_html()); 679// } else { 680// this.container.html(this.get_single_html()); 681// } 682// this.form_field_jq.hide().after(this.container); 683// this.dropdown = this.container.find('div.chosen-drop').first(); 684// this.search_field = this.container.find('input').first(); 685// this.search_results = this.container.find('ul.chosen-results').first(); 686// this.search_field_scale(); 687// this.search_no_results = this.container.find('li.no-results').first(); 688// if (this.is_multiple) { 689// this.search_choices = this.container.find('ul.chosen-choices').first(); 690// this.search_container = this.container.find('li.search-field').first(); 691// } else { 692// this.search_container = this.container.find('div.chosen-search').first(); 693// this.selected_item = this.container.find('.chosen-single').first(); 694// } 695// this.results_build(); 696// this.set_tab_index(); 697// return this.set_label_behavior(); 698// }; 699 700// Chosen.prototype.on_ready = function() { 701// return this.form_field_jq.trigger("chosen:ready", { 702// chosen: this 703// }); 704// }; 705 706// Chosen.prototype.register_observers = function() { 707// this.container.on('touchstart.chosen', (function(_this) { 708// return function(evt) { 709// _this.container_mousedown(evt); 710// }; 711// })(this)); 712// this.container.on('touchend.chosen', (function(_this) { 713// return function(evt) { 714// _this.container_mouseup(evt); 715// }; 716// })(this)); 717// this.container.on('mousedown.chosen', (function(_this) { 718// return function(evt) { 719// _this.container_mousedown(evt); 720// }; 721// })(this)); 722// this.container.on('mouseup.chosen', (function(_this) { 723// return function(evt) { 724// _this.container_mouseup(evt); 725// }; 726// })(this)); 727// this.container.on('mouseenter.chosen', (function(_this) { 728// return function(evt) { 729// _this.mouse_enter(evt); 730// }; 731// })(this)); 732// this.container.on('mouseleave.chosen', (function(_this) { 733// return function(evt) { 734// _this.mouse_leave(evt); 735// }; 736// })(this)); 737// this.search_results.on('mouseup.chosen', (function(_this) { 738// return function(evt) { 739// _this.search_results_mouseup(evt); 740// }; 741// })(this)); 742// this.search_results.on('mouseover.chosen', (function(_this) { 743// return function(evt) { 744// _this.search_results_mouseover(evt); 745// }; 746// })(this)); 747// this.search_results.on('mouseout.chosen', (function(_this) { 748// return function(evt) { 749// _this.search_results_mouseout(evt); 750// }; 751// })(this)); 752// this.search_results.on('mousewheel.chosen DOMMouseScroll.chosen', (function(_this) { 753// return function(evt) { 754// _this.search_results_mousewheel(evt); 755// }; 756// })(this)); 757// this.search_results.on('touchstart.chosen', (function(_this) { 758// return function(evt) { 759// _this.search_results_touchstart(evt); 760// }; 761// })(this)); 762// this.search_results.on('touchmove.chosen', (function(_this) { 763// return function(evt) { 764// _this.search_results_touchmove(evt); 765// }; 766// })(this)); 767// this.search_results.on('touchend.chosen', (function(_this) { 768// return function(evt) { 769// _this.search_results_touchend(evt); 770// }; 771// })(this)); 772// this.form_field_jq.on("chosen:updated.chosen", (function(_this) { 773// return function(evt) { 774// _this.results_update_field(evt); 775// }; 776// })(this)); 777// this.form_field_jq.on("chosen:activate.chosen", (function(_this) { 778// return function(evt) { 779// _this.activate_field(evt); 780// }; 781// })(this)); 782// this.form_field_jq.on("chosen:open.chosen", (function(_this) { 783// return function(evt) { 784// _this.container_mousedown(evt); 785// }; 786// })(this)); 787// this.form_field_jq.on("chosen:close.chosen", (function(_this) { 788// return function(evt) { 789// _this.close_field(evt); 790// }; 791// })(this)); 792// this.search_field.on('blur.chosen', (function(_this) { 793// return function(evt) { 794// _this.input_blur(evt); 795// }; 796// })(this)); 797// this.search_field.on('keyup.chosen', (function(_this) { 798// return function(evt) { 799// _this.keyup_checker(evt); 800// }; 801// })(this)); 802// this.search_field.on('keydown.chosen', (function(_this) { 803// return function(evt) { 804// _this.keydown_checker(evt); 805// }; 806// })(this)); 807// this.search_field.on('focus.chosen', (function(_this) { 808// return function(evt) { 809// _this.input_focus(evt); 810// }; 811// })(this)); 812// this.search_field.on('cut.chosen', (function(_this) { 813// return function(evt) { 814// _this.clipboard_event_checker(evt); 815// }; 816// })(this)); 817// this.search_field.on('paste.chosen', (function(_this) { 818// return function(evt) { 819// _this.clipboard_event_checker(evt); 820// }; 821// })(this)); 822// if (this.is_multiple) { 823// return this.search_choices.on('click.chosen', (function(_this) { 824// return function(evt) { 825// _this.choices_click(evt); 826// }; 827// })(this)); 828// } else { 829// return this.container.on('click.chosen', function(evt) { 830// evt.preventDefault(); 831// }); 832// } 833// }; 834 835// Chosen.prototype.destroy = function() { 836// $(this.container[0].ownerDocument).off('click.chosen', this.click_test_action); 837// if (this.form_field_label.length > 0) { 838// this.form_field_label.off('click.chosen'); 839// } 840// if (this.search_field[0].tabIndex) { 841// this.form_field_jq[0].tabIndex = this.search_field[0].tabIndex; 842// } 843// this.container.remove(); 844// this.form_field_jq.removeData('chosen'); 845// return this.form_field_jq.show(); 846// }; 847 848// Chosen.prototype.search_field_disabled = function() { 849// this.is_disabled = this.form_field.disabled || this.form_field_jq.parents('fieldset').is(':disabled'); 850// this.container.toggleClass('chosen-disabled', this.is_disabled); 851// this.search_field[0].disabled = this.is_disabled; 852// if (!this.is_multiple) { 853// this.selected_item.off('focus.chosen', this.activate_field); 854// } 855// if (this.is_disabled) { 856// return this.close_field(); 857// } else if (!this.is_multiple) { 858// return this.selected_item.on('focus.chosen', this.activate_field); 859// } 860// }; 861 862// Chosen.prototype.container_mousedown = function(evt) { 863// var ref; 864// if (this.is_disabled) { 865// return; 866// } 867// if (evt && ((ref = evt.type) === 'mousedown' || ref === 'touchstart') && !this.results_showing) { 868// evt.preventDefault(); 869// } 870// if (!((evt != null) && ($(evt.target)).hasClass("search-choice-close"))) { 871// if (!this.active_field) { 872// if (this.is_multiple) { 873// this.search_field.val(""); 874// } 875// $(this.container[0].ownerDocument).on('click.chosen', this.click_test_action); 876// this.results_show(); 877// } else if (!this.is_multiple && evt && (($(evt.target)[0] === this.selected_item[0]) || $(evt.target).parents("a.chosen-single").length)) { 878// evt.preventDefault();
879// this.results_toggle(); 880// } 881// return this.activate_field(); 882// } 883// }; 884 885// Chosen.prototype.container_mouseup = function(evt) { 886// if (evt.target.nodeName === "ABBR" && !this.is_disabled) { 887// return this.results_reset(evt); 888// } 889// }; 890 891// Chosen.prototype.search_results_mousewheel = function(evt) { 892// var delta; 893// if (evt.originalEvent) { 894// delta = evt.originalEvent.deltaY || -evt.originalEvent.wheelDelta || evt.originalEvent.detail; 895// } 896// if (delta != null) { 897// evt.preventDefault(); 898// if (evt.type === 'DOMMouseScroll') { 899// delta = delta * 40; 900// } 901// return this.search_results.scrollTop(delta + this.search_results.scrollTop()); 902// } 903// }; 904 905// Chosen.prototype.blur_test = function(evt) { 906// if (!this.active_field && this.container.hasClass("chosen-container-active")) { 907// return this.close_field(); 908// } 909// }; 910 911// Chosen.prototype.close_field = function() { 912// $(this.container[0].ownerDocument).off("click.chosen", this.click_test_action); 913// this.active_field = false; 914// this.results_hide(); 915// this.container.removeClass("chosen-container-active"); 916// this.clear_backstroke(); 917// this.show_search_field_default(); 918// this.search_field_scale(); 919// return this.search_field.blur(); 920// }; 921 922// Chosen.prototype.activate_field = function() { 923// if (this.is_disabled) { 924// return; 925// } 926// this.container.addClass("chosen-container-active"); 927// this.active_field = true; 928// this.search_field.val(this.search_field.val()); 929// return this.search_field.focus(); 930// }; 931 932// Chosen.prototype.test_active_click = function(evt) { 933// var active_container; 934// active_container = $(evt.target).closest('.chosen-container'); 935// if (active_container.length && this.container[0] === active_container[0]) { 936// return this.active_field = true; 937// } else { 938// return this.close_field(); 939// } 940// }; 941 942// Chosen.prototype.results_build = function() { 943// this.parsing = true; 944// this.selected_option_count = null; 945// this.results_data = SelectParser.select_to_array(this.form_field); 946// if (this.is_multiple) { 947// this.search_choices.find("li.search-choice").remove(); 948// } else { 949// this.single_set_selected_text(); 950// if (this.disable_search || this.form_field.options.length <= this.disable_search_threshold) { 951// this.search_field[0].readOnly = true; 952// this.container.addClass("chosen-container-single-nosearch"); 953// } else { 954// this.search_field[0].readOnly = false; 955// this.container.removeClass("chosen-container-single-nosearch"); 956// } 957// } 958// this.update_results_content(this.results_option_build({ 959// first: true 960// })); 961// this.search_field_disabled(); 962// this.show_search_field_default(); 963// this.search_field_scale(); 964// return this.parsing = false; 965// }; 966 967// Chosen.prototype.result_do_highlight = function(el) { 968// var high_bottom, high_top, maxHeight, visible_bottom, visible_top; 969// if (el.length) { 970// this.result_clear_highlight(); 971// this.result_highlight = el; 972// this.result_highlight.addClass("highlighted"); 973// maxHeight = parseInt(this.search_results.css("maxHeight"), 10); 974// visible_top = this.search_results.scrollTop(); 975// visible_bottom = maxHeight + visible_top; 976// high_top = this.result_highlight.position().top + this.search_results.scrollTop(); 977// high_bottom = high_top + this.result_highlight.outerHeight(); 978// if (high_bottom >= visible_bottom) { 979// return this.search_results.scrollTop((high_bottom - maxHeight) > 0 ? high_bottom - maxHeight : 0); 980// } else if (high_top < visible_top) { 981// return this.search_results.scrollTop(high_top); 982// } 983// } 984// }; 985 986// Chosen.prototype.result_clear_highlight = function() { 987// if (this.result_highlight) { 988// this.result_highlight.removeClass("highlighted"); 989// } 990// return this.result_highlight = null; 991// }; 992 993// Chosen.prototype.results_show = function() { 994// if (this.is_multiple && this.max_selected_options <= this.choices_count()) { 995// this.form_field_jq.trigger("chosen:maxselected", { 996// chosen: this 997// }); 998// return false;
999// } 1000// this.container.addClass("chosen-with-drop"); 1001// this.results_showing = true; 1002// this.search_field.focus(); 1003// this.search_field.val(this.get_search_field_value()); 1004// this.winnow_results(); 1005// return this.form_field_jq.trigger("chosen:showing_dropdown", { 1006// chosen: this 1007// }); 1008// }; 1009 1010// Chosen.prototype.update_results_content = function(content) { 1011// return this.search_results.html(content); 1012// }; 1013 1014// Chosen.prototype.results_hide = function() { 1015// if (this.results_showing) { 1016// this.result_clear_highlight(); 1017// this.container.removeClass("chosen-with-drop"); 1018// this.form_field_jq.trigger("chosen:hiding_dropdown", { 1019// chosen: this 1020// }); 1021// } 1022// return this.results_showing = false; 1023// }; 1024 1025// Chosen.prototype.set_tab_index = function(el) { 1026// var ti; 1027// if (this.form_field.tabIndex) { 1028// ti = this.form_field.tabIndex; 1029// this.form_field.tabIndex = -1; 1030// return this.search_field[0].tabIndex = ti; 1031// } 1032// }; 1033 1034// Chosen.prototype.set_label_behavior = function() { 1035// this.form_field_label = this.form_field_jq.parents("label"); 1036// if (!this.form_field_label.length && this.form_field.id.length) { 1037// this.form_field_label = $("label[for='" + this.form_field.id + "']"); 1038// } 1039// if (this.form_field_label.length > 0) { 1040// return this.form_field_label.on('click.chosen', this.label_click_handler); 1041// } 1042// }; 1043 1044// Chosen.prototype.show_search_field_default = function() { 1045// if (this.is_multiple && this.choices_count() < 1 && !this.active_field) { 1046// this.search_field.val(this.default_text); 1047// return this.search_field.addClass("default"); 1048// } else { 1049// this.search_field.val(""); 1050// return this.search_field.removeClass("default"); 1051// } 1052// }; 1053 1054// Chosen.prototype.search_results_mouseup = function(evt) { 1055// var target; 1056// target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first(); 1057// if (target.length) { 1058// this.result_highlight = target; 1059// this.result_select(evt); 1060// return this.search_field.focus(); 1061// } 1062// }; 1063 1064// Chosen.prototype.search_results_mouseover = function(evt) { 1065// var target; 1066// target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first(); 1067// if (target) { 1068// return this.result_do_highlight(target); 1069// } 1070// }; 1071 1072// Chosen.prototype.search_results_mouseout = function(evt) { 1073// if ($(evt.target).hasClass("active-result") || $(evt.target).parents('.active-result').first()) { 1074// return this.result_clear_highlight(); 1075// } 1076// }; 1077 1078// Chosen.prototype.choice_build = function(item) { 1079// var choice, close_link; 1080// choice = $('<li />', { 1081// "class": "search-choice" 1082// }).html("<span>" + (this.choice_label(item)) + "</span>"); 1083// if (item.disabled) { 1084// choice.addClass('search-choice-disabled'); 1085// } else { 1086// close_link = $('<a />', { 1087// "class": 'search-choice-close', 1088// 'data-option-array-index': item.array_index 1089// }); 1090// close_link.on('click.chosen', (function(_this) { 1091// return function(evt) { 1092// return _this.choice_destroy_link_click(evt); 1093// }; 1094// })(this)); 1095// choice.append(close_link); 1096// } 1097// return this.search_container.before(choice); 1098// }; 1099 1100// Chosen.prototype.choice_destroy_link_click = function(evt) { 1101// evt.preventDefault(); 1102// evt.stopPropagation(); 1103// if (!this.is_disabled) { 1104// return this.choice_destroy($(evt.target)); 1105// } 1106// }; 1107 1108// Chosen.prototype.choice_destroy = function(link) { 1109// if (this.result_deselect(link[0].getAttribute("data-option-array-index"))) { 1110// if (this.active_field) { 1111// this.search_field.focus(); 1112// } else { 1113// this.show_search_field_default(); 1114// } 1115// if (this.is_multiple && this.choices_count() > 0 && this.get_search_field_value().length < 1) { 1116// this.results_hide(); 1117// } 1118// link.parents('li').first().remove(); 1119// return this.search_field_scale(); 1120// } 1121// }; 1122 1123// Chosen.prototype.results_reset = function() { 1124// this.reset_single_select_options(); 1125// this.form_field.options[0].selected = true; 1126// this.single_set_selected_text(); 1127// this.show_search_field_default(); 1128// this.results_reset_cleanup(); 1129// this.trigger_form_field_change(); 1130// if (this.active_field) { 1131// return this.results_hide(); 1132// } 1133// }; 1134 1135// Chosen.prototype.results_reset_cleanup = function() { 1136// this.current_selectedIndex = this.form_field.selectedIndex; 1137// return this.selected_item.find("abbr").remove(); 1138// }; 1139 1140// Chosen.prototype.result_select = function(evt) { 1141// var high, item; 1142// if (this.result_highlight) { 1143// high = this.result_highlight; 1144// this.result_clear_highlight(); 1145// if (this.is_multiple && this.max_selected_options <= this.choices_count()) { 1146// this.form_field_jq.trigger("chosen:maxselected", { 1147// chosen: this 1148// }); 1149// return false;
1150// } 1151// if (this.is_multiple) { 1152// high.removeClass("active-result"); 1153// } else { 1154// this.reset_single_select_options(); 1155// } 1156// high.addClass("result-selected"); 1157// item = this.results_data[high[0].getAttribute("data-option-array-index")]; 1158// item.selected = true; 1159// this.form_field.options[item.options_index].selected = true; 1160// this.selected_option_count = null; 1161// if (this.is_multiple) { 1162// this.choice_build(item); 1163// } else { 1164// this.single_set_selected_text(this.choice_label(item)); 1165// } 1166// if (this.is_multiple && (!this.hide_results_on_select || (evt.metaKey || evt.ctrlKey))) { 1167// if (evt.metaKey || evt.ctrlKey) { 1168// this.winnow_results({ 1169// skip_highlight: true 1170// }); 1171// } else { 1172// this.search_field.val(""); 1173// this.winnow_results(); 1174// } 1175// } else { 1176// this.results_hide(); 1177// this.show_search_field_default(); 1178// } 1179// if (this.is_multiple || this.form_field.selectedIndex !== this.current_selectedIndex) { 1180// this.trigger_form_field_change({ 1181// selected: this.form_field.options[item.options_index].value 1182// }); 1183// } 1184// this.current_selectedIndex = this.form_field.selectedIndex; 1185// evt.preventDefault(); 1186// return this.search_field_scale(); 1187// } 1188// }; 1189 1190// Chosen.prototype.single_set_selected_text = function(text) { 1191// if (text == null) { 1192// text = this.default_text; 1193// } 1194// if (text === this.default_text) { 1195// this.selected_item.addClass("chosen-default"); 1196// } else { 1197// this.single_deselect_control_build(); 1198// this.selected_item.removeClass("chosen-default"); 1199// } 1200// return this.selected_item.find("span").html(text); 1201// }; 1202 1203// Chosen.prototype.result_deselect = function(pos) { 1204// var result_data; 1205// result_data = this.results_data[pos]; 1206// if (!this.form_field.options[result_data.options_index].disabled) { 1207// result_data.selected = false; 1208// this.form_field.options[result_data.options_index].selected = false; 1209// this.selected_option_count = null; 1210// this.result_clear_highlight(); 1211// if (this.results_showing) { 1212// this.winnow_results(); 1213// } 1214// this.trigger_form_field_change({ 1215// deselected: this.form_field.options[result_data.options_index].value 1216// }); 1217// this.search_field_scale(); 1218// return true; 1219// } else { 1220// return false; 1221// } 1222// }; 1223 1224// Chosen.prototype.single_deselect_control_build = function() { 1225// if (!this.allow_single_deselect) { 1226// return; 1227// } 1228// if (!this.selected_item.find("abbr").length) { 1229// this.selected_item.find("span").first().after("<abbr class=\"search-choice-close\"></abbr>"); 1230// } 1231// return this.selected_item.addClass("chosen-single-with-deselect"); 1232// }; 1233 1234// Chosen.prototype.get_search_field_value = function() { 1235// return this.search_field.val(); 1236// }; 1237 1238// Chosen.prototype.get_search_text = function() { 1239// return $.trim(this.get_search_field_value()); 1240// }; 1241 1242// Chosen.prototype.escape_html = function(text) { 1243// return $('<div/>').text(text).html(); 1244// }; 1245 1246// Chosen.prototype.winnow_results_set_highlight = function() { 1247// var do_high, selected_results; 1248// selected_results = !this.is_multiple ? this.search_results.find(".result-selected.active-result") : []; 1249// do_high = selected_results.length ? selected_results.first() : this.search_results.find(".active-result").first(); 1250// if (do_high != null) { 1251// return this.result_do_highlight(do_high); 1252// } 1253// }; 1254 1255// Chosen.prototype.no_results = function(terms) { 1256// var no_results_html; 1257// no_results_html = this.get_no_results_html(terms); 1258// this.search_results.append(no_results_html); 1259// return this.form_field_jq.trigger("chosen:no_results", { 1260// chosen: this 1261// }); 1262// }; 1263 1264// Chosen.prototype.no_results_clear = function() { 1265// return this.search_results.find(".no-results").remove(); 1266// }; 1267 1268// Chosen.prototype.keydown_arrow = function() { 1269// var next_sib; 1270// if (this.results_showing && this.result_highlight) { 1271// next_sib = this.result_highlight.nextAll("li.active-result").first(); 1272// if (next_sib) { 1273// return this.result_do_highlight(next_sib); 1274// } 1275// } else { 1276// return this.results_show(); 1277// } 1278// }; 1279 1280// Chosen.prototype.keyup_arrow = function() { 1281// var prev_sibs; 1282// if (!this.results_showing && !this.is_multiple) { 1283// return this.results_show(); 1284// } else if (this.result_highlight) { 1285// prev_sibs = this.result_highlight.prevAll("li.active-result"); 1286// if (prev_sibs.length) { 1287// return this.result_do_highlight(prev_sibs.first()); 1288// } else { 1289// if (this.choices_count() > 0) { 1290// this.results_hide(); 1291// } 1292// return this.result_clear_highlight(); 1293// } 1294// } 1295// }; 1296 1297// Chosen.prototype.keydown_backstroke = function() { 1298// var next_available_destroy; 1299// if (this.pending_backstroke) { 1300// this.choice_destroy(this.pending_backstroke.find("a").first()); 1301// return this.clear_backstroke(); 1302// } else { 1303// next_available_destroy = this.search_container.siblings("li.search-choice").last(); 1304// if (next_available_destroy.length && !next_available_destroy.hasClass("search-choice-disabled")) { 1305// this.pending_backstroke = next_available_destroy; 1306// if (this.single_backstroke_delete) { 1307// return this.keydown_backstroke(); 1308// } else { 1309// return this.pending_backstroke.addClass("search-choice-focus"); 1310// } 1311// } 1312// } 1313// }; 1314 1315// Chosen.prototype.clear_backstroke = function() { 1316// if (this.pending_backstroke) { 1317// this.pending_backstroke.removeClass("search-choice-focus"); 1318// } 1319// return this.pending_backstroke = null; 1320// }; 1321 1322// Chosen.prototype.search_field_scale = function() { 1323// var div, i, len, style, style_block, styles, width; 1324// if (!this.is_multiple) { 1325// return; 1326// } 1327// style_block = { 1328// position: 'absolute', 1329// left: '-1000px', 1330// top: '-1000px', 1331// display: 'none', 1332// whiteSpace: 'pre' 1333// }; 1334// styles = ['fontSize', 'fontStyle', 'fontWeight', 'fontFamily', 'lineHeight', 'textTransform', 'letterSpacing']; 1335// for (i = 0, len = styles.length; i < len; i++) { 1336// style = styles[i]; 1337// style_block[style] = this.search_field.css(style); 1338// }
vendor: 4,303 bytes, lines 1339-1473
1339// div = $('<div />').css(style_block); 1340// div.text(this.get_search_field_value()); 1341// $('body').append(div); 1342// width = div.width() + 25; 1343// div.remove(); 1344// if (this.container.is(':visible')) { 1345// width = Math.min(this.container.outerWidth() - 10, width); 1346// } 1347// return this.search_field.width(width); 1348// }; 1349 1350// Chosen.prototype.trigger_form_field_change = function(extra) { 1351// this.form_field_jq.trigger("input", extra); 1352// return this.form_field_jq.trigger("change", extra); 1353// }; 1354 1355// return Chosen; 1356 1357// })(AbstractChosen); 1358 1359// }).call(this); 1360 1361 1362 1363 1364 1365 1366 1367/*! 1368Chosen, a Select Box Enhancer for jQuery and Prototype 1369by Patrick Filler for Harvest, http://getharvest.com 1370 1371Version 1.8.7 1372Full source at https://github.com/harvesthq/chosen 1373Copyright (c) 2011-2018 Harvest http://getharvest.com 1374 1375MIT License, https://github.com/harvesthq/chosen/blob/master/LICENSE.md 1376This file is generated by `grunt build`, do not edit it by hand. 1377*/ 1378 1379(function() { 1380 var $, AbstractChosen, Chosen, SelectParser, 1381 bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, 1382 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; }, 1383 hasProp = {}.hasOwnProperty; 1384 1385 SelectParser = (function() { 1386 function SelectParser() { 1387 this.options_index = 0; 1388 this.parsed = []; 1389 } 1390 1391 SelectParser.prototype.add_node = function(child) { 1392 if (child.nodeName.toUpperCase() === "OPTGROUP") { 1393 return this.add_group(child); 1394 } else { 1395 return this.add_option(child); 1396 } 1397 }; 1398 1399 SelectParser.prototype.add_group = function(group) { 1400 var group_position, i, len, option, ref, results1; 1401 group_position = this.parsed.length; 1402 this.parsed.push({ 1403 array_index: group_position, 1404 group: true, 1405 label: group.label, 1406 title: group.title ? group.title : void 0, 1407 children: 0, 1408 disabled: group.disabled, 1409 classes: group.className 1410 }); 1411 ref = group.childNodes; 1412 results1 = []; 1413 for (i = 0, len = ref.length; i < len; i++) { 1414 option = ref[i]; 1415 results1.push(this.add_option(option, group_position, group.disabled)); 1416 } 1417 return results1; 1418 }; 1419 1420 SelectParser.prototype.add_option = function(option, group_position, group_disabled) { 1421 if (option.nodeName.toUpperCase() === "OPTION") { 1422 if (option.text !== "") { 1423 if (group_position != null) { 1424 this.parsed[group_position].children += 1; 1425 } 1426 this.parsed.push({ 1427 array_index: this.parsed.length, 1428 options_index: this.options_index, 1429 value: option.value, 1430 text: option.text, 1431 html: option.innerHTML, 1432 title: option.title ? option.title : void 0, 1433 selected: option.selected, 1434 disabled: group_disabled === true ? group_disabled : option.disabled, 1435 group_array_index: group_position, 1436 group_label: group_position != null ? this.parsed[group_position].label : null, 1437 classes: option.className, 1438 style: option.style.cssText 1439 }); 1440 } else { 1441 this.parsed.push({ 1442 array_index: this.parsed.length, 1443 options_index: this.options_index, 1444 empty: true 1445 }); 1446 } 1447 return this.options_index += 1; 1448 } 1449 }; 1450 1451 return SelectParser; 1452 1453 })(); 1454 1455 SelectParser.select_to_array = function(select) { 1456 var child, i, len, parser, ref; 1457 parser = new SelectParser(); 1458 ref = select.childNodes; 1459 for (i = 0, len = ref.length; i < len; i++) { 1460 child = ref[i]; 1461 parser.add_node(child); 1462 } 1463 return parser.parsed; 1464 }; 1465 1466 AbstractChosen = (function() { 1467 function AbstractChosen(form_field, options1) { 1468 this.form_field = form_field; 1469 this.options = options1 != null ? options1 : {}; 1470 this.label_click_handler = bind(this.label_click_handler, this); 1471 /*if (!AbstractChosen.browser_is_supported()) { 1472 return; 1473 }*/
vendor: 17,727 bytes, lines 1473-1972
1473 1474 this.is_multiple = this.form_field.multiple; 1475 this.set_default_text(); 1476 this.set_default_values(); 1477 this.setup(); 1478 this.set_up_html(); 1479 this.register_observers(); 1480 this.on_ready(); 1481 } 1482 1483 AbstractChosen.prototype.set_default_values = function() { 1484 this.click_test_action = (function(_this) { 1485 return function(evt) { 1486 return _this.test_active_click(evt); 1487 }; 1488 })(this); 1489 this.activate_action = (function(_this) { 1490 return function(evt) { 1491 return _this.activate_field(evt); 1492 }; 1493 })(this); 1494 this.active_field = false; 1495 this.mouse_on_container = false; 1496 this.results_showing = false; 1497 this.result_highlighted = null; 1498 this.is_rtl = this.options.rtl || /\bchosen-rtl\b/.test(this.form_field.className); 1499 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; 1500 this.disable_search_threshold = this.options.disable_search_threshold || 0; 1501 this.disable_search = this.options.disable_search || false; 1502 this.enable_split_word_search = this.options.enable_split_word_search != null ? this.options.enable_split_word_search : true; 1503 this.group_search = this.options.group_search != null ? this.options.group_search : true; 1504 this.search_contains = this.options.search_contains || false; 1505 this.single_backstroke_delete = this.options.single_backstroke_delete != null ? this.options.single_backstroke_delete : true; 1506 this.max_selected_options = this.options.max_selected_options || Infinity; 1507 this.inherit_select_classes = this.options.inherit_select_classes || false; 1508 this.display_selected_options = this.options.display_selected_options != null ? this.options.display_selected_options : true; 1509 this.display_disabled_options = this.options.display_disabled_options != null ? this.options.display_disabled_options : true; 1510 this.include_group_label_in_selected = this.options.include_group_label_in_selected || false; 1511 this.max_shown_results = this.options.max_shown_results || Number.POSITIVE_INFINITY; 1512 this.case_sensitive_search = this.options.case_sensitive_search || false; 1513 return this.hide_results_on_select = this.options.hide_results_on_select != null ? this.options.hide_results_on_select : true; 1514 }; 1515 1516 AbstractChosen.prototype.set_default_text = function() { 1517 if (this.form_field.getAttribute("data-placeholder")) { 1518 this.default_text = this.form_field.getAttribute("data-placeholder"); 1519 } else if (this.is_multiple) { 1520 this.default_text = this.options.placeholder_text_multiple || this.options.placeholder_text || AbstractChosen.default_multiple_text; 1521 } else { 1522 this.default_text = this.options.placeholder_text_single || this.options.placeholder_text || AbstractChosen.default_single_text; 1523 } 1524 this.default_text = this.escape_html(this.default_text); 1525 return this.results_none_found = this.form_field.getAttribute("data-no_results_text") || this.options.no_results_text || AbstractChosen.default_no_result_text; 1526 }; 1527 1528 AbstractChosen.prototype.choice_label = function(item) { 1529 if (this.include_group_label_in_selected && (item.group_label != null)) { 1530 return "<b class='group-name'>" + (this.escape_html(item.group_label)) + "</b>" + item.html; 1531 } else { 1532 return item.html; 1533 } 1534 }; 1535 1536 AbstractChosen.prototype.mouse_enter = function() { 1537 return this.mouse_on_container = true; 1538 }; 1539 1540 AbstractChosen.prototype.mouse_leave = function() { 1541 return this.mouse_on_container = false; 1542 }; 1543 1544 AbstractChosen.prototype.input_focus = function(evt) { 1545 if (this.is_multiple) { 1546 if (!this.active_field) { 1547 return setTimeout(((function(_this) { 1548 return function() { 1549 return _this.container_mousedown(); 1550 }; 1551 })(this)), 50); 1552 } 1553 } else { 1554 if (!this.active_field) { 1555 return this.activate_field(); 1556 } 1557 } 1558 }; 1559 1560 AbstractChosen.prototype.input_blur = function(evt) { 1561 if (!this.mouse_on_container) { 1562 this.active_field = false; 1563 return setTimeout(((function(_this) { 1564 return function() { 1565 return _this.blur_test(); 1566 }; 1567 })(this)), 100); 1568 } 1569 }; 1570 1571 AbstractChosen.prototype.label_click_handler = function(evt) { 1572 if (this.is_multiple) { 1573 return this.container_mousedown(evt); 1574 } else { 1575 return this.activate_field(); 1576 } 1577 }; 1578 1579 AbstractChosen.prototype.results_option_build = function(options) { 1580 var content, data, data_content, i, len, ref, shown_results; 1581 content = ''; 1582 shown_results = 0; 1583 ref = this.results_data; 1584 for (i = 0, len = ref.length; i < len; i++) { 1585 data = ref[i]; 1586 data_content = ''; 1587 if (data.group) { 1588 data_content = this.result_add_group(data); 1589 } else { 1590 data_content = this.result_add_option(data); 1591 } 1592 if (data_content !== '') { 1593 shown_results++; 1594 content += data_content; 1595 } 1596 if (options != null ? options.first : void 0) { 1597 if (data.selected && this.is_multiple) { 1598 this.choice_build(data); 1599 } else if (data.selected && !this.is_multiple) { 1600 this.single_set_selected_text(this.choice_label(data)); 1601 } 1602 } 1603 if (shown_results >= this.max_shown_results) { 1604 break; 1605 } 1606 } 1607 return content; 1608 }; 1609 1610 AbstractChosen.prototype.result_add_option = function(option) { 1611 var classes, option_el; 1612 if (!option.search_match) { 1613 return ''; 1614 } 1615 if (!this.include_option_in_results(option)) { 1616 return ''; 1617 } 1618 classes = []; 1619 if (!option.disabled && !(option.selected && this.is_multiple)) { 1620 classes.push("active-result"); 1621 } 1622 if (option.disabled && !(option.selected && this.is_multiple)) { 1623 classes.push("disabled-result"); 1624 } 1625 if (option.selected) { 1626 classes.push("result-selected"); 1627 } 1628 if (option.group_array_index != null) { 1629 classes.push("group-option"); 1630 } 1631 if (option.classes !== "") { 1632 classes.push(option.classes); 1633 } 1634 option_el = document.createElement("li"); 1635 option_el.className = classes.join(" "); 1636 if (option.style) { 1637 option_el.style.cssText = option.style; 1638 } 1639 option_el.setAttribute("data-option-array-index", option.array_index); 1640 option_el.innerHTML = option.highlighted_html || option.html; 1641 if (option.title) { 1642 option_el.title = option.title; 1643 } 1644 return this.outerHTML(option_el); 1645 }; 1646 1647 AbstractChosen.prototype.result_add_group = function(group) { 1648 var classes, group_el; 1649 if (!(group.search_match || group.group_match)) { 1650 return ''; 1651 } 1652 if (!(group.active_options > 0)) { 1653 return ''; 1654 } 1655 classes = []; 1656 classes.push("group-result"); 1657 if (group.classes) { 1658 classes.push(group.classes); 1659 } 1660 group_el = document.createElement("li"); 1661 group_el.className = classes.join(" "); 1662 group_el.innerHTML = group.highlighted_html || this.escape_html(group.label); 1663 if (group.title) { 1664 group_el.title = group.title; 1665 } 1666 return this.outerHTML(group_el); 1667 }; 1668 1669 AbstractChosen.prototype.results_update_field = function() { 1670 this.set_default_text(); 1671 if (!this.is_multiple) { 1672 this.results_reset_cleanup(); 1673 } 1674 this.result_clear_highlight(); 1675 this.results_build(); 1676 if (this.results_showing) { 1677 return this.winnow_results(); 1678 } 1679 }; 1680 1681 AbstractChosen.prototype.reset_single_select_options = function() { 1682 var i, len, ref, result, results1; 1683 ref = this.results_data; 1684 results1 = []; 1685 for (i = 0, len = ref.length; i < len; i++) { 1686 result = ref[i]; 1687 if (result.selected) { 1688 results1.push(result.selected = false); 1689 } else { 1690 results1.push(void 0); 1691 } 1692 } 1693 return results1; 1694 }; 1695 1696 AbstractChosen.prototype.results_toggle = function() { 1697 if (this.results_showing) { 1698 return this.results_hide(); 1699 } else { 1700 return this.results_show(); 1701 } 1702 }; 1703 1704 AbstractChosen.prototype.results_search = function(evt) { 1705 if (this.results_showing) { 1706 return this.winnow_results(); 1707 } else { 1708 return this.results_show(); 1709 } 1710 }; 1711 1712 AbstractChosen.prototype.winnow_results = function(options) { 1713 var escapedQuery, fix, i, len, option, prefix, query, ref, regex, results, results_group, search_match, startpos, suffix, text; 1714 this.no_results_clear(); 1715 results = 0; 1716 query = this.get_search_text(); 1717 escapedQuery = query.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"); 1718 regex = this.get_search_regex(escapedQuery); 1719 ref = this.results_data; 1720 for (i = 0, len = ref.length; i < len; i++) { 1721 option = ref[i]; 1722 option.search_match = false; 1723 results_group = null; 1724 search_match = null; 1725 option.highlighted_html = ''; 1726 if (this.include_option_in_results(option)) { 1727 if (option.group) { 1728 option.group_match = false; 1729 option.active_options = 0; 1730 } 1731 if ((option.group_array_index != null) && this.results_data[option.group_array_index]) { 1732 results_group = this.results_data[option.group_array_index]; 1733 if (results_group.active_options === 0 && results_group.search_match) { 1734 results += 1; 1735 } 1736 results_group.active_options += 1; 1737 } 1738 text = option.group ? option.label : option.text; 1739 if (!(option.group && !this.group_search)) { 1740 search_match = this.search_string_match(text, regex); 1741 option.search_match = search_match != null; 1742 if (option.search_match && !option.group) { 1743 results += 1; 1744 } 1745 if (option.search_match) { 1746 if (query.length) { 1747 startpos = search_match.index; 1748 prefix = text.slice(0, startpos); 1749 fix = text.slice(startpos, startpos + query.length); 1750 suffix = text.slice(startpos + query.length); 1751 option.highlighted_html = (this.escape_html(prefix)) + "<em>" + (this.escape_html(fix)) + "</em>" + (this.escape_html(suffix)); 1752 } 1753 if (results_group != null) { 1754 results_group.group_match = true; 1755 } 1756 } else if ((option.group_array_index != null) && this.results_data[option.group_array_index].search_match) { 1757 option.search_match = true; 1758 } 1759 } 1760 } 1761 } 1762 this.result_clear_highlight(); 1763 if (results < 1 && query.length) { 1764 this.update_results_content(""); 1765 return this.no_results(query); 1766 } else { 1767 this.update_results_content(this.results_option_build()); 1768 if (!(options != null ? options.skip_highlight : void 0)) { 1769 return this.winnow_results_set_highlight(); 1770 } 1771 } 1772 }; 1773 1774 AbstractChosen.prototype.get_search_regex = function(escaped_search_string) { 1775 var regex_flag, regex_string; 1776 regex_string = this.search_contains ? escaped_search_string : "(^|\\s|\\b)" + escaped_search_string + "[^\\s]*"; 1777 if (!(this.enable_split_word_search || this.search_contains)) { 1778 regex_string = "^" + regex_string; 1779 } 1780 regex_flag = this.case_sensitive_search ? "" : "i"; 1781 return new RegExp(regex_string, regex_flag); 1782 }; 1783 1784 AbstractChosen.prototype.search_string_match = function(search_string, regex) { 1785 var match; 1786 match = regex.exec(search_string); 1787 if (!this.search_contains && (match != null ? match[1] : void 0)) { 1788 match.index += 1; 1789 } 1790 return match; 1791 }; 1792 1793 AbstractChosen.prototype.choices_count = function() { 1794 var i, len, option, ref; 1795 if (this.selected_option_count != null) { 1796 return this.selected_option_count; 1797 } 1798 this.selected_option_count = 0; 1799 ref = this.form_field.options; 1800 for (i = 0, len = ref.length; i < len; i++) { 1801 option = ref[i]; 1802 if (option.selected) { 1803 this.selected_option_count += 1; 1804 } 1805 } 1806 return this.selected_option_count; 1807 }; 1808 1809 AbstractChosen.prototype.choices_click = function(evt) { 1810 evt.preventDefault(); 1811 this.activate_field(); 1812 if (!(this.results_showing || this.is_disabled)) { 1813 return this.results_show(); 1814 } 1815 }; 1816 1817 AbstractChosen.prototype.keydown_checker = function(evt) { 1818 var ref, stroke; 1819 stroke = (ref = evt.which) != null ? ref : evt.keyCode; 1820 this.search_field_scale(); 1821 if (stroke !== 8 && this.pending_backstroke) { 1822 this.clear_backstroke(); 1823 } 1824 switch (stroke) { 1825 case 8: 1826 this.backstroke_length = this.get_search_field_value().length; 1827 break; 1828 case 9: 1829 if (this.results_showing && !this.is_multiple) { 1830 this.result_select(evt); 1831 } 1832 this.mouse_on_container = false; 1833 break; 1834 case 13: 1835 if (this.results_showing) { 1836 evt.preventDefault(); 1837 } 1838 break; 1839 case 27: 1840 if (this.results_showing) { 1841 evt.preventDefault(); 1842 } 1843 break; 1844 case 32: 1845 if (this.disable_search) { 1846 evt.preventDefault(); 1847 } 1848 break; 1849 case 38: 1850 evt.preventDefault(); 1851 this.keyup_arrow(); 1852 break; 1853 case 40: 1854 evt.preventDefault(); 1855 this.keydown_arrow(); 1856 break; 1857 } 1858 }; 1859 1860 AbstractChosen.prototype.keyup_checker = function(evt) { 1861 var ref, stroke; 1862 stroke = (ref = evt.which) != null ? ref : evt.keyCode; 1863 this.search_field_scale(); 1864 switch (stroke) { 1865 case 8: 1866 if (this.is_multiple && this.backstroke_length < 1 && this.choices_count() > 0) { 1867 this.keydown_backstroke(); 1868 } else if (!this.pending_backstroke) { 1869 this.result_clear_highlight(); 1870 this.results_search(); 1871 } 1872 break; 1873 case 13: 1874 evt.preventDefault(); 1875 if (this.results_showing) { 1876 this.result_select(evt); 1877 } 1878 break; 1879 case 27: 1880 if (this.results_showing) { 1881 this.results_hide(); 1882 } 1883 break; 1884 case 9: 1885 case 16: 1886 case 17: 1887 case 18: 1888 case 38: 1889 case 40: 1890 case 91: 1891 break; 1892 default: 1893 this.results_search(); 1894 break; 1895 } 1896 }; 1897 1898 AbstractChosen.prototype.clipboard_event_checker = function(evt) { 1899 if (this.is_disabled) { 1900 return; 1901 } 1902 return setTimeout(((function(_this) { 1903 return function() { 1904 return _this.results_search(); 1905 }; 1906 })(this)), 50); 1907 }; 1908 1909 AbstractChosen.prototype.container_width = function() { 1910 if (this.options.width != null) { 1911 return this.options.width; 1912 } else { 1913 return this.form_field.offsetWidth + "px"; 1914 } 1915 }; 1916 1917 AbstractChosen.prototype.include_option_in_results = function(option) { 1918 if (this.is_multiple && (!this.display_selected_options && option.selected)) { 1919 return false; 1920 } 1921 if (!this.display_disabled_options && option.disabled) { 1922 return false; 1923 } 1924 if (option.empty) { 1925 return false; 1926 } 1927 return true; 1928 }; 1929 1930 AbstractChosen.prototype.search_results_touchstart = function(evt) { 1931 this.touch_started = true; 1932 return this.search_results_mouseover(evt); 1933 }; 1934 1935 AbstractChosen.prototype.search_results_touchmove = function(evt) { 1936 this.touch_started = false; 1937 return this.search_results_mouseout(evt); 1938 }; 1939 1940 AbstractChosen.prototype.search_results_touchend = function(evt) { 1941 if (this.touch_started) { 1942 return this.search_results_mouseup(evt); 1943 } 1944 }; 1945 1946 AbstractChosen.prototype.outerHTML = function(element) { 1947 var tmp; 1948 if (element.outerHTML) { 1949 return element.outerHTML; 1950 } 1951 tmp = document.createElement("div"); 1952 tmp.appendChild(element); 1953 return tmp.innerHTML; 1954 }; 1955 1956 AbstractChosen.prototype.get_single_html = function() { 1957 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>"; 1958 }; 1959 1960 AbstractChosen.prototype.get_multi_html = function() { 1961 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>"; 1962 }; 1963 1964 AbstractChosen.prototype.get_no_results_html = function(terms) { 1965 return "<li class=\"no-results\">\n " + this.results_none_found + " <span>" + (this.escape_html(terms)) + "</span>\n</li>"; 1966 }; 1967 1968 AbstractChosen.browser_is_supported = function() { 1969 if ("Microsoft Internet Explorer" === window.navigator.appName) { 1970 return document.documentMode >= 8; 1971 } 1972
1972/*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)) { 1973 return false; 1974 }*/
vendor: 25,771 bytes, lines 1974-2725
1974 1975 return true; 1976 }; 1977 1978 AbstractChosen.default_multiple_text = "Select Some Options"; 1979 1980 AbstractChosen.default_single_text = "Select an Option"; 1981 1982 AbstractChosen.default_no_result_text = "No results match"; 1983 1984 return AbstractChosen; 1985 1986 })(); 1987 1988 $ = jQuery; 1989 1990 $.fn.extend({ 1991 chosen: function(options) { 1992 if (!AbstractChosen.browser_is_supported()) { 1993 return this; 1994 } 1995 return this.each(function(input_field) { 1996 var $this, chosen; 1997 $this = $(this); 1998 chosen = $this.data('chosen'); 1999 if (options === 'destroy') { 2000 if (chosen instanceof Chosen) { 2001 chosen.destroy(); 2002 } 2003 return; 2004 } 2005 if (!(chosen instanceof Chosen)) { 2006 $this.data('chosen', new Chosen(this, options)); 2007 } 2008 }); 2009 } 2010 }); 2011 2012 Chosen = (function(superClass) { 2013 extend(Chosen, superClass); 2014 2015 function Chosen() { 2016 return Chosen.__super__.constructor.apply(this, arguments); 2017 } 2018 2019 Chosen.prototype.setup = function() { 2020 this.form_field_jq = $(this.form_field); 2021 return this.current_selectedIndex = this.form_field.selectedIndex; 2022 }; 2023 2024 Chosen.prototype.set_up_html = function() { 2025 var container_classes, container_props; 2026 container_classes = ["chosen-container"]; 2027 container_classes.push("chosen-container-" + (this.is_multiple ? "multi" : "single")); 2028 if (this.inherit_select_classes && this.form_field.className) { 2029 container_classes.push(this.form_field.className); 2030 } 2031 if (this.is_rtl) { 2032 container_classes.push("chosen-rtl"); 2033 } 2034 container_props = { 2035 'class': container_classes.join(' '), 2036 'title': this.form_field.title 2037 }; 2038 if (this.form_field.id.length) { 2039 container_props.id = this.form_field.id.replace(/[^\w]/g, '_') + "_chosen"; 2040 } 2041 this.container = $("<div />", container_props); 2042 this.container.width(this.container_width()); 2043 if (this.is_multiple) { 2044 this.container.html(this.get_multi_html()); 2045 } else { 2046 this.container.html(this.get_single_html()); 2047 } 2048 this.form_field_jq.hide().after(this.container); 2049 this.dropdown = this.container.find('div.chosen-drop').first(); 2050 this.search_field = this.container.find('input').first(); 2051 this.search_results = this.container.find('ul.chosen-results').first(); 2052 this.search_field_scale(); 2053 this.search_no_results = this.container.find('li.no-results').first(); 2054 if (this.is_multiple) { 2055 this.search_choices = this.container.find('ul.chosen-choices').first(); 2056 this.search_container = this.container.find('li.search-field').first(); 2057 } else { 2058 this.search_container = this.container.find('div.chosen-search').first(); 2059 this.selected_item = this.container.find('.chosen-single').first(); 2060 } 2061 this.results_build(); 2062 this.set_tab_index(); 2063 return this.set_label_behavior(); 2064 }; 2065 2066 Chosen.prototype.on_ready = function() { 2067 return this.form_field_jq.trigger("chosen:ready", { 2068 chosen: this 2069 }); 2070 }; 2071 2072 Chosen.prototype.register_observers = function() { 2073 this.container.on('touchstart.chosen', (function(_this) { 2074 return function(evt) { 2075 _this.container_mousedown(evt); 2076 }; 2077 })(this)); 2078 this.container.on('touchend.chosen', (function(_this) { 2079 return function(evt) { 2080 _this.container_mouseup(evt); 2081 }; 2082 })(this)); 2083 this.container.on('mousedown.chosen', (function(_this) { 2084 return function(evt) { 2085 _this.container_mousedown(evt); 2086 }; 2087 })(this)); 2088 this.container.on('mouseup.chosen', (function(_this) { 2089 return function(evt) { 2090 _this.container_mouseup(evt); 2091 }; 2092 })(this)); 2093 this.container.on('mouseenter.chosen', (function(_this) { 2094 return function(evt) { 2095 _this.mouse_enter(evt); 2096 }; 2097 })(this)); 2098 this.container.on('mouseleave.chosen', (function(_this) { 2099 return function(evt) { 2100 _this.mouse_leave(evt); 2101 }; 2102 })(this)); 2103 this.search_results.on('mouseup.chosen', (function(_this) { 2104 return function(evt) { 2105 _this.search_results_mouseup(evt); 2106 }; 2107 })(this)); 2108 this.search_results.on('mouseover.chosen', (function(_this) { 2109 return function(evt) { 2110 _this.search_results_mouseover(evt); 2111 }; 2112 })(this)); 2113 this.search_results.on('mouseout.chosen', (function(_this) { 2114 return function(evt) { 2115 _this.search_results_mouseout(evt); 2116 }; 2117 })(this)); 2118 this.search_results.on('mousewheel.chosen DOMMouseScroll.chosen', (function(_this) { 2119 return function(evt) { 2120 _this.search_results_mousewheel(evt); 2121 }; 2122 })(this)); 2123 this.search_results.on('touchstart.chosen', (function(_this) { 2124 return function(evt) { 2125 _this.search_results_touchstart(evt); 2126 }; 2127 })(this)); 2128 this.search_results.on('touchmove.chosen', (function(_this) { 2129 return function(evt) { 2130 _this.search_results_touchmove(evt); 2131 }; 2132 })(this)); 2133 this.search_results.on('touchend.chosen', (function(_this) { 2134 return function(evt) { 2135 _this.search_results_touchend(evt); 2136 }; 2137 })(this)); 2138 this.form_field_jq.on("chosen:updated.chosen", (function(_this) { 2139 return function(evt) { 2140 _this.results_update_field(evt); 2141 }; 2142 })(this)); 2143 this.form_field_jq.on("chosen:activate.chosen", (function(_this) { 2144 return function(evt) { 2145 _this.activate_field(evt); 2146 }; 2147 })(this)); 2148 this.form_field_jq.on("chosen:open.chosen", (function(_this) { 2149 return function(evt) { 2150 _this.container_mousedown(evt); 2151 }; 2152 })(this)); 2153 this.form_field_jq.on("chosen:close.chosen", (function(_this) { 2154 return function(evt) { 2155 _this.close_field(evt); 2156 }; 2157 })(this)); 2158 this.search_field.on('blur.chosen', (function(_this) { 2159 return function(evt) { 2160 _this.input_blur(evt); 2161 }; 2162 })(this)); 2163 this.search_field.on('keyup.chosen', (function(_this) { 2164 return function(evt) { 2165 _this.keyup_checker(evt); 2166 }; 2167 })(this)); 2168 this.search_field.on('keydown.chosen', (function(_this) { 2169 return function(evt) { 2170 _this.keydown_checker(evt); 2171 }; 2172 })(this)); 2173 this.search_field.on('focus.chosen', (function(_this) { 2174 return function(evt) { 2175 _this.input_focus(evt); 2176 }; 2177 })(this)); 2178 this.search_field.on('cut.chosen', (function(_this) { 2179 return function(evt) { 2180 _this.clipboard_event_checker(evt); 2181 }; 2182 })(this)); 2183 this.search_field.on('paste.chosen', (function(_this) { 2184 return function(evt) { 2185 _this.clipboard_event_checker(evt); 2186 }; 2187 })(this)); 2188 if (this.is_multiple) { 2189 return this.search_choices.on('click.chosen', (function(_this) { 2190 return function(evt) { 2191 _this.choices_click(evt); 2192 }; 2193 })(this)); 2194 } else { 2195 return this.container.on('click.chosen', function(evt) { 2196 evt.preventDefault(); 2197 }); 2198 } 2199 }; 2200 2201 Chosen.prototype.destroy = function() { 2202 $(this.container[0].ownerDocument).off('click.chosen', this.click_test_action); 2203 if (this.form_field_label.length > 0) { 2204 this.form_field_label.off('click.chosen'); 2205 } 2206 if (this.search_field[0].tabIndex) { 2207 this.form_field_jq[0].tabIndex = this.search_field[0].tabIndex; 2208 } 2209 this.container.remove(); 2210 this.form_field_jq.removeData('chosen'); 2211 return this.form_field_jq.show(); 2212 }; 2213 2214 Chosen.prototype.search_field_disabled = function() { 2215 this.is_disabled = this.form_field.disabled || this.form_field_jq.parents('fieldset').is(':disabled'); 2216 this.container.toggleClass('chosen-disabled', this.is_disabled); 2217 this.search_field[0].disabled = this.is_disabled; 2218 if (!this.is_multiple) { 2219 this.selected_item.off('focus.chosen', this.activate_field); 2220 } 2221 if (this.is_disabled) { 2222 return this.close_field(); 2223 } else if (!this.is_multiple) { 2224 return this.selected_item.on('focus.chosen', this.activate_field); 2225 } 2226 }; 2227 2228 Chosen.prototype.container_mousedown = function(evt) { 2229 var ref; 2230 if (this.is_disabled) { 2231 return; 2232 } 2233 if (evt && ((ref = evt.type) === 'mousedown' || ref === 'touchstart') && !this.results_showing) { 2234 evt.preventDefault(); 2235 } 2236 if (!((evt != null) && ($(evt.target)).hasClass("search-choice-close"))) { 2237 if (!this.active_field) { 2238 if (this.is_multiple) { 2239 this.search_field.val(""); 2240 } 2241 $(this.container[0].ownerDocument).on('click.chosen', this.click_test_action); 2242 this.results_show(); 2243 } else if (!this.is_multiple && evt && (($(evt.target)[0] === this.selected_item[0]) || $(evt.target).parents("a.chosen-single").length)) { 2244 evt.preventDefault(); 2245 this.results_toggle(); 2246 } 2247 return this.activate_field(); 2248 } 2249 }; 2250 2251 Chosen.prototype.container_mouseup = function(evt) { 2252 if (evt.target.nodeName === "ABBR" && !this.is_disabled) { 2253 return this.results_reset(evt); 2254 } 2255 }; 2256 2257 Chosen.prototype.search_results_mousewheel = function(evt) { 2258 var delta; 2259 if (evt.originalEvent) { 2260 delta = evt.originalEvent.deltaY || -evt.originalEvent.wheelDelta || evt.originalEvent.detail; 2261 } 2262 if (delta != null) { 2263 evt.preventDefault(); 2264 if (evt.type === 'DOMMouseScroll') { 2265 delta = delta * 40; 2266 } 2267 return this.search_results.scrollTop(delta + this.search_results.scrollTop()); 2268 } 2269 }; 2270 2271 Chosen.prototype.blur_test = function(evt) { 2272 if (!this.active_field && this.container.hasClass("chosen-container-active")) { 2273 return this.close_field(); 2274 } 2275 }; 2276 2277 Chosen.prototype.close_field = function() { 2278 $(this.container[0].ownerDocument).off("click.chosen", this.click_test_action); 2279 this.active_field = false; 2280 this.results_hide(); 2281 this.container.removeClass("chosen-container-active"); 2282 this.clear_backstroke(); 2283 this.show_search_field_default(); 2284 this.search_field_scale(); 2285 return this.search_field.blur(); 2286 }; 2287 2288 Chosen.prototype.activate_field = function() { 2289 if (this.is_disabled) { 2290 return; 2291 } 2292 this.container.addClass("chosen-container-active"); 2293 this.active_field = true; 2294 this.search_field.val(this.search_field.val()); 2295 return this.search_field.focus(); 2296 }; 2297 2298 Chosen.prototype.test_active_click = function(evt) { 2299 var active_container; 2300 active_container = $(evt.target).closest('.chosen-container'); 2301 if (active_container.length && this.container[0] === active_container[0]) { 2302 return this.active_field = true; 2303 } else { 2304 return this.close_field(); 2305 } 2306 }; 2307 2308 Chosen.prototype.results_build = function() { 2309 this.parsing = true; 2310 this.selected_option_count = null; 2311 this.results_data = SelectParser.select_to_array(this.form_field); 2312 if (this.is_multiple) { 2313 this.search_choices.find("li.search-choice").remove(); 2314 } else { 2315 this.single_set_selected_text(); 2316 if (this.disable_search || this.form_field.options.length <= this.disable_search_threshold) { 2317 this.search_field[0].readOnly = true; 2318 this.container.addClass("chosen-container-single-nosearch"); 2319 } else { 2320 this.search_field[0].readOnly = false; 2321 this.container.removeClass("chosen-container-single-nosearch"); 2322 } 2323 } 2324 this.update_results_content(this.results_option_build({ 2325 first: true 2326 })); 2327 this.search_field_disabled(); 2328 this.show_search_field_default(); 2329 this.search_field_scale(); 2330 return this.parsing = false; 2331 }; 2332 2333 Chosen.prototype.result_do_highlight = function(el) { 2334 var high_bottom, high_top, maxHeight, visible_bottom, visible_top; 2335 if (el.length) { 2336 this.result_clear_highlight(); 2337 this.result_highlight = el; 2338 this.result_highlight.addClass("highlighted"); 2339 maxHeight = parseInt(this.search_results.css("maxHeight"), 10); 2340 visible_top = this.search_results.scrollTop(); 2341 visible_bottom = maxHeight + visible_top; 2342 high_top = this.result_highlight.position().top + this.search_results.scrollTop(); 2343 high_bottom = high_top + this.result_highlight.outerHeight(); 2344 if (high_bottom >= visible_bottom) { 2345 return this.search_results.scrollTop((high_bottom - maxHeight) > 0 ? high_bottom - maxHeight : 0); 2346 } else if (high_top < visible_top) { 2347 return this.search_results.scrollTop(high_top); 2348 } 2349 } 2350 }; 2351 2352 Chosen.prototype.result_clear_highlight = function() { 2353 if (this.result_highlight) { 2354 this.result_highlight.removeClass("highlighted"); 2355 } 2356 return this.result_highlight = null; 2357 }; 2358 2359 Chosen.prototype.results_show = function() { 2360 if (this.is_multiple && this.max_selected_options <= this.choices_count()) { 2361 this.form_field_jq.trigger("chosen:maxselected", { 2362 chosen: this 2363 }); 2364 return false; 2365 } 2366 this.container.addClass("chosen-with-drop"); 2367 this.results_showing = true; 2368 this.search_field.focus(); 2369 this.search_field.val(this.get_search_field_value()); 2370 this.winnow_results(); 2371 return this.form_field_jq.trigger("chosen:showing_dropdown", { 2372 chosen: this 2373 }); 2374 }; 2375 2376 Chosen.prototype.update_results_content = function(content) { 2377 return this.search_results.html(content); 2378 }; 2379 2380 Chosen.prototype.results_hide = function() { 2381 if (this.results_showing) { 2382 this.result_clear_highlight(); 2383 this.container.removeClass("chosen-with-drop"); 2384 this.form_field_jq.trigger("chosen:hiding_dropdown", { 2385 chosen: this 2386 }); 2387 } 2388 return this.results_showing = false; 2389 }; 2390 2391 Chosen.prototype.set_tab_index = function(el) { 2392 var ti; 2393 if (this.form_field.tabIndex) { 2394 ti = this.form_field.tabIndex; 2395 this.form_field.tabIndex = -1; 2396 return this.search_field[0].tabIndex = ti; 2397 } 2398 }; 2399 2400 Chosen.prototype.set_label_behavior = function() { 2401 this.form_field_label = this.form_field_jq.parents("label"); 2402 if (!this.form_field_label.length && this.form_field.id.length) { 2403 this.form_field_label = $("label[for='" + this.form_field.id + "']"); 2404 } 2405 if (this.form_field_label.length > 0) { 2406 return this.form_field_label.on('click.chosen', this.label_click_handler); 2407 } 2408 }; 2409 2410 Chosen.prototype.show_search_field_default = function() { 2411 if (this.is_multiple && this.choices_count() < 1 && !this.active_field) { 2412 this.search_field.val(this.default_text); 2413 return this.search_field.addClass("default"); 2414 } else { 2415 this.search_field.val(""); 2416 return this.search_field.removeClass("default"); 2417 } 2418 }; 2419 2420 Chosen.prototype.search_results_mouseup = function(evt) { 2421 var target; 2422 target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first(); 2423 if (target.length) { 2424 this.result_highlight = target; 2425 this.result_select(evt); 2426 return this.search_field.focus(); 2427 } 2428 }; 2429 2430 Chosen.prototype.search_results_mouseover = function(evt) { 2431 var target; 2432 target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first(); 2433 if (target) { 2434 return this.result_do_highlight(target); 2435 } 2436 }; 2437 2438 Chosen.prototype.search_results_mouseout = function(evt) { 2439 if ($(evt.target).hasClass("active-result") || $(evt.target).parents('.active-result').first()) { 2440 return this.result_clear_highlight(); 2441 } 2442 }; 2443 2444 Chosen.prototype.choice_build = function(item) { 2445 var choice, close_link; 2446 choice = $('<li />', { 2447 "class": "search-choice" 2448 }).html("<span>" + (this.choice_label(item)) + "</span>"); 2449 if (item.disabled) { 2450 choice.addClass('search-choice-disabled'); 2451 } else { 2452 close_link = $('<a />', { 2453 "class": 'search-choice-close', 2454 'data-option-array-index': item.array_index 2455 }); 2456 close_link.on('click.chosen', (function(_this) { 2457 return function(evt) { 2458 return _this.choice_destroy_link_click(evt); 2459 }; 2460 })(this)); 2461 choice.append(close_link); 2462 } 2463 return this.search_container.before(choice); 2464 }; 2465 2466 Chosen.prototype.choice_destroy_link_click = function(evt) { 2467 evt.preventDefault(); 2468 evt.stopPropagation(); 2469 if (!this.is_disabled) { 2470 return this.choice_destroy($(evt.target)); 2471 } 2472 }; 2473 2474 Chosen.prototype.choice_destroy = function(link) { 2475 if (this.result_deselect(link[0].getAttribute("data-option-array-index"))) { 2476 if (this.active_field) { 2477 this.search_field.focus(); 2478 } else { 2479 this.show_search_field_default(); 2480 } 2481 if (this.is_multiple && this.choices_count() > 0 && this.get_search_field_value().length < 1) { 2482 this.results_hide(); 2483 } 2484 link.parents('li').first().remove(); 2485 return this.search_field_scale(); 2486 } 2487 }; 2488 2489 Chosen.prototype.results_reset = function() { 2490 this.reset_single_select_options(); 2491 this.form_field.options[0].selected = true; 2492 this.single_set_selected_text(); 2493 this.show_search_field_default(); 2494 this.results_reset_cleanup(); 2495 this.trigger_form_field_change(); 2496 if (this.active_field) { 2497 return this.results_hide(); 2498 } 2499 }; 2500 2501 Chosen.prototype.results_reset_cleanup = function() { 2502 this.current_selectedIndex = this.form_field.selectedIndex; 2503 return this.selected_item.find("abbr").remove(); 2504 }; 2505 2506 Chosen.prototype.result_select = function(evt) { 2507 var high, item; 2508 if (this.result_highlight) { 2509 high = this.result_highlight; 2510 this.result_clear_highlight(); 2511 if (this.is_multiple && this.max_selected_options <= this.choices_count()) { 2512 this.form_field_jq.trigger("chosen:maxselected", { 2513 chosen: this 2514 }); 2515 return false; 2516 } 2517 if (this.is_multiple) { 2518 high.removeClass("active-result"); 2519 } else { 2520 this.reset_single_select_options(); 2521 } 2522 high.addClass("result-selected"); 2523 item = this.results_data[high[0].getAttribute("data-option-array-index")]; 2524 item.selected = true; 2525 this.form_field.options[item.options_index].selected = true; 2526 this.selected_option_count = null; 2527 if (this.is_multiple) { 2528 this.choice_build(item); 2529 } else { 2530 this.single_set_selected_text(this.choice_label(item)); 2531 } 2532 if (this.is_multiple && (!this.hide_results_on_select || (evt.metaKey || evt.ctrlKey))) { 2533 if (evt.metaKey || evt.ctrlKey) { 2534 this.winnow_results({ 2535 skip_highlight: true 2536 }); 2537 } else { 2538 this.search_field.val(""); 2539 this.winnow_results(); 2540 } 2541 } else { 2542 this.results_hide(); 2543 this.show_search_field_default(); 2544 } 2545 if (this.is_multiple || this.form_field.selectedIndex !== this.current_selectedIndex) { 2546 this.trigger_form_field_change({ 2547 selected: this.form_field.options[item.options_index].value 2548 }); 2549 } 2550 this.current_selectedIndex = this.form_field.selectedIndex; 2551 evt.preventDefault(); 2552 return this.search_field_scale(); 2553 } 2554 }; 2555 2556 Chosen.prototype.single_set_selected_text = function(text) { 2557 if (text == null) { 2558 text = this.default_text; 2559 } 2560 if (text === this.default_text) { 2561 this.selected_item.addClass("chosen-default"); 2562 } else { 2563 this.single_deselect_control_build(); 2564 this.selected_item.removeClass("chosen-default"); 2565 } 2566 return this.selected_item.find("span").html(text); 2567 }; 2568 2569 Chosen.prototype.result_deselect = function(pos) { 2570 var result_data; 2571 result_data = this.results_data[pos]; 2572 if (!this.form_field.options[result_data.options_index].disabled) { 2573 result_data.selected = false; 2574 this.form_field.options[result_data.options_index].selected = false; 2575 this.selected_option_count = null; 2576 this.result_clear_highlight(); 2577 if (this.results_showing) { 2578 this.winnow_results(); 2579 } 2580 this.trigger_form_field_change({ 2581 deselected: this.form_field.options[result_data.options_index].value 2582 }); 2583 this.search_field_scale(); 2584 return true; 2585 } else { 2586 return false; 2587 } 2588 }; 2589 2590 Chosen.prototype.single_deselect_control_build = function() { 2591 if (!this.allow_single_deselect) { 2592 return; 2593 } 2594 if (!this.selected_item.find("abbr").length) { 2595 this.selected_item.find("span").first().after("<abbr class=\"search-choice-close\"></abbr>"); 2596 } 2597 return this.selected_item.addClass("chosen-single-with-deselect"); 2598 }; 2599 2600 Chosen.prototype.get_search_field_value = function() { 2601 return this.search_field.val(); 2602 }; 2603 2604 Chosen.prototype.get_search_text = function() { 2605 return $.trim(this.get_search_field_value()); 2606 }; 2607 2608 Chosen.prototype.escape_html = function(text) { 2609 return $('<div/>').text(text).html(); 2610 }; 2611 2612 Chosen.prototype.winnow_results_set_highlight = function() { 2613 var do_high, selected_results; 2614 selected_results = !this.is_multiple ? this.search_results.find(".result-selected.active-result") : []; 2615 do_high = selected_results.length ? selected_results.first() : this.search_results.find(".active-result").first(); 2616 if (do_high != null) { 2617 return this.result_do_highlight(do_high); 2618 } 2619 }; 2620 2621 Chosen.prototype.no_results = function(terms) { 2622 var no_results_html; 2623 no_results_html = this.get_no_results_html(terms); 2624 this.search_results.append(no_results_html); 2625 return this.form_field_jq.trigger("chosen:no_results", { 2626 chosen: this 2627 }); 2628 }; 2629 2630 Chosen.prototype.no_results_clear = function() { 2631 return this.search_results.find(".no-results").remove(); 2632 }; 2633 2634 Chosen.prototype.keydown_arrow = function() { 2635 var next_sib; 2636 if (this.results_showing && this.result_highlight) { 2637 next_sib = this.result_highlight.nextAll("li.active-result").first(); 2638 if (next_sib) { 2639 return this.result_do_highlight(next_sib); 2640 } 2641 } else { 2642 return this.results_show(); 2643 } 2644 }; 2645 2646 Chosen.prototype.keyup_arrow = function() { 2647 var prev_sibs; 2648 if (!this.results_showing && !this.is_multiple) { 2649 return this.results_show(); 2650 } else if (this.result_highlight) { 2651 prev_sibs = this.result_highlight.prevAll("li.active-result"); 2652 if (prev_sibs.length) { 2653 return this.result_do_highlight(prev_sibs.first()); 2654 } else { 2655 if (this.choices_count() > 0) { 2656 this.results_hide(); 2657 } 2658 return this.result_clear_highlight(); 2659 } 2660 } 2661 }; 2662 2663 Chosen.prototype.keydown_backstroke = function() { 2664 var next_available_destroy; 2665 if (this.pending_backstroke) { 2666 this.choice_destroy(this.pending_backstroke.find("a").first()); 2667 return this.clear_backstroke(); 2668 } else { 2669 next_available_destroy = this.search_container.siblings("li.search-choice").last(); 2670 if (next_available_destroy.length && !next_available_destroy.hasClass("search-choice-disabled")) { 2671 this.pending_backstroke = next_available_destroy; 2672 if (this.single_backstroke_delete) { 2673 return this.keydown_backstroke(); 2674 } else { 2675 return this.pending_backstroke.addClass("search-choice-focus"); 2676 } 2677 } 2678 } 2679 }; 2680 2681 Chosen.prototype.clear_backstroke = function() { 2682 if (this.pending_backstroke) { 2683 this.pending_backstroke.removeClass("search-choice-focus"); 2684 } 2685 return this.pending_backstroke = null; 2686 }; 2687 2688 Chosen.prototype.search_field_scale = function() { 2689 var div, i, len, style, style_block, styles, width; 2690 if (!this.is_multiple) { 2691 return; 2692 } 2693 style_block = { 2694 position: 'absolute', 2695 left: '-1000px', 2696 top: '-1000px', 2697 display: 'none', 2698 whiteSpace: 'pre' 2699 }; 2700 styles = ['fontSize', 'fontStyle', 'fontWeight', 'fontFamily', 'lineHeight', 'textTransform', 'letterSpacing']; 2701 for (i = 0, len = styles.length; i < len; i++) { 2702 style = styles[i]; 2703 style_block[style] = this.search_field.css(style); 2704 } 2705 div = $('<div />').css(style_block); 2706 div.text(this.get_search_field_value()); 2707 $('body').append(div); 2708 width = div.width() + 25; 2709 div.remove(); 2710 if (this.container.is(':visible')) { 2711 width = Math.min(this.container.outerWidth() - 10, width); 2712 } 2713 return this.search_field.width(width); 2714 }; 2715 2716 Chosen.prototype.trigger_form_field_change = function(extra) { 2717 this.form_field_jq.trigger("input", extra); 2718 return this.form_field_jq.trigger("change", extra); 2719 }; 2720 2721 return Chosen; 2722 2723 })(AbstractChosen); 2724 2725}).call(this);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.