SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Wizard tgavin's Avatar
    Join Date
    Feb 2003
    Location
    FL
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Integrating fckeditor into existing function

    I'm having some difficulty getting this to work and have no idea why. perhaps somebody else can see something?

    Code JavaScript:
    function add() {
        var parent = document.getElementById('parent');
     
        /* creating new article div */
        var article = document.createElement('DIV');
        var inntertext = "";
     
        /* setting new div id and name attributes */
        article.id = 'article' + elCount;
        article.name = 'article' + elCount;
     
        // FCKeditor
        $oFCKeditor = new FCKeditor(article' + elCount + ');
        $oFCKeditor->BasePath = '<?php echo SITE_URL ?>/includes/classes/fckeditor/';
        $oFCKeditor->Config['ToolbarStartExpanded'] = false ;
        $oFCKeditor->Create();
     
        /* preparing new article form */
        inntertext += '<div class="outer">';
        inntertext += '<textarea name="text' + elCount + '"></textarea>';
        inntertext += '</div>';
     
        /* setting innerHTML of new div */
        article.innerHTML = inntertext;
     
        /* appending the new div to parent */
        parent.appendChild(article);
        elCount++;
    }

    Whenever I click the link that calls the add() function, it just doesn't work. However, if I take out the fck bit it works just fine. I have another textarea on the page that uses fck and it works. The problem is only within this function.

  2. #2
    SitePoint Enthusiast Mr Moo's Avatar
    Join Date
    Oct 2007
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You have mixed JavaScript code with PHP style:

    Code JavaScript:
        // FCKeditor
        var oFCKeditor = new FCKeditor(article' + elCount + ');
        oFCKeditor.BasePath = '<?php echo SITE_URL ?>/includes/classes/fckeditor/';
        oFCKeditor.Config['ToolbarStartExpanded'] = false ;
        oFCKeditor.Create();
    Not one shred of evidence supports the notion that life is serious.
    eternal.co.za - code, thoughts, rants and raves
    f1rivals.net - formula 1 forums, and, hopefully, soon, prediction game

  3. #3
    SitePoint Wizard tgavin's Avatar
    Join Date
    Feb 2003
    Location
    FL
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the response. Sorry for the delay, I was sick for 2 weeks.

    I went back and made some changes and got the FCK editor to work - somewhat.
    It now shows up, but completely overwrites the entire output. Without the fck editor, it works perfectly. With the editor, it's now only the editor and nothing else.

    I need to be able to get the two to play nice. I just don't know enough js to do it.

    Code JavaScript:
    <script type="text/javascript">
    	// <![CDATA[
     
    	var elCount = 1;
     
    	function add() {
    		var parent = document.getElementById('parent');
    		var div = document.getElementById('article');
     
    		/* creating new article div */
    		var article = document.createElement('DIV');
    		var inntertext = "";
     
    		/* setting new div id and name attributes */
    		article.id = 'article' + elCount;
    		article.name = 'article' + elCount;
    /* PROBLEM */		
    		var fck = new FCKeditor('article');
    		fck.BasePath = "<?php echo SITE_URL ?>/admin/includes/classes/fckeditor/";
     
    		/* preparing new article form */
    		inntertext += '<div class="outer">';
    		inntertext += 'Text:';
    		inntertext += '<textarea name="art_txt[' + elCount + ']"></textarea>';;
    		inntertext += '</div>';
     
    		/* setting innerHTML of new div */
    		article.innerHTML = inntertext;
    /* PROBLEM */
    		article.innerHTML = fck.CreateHtml();
     
    		/* appending the new div to parent */
    		parent.appendChild(article);
    		elCount++;
    	}
    	// ]]>
    </script>

  4. #4
    SitePoint Enthusiast Mr Moo's Avatar
    Join Date
    Oct 2007
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not sure what the problem is at your first /* PROBLEM */ but at the second one:
    Code JavaScript:
            /* setting innerHTML of new div */
            article.innerHTML = inntertext;
    /* PROBLEM */
            article.innerHTML += fck.CreateHtml();
    just add the plus :-)
    Not one shred of evidence supports the notion that life is serious.
    eternal.co.za - code, thoughts, rants and raves
    f1rivals.net - formula 1 forums, and, hopefully, soon, prediction game

  5. #5
    SitePoint Wizard tgavin's Avatar
    Join Date
    Feb 2003
    Location
    FL
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Mr Moo View Post
    I'm not sure what the problem is at your first /* PROBLEM */ but at the second one:
    Code JavaScript:
            /* setting innerHTML of new div */
            article.innerHTML = inntertext;
    /* PROBLEM */
            article.innerHTML += fck.CreateHtml();
    just add the plus :-)
    Thank you. Almost got it.
    Now what happens is the fck textarea appears *below* the article 3 textarea, instead of replacing it.

  6. #6
    SitePoint Enthusiast Mr Moo's Avatar
    Join Date
    Oct 2007
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, by calling CreateHtml() you're asking it to create itself, not replace text areas. I'm not sure what the call is to replace text areas, but I'm sure if you look at the docs you'll find it.

    Actually, here's the link to the specific page you'll need, I think.
    Not one shred of evidence supports the notion that life is serious.
    eternal.co.za - code, thoughts, rants and raves
    f1rivals.net - formula 1 forums, and, hopefully, soon, prediction game

  7. #7
    SitePoint Wizard tgavin's Avatar
    Join Date
    Feb 2003
    Location
    FL
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Mr Moo View Post
    Well, by calling CreateHtml() you're asking it to create itself, not replace text areas. I'm not sure what the call is to replace text areas, but I'm sure if you look at the docs you'll find it.

    Actually, here's the link to the specific page you'll need, I think.
    Yep. That's where I got the code. Method 3 is the ajax method that the dev recommended. However, it's looking like that's not what I want. Will the other methods work in my script? I don't think window.onload will work for me since this is ajax.

  8. #8
    SitePoint Wizard tgavin's Avatar
    Join Date
    Feb 2003
    Location
    FL
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK. So I changed the code to this
    Code JavaScript:
    article.textarea = 'art_txt['+ elCount +']';
    var fck = new FCKeditor(article.textarea);
    fck.BasePath = "<?php echo SITE_URL ?>/admin/includes/classes/fckeditor/";
    fck.ReplaceTextarea();
    removed the createHTML(); line and added an id to the textarea.

    Now I get an error/alert telling me that the textarea can't be found.
    I'm not sure if I'm on the right path...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •