Esempio n. 1
0
        private void CreateButton(jQueryObject container, ToolButton b)
        {
            var cssClass = b.CssClass ?? "";

            var btn = J(
                "<div class=\"tool-button\">" +
                "<div class=\"button-outer\">" +
                "<span class=\"button-inner\"></span>" +
                "</div>" +
                "</div>")
                      .AppendTo(container);

            btn.AddClass(cssClass);

            if (!b.Hint.IsEmptyOrNull())
            {
                btn.Attribute("title", b.Hint);
            }

            btn.Click(delegate(jQueryEvent e)
            {
                if (btn.HasClass("disabled"))
                {
                    return;
                }

                b.OnClick(e);
            });

            var text = b.Title;

            if (b.HtmlEncode != false)
            {
                text = Q.HtmlEncode(b.Title);
            }

            if (text == null || text.Length == 0)
            {
                btn.AddClass("no-text");
            }
            else
            {
                btn.Find("span").Html(text);
            }

            if (!string.IsNullOrEmpty(b.Hotkey) &&
                Script.IsValue(Window.Instance.As <dynamic>().Mousetrap))
            {
                Mousetrap.Wrap(options.HotkeyContext ?? Window.Document.DocumentElement).Bind(b.Hotkey, (e, action) =>
                {
                    if (btn.Is(":visible"))
                    {
                        btn.TriggerHandler("click");
                    }

                    return(b.HotkeyAllowDefault);
                });
            }
        }
Esempio n. 2
0
        private void CreateButton(jQueryObject container, ToolButton b)
        {
            var cssClass = b.CssClass ?? "";

            var btn = J(
                "<div class=\"tool-button\">" +
                "<div class=\"button-outer\">" +
                "<span class=\"button-inner\"></span>" +
                "</div>" +
                "</div>")
                      .AppendTo(container);

            btn.AddClass(cssClass);

            if (!b.Hint.IsEmptyOrNull())
            {
                btn.Attribute("title", b.Hint);
            }

            btn.Click(delegate(jQueryEvent e)
            {
                if (btn.HasClass("disabled"))
                {
                    return;
                }

                b.OnClick(e);
            });

            var text = b.Title;

            if (b.HtmlEncode != false)
            {
                text = Q.HtmlEncode(b.Title);
            }

            if (text == null || text.Length == 0)
            {
                btn.AddClass("no-text");
            }
            else
            {
                btn.Find("span").Html(text);
            }
        }