1 line
21 KiB
JavaScript
1 line
21 KiB
JavaScript
Type.registerNamespace("Sys.Extended.UI");Sys.Extended.UI.AutoCompleteBehavior=function(n){Sys.Extended.UI.AutoCompleteBehavior.initializeBase(this,[n]);this._servicePath=null;this._serviceMethod=null;this._contextKey=null;this._useContextKey=!1;this._minimumPrefixLength=3;this._completionSetCount=10;this._completionInterval=1e3;this._completionListElementID=null;this._completionListElement=null;this._textColor="windowtext";this._textBackground="window";this._popupBehavior=null;this._popupBehaviorHiddenHandler=null;this._onShowJson=null;this._onHideJson=null;this._timer=null;this._cache=null;this._currentPrefix=null;this._selectIndex=-1;this._focusHandler=null;this._blurHandler=null;this._bodyClickHandler=null;this._completionListBlurHandler=null;this._keyDownHandler=null;this._mouseDownHandler=null;this._mouseUpHandler=null;this._mouseOverHandler=null;this._tickHandler=null;this._enableCaching=!0;this._flyoutHasFocus=!1;this._textBoxHasFocus=!1;this._completionListCssClass=null;this._completionListItemCssClass=null;this._highlightedItemCssClass=null;this._delimiterCharacters=null;this._firstRowSelected=!1;this._showOnlyCurrentWordInCompletionListItem=!1;this._webRequest=null};Sys.Extended.UI.AutoCompleteBehavior.prototype={initialize:function(){Sys.Extended.UI.AutoCompleteBehavior.callBaseMethod(this,"initialize");$common.prepareHiddenElementForATDeviceUpdate();this._popupBehaviorHiddenHandler=Function.createDelegate(this,this._popupHidden);this._tickHandler=Function.createDelegate(this,this._onTimerTick);this._focusHandler=Function.createDelegate(this,this._onGotFocus);this._blurHandler=Function.createDelegate(this,this._onLostFocus);this._keyDownHandler=Function.createDelegate(this,this._onKeyDown);this._mouseDownHandler=Function.createDelegate(this,this._onListMouseDown);this._mouseUpHandler=Function.createDelegate(this,this._onListMouseUp);this._mouseOverHandler=Function.createDelegate(this,this._onListMouseOver);this._completionListBlurHandler=Function.createDelegate(this,this._onCompletionListBlur);this._bodyClickHandler=Function.createDelegate(this,this._onCompletionListBlur);this._timer=new Sys.Timer;this.initializeTimer(this._timer);var n=this.get_element();this.initializeTextBox(n);this._completionListElementID!==null&&(this._completionListElement=$get(this._completionListElementID));this._completionListElement==null&&(this._completionListElement=document.createElement("ul"),this._completionListElement.id=this.get_id()+"_completionListElem",Sys.Browser.agent===Sys.Browser.Safari?document.body.appendChild(this._completionListElement):n.parentNode.insertBefore(this._completionListElement,n.nextSibling));this.initializeCompletionList(this._completionListElement);this._popupBehavior=$create(Sys.Extended.UI.PopupBehavior,{id:this.get_id()+"PopupBehavior",parentElement:n,positioningMode:Sys.Extended.UI.PositioningMode.BottomLeft},null,null,this._completionListElement);this._popupBehavior.add_hidden(this._popupBehaviorHiddenHandler);this._onShowJson&&this._popupBehavior.set_onShow(this._onShowJson);this._onHideJson&&this._popupBehavior.set_onHide(this._onHideJson)},dispose:function(){this._onShowJson=null;this._onHideJson=null;this._popupBehavior&&(this._popupBehaviorHiddenHandler&&this._popupBehavior.remove_hidden(this._popupBehaviorHiddenHandler),this._popupBehavior.dispose(),this._popupBehavior=null);this._timer&&(this._timer.dispose(),this._timer=null);var n=this.get_element();n&&($removeHandler(n,"focus",this._focusHandler),$removeHandler(n,"blur",this._blurHandler),$removeHandler(n,"keydown",this._keyDownHandler),$removeHandler(this._completionListElement,"blur",this._completionListBlurHandler),$removeHandler(this._completionListElement,"mousedown",this._mouseDownHandler),$removeHandler(this._completionListElement,"mouseup",this._mouseUpHandler),$removeHandler(this._completionListElement,"mouseover",this._mouseOverHandler));this._bodyClickHandler&&($removeHandler(document.body,"click",this._bodyClickHandler),this._bodyClickHandler=null);this._popupBehaviorHiddenHandler=null;this._tickHandler=null;this._focusHandler=null;this._blurHandler=null;this._keyDownHandler=null;this._completionListBlurHandler=null;this._mouseDownHandler=null;this._mouseUpHandler=null;this._mouseOverHandler=null;Sys.Extended.UI.AutoCompleteBehavior.callBaseMethod(this,"dispose")},initializeTimer:function(n){n.set_interval(this._completionInterval);n.add_tick(this._tickHandler)},initializeTextBox:function(n){n.autocomplete="off";$addHandler(n,"focus",this._focusHandler);$addHandler(n,"blur",this._blurHandler);$addHandler(n,"keydown",this._keyDownHandler)},initializeCompletionList:function(n){if(this._completionListCssClass)Sys.UI.DomElement.addCssClass(n,this._completionListCssClass);else{var t=n.style;t.textAlign="left";t.visibility="hidden";t.cursor="default";t.listStyle="none";t.padding="0px";t.margin="0px! important";Sys.Browser.agent===Sys.Browser.Safari?(t.border="solid 1px gray",t.backgroundColor="white",t.color="black"):(t.border="solid 1px buttonshadow",t.backgroundColor=this._textBackground,t.color=this._textColor)}$addHandler(n,"mousedown",this._mouseDownHandler);$addHandler(n,"mouseup",this._mouseUpHandler);$addHandler(n,"mouseover",this._mouseOverHandler);$addHandler(n,"blur",this._completionListBlurHandler);$addHandler(document.body,"click",this._bodyClickHandler)},_currentCompletionWord:function(){var u=this.get_element(),t=u.value,r=t,n,i;return this.get_isMultiWord()&&(n=this._getCurrentWordStartIndex(),i=this._getCurrentWordEndIndex(n),r=i<=n?t.substring(n):t.substring(n,i)),r},_getCursorIndex:function(){return this.get_element().selectionStart},_getCurrentWordStartIndex:function(){for(var r,u=this.get_element(),f=u.value.substring(0,this._getCursorIndex()),n=0,t=-1,i=0;i<this._delimiterCharacters.length;++i)r=f.lastIndexOf(this._delimiterCharacters.charAt(i)),r>t&&(t=r);return n=t,n>=this._getCursorIndex()&&(n=0),n<0?0:n+1},_getCurrentWordEndIndex:function(n){for(var i,u=this.get_element(),f=u.value.substring(n),t=0,r=0;r<this._delimiterCharacters.length;++r)i=f.indexOf(this._delimiterCharacters.charAt(r)),i>0&&(i<t||t==0)&&(t=i);return t<=0?u.value.length:t+n},get_isMultiWord:function(){return this._delimiterCharacters!=null&&this._delimiterCharacters!=""},_getTextWithInsertedWord:function(n){var i=n,o=this.get_element(),r=o.value;if(this.get_isMultiWord()){var t=this._getCurrentWordStartIndex(),u=this._getCurrentWordEndIndex(t),f="",e="";t>0&&(f=r.substring(0,t));u>t&&(e=r.substring(u));i=f+n+e}return i},_hideCompletionList:function(){var n=new Sys.CancelEventArgs;(this.raise_hiding(n),n.get_cancel())||this.hidePopup()},showPopup:function(){this._popupBehavior.show();this.raise_shown(Sys.EventArgs.Empty)},hidePopup:function(){this._popupBehavior?this._popupBehavior.hide():this._popupHidden()},_popupHidden:function(){this._completionListElement.innerHTML="";this._selectIndex=-1;this._flyoutHasFocus=!1;this.raise_hidden(Sys.EventArgs.Empty)},_highlightItem:function(n){for(var t,r=this._completionListElement.childNodes,i=0;i<r.length;i++)t=r[i],t._highlighted&&(this._completionListItemCssClass?(Sys.UI.DomElement.removeCssClass(t,this._highlightedItemCssClass),Sys.UI.DomElement.addCssClass(t,this._completionListItemCssClass)):Sys.Browser.agent===Sys.Browser.Safari?(t.style.backgroundColor="white",t.style.color="black"):(t.style.backgroundColor=this._textBackground,t.style.color=this._textColor),this.raise_itemOut(new Sys.Extended.UI.AutoCompleteItemEventArgs(t,t.firstChild.nodeValue,t._value)));this._highlightedItemCssClass?(Sys.UI.DomElement.removeCssClass(n,this._completionListItemCssClass),Sys.UI.DomElement.addCssClass(n,this._highlightedItemCssClass)):Sys.Browser.agent===Sys.Browser.Safari?n.style.backgroundColor="lemonchiffon":(n.style.backgroundColor="highlight",n.style.color="highlighttext");n._highlighted=!0;this.raise_itemOver(new Sys.Extended.UI.AutoCompleteItemEventArgs(n,n.firstChild.nodeValue,n._value))},_onCompletionListBlur:function(){this._hideCompletionList()},_onListMouseDown:function(n){n.target!==this._completionListElement?(this._setText(n.target),this._flyoutHasFocus=!1):this._flyoutHasFocus=!0},_onListMouseUp:function(){if(!this._flyoutHasFocus)try{this.get_element().focus()}catch(n){}},_onListMouseOver:function(n){var i=n.target,r,t;if(i!==this._completionListElement)for(r=this._completionListElement.childNodes,t=0;t<r.length;++t)if(i===r[t]){this._highlightItem(i);this._selectIndex=t;break}},_onGotFocus:function(){this._textBoxHasFocus=!0;this._flyoutHasFocus&&this._hideCompletionList();this._minimumPrefixLength!=0||this.get_element().value||this._timer.set_enabled(!0)},_onKeyDown:function(n){this._textBoxHasFocus=!0;this._timer.set_enabled(!1);var t=n.keyCode?n.keyCode:n.rawEvent.keyCode;t===Sys.UI.Key.esc?(this._hideCompletionList(),n.preventDefault()):t===Sys.UI.Key.up?this._selectIndex>0&&(this._selectIndex--,this._handleScroll(this._completionListElement.childNodes[this._selectIndex],this._selectIndex),this._highlightItem(this._completionListElement.childNodes[this._selectIndex]),n.stopPropagation(),n.preventDefault()):t===Sys.UI.Key.down?this._selectIndex<this._completionListElement.childNodes.length-1&&(this._selectIndex++,this._handleScroll(this._completionListElement.childNodes[this._selectIndex],this._selectIndex),this._highlightItem(this._completionListElement.childNodes[this._selectIndex]),n.stopPropagation(),n.preventDefault()):t===Sys.UI.Key.enter?this._selectIndex!==-1?(this._setText(this._completionListElement.childNodes[this._selectIndex]),n.preventDefault()):this.hidePopup():t===Sys.UI.Key.tab?this._selectIndex!==-1&&this._setText(this._completionListElement.childNodes[this._selectIndex]):this._timer.set_enabled(!0)},_handleScroll:function(n,t){var i=this._completionListElement,r=$common.getBounds(n),u=this._completionListElement.childNodes.length;r.height*t-(i.clientHeight+i.scrollTop)>=0&&(i.scrollTop+=r.height*t-(i.clientHeight+i.scrollTop)+r.height);r.height*(u-(t+1))-(i.scrollHeight-i.scrollTop)>=0&&(i.scrollTop-=r.height*(u-(t+1))-(i.scrollHeight-i.scrollTop)+r.height);i.scrollTop%r.height!=0&&(r.height*(t+1)-(i.clientHeight+i.scrollTop)>=0?i.scrollTop-=i.scrollTop%r.height:i.scrollTop+=r.height-i.scrollTop%r.height)},_handleFlyoutFocus:function(){this._textBoxHasFocus||this._flyoutHasFocus||(this._webRequest&&(this._webRequest.get_executor().abort(),this._webRequest=null),this._hideCompletionList())},_onLostFocus:function(){this._textBoxHasFocus=!1;this._timer.set_enabled(!1);window.setTimeout(Function.createDelegate(this,this._handleFlyoutFocus),500)},_onMethodComplete:function(n,t){this._webRequest=null;this._update(t,n,!0)},_onMethodFailed:function(){this._webRequest=null},_onTimerTick:function(n,t){var i,t,r;if(this._timer.set_enabled(!1),this._servicePath&&this._serviceMethod){if(i=this._currentCompletionWord(),i.trim().length<this._minimumPrefixLength){this._currentPrefix=null;this._update("",null,!1);return}if(this._currentPrefix!==i||i==""&&this._minimumPrefixLength==0){if(this._currentPrefix=i,i!=""&&this._cache&&this._cache[i]){this._update(i,this._cache[i],!1);return}if(t=new Sys.CancelEventArgs,this.raise_populating(t),t.get_cancel())return;r={prefixText:this._currentPrefix,count:this._completionSetCount};this._useContextKey&&(r.contextKey=this._contextKey);this._webRequest&&(this._webRequest.get_executor().abort(),this._webRequest=null);this._webRequest=Sys.Net.WebServiceProxy.invoke(this.get_servicePath(),this.get_serviceMethod(),!1,r,Function.createDelegate(this,this._onMethodComplete),Function.createDelegate(this,this._onMethodFailed),i);$common.updateFormToRefreshATDeviceBuffer()}}},_setText:function(n){var t=n&&n.firstChild?n.firstChild.nodeValue:null;this._timer.set_enabled(!1);var i=this.get_element(),r=i.control,u=this._showOnlyCurrentWordInCompletionListItem?this._getTextWithInsertedWord(t):t;r&&r.set_text?r.set_text(u):i.value=u;$common.tryFireEvent(i,"change");this.raise_itemSelected(new Sys.Extended.UI.AutoCompleteItemEventArgs(n,t,n?n._value:null));this._currentPrefix=this._currentCompletionWord();this._hideCompletionList()},_update:function(n,t,i){var f,r,o,l,u,a,c;if(i&&this.get_enableCaching()&&(this._cache||(this._cache={}),this._cache[n]=t),!this._textBoxHasFocus||n!=this._currentCompletionWord()){this._hideCompletionList();return}if(t&&t.length){this._completionListElement.innerHTML="";this._selectIndex=-1;var s=null,e=null,h=null;for(f=0;f<t.length;f++){r=null;r=this._completionListElementID?document.createElement("div"):document.createElement("li");s==null&&(s=r);try{o=Sys.Serialization.JavaScriptSerializer.deserialize("("+t[f]+")");o&&o.First?(e=o.First,h=o.Second):(e=t[f],h=e)}catch(v){e=t[f];h=t[f]}l=this._showOnlyCurrentWordInCompletionListItem?e:this._getTextWithInsertedWord(e);r.appendChild(document.createTextNode(l));r._value=h;r.__item="";this._completionListItemCssClass?Sys.UI.DomElement.addCssClass(r,this._completionListItemCssClass):(u=r.style,u.padding="0px",u.textAlign="left",u.textOverflow="ellipsis",Sys.Browser.agent===Sys.Browser.Safari?(u.backgroundColor="white",u.color="black"):(u.backgroundColor=this._textBackground,u.color=this._textColor));this._completionListElement.appendChild(r)}a=$common.getBounds(this.get_element());this._completionListElement.style.width=Math.max(1,a.width-2)+"px";this._completionListElement.scrollTop=0;this.raise_populated(Sys.EventArgs.Empty);c=new Sys.CancelEventArgs;this.raise_showing(c);c.get_cancel()||(this.showPopup(),this._firstRowSelected&&s!=null&&(this._highlightItem(s),this._selectIndex=0))}else this._hideCompletionList()},get_onShow:function(){return this._popupBehavior?this._popupBehavior.get_onShow():this._onShowJson},set_onShow:function(n){this._popupBehavior?this._popupBehavior.set_onShow(n):this._onShowJson=n;this.raisePropertyChanged("onShow")},get_onShowBehavior:function(){return this._popupBehavior?this._popupBehavior.get_onShowBehavior():null},onShow:function(){this._popupBehavior&&this._popupBehavior.onShow()},get_onHide:function(){return this._popupBehavior?this._popupBehavior.get_onHide():this._onHideJson},set_onHide:function(n){this._popupBehavior?this._popupBehavior.set_onHide(n):this._onHideJson=n;this.raisePropertyChanged("onHide")},get_onHideBehavior:function(){return this._popupBehavior?this._popupBehavior.get_onHideBehavior():null},onHide:function(){this._popupBehavior&&this._popupBehavior.onHide()},get_completionInterval:function(){return this._completionInterval},set_completionInterval:function(n){this._completionInterval!=n&&(this._completionInterval=n,this.raisePropertyChanged("completionInterval"))},get_completionList:function(){return this._completionListElement},set_completionList:function(n){this._completionListElement!=n&&(this._completionListElement=n,this.raisePropertyChanged("completionList"))},get_completionSetCount:function(){return this._completionSetCount},set_completionSetCount:function(n){this._completionSetCount!=n&&(this._completionSetCount=n,this.raisePropertyChanged("completionSetCount"))},get_minimumPrefixLength:function(){return this._minimumPrefixLength},set_minimumPrefixLength:function(n){this._minimumPrefixLength!=n&&(this._minimumPrefixLength=n,this.raisePropertyChanged("minimumPrefixLength"))},get_serviceMethod:function(){return this._serviceMethod},set_serviceMethod:function(n){this._serviceMethod!=n&&(this._serviceMethod=n,this.raisePropertyChanged("serviceMethod"))},get_servicePath:function(){return this._servicePath},set_servicePath:function(n){this._servicePath!=n&&(this._servicePath=n,this.raisePropertyChanged("servicePath"))},get_contextKey:function(){return this._contextKey},set_contextKey:function(n){this._contextKey!=n&&(this._contextKey=n,this.set_useContextKey(!0),this.raisePropertyChanged("contextKey"))},get_useContextKey:function(){return this._useContextKey},set_useContextKey:function(n){this._useContextKey!=n&&(this._useContextKey=n,this.raisePropertyChanged("useContextKey"))},get_enableCaching:function(){return this._enableCaching},set_enableCaching:function(n){this._enableCaching!=n&&(this._enableCaching=n,this.raisePropertyChanged("enableCaching"))},get_completionListElementID:function(){return this._completionListElementID},set_completionListElementID:function(n){this._completionListElementID!=n&&(this._completionListElementID=n,this.raisePropertyChanged("completionListElementID"))},get_completionListCssClass:function(){return this._completionListCssClass},set_completionListCssClass:function(n){this._completionListCssClass!=n&&(this._completionListCssClass=n,this.raisePropertyChanged("completionListCssClass"))},get_completionListItemCssClass:function(){return this._completionListItemCssClass},set_completionListItemCssClass:function(n){this._completionListItemCssClass!=n&&(this._completionListItemCssClass=n,this.raisePropertyChanged("completionListItemCssClass"))},get_highlightedItemCssClass:function(){return this._highlightedItemCssClass},set_highlightedItemCssClass:function(n){this._highlightedItemCssClass!=n&&(this._highlightedItemCssClass=n,this.raisePropertyChanged("highlightedItemCssClass"))},get_delimiterCharacters:function(){return this._delimiterCharacters},set_delimiterCharacters:function(n){this._delimiterCharacters!=n&&(this._delimiterCharacters=n,this.raisePropertyChanged("delimiterCharacters"))},get_firstRowSelected:function(){return this._firstRowSelected},set_firstRowSelected:function(n){this._firstRowSelected!=n&&(this._firstRowSelected=n,this.raisePropertyChanged("firstRowSelected"))},get_showOnlyCurrentWordInCompletionListItem:function(){return this._showOnlyCurrentWordInCompletionListItem},set_showOnlyCurrentWordInCompletionListItem:function(n){this._showOnlyCurrentWordInCompletionListItem!=n&&(this._showOnlyCurrentWordInCompletionListItem=n,this.raisePropertyChanged("showOnlyCurrentWordInCompletionListItem"))},add_populating:function(n){this.get_events().addHandler("populating",n)},remove_populating:function(n){this.get_events().removeHandler("populating",n)},raise_populating:function(n){var t=this.get_events().getHandler("populating");t&&t(this,n)},raisePopulating:function(n){Sys.Extended.Deprecated("raisePopulating(eventArgs)","raise_populating(eventArgs)");this.raise_populating(n)},add_populated:function(n){this.get_events().addHandler("populated",n)},remove_populated:function(n){this.get_events().removeHandler("populated",n)},raise_populated:function(n){var t=this.get_events().getHandler("populated");t&&t(this,n)},raisePopulated:function(n){Sys.Extended.Deprecated("raisePopulated(eventArgs)","raise_populated(eventArgs)");this.raise_populated(n)},add_showing:function(n){this.get_events().addHandler("showing",n)},remove_showing:function(n){this.get_events().removeHandler("showing",n)},raise_showing:function(n){var t=this.get_events().getHandler("showing");t&&t(this,n)},raiseShowing:function(n){Sys.Extended.Deprecated("raiseShowing(eventArgs)","raise_showing(eventArgs)");this.raise_showing(n)},add_shown:function(n){this.get_events().addHandler("shown",n)},remove_shown:function(n){this.get_events().removeHandler("shown",n)},raise_shown:function(n){var t=this.get_events().getHandler("shown");t&&t(this,n)},raiseShown:function(n){Sys.Extended.Deprecated("raiseShown(eventArgs)","raise_shown(eventArgs)");this.raise_shown(n)},add_hiding:function(n){this.get_events().addHandler("hiding",n)},remove_hiding:function(n){this.get_events().removeHandler("hiding",n)},raise_hiding:function(n){var t=this.get_events().getHandler("hiding");t&&t(this,n)},raiseHiding:function(n){Sys.Extended.Deprecated("raiseHiding(eventArgs)","raise_hiding(eventArgs)");this.raise_hiding(n)},add_hidden:function(n){this.get_events().addHandler("hidden",n)},remove_hidden:function(n){this.get_events().removeHandler("hidden",n)},raise_hidden:function(n){var t=this.get_events().getHandler("hidden");t&&t(this,n)},raiseHidden:function(n){Sys.Extended.Deprecated("raiseHidden(eventArgs)","raise_hidden(eventArgs)");this.raise_hidden(n)},add_itemSelected:function(n){this.get_events().addHandler("itemSelected",n)},remove_itemSelected:function(n){this.get_events().removeHandler("itemSelected",n)},raise_itemSelected:function(n){var t=this.get_events().getHandler("itemSelected");t&&t(this,n)},raiseItemSelected:function(n){Sys.Extended.Deprecated("raiseItemSelected(eventArgs)","raise_itemSelected(eventArgs)");this.raise_itemSelected(n)},add_itemOver:function(n){this.get_events().addHandler("itemOver",n)},remove_itemOver:function(n){this.get_events().removeHandler("itemOver",n)},raise_itemOver:function(n){var t=this.get_events().getHandler("itemOver");t&&t(this,n)},raiseItemOver:function(n){Sys.Extended.Deprecated("raiseItemOver(eventArgs)","raise_itemOver(eventArgs)");this.raise_itemOver(n)},add_itemOut:function(n){this.get_events().addHandler("itemOut",n)},remove_itemOut:function(n){this.get_events().removeHandler("itemOut",n)},raise_itemOut:function(n){var t=this.get_events().getHandler("itemOut");t&&t(this,n)},raiseItemOut:function(n){Sys.Extended.Deprecated("raiseItemOut(eventArgs)","raise_itemOut(eventArgs)");this.raise_itemOut(n)}};Sys.Extended.UI.AutoCompleteBehavior.registerClass("Sys.Extended.UI.AutoCompleteBehavior",Sys.Extended.UI.BehaviorBase);Sys.Extended.UI.AutoCompleteItemEventArgs=function(n,t,i){Sys.Extended.UI.AutoCompleteItemEventArgs.initializeBase(this);this._item=n;this._text=t;this._value=i!==undefined?i:null};Sys.Extended.UI.AutoCompleteItemEventArgs.prototype={get_item:function(){return this._item},set_item:function(n){this._item=n},get_text:function(){return this._text},set_text:function(n){this._text=n},get_value:function(){return this._value},set_value:function(n){this._value=n}};Sys.Extended.UI.AutoCompleteItemEventArgs.registerClass("Sys.Extended.UI.AutoCompleteItemEventArgs",Sys.EventArgs); |