Results 1 to 2 of 2

Thread: TinyMCE Can't load to dynamic ajax content..

  1. #1
    Join Date
    Jan 2010
    Posts
    8
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default TinyMCE Can't load to dynamic ajax content..

    Why TinyMCE can't load to article1.html ?


    index.html
    Code:
    <head>
    <script type="text/javascript" src="js/tw-sack.js"></script> 
    <script type="text/javascript">
    var ajax = new sack();
    var articleListObj;
    var activeArticle = false;
    var clickedArticle = false;
    var contentObj	// Reference to article content <div>
    
    function mouseoverArticle()	{
    	if(this==clickedArticle)return;
    	if(activeArticle && activeArticle!=this){
    		if(activeArticle==clickedArticle)
    			activeArticle.className='articleClick';
    		else
    			activeArticle.className='';
    		
    	}
    	this.className='articleMouseOver';
    	activeArticle = this;	// Storing reference to this article
    }
    
    function showContent(){
    	contentObj.innerHTML = ajax.response;	// ajax.response is a variable that contains the content of the external file	
    }
    function showWaitMessage(){
    	contentObj.innerHTML = 'Finding article.....<br>Please wait';
    }
    function getAjaxFile(fileName){
    	ajax.requestFile = fileName;	
    	ajax.onCompletion = showContent;	
    	ajax.onLoading = showWaitMessage;	
    	ajax.runAJAX();			
    }
    function selectArticle(){
    	getAjaxFile(this.id + '.html');	
    	if(clickedArticle && clickedArticle!=this)clickedArticle.className='articleMouseOver';
    	this.className='articleClick';
    	clickedArticle = this;
    }
    function initAjaxDemo(){
    	articleListObj = document.getElementById('articleList');
    	var articles = articleListObj.getElementsByTagName('LI');
    	for(var no=0;no<articles.length;no++){
    		articles[no].onmouseover = mouseoverArticle;
    		articles[no].onclick = selectArticle;
    	}	
    	
    	contentObj = document.getElementById('contentContainer');
    }
    window.onload = initAjaxDemo;
    </script>
    
    <script type="text/javascript" src="tiny_mce/tiny_mce.js"></script> </script> 
    
    <script type="text/javascript"> 
    tinyMCE.init({ 
    mode : "exact", 
    theme : "simple", 
    elements : "elm1" 
    
    }); 
    </script>
    
    </head> 
    
    <body> 
    
    <div id="mainContainer">
    	<div id="contentContainer">
    		<h2 class="openingText">Click on one of the articles to the right.</h2>
    		<p>This will load the the content of external articles into this DIV</p>
    	</div>
    	<div id="articleListContainer">
    		<ul id="articleList" class="articleList">
    			<li id="article1">Textarea with TinyMCE</li> <!-- go to article1.html -->
    			<li id="article2">Article2</li>
    			<li id="article3">Article3</li>
    		</ul>
    	</div>
    	<div class="clear"></div>
    </div>
    
    
    </body> 
    </html>
    article1.html
    Code:
    <textarea id="elm1" name="elm1" style="width:300px;height:250px"></textarea>
    dynamic ajax content example: http://dynamic-ajax.extermedia.com/

    Please help for the solution...




    .

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    You have to wait to init the editor until it's markup arrives on the page, that would be here:

    Code:
    function showContent(){
    	contentObj.innerHTML = ajax.response;	// ajax.response is a variable that contains the content of the external file	
    }
    So I would remove this from your code:

    Code:
    <script type="text/javascript"> 
    tinyMCE.init({ 
    mode : "exact", 
    theme : "simple", 
    elements : "elm1" 
    
    }); 
    </script>
    because elm1 is not there yet, and modify the first part:

    Code:
    function showContent(){
    	contentObj.innerHTML = ajax.response;	// ajax.response is a variable that contains the content of the external file
    	if(document.getElementById('elm1')){  //check for elm1, if present initialize it
    		tinyMCE.init({ 
    		mode : "exact", 
    		theme : "simple", 
    		elements : "elm1" 
    		}); 
    	}
    }
    However, if tinyMCE cannot deal with its initialized content being removed, then reinserted and reinitialized, there will be problems if the article1 is added, later removed and then added again.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. The Following User Says Thank You to jscheuer1 For This Useful Post:

    ampera (01-14-2010)

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
  •