FCK Editor JavaScript Help

  • MasterZ
  • Expert
  • Expert
  • User avatar
  • Posts: 699
  • Loc: Colorado Springs

Post 3+ Months Ago

Hey guys,

I wouldn't normally ask this but I'm down to my last week on a project and I have one last thing to do, other than bug fixes.. It deals with JavaScript and, sadly, I don't have a lot of experience with that.

I'm working on trying to do this but help would be greatly appreciated. I'm using the FCKEditor (a WYSIWYG editor). I need to insert a pre-formatted link into the box. I found all of the JavaScript functions that need to be run but I can't figure out how to put it all together.

I need
* links that when clicked will run a javascript function
* The function needs to run the command: oEditor.InsertHtml(HTML); and var oEditor = FCKeditorAPI.GetInstance('InstanceName') ;
* Information on the function is here: http://docs.fckeditor.net/FCKeditor_2.x ... ge_Samples
* Lastly, each link inserts different HTML.

If you guys could help me out in any way at all, I would really be grateful.
  • kitcorsa
  • Graduate
  • Graduate
  • kitcorsa
  • Posts: 132

Post 3+ Months Ago

there are full installation instruction for fck editor with the download.

its simple, i never used it before but had it fully running in about 15 mins after reading the instructions.

on you admin/edit page have the following at the top in the java section

Code: [ Select ]
    <script type="text/javascript" src="fckeditor/fckeditor.js"></script>

    <script type="text/javascript">
    window.onload = function()
    {
    var oFCKeditor = new FCKeditor( 'MyTextarea' ) ;
    oFCKeditor.BasePath = "fckeditor/" ;
    oFCKeditor.Height = 600;
    oFCKeditor.ReplaceTextarea() ;
    }
</script>
  1.     <script type="text/javascript" src="fckeditor/fckeditor.js"></script>
  2.     <script type="text/javascript">
  3.     window.onload = function()
  4.     {
  5.     var oFCKeditor = new FCKeditor( 'MyTextarea' ) ;
  6.     oFCKeditor.BasePath = "fckeditor/" ;
  7.     oFCKeditor.Height = 600;
  8.     oFCKeditor.ReplaceTextarea() ;
  9.     }
  10. </script>


obviously change the path to you FCK editor folder and script

Then in the body have the following

Code: [ Select ]
    <?php include_once("fckeditor/fckeditor.php") ; ?>


again change the path to your own

then where you want the editor to appear have the following.

Code: [ Select ]
        <textarea id="MyTextarea" name="content" >
        <? $fn = $_GET['p']; print htmlspecialchars(implode("",file($fn))); ?>
        </textarea><br>
        <input type="submit" value="Change!">
  1.         <textarea id="MyTextarea" name="content" >
  2.         <? $fn = $_GET['p']; print htmlspecialchars(implode("",file($fn))); ?>
  3.         </textarea><br>
  4.         <input type="submit" value="Change!">


P being the information you want to edit ie info from database or txt/php file etc
  • MasterZ
  • Expert
  • Expert
  • User avatar
  • Posts: 699
  • Loc: Colorado Springs

Post 3+ Months Ago

Sorry for any confusion,

I have the editor itself working fine, I just need to make another link on the website that when clicked will insert a bit of html into the editor.
  • kitcorsa
  • Graduate
  • Graduate
  • kitcorsa
  • Posts: 132

Post 3+ Months Ago

oh right, then you need to change this section of the code where the FCK editor is.

Code: [ Select ]
<textarea id="MyTextarea" name="content" >
<? $fn = $_GET['p']; print htmlspecialchars(implode("",file($fn))); ?>
</textarea><br>
<input type="submit" value="Change!">
  1. <textarea id="MyTextarea" name="content" >
  2. <? $fn = $_GET['p']; print htmlspecialchars(implode("",file($fn))); ?>
  3. </textarea><br>
  4. <input type="submit" value="Change!">


where is says $fn = $_get['p'] the P is the html you want to change. so you could put $fn = './text/text.txt' or you can change P to comething like $fn = $_get['usertext'] and define the usertext in the URL or somewhere on the page.
  • MasterZ
  • Expert
  • Expert
  • User avatar
  • Posts: 699
  • Loc: Colorado Springs

Post 3+ Months Ago

oEditor.InsertHtml(HTML) is a function that will insert a certain HTML statement into the editor, so I need a link that when clicked will call that function with an HTML statement assigned to that link, not reload the entire page.

What I'm trying to do is on the website that displays the fckeditor box, I'm trying to list all the documents that were uploaded on another page, and when you click on the document name it inserts an html link into the fckeditor that points to that document.
  • kitcorsa
  • Graduate
  • Graduate
  • kitcorsa
  • Posts: 132

Post 3+ Months Ago

you trying to eddit a hlml file or a txt file or an inc file??
  • MasterZ
  • Expert
  • Expert
  • User avatar
  • Posts: 699
  • Loc: Colorado Springs

Post 3+ Months Ago

I'm trying to figure out how to have a link use this command: oEditor.InsertHtml(HTML); as outlined in this page: http://docs.fckeditor.net/FCKeditor_2.x ... ge_Samples

# InsertHtml( html ) - inserts HTML in the current cursor position in the WYSIWYG editor textarea box.

I think just using an 'onClick' command for the link will do it but I will not get a chance to try it out until tonight.
  • MasterZ
  • Expert
  • Expert
  • User avatar
  • Posts: 699
  • Loc: Colorado Springs

Post 3+ Months Ago

I have been trying to get this to work but I just can't :(

here is the code I am trying:

Code: [ Select ]
    <script language="JavaScript">
        var oEditor = FCKeditorAPI.GetInstance('PageText') ;
    </script>
    
    <button onclick="oEditor.InsertHtml(<b>test</b>);">TEST</button>
  1.     <script language="JavaScript">
  2.         var oEditor = FCKeditorAPI.GetInstance('PageText') ;
  3.     </script>
  4.     
  5.     <button onclick="oEditor.InsertHtml(<b>test</b>);">TEST</button>


any ideas? please, my time on this project is running really short!!!!
  • jalil
  • Born
  • Born
  • jalil
  • Posts: 1

Post 3+ Months Ago

hello, just arrived at this forum.

you may wish to try

<button onclick="oEditor.InsertHtml('<b>test</b>');">TEST</button>

the quotes are needed;

Post Information

  • Total Posts in this topic: 9 posts
  • Users browsing this forum: No registered users and 100 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.