2009-03-17 6 views
4

J'ai un site qui utilise le FCKEditor. Je voudrais faire un plugin incroyablement simple: lorsqu'un utilisateur sélectionne du texte puis frappe MyPluginIcon, l'éditeur entoure le texte dans une balise span avec une classe spécifique.FCKEditor - comment créer un plugin simple?

Il est donc tout comme le bouton Gras ou italique, mais pour:

<span class="blah">EtcEtc</span>

Je suis loin d'être un expert JS, donc je cherche un plugin pour copier. J'ai regardé dans le wiki de FCK mais tous les plugins que j'ai trouvés sont vraiment complexes (les navigateurs de fichiers et autres joyeusetés). Connaissez-vous un super simple plugin FCK Je peux baser mon plugin sur?

Merci!

Répondre

5

Répondre à ma propre question! J'espère que si quelqu'un trouve cela dans le futur, cela aidera.

J'ai utilisé le fichier de base d'ici: http://www.iondev.lu/fckeditor/netnoi.txt

J'ai trouvé et-remplacé le « netnoi » avec mon propre nom, et décommenté la ligne d'icône pour faire apparaître une icône (16x16).

Et les instructions sur la façon de l'installer à partir d'ici: http://docs.fckeditor.net/FCKeditor_2.x/Developers_Guide/Customization/Plug-ins

Assurez-vous de vérifier que le répertoire plugins est correct - dans le dossier drupal plugins est différent d'un défaut FCK installer.

EDIT: Apparemment, le fichier netnoi.txt a disparu. Voici ce que j'ai utilisé:

/*** 
* Create blank command 
*/ 
var FCKPixelCaps_command = function() 
{ 

} 

/*** 
* Add Execute prototype 
*/ 
FCKPixelCaps_command.prototype.Execute = function() 
{ 
     // get whatever is selected in the FCKeditor window 
     var selection = FCK.EditorDocument.getSelection(); 

     // if there is a selection, add tags around it 
     if(selection.length > 0) 
     { 
       FCK.InsertHtml('<span class="caps">' + selection + '</span>'); 
     } else { 
       // for debugging reasons, I added this alert so I see if nothing is selected 
       alert('nothing selected'); 
     } 
} 

/*** 
* Add GetState prototype 
* - This is one of the lines I can't explain 
*/ 
FCKPixelCaps_command.prototype.GetState = function() 
{ 
     return; 
} 

// register the command so it can be use by a button later 
FCKCommands.RegisterCommand('PixelCaps_command' , new FCKPixelCaps_command()) ; 

/*** 
* Create the toolbar button. 
*/ 

// create a button with the label "Netnoi" that calls the netnoi_command 
var oPixelCaps = new FCKToolbarButton('PixelCaps_command', 'Pixels & Pulp Caps') ; 
oPixelCaps.IconPath = FCKConfig.PluginsPath + 'PixelCaps/caps.gif' ; 

// register the item so it can added to a toolbar 
FCKToolbarItems.RegisterItem('PixelCaps', oPixelCaps) ; 
+0

Heureux que vous l'avez résolu vous-même! – Ascalonian

Questions connexes