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