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