How to use CKeditor's file manager out of the CKeditor

If you are using FCKeditor in your CMS' backend, maybe you want to use FCKeditor's file manager also in the rest of your CMS' backend. All you need to do is:

Javascript

<script type="text/javascript"> <!-- 	
var fileManagerInput = null;  	
function SetUrl(url) 	{ 		
    fileManagerInput.value = url;
    document.getElementById('filename').value = url.replace(/.*\//gi, ''); 	
}  	
function openFileBrowser(input) 	{ 		
    fileManagerInput = input;  		
    var sOptions = "toolbar=no,status=no,resizable=yes,dependent=yes,scrollbars=yes" ;
    sOptions += ",width=" + 600 ; 		
    sOptions += ",height=" + 400 ;  		
    window.open( '/fckeditor/editor/filemanager/browser/default/browser.html?Connector='+
        encodeURIComponent('/fckeditor/editor/filemanager/connectors/php/connector.php'),
        'FCKBrowseWindow', sOptions ) ; 	
}  
//--> </script> 

HTML file:

 <input type="text" name="src" id="src"/> <a href="#" onclick="openFileBrowser(document.getElementById('src'))">Select file</a>

After you click on "Select file" link, FCKeditor's file manager is opened. After a file in the file manager is selected, its path is pasted as the input value.

 


Discussion:
Add post
Joss said on Friday, 01-Apr-11 08:56:56 CEST
This was really helpful, thanx! :) One line is confusing though: document.getElementById('filename').value = url.replace(/.*\//gi, ''); What is this 'filename' element? Why do you do this replacement?
GameDev.sk said on Friday, 01-Apr-11 23:46:56 CEST
Hi, the filename is probably just a line I forgot to remove. Removing it now.
GameDev.sk said on Friday, 01-Apr-11 23:49:17 CEST
Oh, and I also add nl2br function to the discussion,
so
you
can
make
new
lines
now.
said on Sunday, 28-Aug-11 04:00:02 CEST