<?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>Teleogistic &#187; tinymce</title>
	<atom:link href="http://teleogistic.net/tag/tinymce/feed/" rel="self" type="application/rss+xml" />
	<link>http://teleogistic.net</link>
	<description></description>
	<lastBuildDate>Thu, 03 May 2012 16:24:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Using init callbacks with TinyMCE and wp_editor() in WordPress</title>
		<link>http://teleogistic.net/2012/02/using-init-callbacks-with-tinymce-and-wp_editor-in-wordpress/</link>
		<comments>http://teleogistic.net/2012/02/using-init-callbacks-with-tinymce-and-wp_editor-in-wordpress/#comments</comments>
		<pubDate>Thu, 09 Feb 2012 16:21:33 +0000</pubDate>
		<dc:creator>Boone Gorges</dc:creator>
				<category><![CDATA[wordpress]]></category>
		<category><![CDATA[buddypress docs]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[tinymce]]></category>
		<category><![CDATA[wp_editor()]]></category>

		<guid isPermaLink="false">http://teleogistic.net/?p=1615</guid>
		<description><![CDATA[WordPress 3.3 introduced wp_editor(). It&#8217;s a big improvement over the earlier hacks needed to get a TinyMCE instance on the WP front end. But it broke the feature in my BuddyPress Docs that detected idle time. The problem, in short, was two-fold: my idle-detection JavaScript was loading before the editor was initialized, and it wasn&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>WordPress 3.3 introduced <a href="http://codex.wordpress.org/Function_Reference/wp_editor"><code>wp_editor()</code></a>. It&#8217;s a big improvement over the earlier hacks needed to get a TinyMCE instance on the WP front end. But it broke the feature in my <a href="http://wordpress.org/extend/plugins/buddypress-docs/">BuddyPress Docs</a> that detected idle time. The problem, in short, was two-fold: my idle-detection JavaScript was loading before the editor was initialized, and it wasn&#8217;t detecting key presses inside of the TinyMCE iframe. The solution to both parts of the problem required passing callbacks to the TinyMCE initialization array, in the <code>setup</code> array. It took me a long time to figure out how to do this, so for posterity&#8217;s sake, here are some takeaways.</p>
<p>First, the code:</p>
<pre class="brush: php">
function bp_docs_add_idle_function_to_tinymce( $initArray ) {
	if ( bp_docs_is_bp_docs_page() ) {

		$initArray[&#039;setup&#039;] = &#039;function(ed) {
			ed.onInit.add(
				function(ed) {
					_initJQuery();

					// Set up listeners
					jQuery(\&#039;#\&#039; + ed.id + \&#039;_parent\&#039;).bind(\&#039;mousemove\&#039;,function (evt){
						_active(evt);
					});	

					bp_docs_load_idle();

				}
			);

			ed.onKeyDown.add(
				function(ed) {
					_active();
				}
			);
		}&#039;;
	}

	return $initArray;
}
add_filter( &#039;tiny_mce_before_init&#039;, &#039;bp_docs_add_idle_function_to_tinymce&#039; );
</pre>
<p>Some notes:</p>
<ul>
<li>I&#8217;m passing a &#8216;setup&#8217; parameter to the TinyMCE init array by filtering <code>tiny_mce_before_init</code></li>
<li>Only do this when you&#8217;re editing a BuddyPress Doc &#8211; that&#8217;s the <code>bp_docs_is_bp_docs_page()</code> check. I don&#8217;t want to mess with every instance of TinyMCE on the installation.</li>
<li>The <code>setup</code> parameter has to be a string. This gets tricky when the string is supposed to define an unnamed JS callback, because you have to be very careful about escaping quotes. As a string, your callback has to be wrapped in quotes. Also, when WP prints the TinyMCE parameters (and when it sees that your paramater begins with the string &#8216;function&#8217;) it&#8217;s going to wrap it in double-quotes. After lots of messing around, I was able to get this to work by using escaped single-quotes. (If you need to double-embed quotes &#8211; like a chain of callbacks &#8211; use escaped double-quotes.)</li>
<li>Where possible, use TinyMCE&#8217;s <a href="http://www.tinymce.com/wiki.php/API3:class.tinymce.Editor">native events</a>. <code>ed.onKeyDown</code> is one of them. It allows me to call my <code>_active()</code> function whenever a key is pressed inside the editor.</li>
<li>There are some kinds of actions that aren&#8217;t really detectable using TinyMCE&#8217;s events. For instance, I wanted to be able to detect when someone was moving their mouse around the iframe and especially TinyMCE&#8217;s toolbar. You can see this where I&#8217;m binding my callback to <code>mousemove</code> in the TinyMCE <code>_parent</code> element.</li>
<li><code>_initJQuery()</code> and <code>bp_docs_load_idle()</code> are my own functions that need to run after the editor has finished setting up. That&#8217;s why they, along with the <code>bind</code>, are called in a callback of <code>ed.onInit</code> &#8211; that&#8217;s the generic place to put things that need to happen once the editor is up and running.</li>
</ul>
<p>Related posts:<ol>
<li><a href='http://teleogistic.net/2009/12/tinymce-in-buddypress/' rel='bookmark' title='TinyMCE in Buddypress'>TinyMCE in Buddypress</a></li>
<li><a href='http://teleogistic.net/2010/08/hiding-wordpress-custom-post-type-menu-items-without-disabling-edit-access/' rel='bookmark' title='Hiding WordPress custom post type menu items without disabling edit access'>Hiding WordPress custom post type menu items without disabling edit access</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://teleogistic.net/2012/02/using-init-callbacks-with-tinymce-and-wp_editor-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>TinyMCE in Buddypress</title>
		<link>http://teleogistic.net/2009/12/tinymce-in-buddypress/</link>
		<comments>http://teleogistic.net/2009/12/tinymce-in-buddypress/#comments</comments>
		<pubDate>Sun, 20 Dec 2009 23:49:02 +0000</pubDate>
		<dc:creator>Boone Gorges</dc:creator>
				<category><![CDATA[dev.wpmued]]></category>
		<category><![CDATA[edtech]]></category>
		<category><![CDATA[buddypress]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[tinymce]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[WPMu]]></category>

		<guid isPermaLink="false">http://teleogistic.net/?p=406</guid>
		<description><![CDATA[I threw a little something together today to add WYSIWYG editing to BuddyPress, using TinyMCE. I want to be careful about the tags I allow, so I&#8217;m whitelisting, which is a bit tedious. As a result, there are only a few buttons available: a, em, strong, ul, ol, li. It&#8217;s a start, though. Seems to [...]]]></description>
			<content:encoded><![CDATA[<p>I threw a little something together today to add WYSIWYG editing to BuddyPress, using TinyMCE. I want to be careful about the tags I allow, so I&#8217;m whitelisting, which is a bit tedious. As a result, there are only a few buttons available: a, em, strong, ul, ol, li. It&#8217;s a start, though.</p>
<p>Seems to work everywhere in BP: forums, wire, messages, profile pages.</p>
<p>A note about TinyMCE: WP ships with TinyMCE, and I thought it made sense to use that version instead of attaching one to this plugin. I think that the path to TinyMCE (line 20 of the plugin) should work on all installations, but you may have to tinker if you don&#8217;t see it popping up in the head of your BP pages. Moreover, the language files for WP&#8217;s version of TinyMCE are misnamed, which means that they don&#8217;t work right out of the box (at least for me they don&#8217;t). You may need to change the name of wp-includes/js/tinymce/langs/<strong>wp-langs-en.php</strong> to <strong>en.php</strong> in order to get the hover and help text in the TinyMCE box to work.</p>
<p><a href="http://wordpress.org/extend/plugins/bp-tinymce/">Download the plugin here</a>.  Don&#8217;t use in a production environment unless you are very certain that you are satisfied with the security of this plugin!</p>
<p>Related posts:<ol>
<li><a href='http://teleogistic.net/2012/02/using-init-callbacks-with-tinymce-and-wp_editor-in-wordpress/' rel='bookmark' title='Using init callbacks with TinyMCE and wp_editor() in WordPress'>Using init callbacks with TinyMCE and wp_editor() in WordPress</a></li>
<li><a href='http://teleogistic.net/2009/09/new-buddypress-bbpress-plugin-group-forum-subscription/' rel='bookmark' title='New BuddyPress / bbPress plugin: Group Forum Subscription'>New BuddyPress / bbPress plugin: Group Forum Subscription</a></li>
<li><a href='http://teleogistic.net/2010/05/new-buddypress-plugin-buddypress-group-email-subscription/' rel='bookmark' title='New BuddyPress plugin: BuddyPress Group Email Subscription'>New BuddyPress plugin: BuddyPress Group Email Subscription</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://teleogistic.net/2009/12/tinymce-in-buddypress/feed/</wfw:commentRss>
		<slash:comments>54</slash:comments>
		</item>
	</channel>
</rss>

