I am trying to extend a "code view" and a "design view" within an application of mine. I am able to use either the code view (Ace Editor) or the design view (tinymce) with no issues. However I would want the two to work together and update the code on either side when developing. This would make me only have to POST one tag rather than doing two and may have issues down the road.
I created this fiddle to show what problem I am having.
In my fiddle I show a tinymce textarea, a regular textarea and a ace editor textarea. The tinymce and regular textarea share the same name and it's being called by Ace editor to update as I am typing. You can see the regular textarea works perfectly however, the tinymce textarea is not.
I believe the issue may be coming from the fact that TinyMCE is using an iFrame and updating the textarea behind the scenes but I am not exactly sure the best way to call that iframe in javascript.
I've tried to sync both, but due to some missing callbacks/events on tinyMCE, this is best I get. The content in ACE is only updating after blur on tinyMCE. There's currently no direct input event:
Fiddle forked
Code:
var editor = ace.edit("edit");
var textarea = $('textarea[name="test"]');
editor.getSession().setValue(textarea.val());
editor.getSession().on('change', function(){
textarea.val(editor.getSession().getValue());
// copy ace to tinyMCE
tinymce.get('test').setContent(editor.getSession().getValue());
});
editor.setTheme("https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.2/theme-terminal.js");
editor.getSession().setMode("https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.2/mode-html.js");
tinymce.init({
selector: ".test",
relative_urls: false,
apply_source_formatting : true,
setup : function(ed) {
ed.on('change', function(e) {
// copy tinyMCE to textarea
textarea.val(tinymce.activeEditor.getContent({format : 'raw'}));
// copy tinyMCE to ace
editor.getSession().setValue(
tinymce.activeEditor.getContent({format : 'raw'})
);
});
}
});
You should be setting ACE theme and mode this way:
editor.setTheme("ace/theme/terminal");
editor.getSession().setMode("ace/mode/html");
Related
Can anyone tell me how to disable the textarea/content area without disabling the buttons?
It's not clear to me what you'd like to accomplish, so perhaps you could explain that in a bit more detail.
In any case, you can make CKEditor read-only by using the setReadOnly() method. This will disable both the toolbar and the content area. Making just the content area disabled with buttons enabled would create a really confusing UX, with the users not really understanding what's going on so perhaps you can re-think your idea?
You can see the Read-only Mode demo and read more about this feature in the Read-Only Mode documentation.
You can try using below hack but please note that you will only be able to style existing content but you won't be able to insert anything (e.g. you won't insert table but you will be able to bold or link your text).
var editor = CKEDITOR.replace( 'editor1', {
language: 'en',
on : {
contentDom : function( event ) {
CKEDITOR.instances.editor1.document.getBody().setAttribute( 'contenteditable', false );
}
}
});
I am using Summernote WYSIWYG editor and I'm stuck in this issue:
Every time the view changes from Rich Text to HTML I want to make some calculations and update the editors content.
But when the editor changes from Rich Text to HTML .code() doesn't seem to work...
After a while I realised that when the editor is in HTML mode, .code() does not work at all - that's why when pressing "codeview" button from text to html doesn't work...
See this feedle: http://jsfiddle.net/Lpp1Lmhn/4/ (press the "Update" button when in Rich Text and then when in HTML mode)
So the question is:
Is there a way to update the editor's content when in HTML view?
Thank you in advance.
Yes you can, but the funny little change you have to make is change ".live" to ".on". here is a link to discussion on the significance of that little change
$(document).ready(function(){
$('#editor').summernote({
height:200,
toolbar: [ ['text', ['bold', 'italic', 'underline']],
['misc', ['codeview']]
]
});
$('[data-event="codeview"]').on('click', function(){
$('#editor').code($('#editor').code()+'a');
});
$('#btn').click(function(){
$('#editor').code($('#editor').code()+'a');
});
});
and you can visit the working fiddle http://jsfiddle.net/2tnua16k/
We have a redactor editor which we populate from the database but once we have submitted the data back we need to clear the textarea.
We have tried various combinations but are unable to clear it out.
jQuery("#redactor").redactor('set', '');
AND
jQuery("#redactor").val("");
$("#redactor").redactor('code.set', '');
updated version
With Redactor version 3, I had to use below code in order to clear redactor textareas:
$('.redactor-in').html('');
Note: This clears all redactor textareas in the current page, one need to change the class name .redactor-in inside the jQuery DOM selector if they want to clear specific textareas and leave some.
As you are working with the DOM you can just clear the innerHTML
$('.redactor_editor').html('');
Source: How to clear input or HTML or text on the redactor wysiwyg editor?
There's also some more documentation on http://imperavi.com/redactor/docs/api/
$('#redactor').redactor('insertHtml', 'your code');
you can use this code sample for RedactorX
$('.rx-editor p').html("")
I am using TinyMCE in my project.I want to get the id attribute of the textarea that is replaced by TinyMCE.Once I get the id of that textarea, then how can I use that id for my jquery functionality like focus,blur,keyup etc. Please give me an example for focus event for that textarea (editor) just by alert something when someone press a key inside the textarea (editor)
I have been stuck with this issue for the last 4 days. So any help in this Please.
Thanks.
Not a final answer, but too many advices for a comment.
There's a jQuery package that "Contains special jQuery build of TinyMCE and a jQuery integration plugin".
Some information about event-handling: e.g. the focus event. Notice the tinymce.activeEditor-snippet.
If you've just one init for one textarea, you should know the selector:
tinymce.init({
// your textarea has the class "myeditor"
// access with jQuery: $('textarea.myeditor').anyFunction();
selector: "textarea.myeditor"
});
Maybe it helps you a little. Good luck!
I'm trying to implement edit in place functionality for a description field, where editing is done using the telerik mvc editor. The editor needs to be hidden unless the user clicks on a span representing the editable section, and once done, hide the editor and have the marked up entry be placed in the editable element.
I'm not sure where to apply the knockout binding so that whatever is entered into the telerik editor is shown in the span after the editor is hidden.The editor creates an iframe that contains the marked-up html that get's generated as the user enter's content. That markup is converted is stored as an html encoded value within a textarea that's just outside the iframe.
If tried adding a bind to the textarea generated, but don't see the span bound with data-bind = "text: imgDescr" updating.
Her'es the razor view
<div>
<span data-bind="text: imgDescr"></span>
</div>
<div>
#{ Html.Telerik().Editor()
.Name("editor")
.HtmlAttributes(new {style = "height:400px"})
.Encode(false)
.Render();
}
</div>
and the js
function appViewModel() {
this.ImgName = ko.observable(helpText);
this.ImgDescr = ko.observable(helpText);
}
$('t-raw-content').attr('data-bind', "value: ImgDescr");
// Activates knockout.js
ko.applyBindings(new appViewModel());
Any suggestions on how this could be done? I also looked into using tinyMCE, but I think the rendering is handled in a similar manner.
If your editor is tinymce editor (?) adding a bind to the textarea is not helpfull.
You may acces the editor content using tinymce.get('editor_id').getContent(); and set it using tinymce.get('editor_id').setContent('This is a demo text.');
Using the examples listed here and here and the bindings example for tinyMCE provided by knockout wiki here I was able to get the editor bound in the way I needed it.
Part of what I was missing was the jquery.tinymce.js script.
The binding was done in a custom binding as in the example above and the only line needed to do the binding was
setTimeout(function() { $(element).tinymce(options); }, 0);
in the init section of the custom binding.
Here's the jsfiddle of what I had. It's not a completely working example within jsFiddle, but shows everything I had on my page.