FontSize.FontSizeBehavior = function(element) { ... // the behaviors we create // this._popupBehavior = null; this._hoverBehavior = null; // Handler delegates // this._hoverHandler = null; this._unhoverHandler = null; this._incrementHandler = null; this._decrementHandler = null; // state bits // this._fontSize = 0; this._popupVisible = false; this._fontUnit = "px"; }
// setup the hover behavior // if (this._hoverCssClass && this._sizePanelElement) { this._hoverHandler = Function.createDelegate(this, this._onTargetHover); this._unhoverHandler = Function.createDelegate(this, this._onTargetUnhover); this._hoverBehavior = $create(
AjaxControlToolkit.HoverBehavior,
{unhoverDelay:200, hoverElement: this._sizePanelElement},
null, null, this.get_element());
this._hoverBehavior.add_hover(this._hoverHandler); this._hoverBehavior.add_unhover(this._unhoverHandler); }
// setup the popup behavior // if (this._sizePanelElement) { this._popupBehavior = $create(
AjaxControlToolkit.PopupBehavior, {id: this.get_id() + "_Popup", // make the ID derive from our ID for uniqueness positioningMode: AjaxControlToolkit.PositioningMode.TopRight, parentElement: this.get_element()}, null, null, this._sizePanelElement); }
_onTargetHover : function(eventArgs) { var e = this.get_element(); Sys.UI.DomElement.addCssClass(e, this._hoverCssClass); if (this._popupBehavior && !this._popupVisible) { this._popupVisible = true; // call show to make the the popup visible // this._popupBehavior.show(); } }, _onTargetUnhover : function(eventArgs) { var e = this.get_element(); Sys.UI.DomElement.removeCssClass(e, this._hoverCssClass); if (this._popupBehavior && this._popupVisible) { this._popupVisible = false; this._popupBehavior.hide(); } },
[Designer(typeof(FontSizeDesigner))] [ClientScriptResource("FontSize.FontSizeBehavior", "FontSize.FontSizeBehavior.js")] [TargetControlType(typeof(Control))] [RequiredScript(typeof(PopupExtender))] [RequiredScript(typeof(HoverExtender))] public class FontSizeExtender : ExtenderControlBase { ... }
initialize : function() { FontSize.FontSizeBehavior.callBaseMethod(this, 'initialize'); ... // set up our handlers for the +/- behavior // if (this._incrementElement) { this._incrementHandler = Function.createDelegate(this, this._onIncrementFontSize); $addHandler(this._incrementElement, "click", this._incrementHandler); } if (this._decrementElement) { this._decrementHandler = Function.createDelegate(this, this._onDecrementFontSize); $addHandler(this._decrementElement, "click", this._decrementHandler); } },
_setFontSize : function(size) { // helper function for setting the font size // this._fontSize = size; // append the units. // this.get_element().style.fontSize = size + this._fontUnit; },
_onDecrementFontSize : function(eventArgs) { var fontSize = this._getCurrentFontSize(); if (fontSize > this.get_MinFontSize()) { fontSize -= this._fontSizeIncrement; } this._setFontSize(fontSize); eventArgs.preventDefault(); }, _onIncrementFontSize : function(eventArgs) { var fontSize = this._getCurrentFontSize(); if (fontSize < this.get_MaxFontSize()) { fontSize += this._fontSizeIncrement; } this._setFontSize(fontSize); eventArgs.preventDefault(); },
_getCurrentFontSize : function() { // this function figures out the current font size of the element. // ... return this._fontSize; },
<fontSize:FontSizeExtender ID="FontSizeExtender1" runat="server" SizePanelControlID="extenderUI1" TargetControlID="pnlLeftColumn" DecreaseSizeControlID="btnDec1" IncreaseSizeControlID="btnInc1" PanelHoverCssClass="panelHover" /> <asp:Panel ID="extenderUI1" runat="server" CssClass="popup"> <asp:Button ID="btnDec1" runat="server" Text="-" /> <asp:Button ID="btnInc1" runat="server" Text="+" /> </asp:Panel> <fontSize:FontSizeExtender ID="FontSizeExtender2" runat="server" SizePanelControlID="extenderUI2" TargetControlID="pnlMiddleColumn" DecreaseSizeControlID="btnDec2" IncreaseSizeControlID="btnInc2" PanelHoverCssClass="panelHover" /> <asp:Panel ID="extenderUI2" runat="server" CssClass="popup"> <asp:Button ID="btnDec2" runat="server" Text="-" /> <asp:Button ID="btnInc2" runat="server" Text="+" /> </asp:Panel> <fontSize:FontSizeExtender ID="FontSizeExtender3" runat="server" SizePanelControlID="extenderUI3" TargetControlID="pnlRightColumn" DecreaseSizeControlID="btnDec3" IncreaseSizeControlID="btnInc3" PanelHoverCssClass="panelHover" /> <asp:Panel ID="extenderUI3" runat="server" CssClass="popup"> <asp:Button ID="btnDec3" runat="server" Text="-" /> <asp:Button ID="btnInc3" runat="server" Text="+" /> </asp:Panel>
public FontSizeExtender() { EnableClientState = true; }
_setFontSize : function(size) { // helper function for setting the font size ... // set the clientState // this.set_ClientState(size + ":" + this._fontUnit); },
initialize : function() { FontSize.FontSizeBehavior.callBaseMethod(this, 'initialize'); ... // check client state // var clientState = this.get_ClientState(); if (clientState) { var stateItems = clientState.split(":"); if (stateItems.length) { this._fontUnit = stateItems[1]; this._setFontSize(parseInt(stateItems[0])); } } },
_onTargetHover : function(eventArgs) { var e = this.get_element(); Sys.UI.DomElement.addCssClass(e, this._hoverCssClass); if (this._popupBehavior && !this._popupVisible) { this._popupVisible = true; this._stopAnimations(); // call show to make the the popup visible // this._popupBehavior.show(); // now animate it's opacity // var anim = $create( AjaxControlToolkit.Animation.FadeInAnimation, {target: this._sizePanelElement, duration: .25, minimumOpacity: 0, maximumOpacity:.75}); // we cache the running animation so we can cancel it if we need to hide. // this._sizePanelElement._runningAnimation = anim; var handler = Function.createDelegate(this, function() { this._sizePanelElement._runningAnimation = null; }); anim.add_ended(handler); anim.play(); } },
_onTargetUnhover : function(eventArgs) { var e = this.get_element(); Sys.UI.DomElement.removeCssClass(e, this._hoverCssClass); if (this._popupBehavior && this._popupVisible) { this._popupVisible = false; // make sure another animation isn't already running. // this._stopAnimations(); var anim = $create( AjaxControlToolkit.Animation.FadeOutAnimation, {target: this._sizePanelElement, duration: .15, minimumOpacity: 0, maximumOpacity:.75}); this._sizePanelElement._runningAnimation = anim; var handler = Function.createDelegate(this, function() { // clear out our state. // this._sizePanelElement._runningAnimation = null; this._popupVisible = false; this._popupBehavior.hide(); }); anim.add_ended(handler); anim.play(); } },
_stopAnimations : function() { // stop any running animation // if (this._sizePanelElement && this._sizePanelElement._runningAnimation) { this._sizePanelElement._runningAnimation.stop(); this._sizePanelElement._runningAnimation = null; } },
[RequiredScript(typeof(AnimationScripts))]
本文出自 “赵��” 博客,转载请与作者联系!