1 line
12 KiB
JavaScript
1 line
12 KiB
JavaScript
Type.registerNamespace("Sys.Extended.UI"),Sys.Extended.UI.ValidatorCalloutBehavior=function(t){Sys.Extended.UI.ValidatorCalloutBehavior.initializeBase(this,[t]),this._warningIconImageUrl=null,this._closeImageUrl=null,this._cssClass="ajax__validatorcallout",this._highlightCssClass=null,this._popupPosition=Sys.Extended.UI.ValidatorCalloutPosition.Right,this._width="200px",this._invalid=!1,this._originalValidationMethod=null,this._validationMethodOverride=null,this._elementToValidate=null,this._popupTable=null,this._errorMessageCell=null,this._calloutArrowCell=null,this._warningIconImage=null,this._closeImage=null,this._closeCellInnerDiv=null,this._popupBehavior=null,this._onShowJson=null,this._onHideJson=null,this._focusAttached=!1,this._isBuilt=!1,this._focusHandler=Function.createDelegate(this,this._onfocus),this._closeClickHandler=Function.createDelegate(this,this._oncloseClick),this._originalValidationMethodOverriden=!1,Sys.Application.add_load(this._loadHandler)},Sys.Extended.UI.ValidatorCalloutBehavior.prototype={initialize:function(){Sys.Extended.UI.ValidatorCalloutBehavior.callBaseMethod(this,"initialize");var t=this.get_ClientState();null!=t&&""!==t&&(this._ensureCallout(),this._highlightCssClass&&Sys.UI.DomElement.addCssClass(this._elementToValidate,this._highlightCssClass),this.show())},_loadHandler:function(t,i){for(var e=i.get_components(),o=0;o<e.length;o++){var a=e[o];a instanceof Sys.Extended.UI.ValidatorCalloutBehavior&&a.attachToValidator()}},attachToValidator:function(){var t=this.get_element(),i=this;this._originalValidationMethodOverriden||(window.jQuery?window.jQuery(function(e){e(function(){i.checkPageValidators(t)})}):i.overrideEvaluationFunction(t),this._originalValidationMethodOverriden=!0)},checkPageValidators:function(t){if("undefined"!=typeof Page_Validators)for(i=0;i<Page_Validators.length;i++){var e=Page_Validators[i];if(e.ValidatorCalloutBehavior===this&&"function"==typeof e.evaluationfunction){t.evaluationfunction=e.evaluationfunction,this.overrideEvaluationFunction(t);break}}},overrideEvaluationFunction:function(t){t.evaluationfunction&&(this._originalValidationMethod=Function.createDelegate(t,t.evaluationfunction),this._validationMethodOverride=Function.createDelegate(this,this._onvalidate),t.evaluationfunction=this._validationMethodOverride,t.removeAttribute("data-val-evaluationfunction"))},_ensureCallout:function(){if(!this._isBuilt){var t=this.get_element(),i=this._elementToValidate=$get(null!=t.controltovalidate?t.controltovalidate:t.getAttribute("data-val-controltovalidate")),e=document.createElement("tbody"),o=document.createElement("tr"),a=document.createElement("td"),s=document.createElement("table"),l=document.createElement("tbody"),n=document.createElement("tr"),h=document.createElement("td"),d=document.createElement("td"),r=this._closeCellInnerDiv=document.createElement("div"),p=this._popupTable=document.createElement("table"),u=this._calloutArrowCell=document.createElement("td"),_=this._warningIconImage=document.createElement("img"),c=this._closeImage=document.createElement("img"),g=this._errorMessageCell=document.createElement("td");if(p.id=this.get_id()+"_popupTable",p.width=this.get_width(),p.className=this._cssClass+" ajax__validatorcallout_popup_table",o.className="ajax__validatorcallout_popup_table_row",a.className="ajax__validatorcallout_callout_cell",s.className="ajax__validatorcallout_callout_table",n.className="ajax__validatorcallout_callout_table_row",this._popupPosition==Sys.Extended.UI.ValidatorCalloutPosition.BottomLeft?u.className="ajax__validatorcallout_callout_arrow_cell_bottomleftpos":this._popupPosition==Sys.Extended.UI.ValidatorCalloutPosition.BottomRight?u.className="ajax__validatorcallout_callout_arrow_cell_bottomrightpos":this._popupPosition==Sys.Extended.UI.ValidatorCalloutPosition.TopLeft?u.className="ajax__validatorcallout_callout_arrow_cell_topleftpos":this._popupPosition==Sys.Extended.UI.ValidatorCalloutPosition.TopRight?u.className="ajax__validatorcallout_callout_arrow_cell_toprightpos":this._popupPosition==Sys.Extended.UI.ValidatorCalloutPosition.Left?u.className="ajax__validatorcallout_callout_arrow_cell_leftpos":u.className="ajax__validatorcallout_callout_arrow_cell",h.className="ajax__validatorcallout_icon_cell",_.border=0,_.src=this.get_warningIconImageUrl(),g.className="ajax__validatorcallout_error_message_cell",g.innerHTML=this._getErrorMessage(),d.className="ajax__validatorcallout_close_button_cell",r.className="ajax__validatorcallout_innerdiv",c.src=this.get_closeImageUrl(),t.parentNode.appendChild(p),p.appendChild(e),e.appendChild(o),o.appendChild(a),a.appendChild(s),s.appendChild(l),l.appendChild(n),n.appendChild(u),o.appendChild(h),h.appendChild(_),o.appendChild(g),o.appendChild(d),r.appendChild(c),d.appendChild(r),this._popupPosition==Sys.Extended.UI.ValidatorCalloutPosition.BottomLeft||this._popupPosition==Sys.Extended.UI.ValidatorCalloutPosition.BottomRight){var C=document.createElement("tr");e.insertBefore(C,o),u.colSpan=2,C.appendChild(u),o.appendChild(h),o.appendChild(g),o.appendChild(d)}else if(this._popupPosition==Sys.Extended.UI.ValidatorCalloutPosition.TopLeft||this._popupPosition==Sys.Extended.UI.ValidatorCalloutPosition.TopRight){var C=document.createElement("tr");e.appendChild(C),u.colSpan=2,C.appendChild(u),o.appendChild(h),o.appendChild(g),o.appendChild(d)}else this._popupPosition==Sys.Extended.UI.ValidatorCalloutPosition.Left?(o.appendChild(h),o.appendChild(g),o.appendChild(d),o.appendChild(a)):(o.appendChild(a),o.appendChild(h),o.appendChild(g),o.appendChild(d));var v=document.createElement("div");if(v.className="ajax__validatorcallout_innerdiv",u.appendChild(v),this._popupPosition==Sys.Extended.UI.ValidatorCalloutPosition.BottomLeft||this._popupPosition==Sys.Extended.UI.ValidatorCalloutPosition.BottomRight){var m=document.createElement("div");m.style.width="1px",m.className="arrowpixel",v.appendChild(m);for(var f=1;f<22;f+=2){var I=document.createElement("div");I.style.width=f.toString()+"px",v.appendChild(I)}}else if(this._popupPosition==Sys.Extended.UI.ValidatorCalloutPosition.TopLeft||this._popupPosition==Sys.Extended.UI.ValidatorCalloutPosition.TopRight){for(var f=23;f>0;f-=2){var I=document.createElement("div");I.style.width=f.toString()+"px",v.appendChild(I)}var m=document.createElement("div");m.style.width="1px",m.className="arrowpixel",v.appendChild(m)}else for(var f=14;f>0;f--){var I=document.createElement("div");I.style.width=f.toString()+"px",v.appendChild(I)}this._popupBehavior=$create(Sys.Extended.UI.PopupBehavior,{parentElement:i},{},null,this._popupTable),this._popupPosition==Sys.Extended.UI.ValidatorCalloutPosition.TopLeft?this._popupBehavior.set_positioningMode(Sys.Extended.UI.PositioningMode.TopLeft):this._popupPosition==Sys.Extended.UI.ValidatorCalloutPosition.TopRight?this._popupBehavior.set_positioningMode(Sys.Extended.UI.PositioningMode.TopRight):this._popupPosition==Sys.Extended.UI.ValidatorCalloutPosition.BottomLeft?this._popupBehavior.set_positioningMode(Sys.Extended.UI.PositioningMode.BottomLeft):this._popupPosition==Sys.Extended.UI.ValidatorCalloutPosition.BottomRight?this._popupBehavior.set_positioningMode(Sys.Extended.UI.PositioningMode.BottomRight):this._popupPosition==Sys.Extended.UI.ValidatorCalloutPosition.Right?this._popupBehavior.set_positioningMode(Sys.Extended.UI.PositioningMode.Right):this._popupPosition==Sys.Extended.UI.ValidatorCalloutPosition.Left?this._popupBehavior.set_positioningMode(Sys.Extended.UI.PositioningMode.Left):this._popupBehavior.set_positioningMode(Sys.Extended.UI.PositioningMode.Right),this._onShowJson&&this._popupBehavior.set_onShow(this._onShowJson),this._onHideJson&&this._popupBehavior.set_onHide(this._onHideJson),$addHandler(this._closeCellInnerDiv,"click",this._closeClickHandler),this._isBuilt=!0}},dispose:function(){this._isBuilt&&(this.hide(),this._focusAttached&&($removeHandler(this._elementToValidate,"focus",this._focusHandler),this._focusAttached=!1),$removeHandler(this._closeCellInnerDiv,"click",this._closeClickHandler),this._onShowJson=null,this._onHideJson=null,this._popupBehavior&&(this._popupBehavior.dispose(),this._popupBehavior=null),this._closeBehavior&&(this._closeBehavior.dispose(),this._closeBehavior=null),this._popupTable&&(this._popupTable.parentNode.removeChild(this._popupTable),this._popupTable=null,this._errorMessageCell=null,this._elementToValidate=null,this._calloutArrowCell=null,this._warningIconImage=null,this._closeImage=null,this._closeCellInnerDiv=null),this._isBuilt=!1),Sys.Extended.UI.ValidatorCalloutBehavior.callBaseMethod(this,"dispose")},_getErrorMessage:function(){var t=this.get_element();return t.errormessage||t.getAttribute("data-val-errormessage")||Sys.Extended.UI.Resources.ValidatorCallout_DefaultErrorMessage},show:function(t){if(t||!this.isOpen()){if(t&&Sys.Extended.UI.ValidatorCalloutBehavior._currentCallout&&Sys.Extended.UI.ValidatorCalloutBehavior._currentCallout.hide(),null!=Sys.Extended.UI.ValidatorCalloutBehavior._currentCallout)return;Sys.Extended.UI.ValidatorCalloutBehavior._currentCallout=this,this._errorMessageCell.innerHTML=this._getErrorMessage(),this._popupBehavior.show()}},hide:function(){Sys.Extended.UI.ValidatorCalloutBehavior._currentCallout==this&&(Sys.Extended.UI.ValidatorCalloutBehavior._currentCallout=null),this.isOpen()&&this._popupBehavior.hide()},_onfocus:function(t){return this._originalValidationMethod(this.get_element())?(this.hide(),!0):(this._ensureCallout(),this._highlightCssClass&&Sys.UI.DomElement.addCssClass(this._elementToValidate,this._highlightCssClass),this.show(!0),!1)},_oncloseClick:function(t){this.hide()},_onvalidate:function(t){return this._originalValidationMethod(t)?(this._highlightCssClass&&this._invalid&&Sys.UI.DomElement.removeCssClass(this._elementToValidate,this._highlightCssClass),this._invalid=!1,this.hide(),!0):(this._ensureCallout(),this._highlightCssClass&&Sys.UI.DomElement.addCssClass(this._elementToValidate,this._highlightCssClass),this._focusAttached||($addHandler(this._elementToValidate,"focus",this._focusHandler),this._focusAttached=!0),this.show(!1),this._invalid=!0,!1)},get_onShow:function(){return this._popupBehavior?this._popupBehavior.get_onShow():this._onShowJson},set_onShow:function(t){this._popupBehavior?this._popupBehavior.set_onShow(t):this._onShowJson=t,this.raisePropertyChanged("onShow")},onShow:function(){this._popupBehavior&&this._popupBehavior.onShow()},get_onShowBehavior:function(){return this._popupBehavior?this._popupBehavior.get_onShowBehavior():null},get_onHide:function(){return this._popupBehavior?this._popupBehavior.get_onHide():this._onHideJson},set_onHide:function(t){this._popupBehavior?this._popupBehavior.set_onHide(t):this._onHideJson=t,this.raisePropertyChanged("onHide")},onHide:function(){this._popupBehavior&&this._popupBehavior.onHide()},get_onHideBehavior:function(){return this._popupBehavior?this._popupBehavior.get_onHideBehavior():null},get_warningIconImageUrl:function(){return this._warningIconImageUrl},set_warningIconImageUrl:function(t){this._warningIconImageUrl!=t&&(this._warningIconImageUrl=t,this.get_isInitialized()&&(this._warningIconImage.src=t),this.raisePropertyChanged("warningIconImageUrl"))},get_closeImageUrl:function(){return this._closeImageUrl},set_closeImageUrl:function(t){this._closeImageUrl!=t&&(this._closeImageUrl=t,this.get_isInitialized()&&(this._closeImage.src=t),this.raisePropertyChanged("closeImageUrl"))},get_width:function(){return this._width},set_width:function(t){this._width!=t&&(this._width=t,this.get_isInitialized()&&(this._popupTable.style.width=_width),this.raisePropertyChanged("width"))},get_popupPosition:function(){return this._popupPosition},set_popupPosition:function(t){this._popupPosition!=t&&(this._popupPosition=t,this.raisePropertyChanged("popupPosition"))},get_cssClass:function(){return this._cssClass},set_cssClass:function(t){this._cssClass!=t&&(this._cssClass=t,this.raisePropertyChanged("cssClass"))},get_highlightCssClass:function(){return this._highlightCssClass},set_highlightCssClass:function(t){this._highlightCssClass!=t&&(this._highlightCssClass=t,this.raisePropertyChanged("highlightCssClass"))},isOpen:function(){return $common.getVisible(this._popupTable)},get_isOpen:function(){return Sys.Extended.Deprecated("get_isOpen()","isOpen()"),this.isOpen()}},Sys.Extended.UI.ValidatorCalloutBehavior.registerClass("Sys.Extended.UI.ValidatorCalloutBehavior",Sys.Extended.UI.BehaviorBase),Sys.Extended.UI.ValidatorCalloutPosition=function(){throw Error.invalidOperation()},Sys.Extended.UI.ValidatorCalloutPosition.prototype={Right:0,Left:1,BottomLeft:2,BottomRight:3,TopLeft:4,TopRight:5},Sys.Extended.UI.ValidatorCalloutPosition.registerEnum("Sys.Extended.UI.ValidatorCalloutPosition"); |