private ElementActivationBehavior(ResourceInfo resource = null, FormAction action = null, string script = "")
        {
            if (action == null && !script.Any())
            {
                HyperlinkBehavior hyperlinkBehavior = resource;

                Classes               = hyperlinkBehavior.HasDestination ? ActivatableClass : ElementClassSet.Empty;
                AttributeGetter       = () => hyperlinkBehavior.AttributeGetter(true);
                IncludesIdAttribute   = () => hyperlinkBehavior.IncludesIdAttribute(true);
                EtherealChildren      = hyperlinkBehavior.EtherealChildren;
                JsInitStatementGetter = id => hyperlinkBehavior.JsInitStatementGetter(id, true);
                IsFocusable           = hyperlinkBehavior.IsFocusable;
                PostBackAdder         = hyperlinkBehavior.PostBackAdder;
            }
            else
            {
                var buttonBehavior = action != null ? (ButtonBehavior) new FormActionBehavior(action) : new CustomButtonBehavior(() => script + ";");

                Classes               = ActivatableClass;
                AttributeGetter       = () => buttonBehavior.GetAttributes().Materialize();
                IncludesIdAttribute   = buttonBehavior.IncludesIdAttribute;
                EtherealChildren      = buttonBehavior.GetEtherealChildren();
                JsInitStatementGetter = buttonBehavior.GetJsInitStatements;
                IsFocusable           = true;
                PostBackAdder         = buttonBehavior.AddPostBack;
            }
        }
        /// <summary>
        /// Creates a hyperlink.
        /// </summary>
        /// <param name="behavior">The behavior. Pass a <see cref="ResourceInfo"/> to navigate to the resource in the default way, or call
        /// <see cref="HyperlinkBehaviorExtensionCreators.ToHyperlinkNewTabBehavior(ResourceInfo, bool)"/> or
        /// <see cref="HyperlinkBehaviorExtensionCreators.ToHyperlinkModalBoxBehavior(ResourceInfo, bool, BrowsingContextSetup)"/>. For a mailto link, call
        /// <see cref="HyperlinkBehaviorExtensionCreators.ToHyperlinkBehavior(Email.EmailAddress, string, string, string, string)"/>. If you need to add additional
        /// JavaScript action statements to any behavior, we recommend using the jQuery document ready event to add a click handler to the appropriate a element(s),
        /// which you can select using a class if there is no simpler way.</param>
        /// <param name="style">The style.</param>
        /// <param name="displaySetup"></param>
        /// <param name="classes">The classes on the hyperlink.</param>
        public EwfHyperlink(HyperlinkBehavior behavior, HyperlinkStyle style, DisplaySetup displaySetup = null, ElementClassSet classes = null)
        {
            children = new DisplayableElement(
                context => {
                behavior.PostBackAdder();
                return(new DisplayableElementData(
                           displaySetup,
                           () => {
                    DisplayableElementFocusDependentData getFocusDependentData(bool isFocused) =>
                    new DisplayableElementFocusDependentData(
                        attributes: behavior.AttributeGetter(false),
                        includeIdAttribute: behavior.IncludesIdAttribute(false) || isFocused,
                        jsInitStatements: StringTools.ConcatenateWithDelimiter(
                            " ",
                            behavior.JsInitStatementGetter(context.Id, false),
                            style.GetJsInitStatements(context.Id),
                            isFocused ? "document.getElementById( '{0}' ).focus();".FormatWith(context.Id) : ""));

                    return behavior.IsFocusable
                                                                       ? new DisplayableElementLocalData("a", new FocusabilityCondition(true), getFocusDependentData)
                                                                       : new DisplayableElementLocalData("a", focusDependentData: getFocusDependentData(false));
                },
                           classes: behavior.Classes.Add(style.GetClasses()).Add(classes ?? ElementClassSet.Empty),
                           children: style.GetChildren(behavior.Url.Value),
                           etherealChildren: behavior.EtherealChildren));
            }).ToCollection();
        }
Exemple #3
0
        // Web Forms compatibility. Remove when EnduraCode goal 790 is complete.
        internal void SetUpClickableControl(WebControl clickableControl)
        {
            if (resource == null && action == null && script == "")
            {
                return;
            }

            clickableControl.CssClass = clickableControl.CssClass.ConcatenateWithSpace(ActivatableClass.ClassName);

            if (resource != null && EwfPage.Instance.IsAutoDataUpdater)
            {
                action   = HyperlinkBehavior.GetHyperlinkPostBackAction(resource);
                resource = null;
            }

            Func <string> scriptGetter;

            if (resource != null)
            {
                scriptGetter = () => "location.href = '" + EwfPage.Instance.GetClientUrl(resource.GetUrl()) + "'; return false";
            }
            else if (action != null)
            {
                action.AddToPageIfNecessary();
                scriptGetter = () => action.GetJsStatements() + " return false";
            }
            else
            {
                scriptGetter = () => script;
            }

            // Defer script generation until after all controls have IDs.
            EwfPage.Instance.PreRender += delegate { clickableControl.AddJavaScriptEventScript(JsWritingMethods.onclick, scriptGetter()); };
        }
 private ElementActivationBehavior(HyperlinkBehavior hyperlinkBehavior)
 {
     Classes               = hyperlinkBehavior.HasDestination ? ActivatableClass : ElementClassSet.Empty;
     AttributeGetter       = () => hyperlinkBehavior.AttributeGetter(true);
     IncludesIdAttribute   = () => hyperlinkBehavior.IncludesIdAttribute(true);
     EtherealChildren      = hyperlinkBehavior.EtherealChildren;
     JsInitStatementGetter = id => hyperlinkBehavior.JsInitStatementGetter(id, true);
     IsFocusable           = hyperlinkBehavior.IsFocusable;
     PostBackAdder         = hyperlinkBehavior.PostBackAdder;
 }
Exemple #5
0
 /// <summary>
 /// Creates a hyperlink.
 /// </summary>
 /// <param name="behavior">The behavior. Pass a <see cref="ResourceInfo"/> to navigate to the resource in the default way, or call
 /// <see cref="HyperlinkBehaviorExtensionCreators.ToHyperlinkNewTabBehavior(ResourceInfo)"/>. For a mailto link, call
 /// <see cref="HyperlinkBehaviorExtensionCreators.ToHyperlinkBehavior(Email.EmailAddress, string, string, string, string)"/>.</param>
 /// <param name="style">The style.</param>
 /// <param name="displaySetup"></param>
 /// <param name="classes">The classes on the hyperlink.</param>
 public EwfHyperlink(HyperlinkBehavior behavior, HyperlinkStyle style, DisplaySetup displaySetup = null, ElementClassSet classes = null)
 {
     children = new DisplayableElement(
         context => {
         behavior.PostBackAdder();
         return(new DisplayableElementData(
                    displaySetup,
                    () =>
                    new DisplayableElementLocalData(
                        "a",
                        attributes: behavior.AttributeGetter(),
                        includeIdAttribute: behavior.IncludeIdAttribute,
                        jsInitStatements: behavior.JsInitStatementGetter(context.Id) + style.GetJsInitStatements(context.Id)),
                    classes: behavior.Classes.Add(style.GetClasses()).Add(classes ?? ElementClassSet.Empty),
                    children: style.GetChildren(behavior.Url),
                    etherealChildren: behavior.EtherealChildren));
     }).ToCollection();
 }
 /// <summary>
 /// Creates hyperlink behavior. EnduraCode goal 2450 will add a JavaScript predicate parameter to this method.
 /// </summary>
 /// <param name="hyperlinkBehavior">The behavior. Pass a <see cref="ResourceInfo"/> to navigate to the resource in the default way, or call
 /// <see cref="HyperlinkBehaviorExtensionCreators.ToHyperlinkNewTabBehavior(ResourceInfo, bool)"/> or
 /// <see cref="HyperlinkBehaviorExtensionCreators.ToHyperlinkModalBoxBehavior(ResourceInfo, bool, BrowsingContextSetup)"/>. For a mailto link, call
 /// <see cref="HyperlinkBehaviorExtensionCreators.ToHyperlinkBehavior(Email.EmailAddress, string, string, string, string)"/>.</param>
 public static ElementActivationBehavior CreateHyperlink(HyperlinkBehavior hyperlinkBehavior) => new ElementActivationBehavior(hyperlinkBehavior);
 /// <summary>
 /// Creates a hyperlink setup object.
 /// </summary>
 /// <param name="behavior">The behavior. Pass a <see cref="ResourceInfo"/> to navigate to the resource in the default way, or call
 /// <see cref="HyperlinkBehaviorExtensionCreators.ToHyperlinkNewTabBehavior(ResourceInfo)"/> or
 /// <see cref="HyperlinkBehaviorExtensionCreators.ToHyperlinkModalBoxBehavior(ResourceInfo, BrowsingContextSetup)"/>. For a mailto link, call
 /// <see cref="HyperlinkBehaviorExtensionCreators.ToHyperlinkBehavior(Email.EmailAddress, string, string, string, string)"/>.</param>
 /// <param name="text">Do not pass null. Pass the empty string to use the destination URL.</param>
 /// <param name="displaySetup"></param>
 /// <param name="icon">The icon.</param>
 public HyperlinkSetup(HyperlinkBehavior behavior, string text, DisplaySetup displaySetup = null, ActionComponentIcon icon = null)
 {
     DisplaySetup    = displaySetup;
     hyperlinkGetter = hyperlinkStyleSelector =>
                       behavior.UserCanNavigateToDestination() ? new EwfHyperlink(behavior, hyperlinkStyleSelector(text, icon)) : null;
 }