<?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>Amicalement Web - Astuces et Bons plans dans le développement web &#187; fckeditor</title>
	<atom:link href="http://www.amicalement-web.net/tag/fckeditor/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.amicalement-web.net</link>
	<description>Astuces et bons plans d&#039;un web developpeur</description>
	<lastBuildDate>Mon, 30 Aug 2010 12:50:11 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to: Créer un plugin fckeditor</title>
		<link>http://www.amicalement-web.net/how-to-creer-un-plugin-fckeditor/2009/07/23/</link>
		<comments>http://www.amicalement-web.net/how-to-creer-un-plugin-fckeditor/2009/07/23/#comments</comments>
		<pubDate>Thu, 23 Jul 2009 12:00:22 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[fckeditor]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://www.amicalement-web.net/?p=458</guid>
		<description><![CDATA[ Dans le monde du développement web, il y a un domaine où je n&#8217;ai pas encore trouvé une recette miracle: La publication de contenu avec un éditeur WYSIWYG. En même temps, la problématique est costaud, faire éditer du HTML à des gens qui ont déjà du mal avec Word, sans qu&#8217;ils sachent qu&#8217;ils éditent [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.amicalement-web.net/wp-content/uploads/applications-system.png" alt="applications-system" title="applications-system" width="48" height="48" class="alignleft size-full wp-image-31" /> Dans le monde du développement web, il y a un domaine où je n&#8217;ai pas encore trouvé une recette miracle: La publication de contenu avec un éditeur <acronym title="What You See Is What You Get">WYSIWYG</acronym>. En même temps, la problématique est costaud, faire éditer du HTML à des gens qui ont déjà du mal avec Word, sans qu&#8217;ils sachent qu&#8217;ils éditent du HTML.</p>
<p>Après avoir définitivement abandonné <a  href="http://tinymce.moxiecode.com/" class="extern">TinyMCE</a>, car trop usine à gaz et n&#8217;en faisant qu&#8217;à sa tête, j&#8217;ai essayé <a  href="http://nicedit.com/" class="extern">nicedit</a> comme je vous l&#8217;avais signalé dans <a  href="/developpement-web-les-bons-plans-de-la-semaine-3/2009/06/19/">un bon plan de la semaine</a>. Malheureusement, il reste un peu juste pour certains besoins.<br />
Sur les conseils de <a  href="http://blog.samuel-trocme.fr/12-07-2009/fckeditor-peut-etre-le-meilleur-rte.html" class="extern">Sam</a>, je me suis donc relancé dans une vieille connaissance, <a  href="http://www.fckeditor.net/" class="extern">FCKEditor</a>, un des plus vieux <acronym title="Rich Text Editor">RTE</acronym> avec TinyMCE.<br />
<span id="more-458"></span><br />
S&#8217;il est a noté de nets progrès, il fait encore un peu usine à gaz (mais moins que TinyMCE quand même) et je le trouve particulièrement moche, mais c&#8217;est un détail qui peut se modifier, donc on va le mettre de côté pour l&#8217;instant ;)</p>
<p>Un des impératifs par contre, c&#8217;est la personnalisation et donc la création de plugin permettant de rajouter des boutons avec des fonctionnalités que l&#8217;on aura déterminer nous même. Et vu les difficultés que j&#8217;ai pu rencontrer pour créer mon premier, je me suis dis que ca valait bien quelques explications. Dans un souci de clarté, je ne détaillerai pas l&#8217;installation de fck, je vous invite à faire un tour sur leur site pour ça.</p>
<p>Première chose quand on veut créer un plugin fck, créer son arborescence, dans <code>editor/plugins</code>. Ici, on va créer un plugin qui nous permettra de rajouter un bouton à notre toolbar qui lancera une fenêtre nous permettant de faire un peu ce qu&#8217;on veut, en l&#8217;occurrence dans notre cas, afficher une liste des pages de notre gestionnaire de contenus symfony afin de pouvoir insérer des liens internes entre elle.  </p>
<p>Dans notre nouveau dossier, vous créez donc un fichier plugin.js avec à l&#8217;intérieur:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// Ici je crée une action FCK qui s'appelle Internlink, et qui chargera le fichier test.html (qui sera au même niveau que ce fichier) lors de son appel</span>
FCKCommands.<span style="color: #660066;">RegisterCommand</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Internlink'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">new</span> FCKDialogCommand<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Internlink'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'Ajout lien interne'</span><span style="color: #339933;">,</span>FCKConfig.<span style="color: #660066;">PluginsPath</span><span style="color: #339933;">+</span><span style="color: #3366CC;">'internlink/test.html'</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">300</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">300</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// Ici je crée un bouton pour la toolbar auquel j'associe l'action précédemment définie</span>
FCKToolbarItems.<span style="color: #660066;">RegisterItem</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'Internlink'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">new</span> FCKToolbarButton<span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'Internlink'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'Lien interne'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">,</span> FCK_TOOLBARITEM_ICONTEXT<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">1</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">;</span></pre></div></div>

<p>Ensuite on enchaine avec le template de notre popup qu&#8217;on a appelé test.html plus haut (on le met bien où on veut mais j&#8217;ai définis au-dessus de le mettre au même niveau):</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #00bbdd;">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot; &quot;http://www.w3.org/TR/html4/loose.dtd&quot;&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;html<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;head<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;meta</span> <span style="color: #000066;">http-equiv</span>=<span style="color: #ff0000;">&quot;Content-Type&quot;</span> <span style="color: #000066;">content</span>=<span style="color: #ff0000;">&quot;text/html; charset=UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;script</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;script</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    // Cette partie est nécessaire pour pouvoir utiliser les fonctions de fck à l'intérieur de notre popup 
    var oEditor = window.parent.InnerDialogLoaded();
    var FCKConfig = oEditor.FCKConfig;
    var dialog = window.parent;
    document.write('<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;script</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;' + FCKConfig.BasePath + 'dialog/common/fck_dialog_common.js&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>&lt;\/script<span style="color: #000000; font-weight: bold;">&gt;</span></span>');
    dialog.SetOkButton(true); // Par défaut, seul le bouton annuler est affiché, on rajoute le bouton ok	
&nbsp;
    // Maintenant on fait bien ce qu'on veux, ici j'ai décidé de récupérer en AJAX, une liste en JSON de toutes mes pages et d'alimenter ma selectbox avec
    jQuery(document).ready(function(){
      $.getJSON(&quot;/content/selectJson&quot;,{}, function(j){
        var options = '';
        for (var i = 0; i <span style="color: #009900;">&lt; j.length; i++<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></span>
<span style="color: #009900;">          options += <span style="color: #ff0000;">'&lt;option value=&quot;'</span> + j<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.optionValue + <span style="color: #ff0000;">'&quot;&gt;</span></span>' + j[i].optionDisplay + '<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/option<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>';
        }
        $(&quot;select#intern-link&quot;).html(options);
      })
    });
&nbsp;
    // Puis on surdéfinit une fonction Ok qui est appelé par fck quand on appuye sur le bouton ... ok
    function Ok()
    {
      // Maintenant on utilise fck pour rajouter du contenu à notre RTE. Ici je rajoute simplement les valeurs de mes 2 champs définis dans mon HTML ci-dessous
      oEditor.FCK.InsertHtml( '<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;a</span> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;'+ jQuery('#intern-link').val() +'&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;extern&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>'+ jQuery('#intern-label').val() +'<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/a<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>' );
      return true; // Il faut renvoyer true pour fermer la popup
    }
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/head<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;add-intern-link&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>		
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;label</span> <span style="color: #000066;">for</span>=<span style="color: #ff0000;">&quot;intern-link&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Lien interne<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;select</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;intern-link&quot;</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;intern-link&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/select<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>						
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;label</span> <span style="color: #000066;">for</span>=<span style="color: #ff0000;">&quot;intern-label&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Label<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;input</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;intern-label&quot;</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;intern-label&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>						
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/html<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Il ne reste plus qu&#8217;à charger notre plugin dans notre conf:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">FCKConfig.<span style="color: #660066;">Plugins</span>.<span style="color: #660066;">Add</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'internlink'</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">;</span></pre></div></div>

<p>et ajouter le bouton à notre toolbar comme par exemple:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">FCKConfig.<span style="color: #660066;">ToolbarSets</span><span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;nice&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'Internlink'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></pre></div></div>

<p> et on obtient:<br />
<a  href="http://www.amicalement-web.net/wp-content/uploads/Image-67.png"><img src="http://www.amicalement-web.net/wp-content/uploads/Image-67-300x37.png" alt="Image 67" title="Image 67" width="300" height="37" class="alignnone size-medium wp-image-461" /></a></p>
<p><a  href="http://www.amicalement-web.net/wp-content/uploads/Image-68.png"><img src="http://www.amicalement-web.net/wp-content/uploads/Image-68.png" alt="Image 68" title="Image 68" width="287" height="298" class="alignnone size-full wp-image-460" /></a></p>
<p>On a maintenant accès à toutes nos pages, et un clic sur ok, nous rajoutera un lien dans notre contenu avec le label renseigné. </p>
<p>Il ne reste plus qu&#8217;à adapter à vos besoins ces petits bouts de codes!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.amicalement-web.net/how-to-creer-un-plugin-fckeditor/2009/07/23/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
