{"id":390,"date":"2012-02-24T11:59:00","date_gmt":"2012-02-24T11:59:00","guid":{"rendered":"https:\/\/staging.infragistics.com\/blogs\/?p=390"},"modified":"2025-02-25T13:37:51","modified_gmt":"2025-02-25T13:37:51","slug":"rich-text-editing","status":"publish","type":"post","link":"https:\/\/www.infragistics.com\/blogs\/rich-text-editing","title":{"rendered":"Rich Text Editing with Infragistics HTML Editor in both jQuery and ASP.NET MVC"},"content":{"rendered":"\n<p>Along all the exciting features introduced for NetAdvantage for jQuery 11.2 release (read: new Hierarchical grid, tree, combo controls) and CTP Charting with Motion Framework \u2013 it\u2019s not that surprising some controls didn\u2019t get their full share of the spotlight.<\/p>\n\n\n\n<p>I am talking about the jQuery-based, WYSIWYG-implementing HTML Editor control. WYSIWYG stands for \u2018what you see is what you get\u2019 (read on about it on <a title=\"Wikipedia page on WYSIWYG\" href=\"http:\/\/en.wikipedia.org\/wiki\/WYSIWYG\" rel=\"noopener\">Wikipedia<\/a>), which is exactly what in its core this control is meant to provide. Transforming the opening and closing angle brackets ( \u201c&lt;\u201d and \u201c>\u201d) into equivalent HTML \u2013 \u201c&amp;lt\u201d\/\u201d&amp;gt\u201d. That is just an example but it is what my blog editor does as well, so those can be properly presented by the browser and not only \u2013 some servers block such content as potential threat. Even if you haven\u2019t noticed, this kind of functionality is offered pretty much anywhere user generated content is supported \u2013 like this blog, the comments, forums, etc.<\/p>\n\n\n\n<p>And now you can provide your users with that kind of functionality using the igHtmlEditor widget and much more!<\/p>\n\n\n\n<p>Here should be mentioned the HTML Editor is CTP ( Community Technology Preview ) which mean it is still in the beta stage of its development. For that reason, until its official release nothing set in stone, but then again, there\u2019s also no reason not to give it a try and get to know the control ahead of time. It is also advisable if you use the latest service release version.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"getting-started\">Getting Started<\/h2>\n\n\n\n<p>The widget is built on top of jQuery UI, therefore as with other NetAdvantage for jQuery controls you will need first jQuery and then jQuery UI added to your page. The script for the igHtmlEditor, however, is not included in the default \u201cig.ui.min.js\u201d file, but rather in its own \u201cig.ui.htmleditor.min.js\u201d. The latter is actually the only required script file to include after the jQuery ones.<\/p>\n\n\n\n<p>The default styles, you might be already familiar already with, are also required. Once more, I will encourage you to check out our <a title=\"NetAdvantage for jQuery Deployment Guide\" href=\"http:\/\/help.infragistics.com\/NetAdvantage\/jQuery\/Current\/CLR4.0?page=Deployment_Guide.html\">Deployment Guide<\/a>, where you can read exactly how to find and manage the required resources.<\/p>\n\n\n\n<p>I will, of course, provide a combined piece of code you can use for reference ( assuming you have \u2018Scripts\u2019 and \u2018themes\u2019 folders by default) and adding the igHtmlEditor to the page is as trivial as it gets \u2013 an HTML DIV element as container and a line of script to create a new instance of the widget in JavaScript&nbsp; and it\u2019s just as easy in ASP.NET MVC. Combined code snippets for both:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;!-- ## Javascript\/HTML ## -->\n    &lt;!-- CSS -->\n    &lt;link href=\"..\/..\/themes\/min\/ig\/jquery.ui.custom.min.css\" rel=\"stylesheet\" type=\"text\/css\" \/>\n    &lt;link href=\"..\/..\/themes\/base\/ig.ui.min.css\")\" rel=\"stylesheet\" type=\"text\/css\" \/>\n    &lt;!-- Scripts -->\n    &lt;script src=\"..\/Scripts\/jquery.min.js\">&lt;\/script>\n    &lt;script src=\"..\/Scripts\/jquery-ui.min.js\">&lt;\/script>\n    &lt;script src=\"..\/Scripts\/ig.ui.htmleditor.min.js\">&lt;\/script>\n    &lt;!-- in the body of the document: -->\n    &lt;div id=\"HtmlEditor1\">&lt;\/div>\n    &lt;!-- initialize the editor on document ready: -->\n    &lt;script type=\"text\/javascript\">\n        $(document).ready(function () {\n            $(\"#HtmlEditor1\").igHtmlEditor();\n        });\n    &lt;\/script>\n \n&lt;!--## ASP.NET MVC  ##-->\n    &lt;!-- CSS -->\n    &lt;link href=\"@Url.Content(\"~\/Content\/themes\/min\/ig\/jquery.ui.custom.min.css\")\" rel=\"stylesheet\" type=\"text\/css\" \/>\n    &lt;link href=\"@Url.Content(\"~\/Content\/themes\/base\/ig.ui.min.css\")\" rel=\"stylesheet\" type=\"text\/css\" \/>\n    &lt;!-- Scripts -->\n    &lt;script src=\"@Url.Content(\"~\/Scripts\/jquery-1.5.1.min.js\")\" type=\"text\/javascript\">&lt;\/script>\n    &lt;script src=\"@Url.Content(\"~\/Scripts\/jquery-ui-1.8.11.min.js\")\" type=\"text\/javascript\">&lt;\/script>\n    &lt;script src=\"@Url.Content(\"~\/Scripts\/ig.ui.htmleditor.min.js\")\" type=\"text\/javascript\">&lt;\/script>\n    &lt;!-- in your View: -->\n    @using Infragistics.Web.Mvc\n    @( Html.Infragistics().HtmlEditor().Render()\n    )<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"features-features-features\">Features, Features, Features!<\/h2>\n\n\n\n<p>Even though it is not finished, the jQuery Html Editor widget has an impressive array of features. In its current implementation almost all of them are provided without the need for further customization, so from developer perspective there aren\u2019t that many things you have to set and the users always get a handful. Almost everything the user has access to is located in a toolbar area on top and options are grouped neatly in relevant sets.<\/p>\n\n\n\n<p>The best part is that among them can be found tools for rich text formatting that almost any user would immediately recognize and feel comfortable using. One comprehensive editing experience only recognized after a visual demonstration:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"http:\/\/media.infragistics.com\/community\/Release\/11.2\/JQUERY\/HTML_Editor\/Html-Editor_text_formatting.png\" alt=\"Rich text formatting in the jQuery Html Editor\" title=\"Rich text formatting in the jQuery Html Editor\"\/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Everything on the screenshot (well, except the width of the control I did alter so it would fit in this page) is as the widget creates it by default \u2013 fonts and sizes, bold and italic, underline and strikethrough, text alignment options, lists and bullets, indent control, etc. Apart from the tools on top, the control also conveniently displays the full current <a title=\"Wikipedia page on Document Object Model\" href=\"http:\/\/en.wikipedia.org\/wiki\/Document_Object_Model\" target=\"_blank\" rel=\"noopener noreferrer\">DOM<\/a> path and the user can click on each DOM tree element to have its content highlighted in the editing area. That\u2019s really neat when the user needs to be aware how his input is being handled behind the scenes, but should that not be enough, well the widget provides functionality to switch between the default \u2018design\u2019 and source view in a click of a button:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"http:\/\/media.infragistics.com\/community\/Release\/11.2\/JQUERY\/HTML_Editor\/Html-Editor_source.png\" alt=\"jQuery Html Editor's HTML source view\" title=\"jQuery Html Editor's HTML source view\"\/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>This is the source of the fonts demonstrated in the previous screenshot and you can also see them being applied as styles to the containers.<\/p>\n\n\n\n<p>Furthermore, there was also copied text, which was there to show that the Editor comes with Clipboard support for all common operations \u2013 cut, copy and paste. And it\u2019s not just different text styles being preserved inside the editing area \u2013 you can actually paste rich text and its formatting will remain the way you saw it originally. You can very well copy from a webpage and paste in the editor, but that seems not that impressive considering it\u2019s all HTML based. What you really can do is copy from MS Word , yes, you can and it looks like that:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"http:\/\/media.infragistics.com\/community\/Release\/11.2\/JQUERY\/HTML_Editor\/Html-Editor_clipboard_support.png\" alt=\"jQuery Html Editor's Clipboard support\" title=\"jQuery Html Editor's Clipboard support\"\/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Moreover,&nbsp; the user is provided with an easy way to insert content, other then pasting it. The toolbar offers dialogs to insert both images and links:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"http:\/\/media.infragistics.com\/community\/Release\/11.2\/JQUERY\/HTML_Editor\/Html-Editor_add_image_link_dialog.png\" alt=\"jQuery Html Editor's dialogs to add new image or link.\" title=\"jQuery Html Editor's dialogs to add new image or link.\"\/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>There is one more dialog available, and it lets the user add HTML table element with little to no effort and defining the number of columns and rows in a natural way by dragging their pointer to the desired size:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"http:\/\/media.infragistics.com\/community\/Release\/11.2\/JQUERY\/HTML_Editor\/Html-Editor_add_table_dialog.png\" alt=\"jQuery Html Editor's dialogs to add a table.\" title=\"jQuery Html Editor's dialogs to add a table.\"\/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>On the toolbar can also be found buttons for removing or adding new rows and columns with one click.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"customization\">Customization<\/h2>\n\n\n\n<p>When mentioned there isn\u2019t much you have to set from developers\u2019 view, it doesn&#8217;t mean the widget can\u2019t be customized to fit your needs. When setting up the control you are allowed to define the toolbar items to be presented to the users. The default is of course \u201call\u201d, but the activeToolbars property allows for custom set of toolbars to be defined. The property accepts a single string containing the names of the toolbars to use and here is a list of the default ones:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>fontProperties<\/li>\n\n\n\n<li>textFormat<\/li>\n\n\n\n<li>textAlign<\/li>\n\n\n\n<li>textIndent<\/li>\n\n\n\n<li>table<\/li>\n\n\n\n<li>source<\/li>\n<\/ul>\n\n\n\n<p>But surely you are not fooled this is where customization stops \u2013 there is, of course, an option to add your own toolbar. All toolbars contain button and combo elements, namely igButton and igCombo, that can be added as items to your custom toolbar. The igButton is our styled version of the <a title=\"jQuery UI button\" href=\"http:\/\/jqueryui.com\/demos\/button\/\" target=\"_blank\" rel=\"noopener noreferrer\">jQuery UI button<\/a> and the igCombo is part of our <a title=\"NetAdvantage for jQuery Overview\" href=\"\/products\/ignite-ui#Overview\" target=\"_blank\" rel=\"noopener noreferrer\">NetAdvantage for jQuery<\/a> product.<\/p>\n\n\n\n<p>For example, let\u2019s add a button that would link to Infragistics homepage to the toolbar and I\u2019ve added a nice logo to it for good measure. Here is the snippet to add your own to the \u2018toolbars\u2019 property along with setting the active ones in both JavaScript and ASP.NET MVC 3 with Chaining and Razor syntax :<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;!-- ## In Javascript ## -->\n&lt;script type=\"text\/javascript\">\n    $(document).ready(function () {\n        $(\"#HtmlEditor1\").igHtmlEditor({\n            width: '750',\n            toolbars: [\n            {\n                name: 'custom',\n                items: [\n                {\n                    type: 'igButton', link: { href: 'http:\/\/www.infragistics.com', target: '_blank' }\n                }]\n            }],\n            activeToolbars: 'fontProperties textFormat textIndent source custom'\n        });\n    });\n&lt;\/script>\n \n&lt;!-- ## In ASP.NET MVC ## -->\n@( Html.Infragistics().HtmlEditor()\n            .Width(\"750\")\n            .Toolbars(toolbars =>\n                {\n                    toolbars.AddToolbar().Name(\"custom\").Items(items =>\n                        {\n                            items.AddIgButtonItem()\n                                .Link(link =>\n                                {\n                                    link.Href(\"http:\/\/www.infragistics.com\").Target(\"_blank\");\n                                });\n                        });\n                })\n            .ActiveToolbars(\"fontProperties textFormat textIndent source custom\")\n            .Render()\n)<\/pre>\n\n\n\n<p>Yours will be added automatically, because the default active toolbars being \u2018all\u2019, but you can of course name it and include it to the list to be used as seen above. And the very same method can be used to add igCombo(s) or just more buttons. Here is how the result from the code above can look (notice the last button is our custom toolbar addition and clicking it opens the Infragistics homepage in a new tab\/window):<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"http:\/\/media.infragistics.com\/community\/Release\/11.2\/JQUERY\/HTML_Editor\/Html-Editor_custom_toolbar_addition.png\" alt=\"A custom toolbar with a button added to the jQuery Html Editor.\" title=\"A custom toolbar with a button added to the jQuery Html Editor.\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"conclusion\">Conclusion<\/h2>\n\n\n\n<p>The jQuery HTML Editor provides rich text formatting driven by pure client-side scripts and has set course to offer a combination of familiar and rather instinctive features and the end goal is to provide the user with amazing experience and comprehensive toolset. And the ability to create your own toolset and add it to the toolbar means this control can be as customizable as you are willing to make it. And as it is expected, it can be styled with the jQuery Themeroller and you can find instructions of that in the Deployment Guide linked above as well.<\/p>\n\n\n\n<p>You can visit our <a title=\"NetAdvantage for jQuery HTML Editor Online Samples\" href=\"https:\/\/www.igniteui.com\/html-editor\/overview\" rel=\"noopener\">NetAdvantage for jQuery Online Samples<\/a> and you can also download the <a title=\"HTML Editor demo project\" href=\"http:\/\/media.infragistics.com\/community\/Release\/11.2\/JQUERY\/HTML_Editor\/HTML_Editor.zip\">demo project<\/a> for this blog, that contains a APS.NET MVC3 project with both Razor and jQuery only implementations.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Along all the exciting features introduced for NetAdvantage for jQuery 11.2 release (read: new Hierarchical grid, tree, combo controls) and CTP Charting with Motion Framework \u2013 it\u2019s not that surprising some controls didn\u2019t get their full share of the spotlight. <\/p>\n","protected":false},"author":68,"featured_media":997,"comment_status":"publish","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16,17],"tags":[],"class_list":["post-390","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-jquery","category-how-to"],"_links":{"self":[{"href":"https:\/\/www.infragistics.com\/blogs\/wp-json\/wp\/v2\/posts\/390","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.infragistics.com\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.infragistics.com\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.infragistics.com\/blogs\/wp-json\/wp\/v2\/users\/68"}],"replies":[{"embeddable":true,"href":"https:\/\/www.infragistics.com\/blogs\/wp-json\/wp\/v2\/comments?post=390"}],"version-history":[{"count":2,"href":"https:\/\/www.infragistics.com\/blogs\/wp-json\/wp\/v2\/posts\/390\/revisions"}],"predecessor-version":[{"id":2190,"href":"https:\/\/www.infragistics.com\/blogs\/wp-json\/wp\/v2\/posts\/390\/revisions\/2190"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.infragistics.com\/blogs\/wp-json\/wp\/v2\/media\/997"}],"wp:attachment":[{"href":"https:\/\/www.infragistics.com\/blogs\/wp-json\/wp\/v2\/media?parent=390"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.infragistics.com\/blogs\/wp-json\/wp\/v2\/categories?post=390"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.infragistics.com\/blogs\/wp-json\/wp\/v2\/tags?post=390"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}