Drupal.wysiwyg.editor.instance needs additional methods
liquidcms - October 25, 2009 - 19:00
| Project: | Wysiwyg |
| Version: | 7.x-2.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs review |
Description
I am working on getting the Autosave module to work with wysiwyg module rather than being tied to a specific editor (D5 versiononly works with Tiny 2.0). Jide has been helping me with the wysiwyg api to figure things out and he added a patch #613204: Add Drupal.wysiwyg.editor.instance[id].getContent() for adding a getContent method. This really helps my cause.
But, in a similar vain it would be useful if there were 1 or both of a removeContent or replaceContent methods.

#1
Good suggestions! I did see that other issue, just haven't gotten around to reply yet. We're planning on building a proper API for Wysiwyg 3.x (first for 7.x-3.x then backport) and methods like these would indeed be somehting to consider when building it.
#2
Hey TwoD,
I'm also in need for such API functions, e.g. for the Wysiwyg Cleaner module. I'm willing to help for this. Would it be useful if I continue to submit patches for this ?
#3
Here is a patch for 6.x-2.x-dev which adds two methods : getContent and setContent. It supports TinyMCE 3, FCKEditor and CKEditor.
Sorry I don't have the time to set up a 7.x-3.x version right now but I think it is pretty straightforward to adapt.
I mark #613204 as a duplicate since this issue overlaps it.
#4
thanks, trying it out now
btw, i think patch files are supposed to be relative to the module folder, not the modules folder. I have been editing them to fix this.
#5
and i guess this includes patch-4 you provided the other day?
#6
Yes, it does.
#7
Comment removed because it was stupid =)
#8
tested with new rel of Autosave module and works great. So far only tested with Tiny 3.0, will test with FCK later this week.
Autosave project page outlines need for dev version of wysiwyg and that it requires this patch; hopefully this will be committed soon and new rel made for WYSIWYG.
thanks again for you help with this jide.
#9
+++ wysiwyg/editors/js/fckeditor-2.6.js 2009-10-26 20:55:22.000000000 +0100
@@ -151,6 +151,16 @@ Drupal.wysiwyg.editor.instance.fckeditor
+ },
+ getContent: function() {
+ var instance = FCKeditorAPI.GetInstance(this.field);
+ return instance.GetData();
+ },
+
+ setContent: function(content) {
+ var instance = FCKeditorAPI.GetInstance(this.field);
+ instance.SetHTML(content);
+ }
+
+};
Empty lines should be completely empty.
+++ wysiwyg/editors/js/none.js 2009-10-26 21:13:10.000000000 +0100@@ -66,5 +66,13 @@ Drupal.wysiwyg.editor.instance.none = {
+ },
+ getContent: function() {
+ var editor = document.getElementById(this.field);
+ return editor.value;
+ },
+ setContent: function(content) {
+ var editor = document.getElementById(this.field);
+ editor.value = content;
Indents on the 'var ...' lines have tabs.
+++ wysiwyg/editors/js/tinymce-3.js 2009-10-26 20:52:31.000000000 +0100@@ -11,6 +11,8 @@
Drupal.wysiwyg.editor.init.tinymce = function(settings) {
+//console.log(settings);
+//console.log(Drupal.settings.wysiwyg.plugins);
// @see #454992: drupal_get_js() must not use 'q' as query string.
Please remove these comments.
+++ wysiwyg/editors/js/tinymce-3.js 2009-10-26 20:52:31.000000000 +0100@@ -209,6 +211,16 @@ Drupal.wysiwyg.editor.instance.tinymce =
+ getContent: function() {
+ var editor = tinyMCE.get(this.field);
+ return editor.getContent();
+ },
+
+ setContent: function(content) {
+ content = this.prepareContent(content);
+ tinyMCE.execInstanceCommand(this.field, 'mceSetContent', false, content);
+ }
+
We need to check if TinyMCE is in fullscreen mode. See #606952: Inserting content in fullscreen TinyMCE. This patch could on the other hand be committed first, and then we adapt the other patch. Probably makes more sense than partially fixing this in two patches, so let's do it like that.
And yes, patches are best made relative to the module folder.
As long as the patch only touches the editor implementation files, it should apply fine to 7.x-3.x-dev for now.
Note that I have not yet tested the functionality provided by the patch, only reviewed for visible errors.
This review is powered by Dreditor.
#10
Ouch, I missed (again) some debug code. And some tabs. I promise I'll be more careful next time.
I'll clean this up and make it relative to the module folder.
About 7.x-3.x-dev, I grabbed the last CVS version and could not make it work on HEAD version of Drupal 7 CVS. If you could provide some help on how to set up an instance, it would be helpful.
Any more methods we could add to this and that might be useful ?
#11
A cleaner patch.
#12
not a patch expert but they still look odd.
this:
--- ./editors/js/ckeditor-3.0.js 2009-10-23 04:11:02.000000000 +0200
+++ ../wysiwyg/editors/js/ckeditor-3.0.js 2009-10-27 21:00:04.000000000 +0100
should likely just be this:
--- editors/js/ckeditor-3.0.js 2009-10-23 04:11:02.000000000 +0200
+++ editors/js/ckeditor-3.0.js 2009-10-27 21:00:04.000000000 +0100
#13
Patch from #11 needs the modification from #12 and then it works really nicely. Please include that in HEAD.
#14
#15
Here is the patch created from CVS this time.
#16
This is a nice patch, but we will defer it to the total revamp for 3.x. Read Wysiwyg 3.x - Wrapping it all up for more information.