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