Reported CK Source: http://cksource.com/forums/viewtopic.php?f=11&t=17702&p=45204#p45204How are you? The old work horse fckeditor has outdone ckeditor with regards to loading via JSON.
Okey I am working on a new PAID module for XOOPS called content. And I am working on a more secure form loading using JQuery and JSON. The XOOPS Wrapping class around ckeditor runs fine it is similar to the fckeditor one, but loads the ckeditor..
When i pass the HTML Code to generate the form via JSON with the following code in HTML generated with smarty as you can see in the first screen capture fckeditor is working.
The html for the form is:
<br style="clear:both;" /><script language="javascript" type="text/javascript">
function doJSON_LoadPageForm() {
var params = new Array();
$.getJSON("http://localhost/2.4.3/modules/content/dojson_loadform.php?passkey=0cf859d2ddc5c3f7e7cc61eb3582ea2d&form=content&storyid=2", params, refreshformdesc);
}
function doJSON_LoadPageTemplate() {
var params = new Array();
$.getJSON("http://localhost/2.4.3/modules/content/dojson_loadtemplate.php?passkey=0cf859d2ddc5c3f7e7cc61eb3582ea2d&form=content&storyid=2&template=" + $('#template :selected').text() + "&language=" + $('#language').val() + "&catid=" + $('#catid :selected').val() + "&parent_id=" + $('#parent_id :selected').val() + "&title=" + escape($('#title').val()) + "&ptitle=" + escape($('#ptitle').val()) + "&keywords=" + escape($('#keywords').val()) + "&page_description=" + escape($('#page_description').val()) + "&address=" + escape($('#address').val()), params, refreshformdesc);
}
script><body onLoad="javascript:doJSON_LoadPageForm();" />
<h1>Content Page - 2.7h1>
<p align="center" id='forms'>p>
The Form is placed in the
at the end of the code with a function called
refreshformdesc with innerHTML.
The file
dojson_loadform.php looks like:
include ('header.php');
include ($GLOBALS['xoops']->path(_BRC_PATH_PHP_JSON));
$json = new services_JSON();
$values = array();
$submit = true;
if ($passkey!=content_passkey())
{
ob_start();
xoops_error(_BRC_MSG_SECURITYTOKEN);
$msg = ob_get_contents();
ob_end_clean();
}
switch($form){
case _BRC_URL_FORM_CONTENT:
if (!$msg)
$values['innerhtml']['forms'] = content_addcontent($storyid, $_GET['language']);
else
$values['innerhtml']['forms'] = $msg;
break;
case _BRC_URL_FORM_CATEGORY:
if (!$msg)
$values['innerhtml']['forms'] = content_addcategory($catid, $_GET['language']);
else
$values['innerhtml']['forms'] = $msg;
break;
case _BRC_URL_FORM_BLOCK:
if (!$msg)
$values['innerhtml']['forms'] = content_addblock($blockid, $_GET['language']);
else
$values['innerhtml']['forms'] = $msg;
break;
}
print $json->encode($values);
?>
The file
dojson_loadform.php which generates a human readable code for Java Objects passes an array for the id of
forms to have it
innerhtml populated with the form. The function it is talking to is
refreshformdesc which looks like:
// JavaScript Document
function refreshformdesc(data){
$.each(data, function(i, n){
switch(i){
case 'innerhtml':
$.each(n, function(y, k){
var tmp = document.getElementById(y);
if (tmp)
tmp.innerHTML = k
var tmp = false;
});
break;
case 'disable':
$.each(n, function(y, k){
switch(k){
case '':
case 'false':
var tmp = document.getElementById(y);
if (tmp)
tmp.disabled = false;
var tmp = '';
break;
default:
var tmp = document.getElementById(y);
if (tmp)
tmp.disabled = true;
var tmp = '';
break;
}
});
break;
case 'checked':
$.each(n, function(y, k){
switch(k){
case 'false':
var tmp = document.getElementById(y);
if (tmp)
tmp.checked = false;
var tmp ='';
break;
default:
var tmp = document.getElementById(y);
if (tmp)
tmp.checked = true;
var tmp ='';
break;
}
});
break;
case 'index':
$.each(n, function(y, k){
var tmp = document.getElementById(y)
if (tmp)
tmp.selectedIndex = false;
var tmp ='';
});
break;
}
});
}
All the code works as you can see, if I echo the form, ckeditor loads but if i pass the echo via JSON to innerhtml which is more secure as it means passwords are not in the open text for example even if they are passed to the browser which in some cases is very useful. This is a secure Java exchange for form generation.
But if I load CK Editor by changing the preferences in my new module to ck editor.. This is what it looks like, I can't show you with a YouTube video, it loads for a second, you see it, then it crashes and burns and leaves an open text box.
For some reason when i load ckeditor via JSON to the browser, it will not intialise in any way.. it works fine if passed via a smarty variable but this means i can't have user templates for the editor. But the old work horse FCKEditor works fine..