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