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