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