1// Chosen, a Select Box Enhancer for jQuery and Protoype 2// by Patrick Filler for Harvest, http://getharvest.com 3// 4// Version 0.9.8.1 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 `cake build`, do not edit it by hand. 10(function() { 11 var SelectParser; 12 13 SelectParser = (function() { 14 15 function SelectParser() { 16 this.options_index = 0; 17 this.parsed = []; 18 } 19 20 SelectParser.prototype.add_node = function(child) { 21 if (child.nodeName === "OPTGROUP") { 22 return this.add_group(child); 23 } else { 24 return this.add_option(child); 25 } 26 }; 27 28 SelectParser.prototype.add_group = function(group) { 29 var group_position, option, _i, _len, _ref, _results; 30 group_position = this.parsed.length; 31 this.parsed.push({ 32 array_index: group_position, 33 group: true, 34 label: group.label, 35 classes: group.className, // PrestaShop 36 children: 0, 37 disabled: group.disabled 38 }); 39 _ref = group.childNodes; 40 _results = []; 41 for (_i = 0, _len = _ref.length; _i < _len; _i++) { 42 option = _ref[_i]; 43 _results.push(this.add_option(option, group_position, group.disabled)); 44 } 45 return _results; 46 }; 47 48 SelectParser.prototype.add_option = function(option, group_position, group_disabled) { 49 if (option.nodeName === "OPTION") { 50 if (option.text !== "") { 51 if (group_position != null) this.parsed[group_position].children += 1; 52 this.parsed.push({ 53 array_index: this.parsed.length, 54 options_index: this.options_index, 55 value: option.value, 56 text: option.text, 57 html: option.innerHTML, 58 selected: option.selected, 59 disabled: group_disabled === true ? group_disabled : option.disabled, 60 group_array_index: group_position, 61 classes: option.className, 62 style: option.style.cssText 63 }); 64 } else { 65 this.parsed.push({ 66 array_index: this.parsed.length, 67 options_index: this.options_index, 68 empty: true 69 }); 70 } 71 return this.options_index += 1; 72 } 73 }; 74 75 return SelectParser; 76 77 })(); 78 79 SelectParser.select_to_array = function(select) { 80 var child, parser, _i, _len, _ref; 81 parser = new SelectParser(); 82 _ref = select.childNodes; 83 for (_i = 0, _len = _ref.length; _i < _len; _i++) { 84 child = _ref[_i]; 85 parser.add_node(child); 86 } 87 return parser.parsed; 88 }; 89 90 this.SelectParser = SelectParser; 91 92}).call(this); 93 94/* 95 Chosen source: generate output using 'cake build' 96 Copyright (c) 2011 by Harvest 97 */ 98 99(function() { 100 var AbstractChosen, root; 101 102 root = this; 103 104 AbstractChosen = (function() { 105 106 function AbstractChosen(form_field, options) { 107 this.form_field = form_field; 108 this.options = options != null ? options : {}; 109 this.set_default_values(); 110 this.is_multiple = this.form_field.multiple; 111 this.default_text_default = this.is_multiple ? "Select Some Options" : "Select an Option"; 112 this.setup(); 113 this.set_up_html(); 114 this.register_observers(); 115 this.finish_setup(); 116 } 117 118 AbstractChosen.prototype.set_default_values = function() { 119 var _this = this; 120 this.click_test_action = function(evt) { 121 return _this.test_active_click(evt); 122 }; 123 this.activate_action = function(evt) { 124 return _this.activate_field(evt); 125 }; 126 this.active_field = false; 127 this.mouse_on_container = false; 128 this.results_showing = false; 129 this.result_highlighted = null; 130 this.result_single_selected = null; 131 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; 132 this.disable_search_threshold = this.options.disable_search_threshold || 0; 133 this.search_contains = this.options.search_contains || false; 134 this.show_on_blur = this.options.show_on_blur || false; 135 this.choices = 0; 136 return this.results_none_found = this.options.no_results_text || "No results match"; 137 }; 138 139 AbstractChosen.prototype.mouse_enter = function() { 140 return this.mouse_on_container = true; 141 }; 142 143 AbstractChosen.prototype.mouse_leave = function() { 144 return this.mouse_on_container = false;
145 }; 146 147 AbstractChosen.prototype.input_focus = function(evt) { 148 var _this = this; 149 if (!this.active_field) { 150 return setTimeout((function() { 151 return _this.container_mousedown(); 152 }), 50); 153 } 154 }; 155 156 AbstractChosen.prototype.input_blur = function(evt) { 157 var _this = this; 158 if (!this.mouse_on_container) { 159 this.active_field = false; 160 return setTimeout((function() { 161 return _this.blur_test(); 162 }), 100); 163 } 164 }; 165 166 AbstractChosen.prototype.result_add_option = function(option) { 167 var classes, style; 168 if (!option.disabled) { 169 option.dom_id = this.container_id + "_o_" + option.array_index; 170 classes = option.selected && this.is_multiple ? [] : ["active-result"]; 171 if (option.selected) classes.push("result-selected"); 172 if (option.group_array_index != null) classes.push("group-option"); 173 if (option.classes !== "") classes.push(option.classes); 174 style = option.style.cssText !== "" ? " style=\"" + option.style + "\"" : ""; 175 return '<li id="' + option.dom_id + '" class="' + classes.join(' ') + '"' + style + '>' + option.html + '</li>'; 176 } else { 177 return ""; 178 } 179 }; 180 181 AbstractChosen.prototype.results_update_field = function() { 182 this.result_clear_highlight(); 183 this.result_single_selected = null; 184 return this.results_build(); 185 }; 186 187 AbstractChosen.prototype.results_toggle = function() { 188 if (this.results_showing) { 189 return this.results_hide(); 190 } else { 191 return this.results_show(); 192 } 193 }; 194 195 AbstractChosen.prototype.results_search = function(evt) { 196 if (this.results_showing) { 197 return this.winnow_results(); 198 } else { 199 return this.results_show(); 200 } 201 }; 202 203 AbstractChosen.prototype.keyup_checker = function(evt) { 204 var stroke, _ref; 205 stroke = (_ref = evt.which) != null ? _ref : evt.keyCode; 206 this.search_field_scale(); 207 switch (stroke) { 208 case 8: 209 if (this.is_multiple && this.backstroke_length < 1 && this.choices > 0) { 210 return this.keydown_backstroke(); 211 } else if (!this.pending_backstroke) { 212 this.result_clear_highlight(); 213 return this.results_search(); 214 } 215 break; 216 case 13: 217 evt.preventDefault(); 218 if (this.results_showing) return this.result_select(evt); 219 break; 220 case 27: 221 if (this.results_showing) this.results_hide(); 222 return true; 223 case 9: 224 case 38:
225 case 40: 226 case 16: 227 case 91: 228 case 17: 229 break; 230 default: 231 return this.results_search(); 232 } 233 }; 234 235 AbstractChosen.prototype.generate_field_id = function() { 236 var new_id; 237 new_id = this.generate_random_id(); 238 this.form_field.id = new_id; 239 return new_id; 240 }; 241 242 AbstractChosen.prototype.generate_random_char = function() { 243 var chars, newchar, rand; 244 chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZ"; 245 rand = Math.floor(Math.random() * chars.length); 246 return newchar = chars.substring(rand, rand + 1); 247 }; 248 249 return AbstractChosen; 250 251 })(); 252 253 root.AbstractChosen = AbstractChosen; 254 255}).call(this); 256 257/* 258 Chosen source: generate output using 'cake build' 259 Copyright (c) 2011 by Harvest 260 */ 261 262(function() { 263 var $, Chosen, get_side_border_padding, root, 264 __hasProp = Object.prototype.hasOwnProperty, 265 __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; }; 266 267 root = this; 268 269 $ = jQuery; 270 271 $.fn.extend({ 272 chosen: function(options) { 273 if ($.browser.msie && ($.browser.version === "6.0" || $.browser.version === "7.0")) { 274 return this; 275 } 276 return $(this).each(function(input_field) { 277 if (!($(this)).hasClass("chzn-done")) return new Chosen(this, options); 278 }); 279 }, 280 chosenDestroy: function () { 281 $(this).show().removeClass('chzn-done'); 282 $(this).next().remove() 283 return $(this); 284 } 285 }); 286 287 Chosen = (function(_super) { 288 289 __extends(Chosen, _super); 290 291 function Chosen() { 292 Chosen.__super__.constructor.apply(this, arguments); 293 } 294 295 Chosen.prototype.setup = function() { 296 this.form_field_jq = $(this.form_field); 297 return this.is_rtl = this.form_field_jq.hasClass("chzn-rtl"); 298 }; 299 300 Chosen.prototype.finish_setup = function() { 301 return this.form_field_jq.addClass("chzn-done"); 302 }; 303 304 Chosen.prototype.set_up_html = function() { 305 var container_div, dd_top, dd_width, sf_width; 306 this.container_id = this.form_field.id.length ? this.form_field.id.replace(/[^\w]/g, '_') : this.generate_field_id(); 307 this.container_id += "_chzn"; 308 this.f_width = this.form_field_jq.outerWidth(); 309 this.default_text = this.form_field_jq.data('placeholder') ? this.form_field_jq.data('placeholder') : this.default_text_default; 310 container_div = $("<div />", { 311 id: this.container_id, 312 "class": "chzn-container" + (this.is_rtl ? ' chzn-rtl' : ''), 313 style: 'width: ' + this.f_width + 'px;' 314 }); 315 if (this.is_multiple) { 316 container_div.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" style="left:-9000px;"><ul class="chzn-results"></ul></div>'); 317 } else { 318 container_div.html('<a href="javascript:void(0)" class="chzn-single chzn-default"><span>' + this.default_text + '</span><div><b></b></div></a><div class="chzn-drop" style="left:-9000px;"><div class="chzn-search"><input type="text" autocomplete="off" /></div><ul class="chzn-results"></ul></div>'); 319 } 320 this.form_field_jq.hide().after(container_div); 321 this.container = $('#' + this.container_id); 322 this.container.addClass("chzn-container-" + (this.is_multiple ? "multi" : "single")); 323 this.dropdown = this.container.find('div.chzn-drop').first(); 324 dd_top = this.container.height(); 325 dd_width = this.f_width - get_side_border_padding(this.dropdown); 326 this.dropdown.css({ 327 "width": dd_width + "px", 328 "top": dd_top + "px" 329 }); 330 this.search_field = this.container.find('input').first(); 331 this.search_results = this.container.find('ul.chzn-results').first(); 332 this.search_field_scale(); 333 this.search_no_results = this.container.find('li.no-results').first(); 334 if (this.is_multiple) { 335 this.search_choices = this.container.find('ul.chzn-choices').first(); 336 this.search_container = this.container.find('li.search-field').first(); 337 } else { 338 this.search_container = this.container.find('div.chzn-search').first(); 339 this.selected_item = this.container.find('.chzn-single').first(); 340 sf_width = dd_width - get_side_border_padding(this.search_container) - get_side_border_padding(this.search_field); 341 this.search_field.css({ 342 "width": sf_width + "px" 343 }); 344 } 345 this.results_build(); 346 this.set_tab_index(); 347 return this.form_field_jq.trigger("liszt:ready", { 348 chosen: this 349 }); 350 }; 351 352 Chosen.prototype.register_observers = function() { 353 var _this = this; 354 this.container.mousedown(function(evt) { 355 return _this.container_mousedown(evt); 356 }); 357 this.container.mouseup(function(evt) { 358 return _this.container_mouseup(evt); 359 }); 360 this.container.mouseenter(function(evt) { 361 return _this.mouse_enter(evt); 362 }); 363 this.container.mouseleave(function(evt) { 364 return _this.mouse_leave(evt); 365 }); 366 this.search_results.mouseup(function(evt) { 367 return _this.search_results_mouseup(evt); 368 }); 369 this.search_results.mouseover(function(evt) { 370 return _this.search_results_mouseover(evt); 371 }); 372 this.search_results.mouseout(function(evt) { 373 return _this.search_results_mouseout(evt); 374 }); 375 this.form_field_jq.bind("liszt:updated", function(evt) { 376 return _this.results_update_field(evt); 377 }); 378 this.search_field.blur(function(evt) { 379 return _this.input_blur(evt); 380 }); 381 this.search_field.keyup(function(evt) { 382 return _this.keyup_checker(evt); 383 }); 384 this.search_field.keydown(function(evt) { 385 return _this.keydown_checker(evt); 386 }); 387 if (this.is_multiple) { 388 this.search_choices.click(function(evt) { 389 return _this.choices_click(evt); 390 }); 391 return this.search_field.focus(function(evt) { 392 return _this.input_focus(evt); 393 }); 394 } else { 395 return this.container.click(function(evt) { 396 return evt.preventDefault(); 397 }); 398 } 399 }; 400 401 Chosen.prototype.search_field_disabled = function() { 402 this.is_disabled = this.form_field_jq[0].disabled; 403 if (this.is_disabled) { 404 this.container.addClass('chzn-disabled'); 405 this.search_field[0].disabled = true; 406 if (!this.is_multiple) { 407 this.selected_item.unbind("focus", this.activate_action); 408 } 409 return this.close_field(); 410 } else { 411 this.container.removeClass('chzn-disabled'); 412 this.search_field[0].disabled = false;
413 if (!this.is_multiple) { 414 return this.selected_item.bind("focus", this.activate_action); 415 } 416 } 417 }; 418 419 Chosen.prototype.container_mousedown = function(evt) { 420 var target_closelink; 421 if (!this.is_disabled) { 422 target_closelink = evt != null ? ($(evt.target)).hasClass("search-choice-close") : false; 423 if (evt && evt.type === "mousedown" && !this.results_showing) { 424 evt.stopPropagation(); 425 } 426 if (!this.pending_destroy_click && !target_closelink) { 427 if (!this.active_field) { 428 if (this.is_multiple) this.search_field.val(""); 429 $(document).click(this.click_test_action); 430 this.results_show(); 431 } else if (!this.is_multiple && evt && (($(evt.target)[0] === this.selected_item[0]) || $(evt.target).parents("a.chzn-single").length)) { 432 evt.preventDefault(); 433 this.results_toggle(); 434 } 435 return this.activate_field(); 436 } else { 437 return this.pending_destroy_click = false; 438 } 439 } 440 }; 441 442 Chosen.prototype.container_mouseup = function(evt) { 443 if (evt.target.nodeName === "ABBR") return this.results_reset(evt); 444 }; 445 446 Chosen.prototype.blur_test = function(evt) { 447 if (!this.active_field && this.container.hasClass("chzn-container-active")) { 448 return this.close_field(); 449 } 450 }; 451 452 Chosen.prototype.close_field = function() { 453 $(document).unbind("click", this.click_test_action); 454 if (!this.is_multiple) { 455 this.selected_item.attr("tabindex", this.search_field.attr("tabindex")); 456 this.search_field.attr("tabindex", -1); 457 } 458 this.active_field = false; 459 if (!this.show_on_blur) { 460 this.results_hide(); 461 this.container.removeClass("chzn-container-active"); 462 } 463 this.winnow_results_clear(); 464 this.clear_backstroke(); 465 this.show_search_field_default(); 466 return this.search_field_scale(); 467 }; 468 469 Chosen.prototype.activate_field = function() { 470 if (!this.is_multiple && !this.active_field) { 471 this.search_field.attr("tabindex", this.selected_item.attr("tabindex")); 472 this.selected_item.attr("tabindex", -1); 473 } 474 this.container.addClass("chzn-container-active"); 475 this.active_field = true; 476 this.search_field.val(this.search_field.val()); 477 478 if (this.container.hasClass("chzn-container-single-nosearch")) { 479 return true; 480 }else{ 481 return this.search_field.focus(); 482 } 483 484 }; 485 486 Chosen.prototype.test_active_click = function(evt) { 487 if ($(evt.target).parents('#' + this.container_id).length) { 488 return this.active_field = true; 489 } else { 490 return this.close_field(); 491 } 492 }; 493 494 Chosen.prototype.results_build = function() { 495 var content, data, _i, _len, _ref; 496 this.parsing = true; 497 this.results_data = root.SelectParser.select_to_array(this.form_field); 498 if (this.is_multiple && this.choices > 0) { 499 this.search_choices.find("li.search-choice").remove(); 500 this.choices = 0; 501 } else if (!this.is_multiple) { 502 this.selected_item.find("span").text(this.default_text); 503 if (this.form_field.options.length <= this.disable_search_threshold) { 504 this.container.addClass("chzn-container-single-nosearch"); 505 } else { 506 this.container.removeClass("chzn-container-single-nosearch"); 507 } 508 } 509 content = ''; 510 _ref = this.results_data; 511 for (_i = 0, _len = _ref.length; _i < _len; _i++) { 512 data = _ref[_i]; 513 if (data.group) { 514 content += this.result_add_group(data); 515 } else if (!data.empty) { 516 content += this.result_add_option(data); 517 if (data.selected && this.is_multiple) { 518 this.choice_build(data); 519 } else if (data.selected && !this.is_multiple) { 520 this.selected_item.removeClass("chzn-default").find("span").text(data.text); 521 if (this.allow_single_deselect) this.single_deselect_control_build(); 522 } 523 } 524 } 525 this.search_field_disabled(); 526 this.show_search_field_default(); 527 this.search_field_scale(); 528 this.search_results.html(content); 529 return this.parsing = false; 530 }; 531 532 Chosen.prototype.result_add_group = function(group) { 533 if (!group.disabled) { 534 group.dom_id = this.container_id + "_g_" + group.array_index; 535 return '<li id="' + group.dom_id + '" class="group-result '+group.classes+'">' + $("<div />").text(group.label).html() + '</li>'; // PrestaShop 536 } else { 537 return ""; 538 } 539 }; 540 541 Chosen.prototype.result_do_highlight = function(el) { 542 var high_bottom, high_top, maxHeight, visible_bottom, visible_top; 543 if (el.length) { 544 this.result_clear_highlight(); 545 this.result_highlight = el; 546 this.result_highlight.addClass("highlighted"); 547 maxHeight = parseInt(this.search_results.css("maxHeight"), 10); 548 visible_top = this.search_results.scrollTop(); 549 visible_bottom = maxHeight + visible_top; 550 high_top = this.result_highlight.position().top + this.search_results.scrollTop(); 551 high_bottom = high_top + this.result_highlight.outerHeight(); 552 if (high_bottom >= visible_bottom) { 553 return this.search_results.scrollTop((high_bottom - maxHeight) > 0 ? high_bottom - maxHeight : 0); 554 } else if (high_top < visible_top) { 555 return this.search_results.scrollTop(high_top); 556 } 557 } 558 }; 559 560 Chosen.prototype.result_clear_highlight = function() { 561 if (this.result_highlight) this.result_highlight.removeClass("highlighted"); 562 return this.result_highlight = null; 563 }; 564 565 Chosen.prototype.results_show = function() { 566 var dd_top; 567 if (!this.is_multiple) { 568 this.selected_item.addClass("chzn-single-with-drop"); 569 if (this.result_single_selected) { 570 this.result_do_highlight(this.result_single_selected); 571 } 572 } 573 dd_top = this.is_multiple ? this.container.height() : this.container.height() - 1; 574 this.dropdown.css({ 575 "top": dd_top + "px", 576 "left": 0 577 }); 578 this.results_showing = true; 579 580 if (!this.container.hasClass("chzn-container-single-nosearch")) { 581 this.search_field.focus(); 582 } 583 584 this.search_field.val(this.search_field.val()); 585 return this.winnow_results(); 586 }; 587 588 Chosen.prototype.results_hide = function() { 589 if (!this.is_multiple) { 590 this.selected_item.removeClass("chzn-single-with-drop"); 591 } 592 this.result_clear_highlight(); 593 this.dropdown.css({ 594 "left": "-9000px" 595 }); 596 return this.results_showing = false;
597 }; 598 599 Chosen.prototype.set_tab_index = function(el) { 600 var ti; 601 if (this.form_field_jq.attr("tabindex")) { 602 ti = this.form_field_jq.attr("tabindex"); 603 this.form_field_jq.attr("tabindex", -1); 604 if (this.is_multiple) { 605 return this.search_field.attr("tabindex", ti); 606 } else { 607 this.selected_item.attr("tabindex", ti); 608 return this.search_field.attr("tabindex", -1); 609 } 610 } 611 }; 612 613 Chosen.prototype.show_search_field_default = function() { 614 if (this.is_multiple && this.choices < 1 && !this.active_field) { 615 this.search_field.val(this.default_text); 616 return this.search_field.addClass("default"); 617 } else { 618 this.search_field.val(""); 619 return this.search_field.removeClass("default"); 620 } 621 }; 622 623 Chosen.prototype.search_results_mouseup = function(evt) { 624 var target; 625 target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first(); 626 if (target.length) { 627 this.result_highlight = target; 628 return this.result_select(evt); 629 } 630 }; 631 632 Chosen.prototype.search_results_mouseover = function(evt) { 633 var target; 634 target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first(); 635 if (target) return this.result_do_highlight(target); 636 }; 637 638 Chosen.prototype.search_results_mouseout = function(evt) { 639 if ($(evt.target).hasClass("active-result" || $(evt.target).parents('.active-result').first())) { 640 return this.result_clear_highlight(); 641 } 642 }; 643 644 Chosen.prototype.choices_click = function(evt) { 645 evt.preventDefault(); 646 if (this.active_field && !($(evt.target).hasClass("search-choice" || $(evt.target).parents('.search-choice').first)) && !this.results_showing) { 647 return this.results_show(); 648 } 649 }; 650 651 Chosen.prototype.choice_build = function(item) { 652 var choice_id, link, 653 _this = this; 654 choice_id = this.container_id + "_c_" + item.array_index; 655 this.choices += 1; 656 this.search_container.before('<li class="search-choice" id="' + choice_id + '"><span>' + item.html + '</span><a href="javascript:void(0)" class="search-choice-close" rel="' + item.array_index + '"></a></li>'); 657 link = $('#' + choice_id).find("a").first(); 658 return link.click(function(evt) { 659 return _this.choice_destroy_link_click(evt); 660 }); 661 }; 662 663 Chosen.prototype.choice_destroy_link_click = function(evt) { 664 evt.preventDefault(); 665 if (!this.is_disabled) { 666 this.pending_destroy_click = true; 667 return this.choice_destroy($(evt.target)); 668 } else { 669 return evt.stopPropagation; 670 } 671 }; 672 673 Chosen.prototype.choice_destroy = function(link) { 674 this.choices -= 1; 675 this.show_search_field_default(); 676 if (this.is_multiple && this.choices > 0 && this.search_field.val().length < 1) { 677 this.results_hide(); 678 } 679 this.result_deselect(link.attr("rel")); 680 return link.parents('li').first().remove(); 681 }; 682 683 Chosen.prototype.results_reset = function(evt) { 684 this.form_field.options[0].selected = true; 685 this.selected_item.find("span").text(this.default_text); 686 if (!this.is_multiple) this.selected_item.addClass("chzn-default"); 687 this.show_search_field_default(); 688 $(evt.target).remove(); 689 this.form_field_jq.trigger("change"); 690 if (this.active_field) return this.results_hide(); 691 }; 692 693 Chosen.prototype.result_select = function(evt) { 694 var high, high_id, item, position; 695 if (this.result_highlight) { 696 high = this.result_highlight; 697 high_id = high.attr("id"); 698 this.result_clear_highlight(); 699 if (this.is_multiple) { 700 this.result_deactivate(high); 701 } else { 702 this.search_results.find(".result-selected").removeClass("result-selected"); 703 this.result_single_selected = high; 704 this.selected_item.removeClass("chzn-default"); 705 } 706 high.addClass("result-selected"); 707 position = high_id.substr(high_id.lastIndexOf("_") + 1); 708 item = this.results_data[position]; 709 item.selected = true; 710 this.form_field.options[item.options_index].selected = true; 711 if (this.is_multiple) { 712 this.choice_build(item); 713 } else { 714 this.selected_item.find("span").first().text(item.text); 715 if (this.allow_single_deselect) this.single_deselect_control_build(); 716 } 717 if (!(evt.metaKey && this.is_multiple)) this.results_hide(); 718 this.search_field.val(""); 719 this.form_field_jq.trigger("change"); 720 return this.search_field_scale(); 721 } 722 }; 723 724 Chosen.prototype.result_activate = function(el) { 725 return el.addClass("active-result"); 726 }; 727 728 Chosen.prototype.result_deactivate = function(el) { 729 return el.removeClass("active-result"); 730 }; 731 732 Chosen.prototype.result_deselect = function(pos) { 733 var result, result_data; 734 result_data = this.results_data[pos]; 735 result_data.selected = false;
736 this.form_field.options[result_data.options_index].selected = false; 737 result = $("#" + this.container_id + "_o_" + pos); 738 result.removeClass("result-selected").addClass("active-result").show(); 739 this.result_clear_highlight(); 740 this.winnow_results(); 741 this.form_field_jq.trigger("change"); 742 return this.search_field_scale(); 743 }; 744 745 Chosen.prototype.single_deselect_control_build = function() { 746 if (this.allow_single_deselect && this.selected_item.find("abbr").length < 1) { 747 return this.selected_item.find("span").first().after("<abbr class=\"search-choice-close\"></abbr>"); 748 } 749 }; 750 751 Chosen.prototype.winnow_results = function() { 752 var found, option, part, parts, regex, regexAnchor, result, result_id, results, searchText, startpos, text, zregex, _i, _j, _len, _len2, _ref; 753 this.no_results_clear(); 754 results = 0; 755 searchText = this.search_field.val() === this.default_text ? "" : $('<div/>').text($.trim(this.search_field.val())).html(); 756 regexAnchor = this.search_contains ? "" : "^"; 757 regex = new RegExp(regexAnchor + searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i'); 758 zregex = new RegExp(searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i'); 759 _ref = this.results_data; 760 for (_i = 0, _len = _ref.length; _i < _len; _i++) { 761 option = _ref[_i]; 762 if (!option.disabled && !option.empty) { 763 if (option.group) { 764 $('#' + option.dom_id).css('display', 'none'); 765 } else if (!(this.is_multiple && option.selected)) { 766 found = false; 767 result_id = option.dom_id; 768 result = $("#" + result_id); 769 if (regex.test(option.html)) { 770 found = true; 771 results += 1; 772 } else if (option.html.indexOf(" ") >= 0 || option.html.indexOf("[") === 0) { 773 parts = option.html.replace(/\[|\]/g, "").split(" "); 774 if (parts.length) { 775 for (_j = 0, _len2 = parts.length; _j < _len2; _j++) { 776 part = parts[_j]; 777 if (regex.test(part)) { 778 found = true; 779 results += 1; 780 } 781 } 782 } 783 } 784 if (found) { 785 if (searchText.length) { 786 startpos = option.html.search(zregex); 787 text = option.html.substr(0, startpos + searchText.length) + '</em>' + option.html.substr(startpos + searchText.length); 788 text = text.substr(0, startpos) + '<em>' + text.substr(startpos); 789 } else { 790 text = option.html; 791 } 792 result.html(text); 793 this.result_activate(result); 794 if (option.group_array_index != null) { 795 $("#" + this.results_data[option.group_array_index].dom_id).css('display', 'list-item'); 796 } 797 } else { 798 if (this.result_highlight && result_id === this.result_highlight.attr('id')) { 799 this.result_clear_highlight(); 800 } 801 this.result_deactivate(result); 802 } 803 } 804 } 805 } 806 if (results < 1 && searchText.length) { 807 return this.no_results(searchText); 808 } else { 809 return this.winnow_results_set_highlight(); 810 } 811 }; 812 813 Chosen.prototype.winnow_results_clear = function() { 814 var li, lis, _i, _len, _results; 815 this.search_field.val(""); 816 lis = this.search_results.find("li"); 817 _results = []; 818 for (_i = 0, _len = lis.length; _i < _len; _i++) { 819 li = lis[_i]; 820 li = $(li); 821 if (li.hasClass("group-result")) { 822 _results.push(li.css('display', 'auto')); 823 } else if (!this.is_multiple || !li.hasClass("result-selected")) { 824 _results.push(this.result_activate(li)); 825 } else { 826 _results.push(void 0); 827 } 828 } 829 return _results; 830 }; 831 832 Chosen.prototype.winnow_results_set_highlight = function() { 833 var do_high, selected_results; 834 if (!this.result_highlight) { 835 selected_results = !this.is_multiple ? this.search_results.find(".result-selected.active-result") : []; 836 do_high = selected_results.length ? selected_results.first() : this.search_results.find(".active-result").first(); 837 if (do_high != null) return this.result_do_highlight(do_high); 838 } 839 }; 840 841 Chosen.prototype.no_results = function(terms) { 842 var no_results_html; 843 no_results_html = $('<li class="no-results">' + this.results_none_found + ' "<span></span>"</li>'); 844 no_results_html.find("span").first().html(terms); 845 return this.search_results.append(no_results_html); 846 }; 847 848 Chosen.prototype.no_results_clear = function() { 849 return this.search_results.find(".no-results").remove(); 850 }; 851 852 Chosen.prototype.keydown_arrow = function() { 853 var first_active, next_sib; 854 if (!this.result_highlight) { 855 first_active = this.search_results.find("li.active-result").first(); 856 if (first_active) this.result_do_highlight($(first_active)); 857 } else if (this.results_showing) { 858 next_sib = this.result_highlight.nextAll("li.active-result").first(); 859 if (next_sib) this.result_do_highlight(next_sib); 860 } 861 if (!this.results_showing) return this.results_show(); 862 }; 863 864 Chosen.prototype.keyup_arrow = function() { 865 var prev_sibs; 866 if (!this.results_showing && !this.is_multiple) { 867 return this.results_show(); 868 } else if (this.result_highlight) { 869 prev_sibs = this.result_highlight.prevAll("li.active-result"); 870 if (prev_sibs.length) { 871 return this.result_do_highlight(prev_sibs.first()); 872 } else { 873 if (this.choices > 0) this.results_hide(); 874 return this.result_clear_highlight(); 875 } 876 } 877 }; 878 879 Chosen.prototype.keydown_backstroke = function() { 880 if (this.pending_backstroke) { 881 this.choice_destroy(this.pending_backstroke.find("a").first()); 882 return this.clear_backstroke(); 883 } else { 884 this.pending_backstroke = this.search_container.siblings("li.search-choice").last(); 885 return this.pending_backstroke.addClass("search-choice-focus"); 886 } 887 }; 888 889 Chosen.prototype.clear_backstroke = function() { 890 if (this.pending_backstroke) { 891 this.pending_backstroke.removeClass("search-choice-focus"); 892 } 893 return this.pending_backstroke = null; 894 }; 895 896 Chosen.prototype.keydown_checker = function(evt) { 897 var stroke, _ref; 898 stroke = (_ref = evt.which) != null ? _ref : evt.keyCode; 899 this.search_field_scale(); 900 if (stroke !== 8 && this.pending_backstroke) this.clear_backstroke(); 901 switch (stroke) { 902 case 8: 903 this.backstroke_length = this.search_field.val().length; 904 break; 905 case 9: 906 if (this.results_showing && !this.is_multiple) this.result_select(evt); 907 this.mouse_on_container = false;
908 break; 909 case 13: 910 evt.preventDefault(); 911 break; 912 case 38: 913 evt.preventDefault(); 914 this.keyup_arrow(); 915 break; 916 case 40: 917 this.keydown_arrow(); 918 break; 919 } 920 }; 921 922 Chosen.prototype.search_field_scale = function() { 923 var dd_top, div, h, style, style_block, styles, w, _i, _len; 924 if (this.is_multiple) { 925 h = 0; 926 w = 0; 927 style_block = "position:absolute; left: -1000px; top: -1000px; display:none;"; 928 styles = ['font-size', 'font-style', 'font-weight', 'font-family', 'line-height', 'text-transform', 'letter-spacing']; 929 for (_i = 0, _len = styles.length; _i < _len; _i++) { 930 style = styles[_i]; 931 style_block += style + ":" + this.search_field.css(style) + ";"; 932 } 933 div = $('<div />', { 934 'style': style_block 935 }); 936 div.text(this.search_field.val()); 937 $('body').append(div); 938 w = div.width() + 25; 939 div.remove(); 940 if (w > this.f_width - 10) w = this.f_width - 10; 941 this.search_field.css({ 942 'width': w + 'px' 943 }); 944 dd_top = this.container.height(); 945 return this.dropdown.css({ 946 "top": dd_top + "px" 947 }); 948 } 949 }; 950 951 Chosen.prototype.generate_random_id = function() { 952 var string; 953 string = "sel" + this.generate_random_char() + this.generate_random_char() + this.generate_random_char(); 954 while ($("#" + string).length > 0) { 955 string += this.generate_random_char(); 956 } 957 return string; 958 }; 959 960 return Chosen; 961 962 })(AbstractChosen); 963 964 get_side_border_padding = function(elmt) { 965 var side_border_padding; 966 return side_border_padding = elmt.outerWidth() - elmt.width(); 967 }; 968 969 root.get_side_border_padding = get_side_border_padding; 970 971}).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.