ASPxClientButton = _aspxCreateClass(ASPxClientControl, { constructor: function(name) { this.constructor.prototype.constructor.call(this, name); this.isASPxClientButton = true; this.allowFocus = true; this.autoPostBackFunction = null; this.causesValidation = true; this.checked = false; this.clickLocked = false; this.groupName = ""; this.focusElementSelected = false; this.pressed = false; this.useSubmitBehavior = true; this.validationGroup = ""; this.validationContainerID = null; this.validateInvisibleEditors = false; this.originalWidth = null; this.originalHeight = null; this.buttonCell = null; this.contentDiv = null; this.checkedInput = null; this.buttonImage = null; this.internalButton = null; this.textElement = null; this.textControl = null; this.textContainer = null; this.isTextEmpty = false; this.CheckedChanged = new ASPxClientEvent(); this.GotFocus = new ASPxClientEvent(); this.LostFocus = new ASPxClientEvent(); this.Click = new ASPxClientEvent(); }, InlineInitialize: function() { var mainElement = this.GetMainElement(); this.originalWidth = mainElement.style.width; this.originalHeight = mainElement.style.height; ASPxClientControl.prototype.InlineInitialize.call(this); this.InitializeElementIDs(); this.InitializeEvents(); this.InitializeEnabled(); this.InitializeChecked(); if(this.IsLink()) this.InitializeLink(); this.PreventButtonImageDragging(); }, InitializeElementIDs: function(){ var mainElement = this.GetMainElement(); var contentElement = _aspxGetChildByTagName(mainElement, "DIV", 0); if(contentElement) contentElement.id = this.name + "_CD"; var imageElement = _aspxGetChildByTagName(mainElement, "IMG", 0); if(imageElement) imageElement.id = this.name + "Img"; }, InitializeEnabled: function(){ this.SetEnabledInternal(this.clientEnabled, true); }, InitializeChecked: function(){ this.SetCheckedInternal(this.checked, true); }, InitializeLink: function(){ var mainElement = this.GetMainElement(); if(this.enabled) mainElement.href = "javascript:;"; if(!this.allowFocus) mainElement.style.outline = 0; if(!this.GetTextContainer()) mainElement.style.fontSize = "0pt"; }, InitializeEvents: function(){ if (!this.isNative && !this.IsLink()) { var element = this.GetInternalButton(); if(element) element.onfocus = null; var textControl = this.GetTextControl(); if (textControl) { if (__aspxIE) _aspxAttachEventToElement(textControl, "mouseup", _aspxClearSelection); _aspxPreventElementDragAndSelect(textControl, false); } } var name = this.name; this.onClick = function() { var processOnServer = aspxBClick(name); if (!processOnServer) { var evt = _aspxGetEvent(arguments[0]); if (evt) _aspxPreventEvent(evt); } return processOnServer; }; this.onGotFocus = function() { aspxBGotFocus(name); }; this.onLostFocus = function() { aspxBLostFocus(name); }; this.onKeyUp = function(evt) { aspxBKeyUp(evt, name); }; this.onKeyDown = function(evt) { aspxBKeyDown(evt, name); }; if(!this.isNative && !this.IsLink()) { this.AttachNativeHandlerToMainElement("focus", "SetFocus"); this.AttachNativeHandlerToMainElement("click", "DoClick"); } }, AdjustControlCore: function () { if(this.isNative || this.IsLink()) return; var buttonImage = this.GetButtonImage(); if(buttonImage && buttonImage.offsetHeight === 0 && buttonImage.offsetWidth === 0) buttonImage.onload = function() { this.UpdateSize(); }.aspxBind(this); else this.UpdateSize(); }, UpdateSize: function(){ this.UpdateWidth(); this.UpdateHeight(); }, UpdateHeight: function(){ if(this.isNative || this.IsLink() || this.originalHeight === null || _aspxIsPercentageSize(this.originalHeight)) return; var height; var mainElement = this.GetMainElement(); var borderAndPadding = _aspxGetTopBottomBordersAndPaddingsSummaryValue(mainElement); if(!this.originalHeight) { mainElement.style.height = ""; height = mainElement.offsetHeight - borderAndPadding; } else height = (_aspxPxToInt(this.originalHeight) - borderAndPadding); if(height){ mainElement.style.height = height + "px"; var contentDiv = this.GetContentDiv(); if(contentDiv && contentDiv.offsetHeight > 0){ var contentDivCurrentStyle = _aspxGetCurrentStyle(contentDiv); var paddingTop = parseInt(contentDivCurrentStyle.paddingTop); if(!paddingTop) paddingTop = 0; var paddingBottom = parseInt(contentDivCurrentStyle.paddingBottom); if(!paddingBottom) paddingBottom = 0; var clientHeightDiff = height - contentDiv.offsetHeight; var verticalAlign = _aspxGetCurrentStyle(mainElement).verticalAlign; if(verticalAlign == "top") paddingBottom = paddingBottom + clientHeightDiff; else if(verticalAlign == "bottom") paddingTop = paddingTop + clientHeightDiff; else{ var halfClientHeightDiff = Math.floor(clientHeightDiff / 2); paddingTop = paddingTop + halfClientHeightDiff; paddingBottom = paddingBottom + (clientHeightDiff - halfClientHeightDiff); } contentDiv.style.paddingTop = (paddingTop > 0 ? paddingTop : 0) + "px"; contentDiv.style.paddingBottom = (paddingBottom > 0 ? paddingBottom : 0) + "px"; } } }, UpdateWidth: function(){ if(this.isNative || this.IsLink() || this.originalWidth === null) return; if(!_aspxIsPercentageSize(this.originalWidth)) { var mainElement = this.GetMainElement(); var borderAndPadding = _aspxGetLeftRightBordersAndPaddingsSummaryValue(mainElement); if(__aspxIE && __aspxBrowserVersion < 8){ mainElement.style.display = "inline"; mainElement.style.width = ""; if(mainElement.offsetWidth > 0) mainElement.style.width = (mainElement.offsetWidth + borderAndPadding) + "px"; mainElement.style.display = ""; } else { if(this.originalWidth && _aspxIsTextWrapped(this.GetTextContainer())) mainElement.style.width = (_aspxPxToInt(this.originalWidth) - borderAndPadding) + "px"; else mainElement.style.width = ""; } var width = mainElement.offsetWidth - borderAndPadding; if(this.originalWidth && width < _aspxPxToInt(this.originalWidth) - borderAndPadding) width = _aspxPxToInt(this.originalWidth) - borderAndPadding; if(width) mainElement.style.width = (width > 0 ? width : 0) + "px"; } this.CorrectWrappedText(this.GetContentDiv, "Text", true); }, GetAdjustedSizes: function() { var sizes = ASPxClientControl.prototype.GetAdjustedSizes.call(this); var image = this.GetButtonImage(); if(image) { sizes.imageWidth = image.offsetWidth; sizes.imageHeight = image.offsetHeight; } return sizes; }, PreventButtonImageDragging: function() { _aspxPreventImageDragging(this.GetButtonImage()); }, AttachNativeHandlerToMainElement: function(handlerName, correspondingMethodName) { var mainElement = this.GetMainElement(); if (!_aspxIsExistsElement(mainElement)) return; mainElement[handlerName] = Function("_aspxBCallButtonMethod('" + this.name + "', '" + correspondingMethodName + "')"); }, GetContentDiv: function(){ if(!_aspxIsExistsElement(this.contentDiv)) this.contentDiv = this.GetChild("_CD"); return this.contentDiv; }, GetButtonCheckedInput: function(){ if(!_aspxIsExistsElement(this.checkedInput)) this.checkedInput = _aspxGetElementById(this.name + "_CH"); return this.checkedInput; }, GetButtonImage: function(){ if(!_aspxIsExistsElement(this.buttonImage)) this.buttonImage = _aspxGetChildByTagName(this.GetMainElement(), "IMG", 0); return this.buttonImage; }, GetInternalButton: function() { if(!_aspxIsExistsElement(this.internalButton)) this.internalButton = this.isNative || this.IsLink() ? this.GetMainElement() : _aspxGetChildByTagName(this.GetMainElement(), "INPUT", 0); return this.internalButton; }, GetTextContainer: function() { if (!this.textContainer) { if(this.isNative) this.textContainer = this.GetMainElement(); else{ var textElement = this.IsLink() ? this.GetMainElement() : this.GetContentDiv(); this.textContainer = _aspxGetChildByTagName(textElement, "SPAN", 0); } } return this.textContainer; }, GetTextControl: function(){ if(!_aspxIsExistsElement(this.textControl)) this.textControl = _aspxGetParentByTagName(this.GetContentDiv(), "DIV"); if (!_aspxIsExistsElement(this.textControl) || (this.textControl.id == this.name)) this.textControl = this.GetContentDiv(); return this.textControl; }, IsLink: function(){ return this.GetMainElement().tagName === "A"; }, IsHovered: function(){ var hoverElement = this.GetMainElement(); return aspxGetStateController().currentHoverItemName == hoverElement.id; }, SetEnabledInternal: function(enabled, initialization) { if(!this.enabled) return; if(!initialization || !enabled) this.ChangeEnabledStateItems(enabled); this.ChangeEnabledAttributes(enabled); }, ChangeEnabledAttributes: function(enabled) { var element = this.GetInternalButton(); if(element) { element.disabled = !enabled; if(this.IsLink()){ var method = _aspxChangeAttributesMethod(enabled); method(this.GetMainElement(), "href"); } } this.ChangeEnabledEventsAttributes(_aspxChangeEventsMethod(enabled)); }, ChangeEnabledEventsAttributes: function(method) { var element = this.GetMainElement(); method(element, "click", this.onClick); if (this.allowFocus){ if (!this.isNative && !this.IsLink()) element = this.GetInternalButton(); if(element) { method(element, "focus", this.onGotFocus); method(element, "blur", this.onLostFocus); if (!this.isNative && !this.IsLink()){ method(element, "keyup", this.onKeyUp); method(element, "blur", this.onKeyUp); method(element, "keydown", this.onKeyDown); } } } }, ChangeEnabledStateItems: function(enabled){ if(this.isNative) return; aspxGetStateController().SetElementEnabled(this.GetMainElement(), enabled); this.UpdateFocusedStyle(); }, RequiredPreventDoublePostback: function(){ return __aspxFirefox && !this.isNative; }, OnFocus: function() { if(!this.allowFocus) return false; this.focused = true; if(this.isInitialized) this.RaiseFocus(); this.UpdateFocusedStyle(); }, OnLostFocus: function() { if(!this.allowFocus) return false; this.focused = false; if(this.isInitialized) this.RaiseLostFocus(); this.UpdateFocusedStyle(); }, CauseValidation: function() { if (this.causesValidation && typeof(ASPxClientEdit) != "undefined") return this.validationContainerID != null ? ASPxClientEdit.ValidateEditorsInContainerById(this.validationContainerID, this.validationGroup, this.validateInvisibleEditors) : ASPxClientEdit.ValidateGroup(this.validationGroup, this.validateInvisibleEditors); else return true; }, OnClick: function() { if(this.clickLocked) return true; if(this.checked && this.groupName != "" && this.GetCheckedGroupList().length > 1) return; this.SetFocus(); var isValid = this.CauseValidation(); var processOnServer = this.autoPostBack; if (this.groupName != "") { if(this.GetCheckedGroupList().length == 1) this.SetCheckedInternal(!this.checked, false); else { this.SetCheckedInternal(true, false); this.ClearButtonGroupChecked(true); } processOnServer = this.RaiseCheckedChanged(); if (processOnServer && isValid) this.SendPostBack("CheckedChanged"); } processOnServer = this.RaiseClick(); if (processOnServer && isValid){ var requiredPreventDoublePostback = this.RequiredPreventDoublePostback(); var postponePostback = __aspxAndroidMobilePlatform; if(requiredPreventDoublePostback || postponePostback) _aspxSetTimeout("_aspxBCallButtonMethod(\"" + this.name + "\", \"SendPostBack\", \"Click\" );", 0); else this.SendPostBack("Click"); return !requiredPreventDoublePostback; } return false; }, OnKeyUp: function(evt) { if(this.pressed) this.SetUnpressed(); }, OnKeyDown: function(evt) { if(evt.keyCode == ASPxKey.Enter || evt.keyCode == ASPxKey.Space) this.SetPressed(); }, GetChecked: function(){ return this.groupName != "" ? this.GetButtonCheckedInput().value == "1" : false; }, GetCheckedGroupList: function(){ var result = [ ]; aspxGetControlCollection().ForEachControl(function(control) { if (ASPxIdent.IsASPxClientButton(control) && (control.groupName == this.groupName) && control.RenderExistsOnPage()) result.push(control); }, this); return result; }, ClearButtonGroupChecked: function(raiseCheckedChanged){ var list = this.GetCheckedGroupList(); for(var i = 0; i < list.length; i ++){ if(list[i] != this && list[i].checked) { list[i].SetCheckedInternal(false, false); if(raiseCheckedChanged) list[i].RaiseCheckedChanged(); } } }, ApplyCheckedStyle: function(){ var stateController = aspxGetStateController(); if(this.IsHovered()) stateController.SetCurrentHoverElement(null); stateController.SelectElementBySrcElement(this.GetMainElement()); }, ApplyUncheckedStyle: function(){ var stateController = aspxGetStateController(); if(this.IsHovered()) stateController.SetCurrentHoverElement(null); stateController.DeselectElementBySrcElement(this.GetMainElement()); }, SetCheckedInternal: function(checked, initialization){ if(initialization && checked || (this.checked != checked)){ this.checked = checked; var inputElement = this.GetButtonCheckedInput(); if(inputElement) inputElement.value = checked ? "1" : "0"; if(checked) this.ApplyCheckedStyle(); else this.ApplyUncheckedStyle(); } }, ApplyPressedStyle: function(){ aspxGetStateController().OnMouseDownOnElement(this.GetMainElement()); }, ApplyUnpressedStyle: function(){ aspxGetStateController().OnMouseUpOnElement(this.GetMainElement()); }, SetPressed: function(){ this.pressed = true; this.ApplyPressedStyle(); }, SetUnpressed: function(){ this.pressed = false; this.ApplyUnpressedStyle(); }, SetFocus: function(){ if(!this.allowFocus || this.focused) return; var element = this.GetInternalButton(); if(element) { var hiddenInternalButtonRequiresVisibilityToGetFocused = __aspxWebKitFamily && !this.isNative && !this.IsLink(); if(hiddenInternalButtonRequiresVisibilityToGetFocused) ASPxClientButton.MakeHiddenElementFocusable(element); if(_aspxIsFocusable(element) && _aspxGetActiveElement() != element) element.focus(); if(hiddenInternalButtonRequiresVisibilityToGetFocused) ASPxClientButton.RestoreHiddenElementAppearance(element); } }, ApplyFocusedStyle: function(){ if(this.focusElementSelected) return; if(typeof(aspxGetStateController) != "undefined") aspxGetStateController().SelectElementBySrcElement(this.GetContentDiv()); this.focusElementSelected = true; }, ApplyUnfocusedStyle: function(){ if(!this.focusElementSelected) return; if(typeof(aspxGetStateController) != "undefined") aspxGetStateController().DeselectElementBySrcElement(this.GetContentDiv()); this.focusElementSelected = false; }, UpdateFocusedStyle: function(){ if(this.isNative || this.IsLink()) return; if(this.enabled && this.clientEnabled && this.allowFocus && this.focused) this.ApplyFocusedStyle(); else this.ApplyUnfocusedStyle(); }, SendPostBack: function(postBackArg){ if(!this.enabled || !this.clientEnabled) return; var arg = postBackArg || ""; if(this.autoPostBackFunction) this.autoPostBackFunction(arg); else if(!this.useSubmitBehavior || this.IsLink()) ASPxClientControl.prototype.SendPostBack.call(this, arg); if(this.useSubmitBehavior && !this.isNative) this.ClickInternalButton(); }, ClickInternalButton: function(){ var element = this.GetInternalButton(); if(element) { this.clickLocked = true; if (__aspxNetscapeFamily) this.CreateUniqueIDCarrier(); _aspxDoElementClick(element); if (__aspxNetscapeFamily) this.RemoveUniqueIDCarrier(); this.clickLocked = false; } }, CreateUniqueIDCarrier: function() { var name = this.uniqueID; var id = this.GetUniqueIDCarrierID(); var field = _aspxCreateHiddenField(name, id); var form = this.GetParentForm(); if(form) form.appendChild(field); }, RemoveUniqueIDCarrier: function() { var field = document.getElementById(this.GetUniqueIDCarrierID()); if (field) field.parentNode.removeChild(field); }, GetUniqueIDCarrierID: function() { return this.uniqueID + "_UIDC"; }, DoClick: function(){ if(!this.enabled || !this.clientEnabled) return; var button = (this.isNative || this.IsLink()) ? this.GetMainElement() : this.GetInternalButton(); if(button) _aspxDoElementClick(button); else this.OnClick(); }, GetChecked: function(){ return this.checked; }, SetChecked: function(checked){ this.SetCheckedInternal(checked, false); this.ClearButtonGroupChecked(false); }, GetText: function(){ if(!this.isTextEmpty) return this.isNative ? this.GetTextContainer().value : this.GetTextContainer().innerHTML; return ""; }, SetText: function(text){ this.isTextEmpty = (text == null || text == ""); var textContainer = this.GetTextContainer(); if(textContainer){ if(this.isNative) textContainer.value = (text != null) ? text : ""; else { textContainer.innerHTML = this.isTextEmpty ? " " : text; if (this.clientVisible && __aspxIE && __aspxBrowserVersion >= 9) _aspxSetElementDisplay(this.GetMainElement(), true); } this.UpdateSize(); } }, GetImageUrl: function(){ var img = this.GetButtonImage(); return img ? img.src : ""; }, SetImageUrl: function(url){ var img = this.GetButtonImage(); if (img) { img.src = url; this.UpdateSize(); } }, SetEnabled: function(enabled){ if (this.clientEnabled != enabled) { if (!enabled && this.focused) this.OnLostFocus(); this.clientEnabled = enabled; this.SetEnabledInternal(enabled, false); } }, GetEnabled: function(){ return this.enabled && this.clientEnabled; }, Focus: function(){ this.SetFocus(); }, RaiseCheckedChanged: function(){ var processOnServer = this.autoPostBack || this.IsServerEventAssigned("CheckedChanged"); if(!this.CheckedChanged.IsEmpty()){ var args = new ASPxClientProcessingModeEventArgs(processOnServer); this.CheckedChanged.FireEvent(this, args); processOnServer = args.processOnServer; } return processOnServer; }, RaiseFocus: function(){ if(!this.GotFocus.IsEmpty()){ var args = new ASPxClientEventArgs(); this.GotFocus.FireEvent(this, args); } }, RaiseLostFocus: function(){ if(!this.LostFocus.IsEmpty()){ var args = new ASPxClientEventArgs(); this.LostFocus.FireEvent(this, args); } }, RaiseClick: function(){ var processOnServer = this.autoPostBack || this.IsServerEventAssigned("Click"); if(!this.Click.IsEmpty()){ var args = new ASPxClientProcessingModeEventArgs(processOnServer); this.Click.FireEvent(this, args); processOnServer = args.processOnServer; } return processOnServer; } }); ASPxClientButton.Cast = ASPxClientControl.Cast; ASPxClientButton.MakeHiddenElementFocusable = function(element) { element.__dxHiddenElementState = { parentDisplay: element.parentNode.style.display, height: element.style.height, width: element.style.width }; element.parentNode.style.display = "block"; element.style.height = "1px"; element.style.width = "1px"; }; ASPxClientButton.RestoreHiddenElementAppearance = function(element) { var state = element.__dxHiddenElementState; element.parentNode.style.display = state.parentDisplay; element.style.height = state.height; element.style.width = state.width; delete element.__dxHiddenElementState; }; ASPxIdent.IsASPxClientButton = function(obj) { return !!obj.isASPxClientButton; }; function _aspxBCallButtonMethod(name, methodName, arg) { var button = aspxGetControlCollection().Get(name); if (button != null) button[methodName](arg); } function aspxBGotFocus(name){ var button = aspxGetControlCollection().Get(name); if(button != null) return button.OnFocus(); } function aspxBLostFocus(name){ var button = aspxGetControlCollection().Get(name); if(button != null) return button.OnLostFocus(); } function aspxBClick(name){ var button = aspxGetControlCollection().Get(name); if(button != null) return button.OnClick(); } function aspxBKeyDown(evt,name){ var button = aspxGetControlCollection().Get(name); if(button != null) button.OnKeyDown(evt); } function aspxBKeyUp(evt,name){ var button = aspxGetControlCollection().Get(name); if(button != null) button.OnKeyUp(evt); }