<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>online based editor &#8211; stoimen&#039;s web log</title>
	<atom:link href="/tag/online-based-editor/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>on web development</description>
	<lastBuildDate>Tue, 13 Feb 2018 08:18:15 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.0.3</generator>
	<item>
		<title>Adding a Custom Button to TinyMCE</title>
		<link>/2011/02/16/adding-a-custom-button-to-tinymce/</link>
		<comments>/2011/02/16/adding-a-custom-button-to-tinymce/#comments</comments>
		<pubDate>Wed, 16 Feb 2011 08:31:04 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[CKEditor]]></category>
		<category><![CDATA[Computer programming]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[editor]]></category>
		<category><![CDATA[FCKEditor]]></category>
		<category><![CDATA[Google Inc.]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[JavaScript programming language]]></category>
		<category><![CDATA[online based editor]]></category>
		<category><![CDATA[opinion]]></category>
		<category><![CDATA[Software engineering]]></category>
		<category><![CDATA[TinyMCE]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[WYSIWYG]]></category>
		<category><![CDATA[yahoo]]></category>

		<guid isPermaLink="false">/?p=2176</guid>
		<description><![CDATA[TinyMCE First thing to say TinyMCE is a very popular WYSIWYG online based editor. It&#8217;s very widely used in the web, as may already know it it&#8217;s part of the default WordPress installation. Out of the web, of course, there are some other editors as well. The most used and well developed projects are the &#8230; <a href="/2011/02/16/adding-a-custom-button-to-tinymce/" class="more-link">Continue reading <span class="screen-reader-text">Adding a Custom Button to TinyMCE</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2011/02/17/adding-a-custom-button-to-tinymce-revised/" rel="bookmark" title="Adding a Custom Button to TinyMCE &#8211; REVISED">Adding a Custom Button to TinyMCE &#8211; REVISED </a></li>
<li><a href="/2010/01/31/speed-up-the-javascript-it-can-change-dramatically-the-user-experience/" rel="bookmark" title="Speed up the JavaScript. It can change dramatically the user experience.">Speed up the JavaScript. It can change dramatically the user experience. </a></li>
<li><a href="/2010/02/11/javascript-optimization-lazy-loading/" rel="bookmark" title="JavaScript optimization. Lazy loading.">JavaScript optimization. Lazy loading. </a></li>
<li><a href="/2011/04/05/jquery-unbind/" rel="bookmark" title="jQuery.unbind()">jQuery.unbind() </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>TinyMCE</h2>
<p>First thing to say <a title="TinyMCE Homepage" href="http://tinymce.moxiecode.com/" target="_blank">TinyMCE</a> is a very popular <a title="WYSIWYG Wikipedia page" href="http://en.wikipedia.org/wiki/WYSIWYG" target="_blank">WYSIWYG</a> online based editor. It&#8217;s very widely used in the web, as may already know it it&#8217;s part of the default WordPress installation. Out of the web, of course, there are some other editors as well. The most used and well developed projects are the <a title="YUI 2 Rich Text Editor Homepage" href="http://developer.yahoo.com/yui/editor/" target="_blank">Yahoo!&#8217;s YUI 2 Rich Text Editor</a> and <a title="CKEditor Homepage" href="http://ckeditor.com/" target="_blank">CKEditor</a> also known with his past name &#8211; FCKEditor.<a href="/wp-content/uploads/2011/02/TinyMCE_Full_Featured.png"><img class="aligncenter size-full wp-image-2206" title="TinyMCE_Full_Featured" src="/wp-content/uploads/2011/02/TinyMCE_Full_Featured.png" alt="TinyMCE Full Featured Example" width="640" height="528" srcset="/wp-content/uploads/2011/02/TinyMCE_Full_Featured.png 640w, /wp-content/uploads/2011/02/TinyMCE_Full_Featured-300x247.png 300w" sizes="(max-width: 640px) 100vw, 640px" /></a></p>
<p>Before I proceed with this post, let me say that I&#8217;m working and this tutorial is based on <strong>version 3.1.1</strong> released on <strong>18 Aug 2008</strong>.<span id="more-2176"></span></p>
<h2>Including TinyMCE</h2>
<p>The only thing you&#8217;ve to do is to include a TinyMCE javascript file and write a simple init. The examples of installing it come with the compressed version of the javascript file:</p>
<pre lang="html4strict">
<script src="/scripts/tinymce/jscripts/tiny_mce/tiny_mce.js"></script>
<script>
tinyMCE.init({
	mode : "textareas",
	theme : "advanced",
	force_br_newlines : true,
	theme_advanced_buttons1 : "link,unlink,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|",
	theme_advanced_buttons2 : "",
	theme_advanced_buttons3 : "",
	theme_advanced_buttons4 : "",
	theme_advanced_toolbar_location : "top",
	theme_advanced_toolbar_align : "left",
	theme_advanced_statusbar_location : "",
	theme_advanced_resizing : true
});
</script>
</pre>
<p>The result of this code is shown on the picture:</p>
<p><a href="/wp-content/uploads/2011/02/TinyMCE_Before.png"><img class="aligncenter size-full wp-image-2207" title="TinyMCE_Before" src="/wp-content/uploads/2011/02/TinyMCE_Before.png" alt="TinyMCE Before" width="653" height="313" srcset="/wp-content/uploads/2011/02/TinyMCE_Before.png 653w, /wp-content/uploads/2011/02/TinyMCE_Before-300x143.png 300w" sizes="(max-width: 653px) 100vw, 653px" /></a></p>
<p>However for this tutorial you&#8217;ve to include the uncompressed file, because the compressed one is impossible to read and modify. At the end of all this you can compress yet again the resulting file with some js compressor as <a title="YUI Compressor Homepage" href="http://developer.yahoo.com/yui/compressor/" target="_blank">YUI Compressor</a>, <a title="JSMin" href="http://www.crockford.com/javascript/jsmin.html" target="_blank">JSMin</a> or <a title="Google Closure Compiler Homepage" href="http://code.google.com/closure/compiler/" target="_blank">Google Closure Compiler</a>. So instead of including the file above, you&#8217;ve to include the _src version as it is:</p>
<pre lang="html4strict">
<script src="/scripts/tinymce/jscripts/tiny_mce/tiny_mce_src.js"></script>
</pre>
<h2>Adding the Button</h2>
<p>Now there is a small configuration object passed to the init function. First you&#8217;ve to modify it a bit:</p>
<pre lang="javascript">
tinyMCE.init({
	mode : "textareas",
	theme : "advanced",
	force_br_newlines : true,
	theme_advanced_buttons1 : "link,unlink,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,mybutton",
	theme_advanced_buttons2 : "",
	theme_advanced_buttons3 : "",
	theme_advanced_buttons4 : "",
	theme_advanced_toolbar_location : "top",
	theme_advanced_toolbar_align : "left",
	theme_advanced_statusbar_location : "",
	theme_advanced_resizing : true
});
</pre>
<p>Usually in the /tinymce/jscripts/tiny_mce/themes/advanced/editor_template_src.js file there are some buttons described:</p>
<pre lang="javascript">
tinymce.create('tinymce.themes.AdvancedTheme', {
	// Control name lookup, format: title, command
	controls : {
		bold : ['bold_desc', 'Bold'],
		italic : ['italic_desc', 'Italic'],
		underline : ['underline_desc', 'Underline'],
		strikethrough : ['striketrough_desc', 'Strikethrough'],
		justifyleft : ['justifyleft_desc', 'JustifyLeft'],
		justifycenter : ['justifycenter_desc', 'JustifyCenter'],
		justifyright : ['justifyright_desc', 'JustifyRight'],
		justifyfull : ['justifyfull_desc', 'JustifyFull'],
		bullist : ['bullist_desc', 'InsertUnorderedList'],
		numlist : ['numlist_desc', 'InsertOrderedList'],
		outdent : ['outdent_desc', 'Outdent'],
		indent : ['indent_desc', 'Indent'],
...
</pre>
<p>What you need to do is simply to add a new line to this config array:</p>
<pre lang="javascript">
...
        blockquote : ['blockquote_desc', 'mceBlockQuote'],
	mybutton : ['mybutton_desc','myFunc']
},
</pre>
<p>That&#8217;s not enough of course! Now TinyMCE sees this definition, but nothing happens. It cannot build the new button yet. What&#8217;s next?</p>
<h2>Styling the Button</h2>
<p>After giving the new button a name, TinyMCE constructs a markup with the given name into the controlbar:</p>
<p><a href="/wp-content/uploads/2011/02/TinyMCE_Button_Step-_1.png"><img class="aligncenter size-full wp-image-2208" title="TinyMCE_Button_Step _1" src="/wp-content/uploads/2011/02/TinyMCE_Button_Step-_1.png" alt="TinyMCE Button Step 1" width="654" height="315" srcset="/wp-content/uploads/2011/02/TinyMCE_Button_Step-_1.png 654w, /wp-content/uploads/2011/02/TinyMCE_Button_Step-_1-300x144.png 300w" sizes="(max-width: 654px) 100vw, 654px" /></a></p>
<pre lang="html4strict">
<td>
	<a title="advanced.mybutton_desc" onclick="return false;" onmousedown="return false;" class="mceButton mceButtonEnabled mce_mybutton" href="javascript:;" id="mce_0_mybutton">
		<span class="mceIcon mce_mybutton"></span>
	</a>
</td>
</pre>
<p>This name can be simply used in the CSS file (/tinymce/jscripts/tiny_mce/themes/advanced/skins/default/ui.css) to style the button. Because TinyMCE uses sprite for its background images, you can copy/paste the style from some other button and than adjust the background position, only after you&#8217;ve added the new icon to the sprite. Here&#8217;s simply a copy of the style from another button:</p>
<pre lang="css">
...
.defaultSkin span.mce_numlist {background-position:-80px 0}
.defaultSkin span.mce_mybutton {background-position:-460px 0}
.defaultSkin span.mce_justifyleft {background-position:-460px 0}
...
</pre>
<p>You can see how the button appears in the control bar!</p>
<p><a href="/wp-content/uploads/2011/02/TinyMCE_Button_Step_2.png"><img class="aligncenter size-full wp-image-2209" title="TinyMCE_Button_Step_2" src="/wp-content/uploads/2011/02/TinyMCE_Button_Step_2.png" alt="TinyMCE Button Step 2" width="655" height="313" srcset="/wp-content/uploads/2011/02/TinyMCE_Button_Step_2.png 655w, /wp-content/uploads/2011/02/TinyMCE_Button_Step_2-300x143.png 300w" sizes="(max-width: 655px) 100vw, 655px" /></a></p>
<h2>Binding the Button</h2>
<p>The final job to do is to bind the button with some action. This thing happens again in /tinymce/jscripts/tiny_mce/themes/advanced/editor_template_src.js. You just have to search for other bindings &#8211; let&#8217;s say mceCleanup. There you can write your new function &#8211; myFunc:</p>
<pre lang="javascript">
FormatBlock : function(ui, val) {
	...
},

myFunc : function() {
	this.editor.selection.setContent('Hello World!');
},

mceCleanup : function() {
	...
},
</pre>
<p>Now after clicking the button the method will be executed. <a href="/wp-content/uploads/2011/02/TinyMCE_Button_Step_3.png"><img class="aligncenter size-full wp-image-2210" title="TinyMCE_Button_Step_3" src="/wp-content/uploads/2011/02/TinyMCE_Button_Step_3.png" alt="TinyMCE Button Step 3" width="653" height="312" srcset="/wp-content/uploads/2011/02/TinyMCE_Button_Step_3.png 653w, /wp-content/uploads/2011/02/TinyMCE_Button_Step_3-300x143.png 300w" sizes="(max-width: 653px) 100vw, 653px" /></a></p>
<p>Note that the name of the method should be exactly the same as described in the controls array in /tinymce/jscripts/tiny_mce/themes/advanced/editor_template_src.js. If not the button wont work ever.</p>
<h2>Final Steps</h2>
<p>Now you&#8217;ve to compress (if you wish) the js files and deploy your editor.</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2011/02/17/adding-a-custom-button-to-tinymce-revised/" rel="bookmark" title="Adding a Custom Button to TinyMCE &#8211; REVISED">Adding a Custom Button to TinyMCE &#8211; REVISED </a></li>
<li><a href="/2010/01/31/speed-up-the-javascript-it-can-change-dramatically-the-user-experience/" rel="bookmark" title="Speed up the JavaScript. It can change dramatically the user experience.">Speed up the JavaScript. It can change dramatically the user experience. </a></li>
<li><a href="/2010/02/11/javascript-optimization-lazy-loading/" rel="bookmark" title="JavaScript optimization. Lazy loading.">JavaScript optimization. Lazy loading. </a></li>
<li><a href="/2011/04/05/jquery-unbind/" rel="bookmark" title="jQuery.unbind()">jQuery.unbind() </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2011/02/16/adding-a-custom-button-to-tinymce/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
