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