<?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>Coding Friends &#187; Javascript</title>
	<atom:link href="http://www.codingfriends.com/index.php/category/programming/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.codingfriends.com</link>
	<description>Coding Friends, place for developers.</description>
	<lastBuildDate>Sun, 04 Dec 2011 21:11:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Ckeditor &#8211; not allow posting of images from the local harddrive</title>
		<link>http://www.codingfriends.com/index.php/2011/10/19/ckeditor-not-allow-posting-of-images-from-the-local-harddrive/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=ckeditor-not-allow-posting-of-images-from-the-local-harddrive</link>
		<comments>http://www.codingfriends.com/index.php/2011/10/19/ckeditor-not-allow-posting-of-images-from-the-local-harddrive/#comments</comments>
		<pubDate>Wed, 19 Oct 2011 20:26:51 +0000</pubDate>
		<dc:creator>genux</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[CKEditor]]></category>
		<category><![CDATA[local harddrive]]></category>

		<guid isPermaLink="false">http://www.codingfriends.com/?p=1743</guid>
		<description><![CDATA[Within the CKEditor you can also add on to the prototypes that allow more control of what is allowed on your website. Sometimes you do not want to allow the user to copy and paste local files to the CKEditor so this is what I done to remove the file:// from within the img tag [...]]]></description>
			<content:encoded><![CDATA[<p>Within the <a href="http://ckeditor.com/" title="CKEDITOR" target="_blank">CKEditor</a> you can also add on to the prototypes that allow more control of what is allowed on your website.</p>
<p>Sometimes you do not want to allow the user to copy and paste local files to the CKEditor so this is what I done to remove the file:// from within the img tag within the copy and paste with using the CKEditor htmlDataProcessor group of functions, in this case the &#8216;toHtml&#8217; function which is called when the user pastes any content into the CKEditor window.  All I am doing it using the regular expression to search for the &lt;img src=&#8221;file .. and replace with a &lt;mg tag&gt; which when they double click on that it will open the CKEditor&#8217;s image browser (which you can include a upload part to it as well <img src='http://www.codingfriends.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  )</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">CKEDITOR.<span style="color: #660066;">htmlDataProcessor</span>.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">toHtml</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span> data<span style="color: #339933;">,</span> fixForBody <span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">return</span> data.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/\&lt;img src=\&quot;file:([^\&gt;])*\&gt;/ig</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;&lt;img title=<span style="color: #000099; font-weight: bold;">\&quot;</span>Please use the Media/Image uploader because can not show files on your harddrive<span style="color: #000099; font-weight: bold;">\&quot;</span> alt=<span style="color: #000099; font-weight: bold;">\&quot;</span>Please use the Media/Image uploader because can not show files on your harddrive<span style="color: #000099; font-weight: bold;">\&quot;</span>/&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>It was very helpful for me.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codingfriends.com/index.php/2011/10/19/ckeditor-not-allow-posting-of-images-from-the-local-harddrive/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Javascript {} []</title>
		<link>http://www.codingfriends.com/index.php/2011/03/26/javascript/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=javascript</link>
		<comments>http://www.codingfriends.com/index.php/2011/03/26/javascript/#comments</comments>
		<pubDate>Sat, 26 Mar 2011 21:38:00 +0000</pubDate>
		<dc:creator>genux</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[[] {}]]></category>

		<guid isPermaLink="false">http://www.codingfriends.com/?p=1581</guid>
		<description><![CDATA[Someone asked me what is the difference between {} and [] within javascript. Basically the difference is one is a key => value pair like PHP &#8216;{}&#8217;, and the other is just a pure array of values &#8216;[]&#8216;. Here is the code. var simplearray = &#91;&#34;genux&#34;,&#34;linux&#34;&#93;; &#160; var keyvaluearray = &#123;&#34;name&#34; : &#34;genux&#34;, &#34;OS&#34; : [...]]]></description>
			<content:encoded><![CDATA[<p>Someone asked me what is the difference between {} and [] within javascript.</p>
<p>Basically the difference is one is a key => value pair like PHP &#8216;{}&#8217;, and the other is just a pure array of values &#8216;[]&#8216;.</p>
<p>Here is the code.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">var simplearray <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;genux&quot;</span>,<span style="color: #0000ff;">&quot;linux&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
var keyvaluearray <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #0000ff;">&quot;name&quot;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;genux&quot;</span>, <span style="color: #0000ff;">&quot;OS&quot;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;linux&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div>

<p>To access the different values, since the simple array is index by numbers 0 onwards you use the [x] notation, and the key value array you can reference the value by the name of the key like in object orientated way.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">alert<span style="color: #009900;">&#40;</span>simplearray<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
alert<span style="color: #009900;">&#40;</span>keyvaluearray.<span style="color: #006633;">name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.codingfriends.com/index.php/2011/03/26/javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Delete object from array within javascript</title>
		<link>http://www.codingfriends.com/index.php/2011/01/12/delete-object-from-array-within-javascript/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=delete-object-from-array-within-javascript</link>
		<comments>http://www.codingfriends.com/index.php/2011/01/12/delete-object-from-array-within-javascript/#comments</comments>
		<pubDate>Wed, 12 Jan 2011 22:47:38 +0000</pubDate>
		<dc:creator>genux</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[delete from array]]></category>

		<guid isPermaLink="false">http://www.codingfriends.com/?p=1300</guid>
		<description><![CDATA[Someone asked me whilst doing a job how to delete parts of a array within javascript, so just like other object oriented languages, you can have a array of data objects and each one can be accessible and removable. To achieve this with javascript you use the delete method as below. var myArray = new [...]]]></description>
			<content:encoded><![CDATA[<p>Someone asked me whilst doing a job how to delete parts of a array within javascript, so just like other object oriented languages, you can have a array of data objects and each one can be accessible and removable.  To achieve this with javascript you use the delete method as below.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> myArray <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Array<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
myArray<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;first value&quot;</span><span style="color: #339933;">;</span>
myArray<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;second value&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// and to delete the second value</span>
<span style="color: #000066; font-weight: bold;">delete</span> myArray<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.codingfriends.com/index.php/2011/01/12/delete-object-from-array-within-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adding floats together with commas and decimal places</title>
		<link>http://www.codingfriends.com/index.php/2011/01/12/adding-floats-together-with-commas-and-decimal-places/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=adding-floats-together-with-commas-and-decimal-places</link>
		<comments>http://www.codingfriends.com/index.php/2011/01/12/adding-floats-together-with-commas-and-decimal-places/#comments</comments>
		<pubDate>Wed, 12 Jan 2011 22:40:38 +0000</pubDate>
		<dc:creator>genux</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[adding floating]]></category>
		<category><![CDATA[Question]]></category>

		<guid isPermaLink="false">http://www.codingfriends.com/?p=1297</guid>
		<description><![CDATA[Someone contacted me about adding some numbers together with comma&#8217;s and dots within there values, here is the email via the contact me page. &#8220;Please I need a javascript code that can enable me add two or more numbers containing dot(.) and/or comma (,) together. For example, 122.34 + 233.56. Or/And 233,239.34 + 323,322.44. Thanks [...]]]></description>
			<content:encoded><![CDATA[<p>Someone contacted me about adding some numbers together with comma&#8217;s and dots within there values, here is the email via the contact me page.</p>
<p>&#8220;Please I need a javascript code that can enable me add two or more numbers containing dot(.) and/or comma (,) together. For example, 122.34 + 233.56. Or/And 233,239.34 + 323,322.44. Thanks in advance.&#8221;</p>
<p>Here is the code that will accomplish the request.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>html<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span> <span style="color: #339933;">&gt;</span>
       <span style="color: #003366; font-weight: bold;">function</span> load<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
       <span style="color: #009900;">&#123;</span>
               <span style="color: #003366; font-weight: bold;">var</span> value1<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;233,122.34&quot;</span><span style="color: #339933;">;</span>
               <span style="color: #003366; font-weight: bold;">var</span> value2<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;233.56&quot;</span><span style="color: #339933;">;</span>
               <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>parseFloat<span style="color: #009900;">&#40;</span>value1.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;,&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span>parseFloat<span style="color: #009900;">&#40;</span>value2.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;,&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
       <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>body <span style="color: #000066;">onload</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;load()&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>body<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>html<span style="color: #339933;">&gt;</span></pre></div></div>

<p>The main part is the parseFloat and replacing the &#8220;,&#8221; with nothing &#8220;&#8221; to remove the none float characters via the object replace method.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codingfriends.com/index.php/2011/01/12/adding-floats-together-with-commas-and-decimal-places/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CKEditor &#8211; auto save</title>
		<link>http://www.codingfriends.com/index.php/2010/12/10/ckeditor-auto-save/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=ckeditor-auto-save</link>
		<comments>http://www.codingfriends.com/index.php/2010/12/10/ckeditor-auto-save/#comments</comments>
		<pubDate>Fri, 10 Dec 2010 22:08:46 +0000</pubDate>
		<dc:creator>genux</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[auto save]]></category>
		<category><![CDATA[CKEditor]]></category>

		<guid isPermaLink="false">http://www.codingfriends.com/?p=1191</guid>
		<description><![CDATA[A follow on from the previous post CKEditor custom dialog you can auto save the content with sending a AJAX call to another page that will save the content and also give back a updated time of that content saved. I created a function called autosave(), that will call itself every 20 seconds (20000 milliseconds). [...]]]></description>
			<content:encoded><![CDATA[<p>A follow on from the previous post <a href="http://www.codingfriends.com/index.php/2010/12/10/ckeditor-custom-dialog/">CKEditor custom dialog</a> you can auto save the content with sending a AJAX call to another page that will save the content and also give back a updated time of that content saved.</p>
<p>I created a function called autosave(), that will call itself every 20 seconds (20000 milliseconds).  This will get the data (getData()) from the CKEditor instance called content and then go some JQuery to do the actual AJAX function which in-turn calls the url autosave.php (can be any backend page that will deal with saving the data) and once the backend page has completed then update the HTML element with the ID of lastsavetime to the new time that is returned from the webpage.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> autosave<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
   <span style="color: #003366; font-weight: bold;">var</span> t <span style="color: #339933;">=</span> setTimeout<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;autosave()&quot;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">20000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #003366; font-weight: bold;">var</span> content <span style="color: #339933;">=</span> escape<span style="color: #009900;">&#40;</span>CKEDITOR.<span style="color: #660066;">instances</span>.<span style="color: #660066;">content</span>.<span style="color: #660066;">getData</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>content.<span style="color: #660066;">length</span> <span style="color: #339933;">&gt;</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span>
   <span style="color: #009900;">&#123;</span>
       $.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span>
       <span style="color: #009900;">&#123;</span>
           type<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;POST&quot;</span><span style="color: #339933;">,</span>
           url<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;autosave.php?method=saveCKEditor&quot;</span><span style="color: #339933;">,</span>
           data <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;content=&quot;</span><span style="color: #339933;">+</span>content<span style="color: #339933;">,</span>
           cache<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">,</span>
           success<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>message<span style="color: #009900;">&#41;</span>
           <span style="color: #009900;">&#123;</span>
               $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#lastsavetime&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Last saved : &quot;</span><span style="color: #339933;">+</span>message<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
           <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</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;">&#125;</span>
$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    autosave<span style="color: #009900;">&#40;</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> <span style="color: #3366CC;">&quot;;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.codingfriends.com/index.php/2010/12/10/ckeditor-auto-save/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>CKEditor &#8211; custom dialog</title>
		<link>http://www.codingfriends.com/index.php/2010/12/10/ckeditor-custom-dialog/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=ckeditor-custom-dialog</link>
		<comments>http://www.codingfriends.com/index.php/2010/12/10/ckeditor-custom-dialog/#comments</comments>
		<pubDate>Fri, 10 Dec 2010 21:58:37 +0000</pubDate>
		<dc:creator>genux</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[CKEditor]]></category>
		<category><![CDATA[Custom]]></category>
		<category><![CDATA[dialog]]></category>

		<guid isPermaLink="false">http://www.codingfriends.com/?p=1189</guid>
		<description><![CDATA[The CKEditor is a great WYSIWYG and the best thing is that you are able to customize the interface to have buttons on the toolbars, here is a way that I created a custom button with custom image attached to it. The editor is created with var editor = CKEDITOR.replace&#40; 'Content'&#41;; So from now on [...]]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://ckeditor.com">CKEditor</a> is a great WYSIWYG and the best thing is that you are able to customize the interface to have buttons on the toolbars, here is a way that I created a custom button with custom image attached to it.</p>
<p>The editor is created with</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">var editor <span style="color: #339933;">=</span> CKEDITOR.<span style="color: #006633;">replace</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'Content'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>So from now on in the variable editor is linked to the CKEditor instance, to setup the plugins to load when the CKEditor is created you call the pluginsLoaded function</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"> editor.<span style="color: #660066;">on</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'pluginsLoaded'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span> ev <span style="color: #009900;">&#41;</span>
         <span style="color: #009900;">&#123;</span>
           <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span>CKEDITOR.<span style="color: #660066;">dialog</span>.<span style="color: #660066;">exists</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'statisticsDialog'</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
                 CKEDITOR.<span style="color: #660066;">dialog</span>.<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'statisticsDialog'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'/statistics.js'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
           <span style="color: #006600; font-style: italic;">// Register the command used to open the dialog.</span>
           editor.<span style="color: #660066;">addCommand</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'statisticsAddCmd'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">new</span> CKEDITOR.<span style="color: #660066;">dialogCommand</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'statisticsDialog'</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
           editor.<span style="color: #660066;">ui</span>.<span style="color: #660066;">addButton</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'Statistics'</span><span style="color: #339933;">,</span>
                    <span style="color: #009900;">&#123;</span>
                        label <span style="color: #339933;">:</span> <span style="color: #3366CC;">'Statistic'</span><span style="color: #339933;">,</span>
                        command <span style="color: #339933;">:</span> <span style="color: #3366CC;">'statisticsAddCmd'</span><span style="color: #339933;">,</span>
                        icon <span style="color: #339933;">:</span> <span style="color: #3366CC;">'/statistics_small.png'</span><span style="color: #339933;">,</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 first part will check to make sure that there is not dialog already created with the same name, and if not then load the javascript file that is the custom built dialog. The second part is adding the command (the button clicked) to be linked to the custom dialog, and the third part is to add the actual button to the user interface (editor.ui).  The addButton function links to the command to bring up the custom dialog.</p>
<p>Here is the custom dialog code that will be called when the user interface button is clicked.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">CKEDITOR.<span style="color: #660066;">dialog</span>.<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'statisticsDialog'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span> editor <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
      <span style="color: #006600; font-style: italic;">// Load data asynchronously.</span>
       <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #009900;">&#123;</span>
               title <span style="color: #339933;">:</span> <span style="color: #3366CC;">'Pick a statistic'</span><span style="color: #339933;">,</span>
               minWidth <span style="color: #339933;">:</span> <span style="color: #CC0000;">400</span><span style="color: #339933;">,</span>
               minHeight <span style="color: #339933;">:</span> <span style="color: #CC0000;">200</span><span style="color: #339933;">,</span>
               onOk <span style="color: #339933;">:</span> insertOntoEditor<span style="color: #339933;">,</span>
               contents <span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span>
                       <span style="color: #009900;">&#123;</span>
                               id <span style="color: #339933;">:</span> <span style="color: #3366CC;">'tab1'</span><span style="color: #339933;">,</span>
                               label <span style="color: #339933;">:</span> <span style="color: #3366CC;">'First Tab'</span><span style="color: #339933;">,</span>
                               title <span style="color: #339933;">:</span> <span style="color: #3366CC;">'First Tab'</span><span style="color: #339933;">,</span>
                               elements <span style="color: #339933;">:</span><span style="color: #009900;">&#91;</span>
                                       <span style="color: #009900;">&#123;</span>  id <span style="color: #339933;">:</span> <span style="color: #3366CC;">'graphselect'</span><span style="color: #339933;">,</span>
                                               type <span style="color: #339933;">:</span> <span style="color: #3366CC;">'select'</span><span style="color: #339933;">,</span>
                                               items <span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span> <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;option1&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;link to image&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#93;</span> <span style="color: #339933;">,</span>
                               <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#93;</span>
                       <span style="color: #009900;">&#125;</span>
               <span style="color: #009900;">&#93;</span>
       <span style="color: #009900;">&#125;</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 dialog, will load up a screen and have a one drop down box that will allow the user to choose from the options (will you need to insert more options, or dynamic created options if you wanted to) and once the OK button is clicked (onOK) it will call this function below</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> insertOntoEditor<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
       elem <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">getContentElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'tab1'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'graphselect'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
       value <span style="color: #339933;">=</span> elem.<span style="color: #660066;">getValue</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
       <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>value <span style="color: #339933;">!=</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span>
       <span style="color: #009900;">&#123;</span>
               <span style="color: #003366; font-weight: bold;">var</span> writer <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> CKEDITOR.<span style="color: #660066;">htmlWriter</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
               <span style="color: #003366; font-weight: bold;">var</span> fragment <span style="color: #339933;">=</span> CKEDITOR.<span style="color: #660066;">htmlParser</span>.<span style="color: #660066;">fragment</span>.<span style="color: #660066;">fromHtml</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'&lt;img src=&quot;http://'</span><span style="color: #339933;">+</span>document.<span style="color: #660066;">domain</span><span style="color: #339933;">+</span>elem.<span style="color: #660066;">getValue</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">'&quot;/&gt;'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
               fragment.<span style="color: #660066;">writeHtml</span><span style="color: #009900;">&#40;</span> writer <span style="color: #009900;">&#41;</span>
&nbsp;
               <span style="color: #006600; font-style: italic;">// need to wrap up the graph image insertion into the ckeditor</span>
               CKEDITOR.<span style="color: #660066;">instances</span>.<span style="color: #660066;">Content</span>.<span style="color: #660066;">insertHtml</span><span style="color: #009900;">&#40;</span>writer.<span style="color: #660066;">getHtml</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
       <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This will basically insert some code into the CKEditor from the drop down box, the &#8220;link to image&#8221; you will need to insert a link for the insertion.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codingfriends.com/index.php/2010/12/10/ckeditor-custom-dialog/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>CKEditor &#8211; Custom upload dialog</title>
		<link>http://www.codingfriends.com/index.php/2010/12/10/ckeditor-custom-upload-dialo/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=ckeditor-custom-upload-dialo</link>
		<comments>http://www.codingfriends.com/index.php/2010/12/10/ckeditor-custom-upload-dialo/#comments</comments>
		<pubDate>Fri, 10 Dec 2010 21:39:13 +0000</pubDate>
		<dc:creator>genux</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[CKEditor]]></category>
		<category><![CDATA[Custom]]></category>
		<category><![CDATA[dialog]]></category>
		<category><![CDATA[upload]]></category>

		<guid isPermaLink="false">http://www.codingfriends.com/?p=1187</guid>
		<description><![CDATA[The great WYSIWYG editor called CKEditor allows you to do a custom file upload, so that you can handle where the file is stored and also you can do your database extra inserts for example. To start with you have to tell the CKEditor where to post the file uploaded to custom built page var [...]]]></description>
			<content:encoded><![CDATA[<p>The great WYSIWYG editor called <a href="http://ckeditor.com/">CKEditor</a> allows you to do a custom file upload, so that you can handle where the file is stored and also you can do your database extra inserts for example.</p>
<p>To start with you have to tell the CKEditor where to post the file uploaded to custom built page</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;">var editor = CKEDITOR.replace( 'Content',{ filebrowserUploadUrl :'/custom.imageuploader.php'});</pre></div></div>

<p>Where the custom.imageuploader.php is the actual php page that will deal with the custom page, can be done in any other language if required.  In the above code, the &#8216;Content&#8217; is the textarea to change to a CKEditor WYSIWYG.</p>
<p>Here is a basic php page that you will need to alter to store the $_FILES["upload"] into the place where you want to store and do any database code to link to the resource that you are uploading, but the bit underneath that you need to have, this will tell the CKEditor what to do after your PHP code has stored the file, the CKEditoFuncName, is required (but passed in) to tell the CKEditor what function to call after the upload has happened, the $wherestorage, is where the actual file is so that the WYSIWYG can show the image and any $message that may help the CKEditor user for any error reports.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">// the files are stored within the upload part of the $_FILES </span>
<span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;upload&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;html&gt;
&lt;body&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
window.parent.CKEDITOR.tools.callFunction(
   <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;CKEditorFuncNum&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;,<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$wherestorage</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>,<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$message</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>
);
&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;
?&gt;</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.codingfriends.com/index.php/2010/12/10/ckeditor-custom-upload-dialo/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

