<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title type="html">TinyMCE - Mr. Roa</title>
  <icon>http://mrroa.com/Content/icons/mushroom.ico</icon>
  <logo>http://mrroa.com/Content/icons/mushroom.png</logo>
  <updated>2009-09-16T10:11:00</updated>
  <subtitle type="html">The name is Roa. Mr. Roa</subtitle>
  <id>http://mrroa.com/tags/tinymce/atom</id>
  <link rel="alternate" type="text/html" hreflang="en" href="/tags/tinymce/atom"/>
  <link rel="self" type="application/atom+xml" href="http://mrroa.com/Tags/TinyMCE/ATOM"/>
  <generator uri="http://oxite.net" version="1.0">Oxite</generator>
  <entry>
    <title type="html">Oxite: Meets TinyMCE</title>
    <link rel="alternate" type="text/html" href="http://mrroa.com/Blog/Oxite-meets-TinyMCE"/>
    <id>http://mrroa.com/Blog/Oxite-meets-TinyMCE</id>
    <updated>2009-10-05T02:56:10.993</updated>
    <published>2009-09-16T10:11:00</published>
    <author>
      <name>Admin</name>
    </author>
    <category term="TinyMCE" />
    <category term="Oxite" />
    <content type="html" xml:lang="en">
      &lt;p&gt;This is the first of a series of blog posts I'll be doing about Oxite, a simple blog engine written using ASP .NET MVC. Which happens to be the one I'm using to administrate and maintain my blog. On my &lt;a title=&quot;Mr. Roa&quot; href=&quot;../../../Blog/Hello-World&quot;&gt;first post&lt;/a&gt;&amp;nbsp;I stated that I intended to modify the blogging engine and complete it &lt;strong&gt;&lt;em&gt;my way&lt;/em&gt;&lt;/strong&gt;. I already created a list of features, that I'd like to see in it in order to get things going.&lt;/p&gt;
&lt;p&gt;So, according to &lt;strong&gt;ME&lt;/strong&gt;, the first &quot;missing&quot; feature in Oxite, is a wysiwyg. I know it can be integrated with &lt;a title=&quot;Using Windows Live Writer to publish in Oxite &quot; href=&quot;http://capitalcoder.com/Blog/Using-Windows-Live-Writer-with-Oxite&quot; target=&quot;_blank&quot;&gt;live writer&lt;/a&gt;, but c'mon a blog engine shouldn't rely on third party applications, even though integration with those it's a nice feature. A blog engine should provide an easy to use text formatting tool. At least for the body of the blog post, taking care of annoying formatting tasks which involve a lot of html markup. With that said, after this blog post I won't be writing html markup directly into a textarea in order to format my blog posts.&lt;/p&gt;
&lt;p&gt;Let's get this thing started then. After a browsing through an extensive list of available &lt;span class=&quot;subhead&quot;&gt;&lt;span style=&quot;font-family: Verdana;&quot;&gt;&lt;a href=&quot;http://www.geniisoft.com/showcase.nsf/WebEditors&quot; target=&quot;_blank&quot;&gt;TTW (&quot;Through the Web&quot;) WYSIWYG Web Editors&lt;/a&gt;, I chose to use &lt;a href=&quot;http://tinymce.moxiecode.com/&quot; target=&quot;_blank&quot;&gt;TinyMCE&lt;/a&gt;. It's widely used, it has a lot of plugins, an active community and it seems really easy to implement.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;subhead&quot;&gt;&lt;span style=&quot;font-family: Verdana;&quot;&gt;Well, I'm done with the first step. I already chose my formatting tool for my blog posts. Anyways I created a little list of things I MUST be able to do when creating a blog post with it:&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;span class=&quot;subhead&quot;&gt;&lt;span style=&quot;font-family: Verdana;&quot;&gt;Use default formatting tools such as bold text, italic, underline, text alignment and justification, etc.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;subhead&quot;&gt;&lt;span style=&quot;font-family: Verdana;&quot;&gt;Have a html view in case I need to teak some of the markup after all.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;subhead&quot;&gt;&lt;span style=&quot;font-family: Verdana;&quot;&gt;An option to wrap text between pre or code tags in order to identify code snippets.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;subhead&quot;&gt;&lt;span style=&quot;font-family: Verdana;&quot;&gt;Spellchecker, of course! This is one of the most useful features when creating articles/posts. (isn't it?)&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Ok, after getting that out of the way. Let's get started shall we?&lt;/p&gt;
&lt;h3&gt;TinyMCE &amp;amp; Code Snippet Wrapping&lt;/h3&gt;
&lt;p&gt;&lt;span class=&quot;subhead&quot;&gt;&lt;span style=&quot;font-family: Verdana;&quot;&gt;In order to get started we need to download TinyMCE, also since one of our requirements is to wrap code snippets between pre/code tags we will need something to make code snippets look prettier. For that matter I'll be using &lt;a href=&quot;http://code.google.com/p/google-code-prettify/&quot; target=&quot;_blank&quot;&gt;prettify&lt;/a&gt;. After downloading both, the script files must be placed inside the Scripts folder of the Oxite theme being used.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;http://s.mrroa.com/tinymcescripts.png&quot; alt=&quot;&quot; width=&quot;269&quot; height=&quot;285&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Prettify also comes with a stylesheet that defines the color schema of our code snippets, so we should also place that file inside of the Styles folder of the Oxite theme.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;http://s.mrroa.com/tinymcestyles.png&quot; alt=&quot;&quot; width=&quot;269&quot; height=&quot;285&quot; /&gt;&lt;/p&gt;
&lt;p&gt;For my taste the code snippet text should be big and clear, so I changed the cascading style sheet to render the code snippet fonts a little bit bigger.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;http://s.mrroa.com/prettifyfontsize.png&quot; alt=&quot;&quot; width=&quot;751&quot; height=&quot;336&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Ok, so now we are closer to having a WYSIWYG with support to paste code snippets in Oxite, but first there are a couple more steps we need to do. In order to be a little bit more organized I created a mrroa.com.js file which is going to contain my client side &lt;em&gt;extensions&lt;/em&gt;. Here we are going to place the initialization script for tinymce as follows.&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;tinyMCE.init({&lt;br /&gt;    mode: &quot;exact&quot;,&lt;br /&gt;    elements: &quot;post_body&quot;,&lt;br /&gt;    theme: &quot;advanced&quot;,&lt;br /&gt;    theme_advanced_buttons1: &quot;codetag,code,separator,bold,italic,underline,strikethrough,separator,justifyleft,&lt;br /&gt;    justifycenter,justifyright,justifyfull,separator,bullist,numlist,separator,undo,redo,separator,link,unlink&quot;,&lt;br /&gt;    theme_advanced_buttons2: &quot;&quot;,&lt;br /&gt;    theme_advanced_buttons3: &quot;&quot;,&lt;br /&gt;    theme_advanced_toolbar_location: &quot;top&quot;,&lt;br /&gt;    theme_advanced_toolbar_align: &quot;left&quot;,&lt;br /&gt;    theme_advanced_statusbar_location: &quot;bottom&quot;,       &lt;br /&gt;    setup: function(ed) {&lt;br /&gt;        //Custom button Code (Code Snippet Wrapper)&lt;br /&gt;        ed.addButton('codetag', {&lt;br /&gt;            title: 'Wrap code tags around selected text',&lt;br /&gt;            image: 'http://mrroa.com/Content/images/code.gif',&lt;br /&gt;            onclick: function() {&lt;br /&gt;                ed.selection.setContent('&amp;lt;pre class=&quot;prettify&quot;&amp;gt;' &lt;br /&gt;                     + ed.selection.getContent({ format: 'text' }) + '&amp;lt;/pre&amp;gt;');             &lt;br /&gt;             }         &lt;br /&gt;         });     &lt;br /&gt;      } });&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;Notice that there's a setup property which contains a javascript function. This is the definition of our code wrapping button, that is not included in TinyMCE's palette of buttons. The setup section in the above snippet, tells TinyMCE to wrap around pre tags our text selection. Also notice how I added the default text formatting tools into the theme_advanced_buttons1 collection. The &lt;span style=&quot;text-decoration: underline;&quot;&gt;&lt;em&gt;code&lt;/em&gt;&lt;/span&gt; button represents the html source viewer, so this WYSIWYG almost has all the features described initially.&lt;/p&gt;
&lt;h3&gt;SpellChecking&lt;/h3&gt;
&lt;p&gt;For this feature we need to work a little bit more. First of all we need to download and reference the TinyMCE &lt;a href=&quot;http://tinymce.moxiecode.com/download.php&quot; target=&quot;_blank&quot;&gt;.NET Package&lt;/a&gt;. Among many features embedded, this package contains a handler which implements the old google spellchecking API, which still works (I figure that eventually they will update the hanlder to implement the new one).&lt;/p&gt;
&lt;p&gt;After referencing the package we need to add the following code to the httpHandlers section of our web.config.&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&amp;lt;add verb=&quot;GET,HEAD,POST&quot; path=&quot;TinyMCE.ashx&quot; type=&quot;Moxiecode.TinyMCE.Web.HttpHandler,Moxiecode.TinyMCE&quot; /&amp;gt;&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;Also we need to add a rule to the Oxite Routing class, in order to tell the ASP .NET MVC routing engine that it shouldn't map to a controller the requests made to the hanlder.&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;routes.Add(new Route(&quot;TinyMCE.ashx&quot;, new StopRoutingHandler()))&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Now we just need to update the script file containing the TinyMCE initialization to implement the spellchecker plugin.&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;tinyMCE.init({&lt;br /&gt;    mode: &quot;exact&quot;,&lt;br /&gt;    elements: &quot;post_body&quot;,&lt;br /&gt;    theme: &quot;advanced&quot;,&lt;br /&gt;    plugins: &quot;spellchecker&quot;,&lt;br /&gt;    theme_advanced_buttons1: &quot;codetag,code,separator,bold,italic,underline,strikethrough,separator,justifyleft,&lt;br /&gt;    justifycenter,justifyright,justifyfull,separator,bullist,numlist,separator,undo,redo,separator,link,unlink,separator,&lt;br /&gt;    spellchecker&quot;,&lt;br /&gt;    theme_advanced_buttons2: &quot;&quot;,&lt;br /&gt;    theme_advanced_buttons3: &quot;&quot;,&lt;br /&gt;    theme_advanced_toolbar_location: &quot;top&quot;,&lt;br /&gt;    theme_advanced_toolbar_align: &quot;left&quot;,&lt;br /&gt;    theme_advanced_statusbar_location: &quot;bottom&quot;,      &lt;br /&gt;    spellchecker_languages: &quot;+English=en,Spanish=es&quot;,&lt;br /&gt;    spellchecker_rpc_url: &quot;/TinyMCE.ashx?module=SpellChecker&quot;,&lt;br /&gt;    setup: function(ed) {&lt;br /&gt;        //Custom button Code (Code Snippet Wrapper)&lt;br /&gt;        ed.addButton('codetag', {&lt;br /&gt;            title: 'Wrap code tags around selected text',&lt;br /&gt;            image: 'http://mrroa.com/Content/images/code.gif',&lt;br /&gt;            onclick: function() {&lt;br /&gt;                ed.selection.setContent('&amp;lt;pre class=&quot;prettify&quot;&amp;gt;' &lt;br /&gt;                     + ed.selection.getContent({ format: 'text' }) + '&amp;lt;/pre&amp;gt;');             &lt;br /&gt;             }         &lt;br /&gt;         });     &lt;br /&gt;      } });&lt;/pre&gt;
&lt;h3&gt;One Final Step&lt;/h3&gt;
&lt;p&gt;Now we need to reference the scripts and stylesheets on the master pages of the site. In order to achieve this we need to place this snippets in two webusercontrols.&lt;/p&gt;
&lt;p&gt;First in HeadCustomAdminContents.ascx&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;Html.RenderScriptTag(&quot;tiny_mce/tiny_mce_src.js&quot;);&lt;br /&gt;Html.RenderScriptTag(&quot;mrroa.com.js&quot;);&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;And then in HeadCustomContents.ascx&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;Html.RenderCssFile(&quot;prettify.css&quot;);&lt;br /&gt;Html.RenderScriptTag(&quot;prettify/prettify.js&quot;);&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h3&gt;The Result&lt;/h3&gt;
&lt;p&gt;Here's a screenshot of my nice and shiny WYSIWYG with all the features I wanted. I guess you can tell I used it to create this post as well ;)&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;http://s.mrroa.com/tinymce.png&quot; alt=&quot;&quot; width=&quot;945&quot; height=&quot;282&quot; /&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h3&gt;Summary&lt;/h3&gt;
&lt;p&gt;In this post, I tried to emphasize on the importance of having text formatting tools like &lt;strong&gt;WYSIWYG&lt;/strong&gt;'s in systems used for publishing. Also I tried to show how to implement TinyMCE, which is widely used, and how to extend it for some specific purposes. Furthermore, this series of articles purpose is to demonstrate how the MVC model allows to achieve with ease extensibility, modifiability and testability.&lt;/p&gt;
    </content>
  </entry>
</feed>
