<?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>Plan Zero Blog &#187; Code Projects</title>
	<atom:link href="http://blog.planzero.org/category/code/code-projects/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.planzero.org</link>
	<description>Mind dump</description>
	<lastBuildDate>Sat, 05 Sep 2009 17:29:18 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>BBEditor, the free BBCode editor</title>
		<link>http://blog.planzero.org/2008/12/bbeditor-the-free-bbcode-editor/</link>
		<comments>http://blog.planzero.org/2008/12/bbeditor-the-free-bbcode-editor/#comments</comments>
		<pubDate>Thu, 18 Dec 2008 13:23:41 +0000</pubDate>
		<dc:creator>Plan Zero</dc:creator>
				<category><![CDATA[Code Projects]]></category>

		<guid isPermaLink="false">http://blog.planzero.org/?p=45</guid>
		<description><![CDATA[<p>Well, I said that I&#8217;d be using this blog to publish code, so here&#8217;s my latest little project.</p>
<p>BBEditor is a <a href="http://en.wikipedia.org/wiki/MIT_License">free</a> BBCode editor written in JavaScript for HTML/PHP. It&#8217;s standards compliant, and really is rather sexy.</p>
<h3>

<dl id="attachment_89" class="wp-caption alignnone" style="width: 310px;">
<dt class="wp-caption-dt"><img class="size-full wp-image-89" title="BBEditor edit bar" src="http://blog.planzero.org/wp-content/uploads/2008/12/bbeditor_bbebar_300x30.png" alt="BBEditor edit bar" width="300" height="30" /></dt>
</dl>

</h3>
<h3>Features:</h3>
<ul>
<li>Easy to integrate</li>
<li>Cross-browser compliant</li>
<li>Degrades wonderfully in old or non-compliant browsers</li>
<li>Sleek code &#8211; fast loading, no bulk, no mess</li>
<li>Easy to style to your needs</li>
<li>Adding additional buttons and&#8230;</li></ul>]]></description>
			<content:encoded><![CDATA[<p>Well, I said that I&#8217;d be using this blog to publish code, so here&#8217;s my latest little project.</p>
<p>BBEditor is a <a href="http://en.wikipedia.org/wiki/MIT_License">free</a> BBCode editor written in JavaScript for HTML/PHP. It&#8217;s standards compliant, and really is rather sexy.</p>
<h3>
<div class="mceTemp">
<dl id="attachment_89" class="wp-caption alignnone" style="width: 310px;">
<dt class="wp-caption-dt"><img class="size-full wp-image-89" title="BBEditor edit bar" src="http://blog.planzero.org/wp-content/uploads/2008/12/bbeditor_bbebar_300x30.png" alt="BBEditor edit bar" width="300" height="30" /></dt>
</dl>
</div>
</h3>
<h3>Features:</h3>
<ul>
<li>Easy to integrate</li>
<li>Cross-browser compliant</li>
<li>Degrades wonderfully in old or non-compliant browsers</li>
<li>Sleek code &#8211; fast loading, no bulk, no mess</li>
<li>Easy to style to your needs</li>
<li>Adding additional buttons and functionality is a sinch!</li>
</ul>
<p>Got you curious? Try the <a href="http://planzero.org/bits/bbeditor_demo/">basic demonstration</a> that comes with BBEditor!</p>
<h3>Download</h3>
<p>Current version: <a title="Download BBEditor" href="http://planzero.org/bits/bbeditor_20081218.tar.bz2">BBEditor v0.1</a></p>
<h3>Integration</h3>
<p>You&#8217;ll like this.</p>
<ol>
<li>Download and extract BBEditor</li>
<li> Add the following two lines to the &lt;head&gt; section of your page:
<pre lang="html" id="line1">&lt;<span class="start-tag">link</span><span class="attribute-name"> href</span>=<span class="attribute-value">"bbeditor.css" </span><span class="attribute-name">rel</span>=<span class="attribute-value">"stylesheet" </span><span class="attribute-name">type</span>=<span class="attribute-value">"text/css" </span><span class="error"><span class="attribute-name">/</span></span>&gt;
&lt;<span class="start-tag">script</span><span class="attribute-name"> src</span>=<span class="attribute-value">"bbeditor.js" </span><span class="attribute-name">type</span>=<span class="attribute-value">"text/javascript"</span>&gt;&lt;/<span class="end-tag">script</span>&gt;</pre>
</li>
<li>Add <em>class=&#8221;bbeditor&#8221;</em> to any &lt;textarea&gt; that uses BBCode</li>
</ol>
<p>Yup, that&#8217;s all there is to it. Simple.</p>
<h3>Customisation</h3>
<p>Customising BBEditor is fairly easy. To <strong>edit the styles</strong> associated with the BBEditor bar, you can edit <em>bbeditor.css</em>. The main bar uses a class named <em>bbebar</em>. To keep things simple, you may want to add the contents of <em>bbeditor.css</em> to your main style sheet. This will also cut down on browser traffic.</p>
<p>To <strong>add your own buttons and functionality</strong> to BBEditor, you&#8217;ll have to have a little JavaScript knowhow. You&#8217;ll find that <em>bbeditor.js</em> has a compressed chunk of code at the top; skip this and go to the bottom of the file. This is where the fun stuff is.</p>
<p>The buttons are defined in a <em>Hash</em>, so to make changes locate and alter the following code (this should be fairly self explanatory, so I won&#8217;t go into detail):</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// Buttons definitions!</span>
bbeButtons<span style="color: #339933;">=</span><span style="color: #003366; font-weight: bold;">new</span> Hash<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
  bold<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">new</span> Hash<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    title<span style="color: #339933;">:</span> <span style="color: #3366CC;">'Embolden Text'</span><span style="color: #339933;">,</span>
    icon<span style="color: #339933;">:</span> bbeSettings.<span style="color: #660066;">get</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'imageBase'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'text_bold.png'</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
  italic<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">new</span> Hash<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    title<span style="color: #339933;">:</span> <span style="color: #3366CC;">'Italicise Text'</span><span style="color: #339933;">,</span>
    icon<span style="color: #339933;">:</span> bbeSettings.<span style="color: #660066;">get</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'imageBase'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'text_italic.png'</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
...
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The function to be performed is defined by the target link associated with each button.  This is defined in the <em>bbeButtons</em> hash, so in the above code, <em>italic</em> and <em>bold</em> are the link targets. To add new functionality, add the relevant link target to the <em>switch() </em>statement in the <em>bbeAction()</em> function:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// Perform an action, determined by the href of the followed link</span>
<span style="color: #003366; font-weight: bold;">function</span> bbeAction<span style="color: #009900;">&#40;</span>el<span style="color: #339933;">,</span> et<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
...
  <span style="color: #000066; font-weight: bold;">switch</span><span style="color: #009900;">&#40;</span>action<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">'#bold'</span><span style="color: #339933;">:</span>
      et.<span style="color: #660066;">insertAroundCursor</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #3366CC;">'before'</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'[b]'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'after'</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'[/b]'</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">'#italic'</span><span style="color: #339933;">:</span>
      et.<span style="color: #660066;">insertAroundCursor</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #3366CC;">'before'</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'[i]'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'after'</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'[/i]'</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
...
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h3>FAQ</h3>
<p><span style="color: #ff6600;"><strong>Why did you write BBEditor when there are other similar tools?</strong></span></p>
<p>When I was looking for a simple BBCode editor, I found so much messy code that I got fed up and decided to take the time to write my own. Many of the existing editors wouldn&#8217;t create a text input box at all if JavaScript was disabled, or were slow and clunky to use. BBEditor is light, and degrades well. If a user doesn&#8217;t have JavaScript, the input box is still usable without the editing bar.</p>
<p><span style="color: #ff6600;"><strong>My images aren&#8217;t loading! Help!</strong></span></p>
<p>If you have moved the location of the script or the images, the images may not load. Don&#8217;t panic! You can set the base location for the images in <em>bbeditor.js</em>. Just update the <em>imageBase</em> setting in the following block of code:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// General settings</span>
bbeSettings<span style="color: #339933;">=</span><span style="color: #003366; font-weight: bold;">new</span> Hash<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
  position<span style="color: #339933;">:</span> <span style="color: #3366CC;">'before'</span><span style="color: #339933;">,</span>
  imageBase<span style="color: #339933;">:</span> <span style="color: #3366CC;">'icons/'</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><span style="color: #ff6600;"><strong>Where did you get those great icons, anyway?</strong></span></p>
<p>I have used the fantastic free <a href="http://www.famfamfam.com/lab/icons/silk/" target="_blank">Silk icon set</a>. If you want to add some buttons, I couldn&#8217;t recommend this set of icons enough.</p>
<p><strong><span style="color: #ff6600;">What technology does BBEditor use?</span></strong></p>
<p>BBEditor uses DOM-compliant JavaScript. For compatibility and efficiency reasons I have used code from the <a href="http://mootools.net/" target="_blank">mootools</a> library complimented by the <a href="http://www.clientcide.com/wiki/cnet-libraries/" target="_blank">Clientcide</a> extension for accessing forms. This is all included in <em>bbeditor.js</em>.</p>
<p><span style="color: #ff6600;"><strong>How much does this all cost?</strong></span></p>
<p>Nothing! This is free, open source software, released under the <a href="http://en.wikipedia.org/wiki/MIT_License" target="_blank">MIT License</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.planzero.org/2008/12/bbeditor-the-free-bbcode-editor/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
	</channel>
</rss>
