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