How can I get Zemanta and Redactor to work together?

330 Views Asked by At

I'm trying to use Zemanta's widgets and the Redactor HTML editor together. I can't get Zemanta to find Redactor's iframe/content and be able to send updates to it after clicking one of the widgets.

Redactor creates an iframe, but keeps the real textarea hidden behind the scenes, I suppose sending updates between, but I can't figure out how to update both at once. If I update the textarea using it's ID, it works, but I don't see it in Redactor unless I click code view. If I use the iframe class, I see it in redactor, but it doesn't make the changes inside the textarea, and when I save I get nothing.

.redactor_frame (redactor IFRAME)
#zemanta_content (textarea)

How can I update both using Zemanta's widget?

            get_editor: function () {
                var elm = null, win = null, editor = {element: null, property: null, type: null, win: null};
                try {
                    elm = $('.redactor_frame').get(0);
                    if (elm && elm.contentWindow) {
                        win = elm.contentWindow;
                        elm = null;
                    } else {
                        elm = $('#zemanta_content').get(0);
                    }
                    editor = win && {element: win.document.body, property: 'innerHTML', type: 'RTE', win: win} ||
                        elm && {element: elm, property: 'value', type: elm.tagName.toLowerCase(), win: null} ||
                        editor;
                } catch (er) {
                    $.zemanta.log(er);
                }
                return editor;
            }
2

There are 2 best solutions below

1
On

Andraz from Zemanta here.

I am not sure this is going to be an easy thing to fix, but we'll engage our front end developers to take a look at this.

Since Redactor editor is behaving in slightly non-standard way, maybe the best thing would be to turn to their support.

0
On

as Andraz pointed out overriding/changing only get_editor() will not suffice in this case. However I can rather point to a different solution. Other editors seem to update the textarea they upgrade with an iframe quite frequently if not constantly and you see that as if they hold the same state. Now, if you're using only one, you can copy the content via JavaScript from the currently active to the background one on some key action (save, update). This approach would save you a lot of time and it's probably very simple to implement.

Did this help you?