protected override void OnPreRender(EventArgs e)
        {
            var options = new JSONObject();
            options.AddValue("mode", "exact");
            if (Width.HasValue)
                options.AddValue("width", Width.Value.Value.ToString());
            else
                options.AddValue("width", 800);
            options.AddValue("elements", _textbox.ClientID);
            options.AddValue("convert_urls", false);
            options.AddValue("theme", "advanced");
            options.AddValue("plugins", GetPlugins());

            var styleOptions = GetStyleOptions();
            if (!string.IsNullOrEmpty(styleOptions))
                options.AddValue("theme_advanced_styles", styleOptions);
            options.AddValue("theme_advanced_buttons1", GetButtons1());
            options.AddValue("theme_advanced_buttons2", GetButtons2());
            options.AddValue("theme_advanced_buttons3", GetButtons3());
            options.AddValue("theme_advanced_toolbar_location", "top");
            options.AddValue("theme_advanced_toolbar_align", "left");
            options.AddValue("theme_advanced_statusbar_location", "bottom");
            options.AddValue("template_external_list_url", "lists/template_list.js");
            options.AddValue("external_link_list_url", "lists/link_list.js");
            options.AddValue("external_image_list_url", "lists/image_list.js");
            options.AddValue("media_external_list_url", "lists/media_list.js");

            if (StyleSheets != null && StyleSheets.Any())
                options.AddValue("content_css", StyleSheets.ToSeparatedString(","));

            options.AddValue("verify_html", false);
            options.AddValue("valid_elements", "*[*]");
            //options.AddValue("valid_elements", GetValidElements());
            options.AddValue("invalid_elements", GetInvalidElements());

            //options.AddValue("template_replace_values", JSONObject.Parse("{ username : \"Some User\", staffid : \"991234\" }"));

            var setup = new JSONDelegate("ed");
            if (!string.IsNullOrEmpty(HiddenId))
            {

                setup.Lines.Add("ed.onInit.add(function(ed, evt) {");
                setup.Lines.Add("initializeEditorValue(ed, doc, '" + HiddenId + "');");
                setup.Lines.Add("var dom = ed.dom;");
                setup.Lines.Add("var doc = ed.getDoc();");
                setup.Lines.Add("tinymce.dom.Event.add(doc, 'blur', function(e) {");
                setup.Lines.Add("updateEditorValue(ed, doc,'" + HiddenId + "');");
                setup.Lines.Add("});");
                setup.Lines.Add("});");
            }

            setup.Lines.Add("ed.onNodeChange.addToTop(function(ed, cm, n) {");
            setup.Lines.Add("var macroElement = ed.dom.getParent(ed.selection.getStart(), 'div.umbMacroHolder');");
            setup.Lines.Add("if (macroElement) {");
            setup.Lines.Add("ed.selection.select(macroElement);");
            setup.Lines.Add("var currentSelection = ed.selection.getStart();");
            setup.Lines.Add("if (tinymce.isIE) {");
            setup.Lines.Add("if (!ed.dom.hasClass(currentSelection, 'umbMacroHolder')) {");
            setup.Lines.Add("while (!ed.dom.hasClass(currentSelection, 'umbMacroHolder') && currentSelection.parentNode) {");
            setup.Lines.Add("currentSelection = currentSelection.parentNode;");
            setup.Lines.Add("}");
            setup.Lines.Add("ed.selection.select(currentSelection);");
            setup.Lines.Add("}");
            setup.Lines.Add("}");
            setup.Lines.Add("cm.setActive('umbracomacro', ed.dom.hasClass(currentSelection, 'umbMacroHolder') || ed.dom.hasClass(macroElement, 'umbMacroHolder'));");
            setup.Lines.Add("}");
            setup.Lines.Add("});");

            options.AddValue("setup", setup);

            var script = new StringBuilder();
            script.AppendLine("tinyMCE.init(" + options.ToString() + ");");

            if (RegisterFormBind)
                script.AppendLine("$(theForm).bind(\"onSave\", function() { $(\"#" + _textbox.ClientID + "\").val(tinyMCE.get('" + _textbox.ClientID + "').save()); });");

            Page.ClientScript.RegisterStartupScript(Page.GetType(), "tinyMCEditor" + _textbox.ClientID, script.ToString(), true);

            base.OnPreRender(e);
        }
Beispiel #2
0
        protected override void OnPreRender(EventArgs e)
        {
            var options = new JSONObject();
            options.AddValue("mode", "exact");
            if (Width.HasValue)
                options.AddValue("width", Width.Value.Value.ToString());
            options.AddValue("elements", _textbox.ClientID);
            options.AddValue("theme", "advanced");
            options.AddValue("plugins", GetPlugins());
            options.AddValue("theme_advanced_buttons1", GetButtons1());
            options.AddValue("theme_advanced_buttons2", GetButtons2());
            options.AddValue("theme_advanced_buttons3", GetButtons3());
            //options.AddValue("theme_advanced_buttons4", GetButtons4());
            options.AddValue("theme_advanced_toolbar_location", "top");
            options.AddValue("theme_advanced_toolbar_align", "left");
            options.AddValue("theme_advanced_statusbar_location", "bottom");
            //options.AddValue("theme_advanced_resizing", true);
            options.AddValue("template_external_list_url", "lists/template_list.js");
            options.AddValue("external_link_list_url", "lists/link_list.js");
            options.AddValue("external_image_list_url", "lists/image_list.js");
            options.AddValue("media_external_list_url", "lists/media_list.js");
            //options.AddValue("style_formats", JSONArray.Parse("[{title : 'Bold text', inline : 'b'},{title : 'Red text', inline : 'span', styles : {color : '#ff0000'}},{title : 'Red header', block : 'h1', styles : {color : '#ff0000'}},{title : 'Example 1', inline : 'span', classes : 'example1'},{title : 'Example 2', inline : 'span', classes : 'example2'},{title : 'Table styles'},{title : 'Table row 1', selector : 'tr', classes : 'tablerow1'}]"));
            options.AddValue("template_replace_values", JSONObject.Parse("{ username : \"Some User\", staffid : \"991234\" }"));

            if (!string.IsNullOrEmpty(HiddenId))
            {
                var setup = new JSONDelegate("ed");
                setup.Lines.Add("ed.onInit.add(function(ed, evt) {");
                setup.Lines.Add("initializeEditorValue(ed, doc, '" + HiddenId + "');");
                setup.Lines.Add("var dom = ed.dom;");
                setup.Lines.Add("var doc = ed.getDoc();");
                setup.Lines.Add("tinymce.dom.Event.add(doc, 'blur', function(e) {");
                setup.Lines.Add("updateEditorValue(ed, doc,'" + HiddenId + "');");
                setup.Lines.Add("});");
                setup.Lines.Add("});");
                options.AddValue("setup", setup);
            }
            var script = new StringBuilder();
            script.AppendLine("tinyMCE.init(" + options.ToString() + ");");

            if (RegisterFormBind)
                script.AppendLine("$(theForm).bind(\"onSave\", function() { $(\"#" + _textbox.ClientID + "\").val(tinyMCE.get('" + _textbox.ClientID + "').save()); });");

            Page.ClientScript.RegisterStartupScript(Page.GetType(), "tinyMCEditor" + _textbox.ClientID, script.ToString(), true);

            base.OnPreRender(e);
        }