Closed 2braincells2go closed 7 years ago
Nice example. Glad to see it's helpful for your project
Thanks @anhnt . Now if we could only get the textarea to work with Keditor. We are stuck and cannot get it save the content...
Using the above setup works perfectly with CKeditor alone BUT, will not when adapted to Keditor. The text.inc is accessed but not written to.
If anyone interested in helping us out, this is what we have setup for Keditor:
`<!DOCTYPE html>
Hi @2braincells2go. KEditor is pretty new so there's not much in the way of content on stackoverflow.
You get the value of the content from KEditor like this:
var fileContent = $('#content-area').keditor('getContent');
Here's the js code we use in Kademi to save, this is from a button click event:
btnSaveFile.on('click', function (e) {
e.preventDefault();
showLoadingIcon();
$('[contenteditable]').blur();
var fileContent = $('#content-area').keditor('getContent');
var saveUrl = postMessageData && postMessageData.pageName ? postMessageData.pageName : fileName;
$.ajax({
url: saveUrl,
type: 'POST',
data: {
body: fileContent
},
dataType: 'json',
success: function () {
if (isEmbeddedIframe) {
doPostMessage({
isSaved: true,
resp: postMessageData.resp,
willClose: postMessageData.willClose
}, postMessageData.url);
} else {
Msg.success('File is saved!');
}
hideLoadingIcon();
body.removeClass('content-changed');
},
error: function (e) {
Msg.error(e.status + ': ' + e.statusText);
hideLoadingIcon();
}
})
});
If it helps, here is that code in context: https://github.com/Kademi/kademi-dev/blob/master/src/main/webapp/templates/apps/admin/contentEditor.js
@bradmac thanks much for input. I will explore your suggestions and see what we can come up with.
If I may make a suggestion: why not setup example using a textarea? Asking around to more advanced people they too seemed confused on how to use.
Really like Keditor and sure it will soon become very popular:)
Thanks! BTW, if you want to see it in action here's a vid of using keditor with dynamic components - http://www.kademi.co/blogs/kb/building-customized-analytics-dashboards/
Well, unfortunately we have gotten no where with our attempts to incorporate Keditor into our classroom project. Using our PHP save method works flawless with CKEditor but after hours of trying to get working Keditor no luck.
Guess we will try again after the Holidays. Will close this.
Thanks
Sorry to hear that. Did you try my JS above? Should only take a few mins to integrate.
@bradmac Yes sir, we tried the example JS you suggested. Never it got it working with our PHP save method. Kept getting undefined errors and such. Sure it is something we were missing.
Thanks!
Just a note that KEditor is not intended as a drop-in replacement for ckeditor, ie you do need to use js to integrate it into your form.
You get the value of the content like this
var fileContent = $('#content-area').keditor('getContent');
And then you need to do something with that. If you are posting a form you need to set that into a form input using js. Eg
$("textarea").val( fileContent );
Thanks again for your input Brad, it is much appreciated.
Totally understand Keditor is not a drop-in replacement for ckeditor. Just trying to get Keditor working with what we have already thrown together. When I say "we", referring to a group of teenagers with oldest being 16 years and then me (old fellow), and I am not strong on javascript.
Another issue we face is working on a school network with tight rules/security. That is another reason we are trying to use the PHP already in place as it is approved (does not set off firewall alarms).
We placed var fileContent = $('#content-area').keditor('getContent');
in many different locations and ended up with error logs in console about not being defined. Positive it is issue with our implementation but have not given up. Just got to keep experimenting and get it right:)
Thanks much!
Cool, sounds like a lot of fun!
One thing you might want to try is doing the post with AJAX instead of an old fashioned page form post. Thats what we do in Kademi which is probably why our code looks very different from yours. But ajax gives a much better experience to the user, and makes it easier for you as developers to implement different requirements.
That can still use the same php service you have now.
Yes, need to move forward with AJAX as some point. Since I only use this whole setup to teach a little about building with Bootstrap, have not ventured into AJAX yet.
By any chance, do you have a working example of using the save function (like you speak of on Kademi)? Looking at your suggestion:
` btnSaveFile.on('click', function (e) { e.preventDefault();
showLoadingIcon();
$('[contenteditable]').blur();
var fileContent = $('#content-area').keditor('getContent');
var saveUrl = postMessageData && postMessageData.pageName ? postMessageData.pageName : fileName;
$.ajax({
url: saveUrl,
type: 'POST',
data: {
body: fileContent
},
dataType: 'json',
success: function () {
if (isEmbeddedIframe) {
doPostMessage({
isSaved: true,
resp: postMessageData.resp,
willClose: postMessageData.willClose
}, postMessageData.url);
} else {
Msg.success('File is saved!');
}
hideLoadingIcon();
body.removeClass('content-changed');
},
error: function (e) {
Msg.error(e.status + ': ' + e.statusText);
hideLoadingIcon();
}
})
});`
Thats our production code, but we dont have that in an example at the moment, sorry. I'll try to knock one up over the holidays. Although all our examples are client side only so we probably wont have an actual server to use it with.
You perhaps did not get a chance to "knock one up" (example based on our try above) did you?
Sorry, no. But keditor is really just a client side tool, its up to you to provide whatever it is that you'll be POSTing to
No problem. Did not mean to bother you guys. Students did not really like the flow of KEditor anyway.
Cheers!
Just stumbled across Keditor again and really like the way it is coming along, great job.
Currently using CKEditor in classroom project and have setup using textarea and some PHP to save the textarea content. I will note this is for learning in classroom only and we are not worried about security.
I had seen in closed issue that Keditor now support textareas. We have been struggling for hours attempting to get Keditor working with textarea and hoping for some input.
Our PHP looks like this:
` <?php
With save button like this:
<input class="btn btn-primary btn-lg raised" id="load" type="submit" name="write" id="write" value="SAVE" />
And textarea is:
<textarea style="width:100%;" class="input-block-level" name="content" id="editor1"><?php include Data/test.inc'; ?></textarea>
Any input will be greatly appreciated. Really like to start using Keditor simply because off the drag and drop.
Cheers!