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