<?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>Labs &#187; tinymce</title>
	<atom:link href="http://labs.iamkoa.net/tag/tinymce/feed/" rel="self" type="application/rss+xml" />
	<link>http://labs.iamkoa.net</link>
	<description>I break it. I fix it. You learn.</description>
	<lastBuildDate>Wed, 22 Sep 2010 19:43:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>TinyMCE &amp; Mootools Ajax.Form Class &#8211; Feel The Love</title>
		<link>http://labs.iamkoa.net/2008/05/31/tinymce-mootools-ajax-form/</link>
		<comments>http://labs.iamkoa.net/2008/05/31/tinymce-mootools-ajax-form/#comments</comments>
		<pubDate>Sat, 31 May 2008 18:34:47 +0000</pubDate>
		<dc:creator>Koa</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[mootools]]></category>
		<category><![CDATA[tinymce]]></category>

		<guid isPermaLink="false">http://labs.iamkoa.net/?p=74</guid>
		<description><![CDATA[TinyMCE (Tiny) is regarded as one of the best open source, HTML WYSIWYG editors of our time &#8211; it&#8217;s powerful, relatively easy for browsers to digest, and free to use. The frustrations of using Tiny arise when you attempt to submit your Tiny-enhanced form via Ajax. Because your Tiny textarea inputs are converted to a [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://tinymce.moxiecode.com/">TinyMCE</a> (Tiny) is regarded as one of the best open source, HTML WYSIWYG editors of our time &#8211; it&#8217;s powerful, relatively easy for browsers to digest, and free to use. The frustrations of using Tiny arise when you attempt to submit your Tiny-enhanced form via Ajax. Because your Tiny <code>textarea</code> inputs are converted to a mess of divs, spans, iframes, etc, <a href="http://demos.mootools.net/Ajax.Form">Mootools Ajax.Form</a> class fails to recognize the textarea. Fear not, there&#8217;s an easy workaround.</p>
<p><span id="more-74"></span></p>
<h2>The Workaround</h2>
<p>Below is a simple Javascript function you can use to convert Tiny-enhanced textareas back into regular form textareas:</p>
<pre class="brush:js">
var fixTiny = function(properties) {
	var properties = properties || new Object();
	var instance = properties.instance || 'mce_editor_0';
	tinyMCE.execInstanceCommand(instance,'mceCleanup');
	tinyMCE.triggerSave(true,true);
	return true;
}
</pre>
<h2>Using The Goods</h2>
<p>Using the above Javascript function is easy. Let&#8217;s assume we&#8217;re submitting two TinyMCE-enhanced textareas named &#8220;excerpt&#8221; and &#8220;body&#8221;, in a form with the id &#8220;myForm&#8221;. Here&#8217;s how to submit the form:</p>
<p>(The form submit code is taken directly from <a href="http://demos.mootools.net/Ajax.Form">this Mootools demos page</a>. Please refer to that page for further Ajax.Form reference.)</p>
<pre class="brush:js">
$('myForm').addEvent('submit', function(e) {
	/**
	 * Prevent the submit event
	 */
	new Event(e).stop();

	fixTiny({instance:'excerpt'});
	fixTiny({instance:'body'});

	/**
	 * This empties the log and shows the spinning indicator
	 */
	var log = $('log_res').empty().addClass('ajax-loading');

	/**
	 * send takes care of encoding and returns the Ajax instance.
	 * onComplete removes the spinner from the log.
	 */
	this.send({
		update: log,
		onComplete: function() {
			log.removeClass('ajax-loading');
		}
	});
});
</pre>
<p>All of this code, including the <code>fixTiny</code> function should be placed within a <code>domready</code> event.</p>
<h2>Simple, Right?</h2>
<p>If I&#8217;ve missed anything, shout at me. You can also refer to the <a href="http://forum.mootools.net/">Mootools forums</a> for further examples of using both TinyMCE and the Ajax.Form class. </p>
]]></content:encoded>
			<wfw:commentRss>http://labs.iamkoa.net/2008/05/31/tinymce-mootools-ajax-form/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

