var Autosuggest = Class.create(ItemsList, { initialize: function($super, element, container, list){ if (!element || !Element.match(element, "input")) return; this.element = $(element); Element.addClassName(this.element, "InputField"); this.container = $(container); if (!this.container) this.container = Element.wrap(this.element, "span", {"class": "DropDown", "style": "visibility: hidden;"}); if (!this.container.JSControl) this.container.JSControl = this; Element.addClassName(this.container, "Autosuggest"); $super(list); if (!$(list)) Element.insert(this.element, {"after": this.list}); Element.setStyle(this.container, {"visibility": ""}); this.ID_ = Element.readAttribute(this.element, "id"); this.highlight=Element.readAttribute(this.container, "highlight"); this.minInput=parseInt(Element.readAttribute(this.container, "min-input"), 10); if(!this.minInput) this.minInput=1; Event.observe(this.element, "keypress", this.onKeyPress.bindAsEventListener(this)); Event.observe(this.element, "keyup", this.onKeyUp.bindAsEventListener(this)); Event.observe(this.list, ItemsList.events["choice"], function(event){ this.setValueFromItem(Event.element(event), false); }.bind(this)); }, checkElement: function($super, element){ return element && ($super(element) || [this.container, this.element].find(function(container){ return element == container || Element.descendantOf(element, container); })); }, setValueFromItem: function(item, silent){ this.element.value = Element.getTextFast(item); if (!silent){ this.setClosed(); Event.fire(this.element, "change"); } }, acceptHighlighted: function(){ if (!this.highlightedItem || !Element.visible(this.highlightedItem)) return; this.setValueFromItem(this.highlightedItem); }, getOptimalPosition: ItemsList.getOptimalPosition, refreshListPosition: function(){ var scrollTop = this.list.scrollTop; var pos = this.getOptimalPosition(this.container, this.list); Element.clonePosition(this.list, this.container, { "setHeight": false, "setWidth": false, "offsetTop": pos.offsetTop }); Element.setStyle(this.list, { "minWidth": this.container.clientWidth + "px", "maxHeight": typeof pos.maxHeight == "undefined" ? "" : pos.maxHeight + "px" }); if (scrollTop != 0) this.list.scrollTop = scrollTop; }, GetContainer: function(){ return this.container; }, ID: function(){ return this.ID_; }, refreshVisibleItems: function(preserve_state){ var val = this.element.value; var noValue = val.length == 0; if (noValue) this.setClosed(); var nVisible = 0; Element.childElements(this.list).each(function(element){ var isVisible = noValue || Element.getTextFast(element).toLowerCase().indexOf(val.toLowerCase()) != -1; if (isVisible) ++nVisible; Element.setStyle(element, { "display": isVisible ? "" : "none" }); }); if (!preserve_state && !noValue) this[nVisible > 0 ? "setOpen" : "setClosed"](); }, RefreshList: function($super, array, keys, hints){ $super(array, keys, hints); this.refreshVisibleItems(); }, onKeyPress: function(event){ switch (event.keyCode){ case Event.KEY_RETURN: this.acceptHighlighted(); Element.fire(this.element, Autosuggest.events["enter-pressed"]); break; default: return true; } return false; }, onKeyUp: function(event){ switch(event.keyCode){ case Event.KEY_DOWN: this.highlightNext(); break; case Event.KEY_UP: this.highlightPrev(); break; case Event.KEY_HOME: this.highlightFirst(); break; case Event.KEY_END: this.highlightLast(); break; case Event.KEY_ESC: this.setClosed(); break; case Event.KEY_INSERT: case Event.KEY_TAB: case Event.KEY_RETURN: break; default: this.refreshVisibleItems(); return true; } return false; } }); Autosuggest.events = Object.extend(ItemsList.events, { "enter-pressed": "autosuggest:enter-pressed" }); var AutosuggestDropdown = Class.create(Autosuggest, { initialize: function($super, element, container, button, list){ $super(element, container, list); this.element.JSControl = this; this.button = $(button); if (!this.button){ this.button = new Element("input", {"type": "button", "class": "ShowOptions"}); Element.insert(this.element, { "after": this.button }); } Event.observe(this.button, "click", this.onbuttonclick.bindAsEventListener(this)); }, SetTabOrder: function(nTabBase){ this.element.tabIndex = nTabBase++; return nTabBase; }, onbuttonclick: function(event){ Form.Element.activate(this.element); this.toggleOpen(); Event.stop(event); }, onKeyPress: function($super, event){ if (event.keyCode == Event.KEY_TAB) this.setClosed(); else $super(event); }, onKeyUp: function($super, event){ switch(event.keyCode){ case Event.KEY_DOWN: if (!this.list.isOpen){ this.setOpen(); this.highlightFirst(); }else this.highlightNext(); break; case Event.KEY_UP: if (this.list.isOpen && this.highlightedItem == this.getFirstItem()) this.setClosed(); else this.highlightPrev(); break; case Event.KEY_HOME: this.highlightFirst(); break; case Event.KEY_END: this.highlightLast(); break; case Event.KEY_ESC: this.setClosed(); break; case Event.KEY_INSERT: case Event.KEY_TAB: case Event.KEY_RETURN: break; default: this.refreshVisibleItems(); } } }); AutosuggestDropdown.events = Autosuggest.events; var DynamicAutosuggest = Class.create({ initialize: function(id, acceptor_id){ this.cont_ = document.getElementById(this.id_ = id); if (!this.cont_) return; this.cont_.JSControl = this; this.localid_ = this.cont_.getAttribute("localid"); if( this.get_attr("text") ) { this.ctrl_and_gap_press = 0; this.caret_position = 0; this.begin_str = ""; this.end_str = ""; } var acc_elem = document.getElementById(acceptor_id); if (!acc_elem) return; window.setTimeout(function(){ if (this.acceptor_ = acc_elem.JSControl) this.set_leader(acc_elem); }.bind(this), 100); this.list_ = document.createElement("ul"); Element.writeAttribute(this.list_, "class", "DropDown Suggester"); Element.setStyle(this.list_, {"position": "fixed"}); var awnd = this.awnd_ = AControl.GetParentWindow(this.ID()); if (awnd){ awnd.Subscribe("WM_BACK", this.onWMBACK, this); awnd.Subscribe("WM_POPUP", this.onWMPOPUP, this); if( !this.get_attr("text") ) awnd.Subscribe("INPUT", this.onINPUT, this); } }, ID: function(){ return this.id_; }, set_attr: function(nam, val){ if (typeof this.attrs_ == "undefined") this.attrs_ = {}; this.attrs_[nam] = val; }, get_attr: function(nam){ if (typeof this.attrs_ == "undefined" || typeof this.attrs_[nam] == "undefined") return null; else return this.attrs_[nam]; }, get_attr_or: function(nam, dfl){ if (typeof this.attrs_ == "undefined" || typeof this.attrs_[nam] == "undefined") return dfl; else return this.attrs_[nam]; }, SetAttribute: function(nam, val){ switch (nam){ case "src": if (this.url_ == val) break; this.url_ = val; delete this.datasource_; this.clear_list(); break; case "key-column": case "new-phrase": case "new-key": case "new-show": case "arg": this.set_attr(nam, val); break; case "show": this.set_attr(nam, val); if (!this.get_attr("key-column")) this.set_attr("key-column", val); break; case "hint": this.hints_ = val ? val.split(" ") : []; break; case "min-input": var num = parseInt(val, 10); if (!isNaN(num)) this.set_attr(nam, num); break; case "text": this.set_attr(nam, val); break; } }, clear_list: function(){ if (!this.list_) return; for (var child = this.list_.firstChild; child;){ var ref = child; child = child.nextSibling; if (ref.nodeType != Node.ELEMENT_NODE || !Element.hasClassName(ref, "NewElement")) this.list_.removeChild(ref); } if (this.highlighted_ && this.highlighted_.parentNode != this.list_) this.highlight(null); }, set_leader: function(elem){ if (!elem || this.leader_ == elem) return; if (typeof this.leader_callbacks_ != "undefined"){ this.remove_callbacks(this.leader_callbacks_); delete this.leader_callbacks_; } if (this.leader_) delete this.leader_; // if (elem && Node.localName(elem).toLowerCase() == "input" || Node.localName(elem).toLowerCase() == "textarea" ){ if (elem){ this.leader_ = elem; this.add_callbacks(this.leader_callbacks_ = [ // [elem, SuperclassInput.keypress_name(), this.leader_keypress.bindAsEventListener(this)], [elem, "keydown", this.leader_keypress.bindAsEventListener(this)], [elem, "keyup", this.leader_keyup.bindAsEventListener(this)], [elem, "keydown", this.leader_keydown.bindAsEventListener(this)] ]); if (this.awnd_) this.awnd_.Unsubscribe("INPUT", this.onINPUT, this); } }, onINPUT: function(aevent){ var emitter = aevent.Emitter(); if (!this.acceptor_ || emitter != this.acceptor_) return; this.set_substr(this.acceptor_.Value()); this.set_leader(document.getElementById(this.acceptor_.ID())); }, set_substr: function(val){ // console.log("set_substr: " + Object.toJSON(val)) var str = this.val2str(val); if (this.substr_ == str && this.get_attr("text") != "yes" ) return; this.substr_ = str; this.abort_request_timer(); if (!str || this.substr_.length < this.get_attr_or("min-input", 1)){ this.abort_server_call(); this.process_data(null); }else if (!this.datasource_) this.refresh_datasource(str); else this.substr_timer_ = window.setTimeout(this.filter.curry(str).bind(this), 50); }, val2str: function(val){ while (val instanceof Optional) val = val.Value(); if (typeof val == "undefined" || null === val) return ""; else if (typeof val == "string") return val; else return String(str); }, abort_request_timer: function(){ if (typeof this.substr_timer_ != "undefined"){ window.clearTimeout(this.substr_timer_); delete this.substr_timer_; } }, refresh_datasource: function(str){ if (this.datasource_) delete this.datasource_; if (!this.url_) return void this.abort_server_call(); var qidx = this.url_.indexOf("?"); var method = qidx == -1 ? this.url_ : this.url_.substr(0, qidx); var params = qidx == -1 ? {} : URLRestoreVS(this.url_.substr(qidx + 1)); var arg = this.get_attr("arg"); if (arg) params[arg] = str; if( this.get_attr("text") && this.get_attr("text") == "yes" && this.ctrl_and_gap_press == 1 ) { this.caret_position = getSelectionStart( document.getElementById(this.acceptor_.ID())); var arr_symbols = [ " ", "\n" ]; var num_start = Math.max( str.lastIndexOf(arr_symbols[0], this.caret_position-1), str.lastIndexOf(arr_symbols[1], this.caret_position-1) ); if( num_start == -1 ) num_start = 0; else num_start = num_start + 1; var num_end = Math.min( str.indexOf(arr_symbols[0], this.caret_position-1), str.indexOf(arr_symbols[1], this.caret_position-1) ); if( num_end == -1 ) num_end = this.caret_position - 1; else num_end = num_end - 1; var now_str = str.substring(num_start, num_end + 1); this.begin_str = str.substring(0, num_start); this.end_str = str.substring(num_end+1); params[arg] = now_str; this.substr_ = now_str; } /// if - того чтобы при изначальном вбивании не показывался список вариантов if( !this.get_attr("text") || ( this.get_attr("text") && this.get_attr("text") == "yes" && this.ctrl_and_gap_press == 1 ) ) { this.make_server_call(method, URLSerializeVS(params), { "onSuccess": function(apacket){ var data = apacket.Data(); if (data && data.DataSource){ this.datasource_ = data.DataSource; this.filter(str); }else this.process_data(data); }, "thisObject": this }); } }, abort_server_call: function(){ if (this.server_call_){ this.server_call_.Abort(); delete this.server_call_; } }, make_server_call: function(){ this.abort_server_call(); var ctor = function(){}; ctor.prototype = ServerCall.prototype; this.server_call_ = new ctor(); ServerCall.apply(this.server_call_, arguments); }, filter: function(str){ this.abort_request_timer(); var feeder = this.datasource_.Feeder(); var filters = {}; var show = this.get_attr("show"); if (show) filters[show] = str; var method = "/" + ["srv", feeder.ContName(), feeder.ObjName(), "Pass"].join("/"); var params = { "Filters": filters, "SmartSortHints": filters, "FirstRow": unsigned(0), "Size": unsigned(10), "AsArray": 1 }; this.make_server_call(method, URLSerializeVS(params), { "onSuccess": function(apacket){ this.process_data(apacket.Data()); }, "onException": function(msg, errcode){ LogE("DynamicAutosuggest: PASS failed: message=" + Object.toJSON(msg) + ", " +// "error code=" + errcode + ")"); if (errcode) this.refresh_datasource(this.substr_); }, "thisObject": this }); }, process_data: function(data){ if (!this.list_) return; this.clear_list(); var lastchild = this.list_.lastChild; if (data){ var show = this.get_attr("show"); var key = this.get_attr("key-column"); var lowercase = String(this.substr_ || "").toLowerCase(); for (var iii = 0; iii < data.length; ++iii){ var row = data[iii]; var child = document.createElement("li"); child.key = row[key]; if (this.hints_){ var span = document.createElement("span"); Element.writeAttribute(span, "class", "SuggesterHint"); var str = new Array(this.hints_.length); for (var jjj = 0; jjj < this.hints_.length; ++jjj) str[jjj] = row[this.hints_[jjj]]; span.appendChild(document.createTextNode(str.join(" "))); child.appendChild(span); } var main = document.createElement("span"); var text = String(child.show = row[show]); var ind = this.substr_ ? text.toLowerCase().indexOf(lowercase) : -1; if (lowercase && -1 == ind) continue; else if (-1 == ind) main.appendChild(document.createTextNode(text)); else{ if (ind > 0) main.appendChild(document.createTextNode(text.substr(0, ind))); var hlt = document.createElement("font"); Element.writeAttribute(hlt, "class", "Highlight"); hlt.appendChild(document.createTextNode(text.substr(ind, lowercase.length))); main.appendChild(hlt); ind += lowercase.length; if (ind < text.length) main.appendChild(document.createTextNode(text.substr(ind))); } child.appendChild(main); if (lastchild) this.list_.insertBefore(child, lastchild); else this.list_.appendChild(child); } } if (!lastchild){ var newphrase = this.get_attr("new-phrase"); if (newphrase){ var child = lastchild = document.createElement("li"); Element.writeAttribute(child, "class", "NewElement"); var span = document.createElement("span"); span.appendChild(document.createTextNode(newphrase)); child.appendChild(span); this.list_.appendChild(child); } } var child = this.list_.firstChild; this.highlight(child); if (child && !Element.hasClassName(child, "NewElement") && this.leader_ &&// this.val2str(child.show) == this.leader_.value) this.accept(child, true); else this.update_value(); if (child && this.substr_.length >= this.get_attr_or("min-input", 1)) this.show(); else this.hide(); }, get_last_child: function(elem){ if (!elem) return null; for (var child = elem.lastChild; child; child = child.previousSibling) if (child.nodeType == Node.ELEMENT_NODE) return child; return null; }, attached: function(node){ if (!node) return false; if (!node.parentNode) return false; if (node.parentNode.nodeType != Node.ELEMENT_NODE) return false; return true; }, show: function(){ if (!this.list_) return; this.update_list_position(); if (!this.attached(this.list_) && this.acceptor_){ var elem = document.getElementById(this.acceptor_.ID()); if (elem && elem.parentNode) elem.parentNode.insertBefore(this.list_, elem); } if (!this.attached(this.list_)) return; Element.setStyle(this.list_, {"display": ""}); this.list_.isopen_ = true; if (this.list_callbacks_) return; var resize = function(event){ if (this.list_ && this.list_.isopen_) this.update_list_position(); }.bindAsEventListener(this); this.list_callbacks_ = [// [this.list_, "mouseover", this.list_mouseover.bindAsEventListener(this)], [this.list_, "mouseout", this.list_mouseout.bindAsEventListener(this)], [this.list_, "mousedown", this.list_mousedown.bindAsEventListener(this)], [this.list_, "mouseup", this.list_mouseup.bindAsEventListener(this)], [window, "resize", resize], [document, "mousewheel", resize], [document, "DOMMouseScroll", resize] ]; if (this.leader_ ) this.list_callbacks_.push([this.leader_, "blur", this.leader_blur.bindAsEventListener(this)]); this.add_callbacks(this.list_callbacks_); }, add_callbacks: function(arr){ arr.each(function(args){ Event.observe.apply(null, args); }); }, remove_callbacks: function(arr){ arr.each(function(args){ Event.stopObserving.apply(null, args); }); }, update_list_position: function(){ if (!this.list_ || !this.acceptor_) return; var aligner = document.getElementById(this.acceptor_.ID()); if (!aligner) return; var clone = this.list_.cloneNode(true); Element.setStyle(clone, {"visibility": "hidden", "display": "",// "top": "-10000px", "height": "", "maxHeight": "",// "left": "-10000px", "width": "", "maxWidth": ""}); Element.select(clone, "span.SuggesterHint").invoke("setStyle", {"width": "", "maxWidth": "", "float": "none"}); aligner.parentNode.insertBefore(clone, aligner); var pos = ItemsList.getOptimalPosition(aligner, clone); var cloneW = Element.getWidth(clone); var alignW, alignL; if (aligner.getBoundingClientRect){ var rect = aligner.getBoundingClientRect(); alignW = rect.width || rect.right - rect.left; alignL = rect.left; }else{ alignW = Element.getWidth(aligner); alignL = Element.viewportOffset(aligner).left; } var docW = document.viewport.getWidth(); var maxwidth = Math.max(alignW, docW - alignL - 10); if (cloneW > maxwidth) pos["maxWidth"] = maxwidth; ["offsetLeft", "offsetTop"].each(function(nam){ if (!(nam in pos)) pos[nam] = 0; }); if (Prototype.Browser.IE && !("maxWidth" in pos)) pos["maxWidth"] = Math.max(pos["offsetLeft"] + alignW, cloneW); if ("maxWidth" in pos){ for (var child = this.list_.firstChild, _child = clone.firstChild; child && _child; child = child.nextSibling, _child = _child.nextSibling){ var hint = Element.down(child, "span.SuggesterHint"); if (!hint) continue; var hintwidth = pos.maxWidth - (Prototype.Browser.IE ? 40 : 20); for (var _grandchild = _child.firstChild; _grandchild; _grandchild = _grandchild.nextSibling){ if (_grandchild.nodeType === Node.ELEMENT_NODE && // !Element.hasClassName(_grandchild, "SuggesterHint")) hintwidth -= Element.getWidth(_grandchild); } Element.setStyle(hint, {"visibility": hintwidth > 0 ? "" : "hidden",// "maxWidth": Math.max(hintwidth, 0) + "px"}); } }else Element.select(this.list_, "span.SuggesterHint").invoke("setStyle", {"maxWidth": "", "visibility": ""}); if (Prototype.Browser.IE){ pos["width"] = pos["maxWidth"]; delete pos["maxWidth"]; } if (Prototype.Browser.IE && clone.getBoundingClientRect){ var rect = clone.getBoundingClientRect(); pos.offsetLeft += clone.offsetLeft - rect.left; pos.offsetTop += clone.offsetTop - rect.top; } clone.parentNode.removeChild(clone); if (aligner.getBoundingClientRect){ var rect = aligner.getBoundingClientRect(); if( this.get_attr("text") ) { var text_clone = document.getElementById(this.acceptor_.ID()).cloneNode(true); Element.setStyle( text_clone, {"visibility": "yes", "height": "" ,"top": "0px", "left": "0px", "position": "fixed" , "background-color": "#EA9B9B"}); document.body.appendChild( text_clone ); text_clone.setAttribute("rows",1); text_clone.setAttribute("id","ForSuggester"); text_clone.setAttribute("auto-grow","no"); text_clone.update( this.begin_str ); var scr = text_clone.scrollHeight; document.body.removeChild( text_clone ); Element.setStyle(this.list_, {"left": rect.left + pos.offsetLeft + "px", "top": rect.top + scr + "px"}); } else Element.setStyle(this.list_, {"left": rect.left + pos.offsetLeft + "px", "top": rect.top + pos.offsetTop + "px"}); }else Element.clonePosition(this.list_, aligner, { "setHeight": false, "setWidth": false,// "offsetTop": pos.offsetTop, "offsetLeft": pos.offsetLeft }); var style = {"minWidth": aligner.clientWidth + "px"}; ["maxWidth", "maxHeight", "width"].each(// function(key){ if (key in pos) style[key] = pos[key] + "px"; }); Element.setStyle(this.list_, style); }, hide: function(){ if (!this.list_ || !this.list_.isopen_) return; Element.setStyle(this.list_, {"display": "none"}); if (this.list_callbacks_){ this.remove_callbacks(this.list_callbacks_); delete this.list_callbacks_; } this.list_.isopen_ = false; }, SetValue: function(val){ if (URLSerialize(this.value_) != URLSerialize(val)) this.update_error(this.value_ = val); }, Value: function(val){ return this.value_; }, list_mouseover: function(event){ var child = Event.findElement(event, "li"); if (child && child.parentNode == this.list_) this.highlight(child); }, list_mouseout: function(event){ var child = Event.findElement(event, "li"); if (child && child.parentNode == this.list_ && this.highlighted_ == child){ Element.removeClassName(this.highlighted_, this.highlighted_classname_); delete this.highlighted_; } }, list_mousedown: function(event){ if (Prototype.Browser.IE) this.ignore_blur_ = true; event.preventDefault(); }, highlighted_classname_: "Active", highlight: function(child){ if (this.highlighted_ == child) return; if (this.highlighted_){ Element.removeClassName(this.highlighted_, this.highlighted_classname_); delete this.highlighted_; } if (child && child.parentNode == this.list_) Element.addClassName(this.highlighted_ = child, this.highlighted_classname_); }, highlight_prev: function(){ this.highlight((this.highlighted_ && this.highlighted_.parentNode == this.list_ ?// this.highlighted_.previousSibling : null) || this.list_.lastChild); }, highlight_next: function(){ this.highlight((this.highlighted_ && this.highlighted_.parentNode == this.list_ ?// this.highlighted_.nextSibling : null) || this.list_.firstChild); }, list_mouseup: function(event){ this.accept(Event.findElement(event, "li")); }, accept: function(child, stay_open){ if (!stay_open) this.hide(); if (!child || child.parentNode != this.list_) return; if (Element.hasClassName(child, "NewElement")){ if (this.acceptor_) new AEvent("WM_INIT", {}, this.acceptor_); new AEvent("ADD", {}, this); }else if (URLSerialize(this.Value()) == URLSerialize(child.key)) return; else{ if( this.get_attr("text") && this.get_attr("text")=="yes" && this.ctrl_and_gap_press == 1 ) { var insert_item = this.val2str(child.show); this.ctrl_and_gap_press = 0; var pos = this.begin_str.length + insert_item.length; this.set_acceptor_value( this.substr_ = (this.begin_str + insert_item + this.end_str) ); this.update_value(this.substr_); document.getElementById(this.acceptor_.ID()).setSelectionRange( pos, pos ); // setSelectionRange( document.getElementById(this.acceptor_.ID()), pos, pos ); } else { this.set_acceptor_value(this.substr_ = this.val2str(child.show)); this.update_value(child.key); } } }, set_acceptor_value: function(val){ if (!this.acceptor_) return; this.acceptor_.SetValue(val); new AEvent("WM_INIT", {}, this.acceptor_); }, update_value: function(val){ if (URLSerialize(this.value_) != URLSerialize(val)){ this.update_error(this.value_ = val); new AEvent("CHANGE", {}, this); }else this.update_error(val); }, update_error: function(val){ // console.log("update_error: " + Object.toJSON(val)) if (this.get_attr("highlight") == "no") return; Element[typeof val == "undefined" && this.leader_ && this.leader_.value ?// "addClassName" : "removeClassName"](this.leader_, "NotSelected"); }, leader_keypress: function(event){ switch (event.keyCode){ case Event.KEY_RETURN: if (!this.list_.isopen_) return; this.accept(this.highlighted_); this.hide(); event.stop(); return false; break; case Event.KEY_UP: this.highlight_prev(); event.stop(); break; case Event.KEY_DOWN: this.highlight_next(); event.stop(); break; case Event.KEY_RIGHT: if (!this.leader_ || !this.list_.isopen_) break; var child = this.highlighted_; if (!child || child.parentNode != this.list_ || Element.hasClassName(child, "NewElement")) break; var ss = getSelectionStart(this.leader_); if (ss < this.leader_.value.length) break; var se = getSelectionEnd(this.leader_); if (se < this.leader_.value.length) break; this.accept(child); //or this.accept(child, true) to leave it open break; } // if( this.get_attr("text") && this.get_attr("text") == "yes" && this.ctrl_and_gap_press == 1 ) { // document.getElementById(this.acceptor_.ID()).setSelectionRange( this.caret_position, this.caret_position ); // } }, leader_keyup: function(event){ if (!this.acceptor_ || event.ctrlKey || event.altKey ||// [Event.KEY_RETURN,// Event.KEY_LEFT, Event.KEY_UP, Event.KEY_RIGHT, Event.KEY_DOWN,// Event.KEY_HOME, Event.KEY_END].indexOf(event.keyCode) != -1) return; else this.set_substr(this.acceptor_.Value()); }, leader_keydown: function(event){ if (!this.acceptor_ ) return; var key=event.which || event.keyCode; if( this.get_attr("text") && this.get_attr("text") == "yes" && key==32 && event.ctrlKey ) { this.ctrl_and_gap_press = 1; this.set_substr(this.acceptor_.Value()); if( this.ctrl_and_gap_press == 1 ) event.stop(); } }, leader_blur: function(event){ if (this.ignore_blur_) { document.body.removeChild( this.list_ ); delete this.ignore_blur_; } else if( this.get_attr("text") && this.get_attr("text")=="yes" && this.ctrl_and_gap_press == 1 ) { this.ctrl_and_gap_press = 0; this.hide(); event.stop(); } else this.hide(); }, onWMBACK: function(aevent){ if (!this.popup_ || aevent.Emitter() != this.popup_) return; aevent.Stop(); this.popup_.oPopup.Close(); this.popup_.Die(); delete this.popup_; delete this.datasource_; var args = aevent.Data().args; var newshow = this.get_attr("new-show"); if (newshow && args[newshow]) this.set_acceptor_value(args[newshow]); var newkey = this.get_attr("new-key") if (newkey && args[newkey]) this.update_value(args[newkey]); }, onWMPOPUP: function(aevent){ var data = aevent.Data(); if (!data || typeof data["id"] == "undefined" || data["id"] != this.localid_) return; aevent.Stop(); var args = { "autoSize": true, "bFitToScreen": true, "canResize": false,// "sParent": AControl.GetParentWindowInstanceID(this.ID()),// "fOnWMBackCallback": this.onWMBACK.bind(this) }; if (this.acceptor_) args["alignID"] = this.acceptor_.ID(); if (typeof data.src != "undefined") args["sURL"] = data.src; if (typeof data.args != "undefined") args["sParams"] = URLSerializeVS(data.args); this.popup_ = new APopupWindow(args); } });