Beispiel #1
0
        public override void Destroy()
        {
            this.element.Find("div.tool-button").Unbind("click");
            if (mouseTrap != null)
            {
                if (mouseTrap.As <dynamic>().destroy)
                {
                    mouseTrap.As <dynamic>().destroy();
                }
                else
                {
                    mouseTrap.Reset();
                }
                mouseTrap = null;
            }

            base.Destroy();
        }
Beispiel #2
0
        private void CreateButton(jQueryObject container, ToolButton b)
        {
            var cssClass = b.CssClass ?? "";

            if (b.Separator == true)
            {
                J("<div class=\"separator\"></div>")
                .AppendTo(container);
            }

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

            if (cssClass.Length > 0)
            {
                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 (!string.IsNullOrEmpty(b.Icon))
            {
                btn.AddClass("icon-tool-button");

                var klass = b.Icon;
                if (klass.StartsWith("fa-"))
                {
                    klass = "fa " + klass;
                }
                else if (klass.StartsWith("glyphicon-"))
                {
                    klass = "glyphicon " + klass;
                }

                text = "<i class='" + klass + "'></i> " + text;
            }

            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 = mouseTrap ?? Mousetrap.Wrap(options.HotkeyContext ?? Window.Document.DocumentElement);
                mouseTrap.Bind(b.Hotkey, (e, action) =>
                {
                    if (btn.Is(":visible"))
                    {
                        btn.TriggerHandler("click");
                    }

                    return(b.HotkeyAllowDefault);
                });
            }
        }