Losing events after replacing HTML content with aloha editor

63 views Asked by At

I've got a table plugin for the aloha-editor, which, when creating a new table, puts up some extra styles and extra cells used for selecting rows and columns. When the tables are created, events are attached to them which remove the extra styles when the editor goes out of focus so that they don't end up in the final HTML. This all works great currently.

The problem I have is with another plugin that lets you edit the HTML source of the editor. In this case, it creates a <textarea> in a lightbox <div>. It then takes the editor content and places it in the textarea where you can edit the source. Once the source changes, then the content of the editor on the main page is replaced with the textarea version.

What happens next, is that the events that were attached to the table are lost, because the table has been replaced with a new one. Therefore the extra table cells and styling remain on the table.

Am not sure what the best course of action is from here.

An example of how the table plugin binds to events is:

Aloha.bind('aloha-editable-activated', function (__event__, data) {
            that._splitcellsButton.enable(false);
            that._mergecellsButton.enable(false);
            that._splitcellsRowButton.enable(false);
            that._mergecellsRowButton.enable(false);
            that._splitcellsColumnButton.enable(false);
            that._mergecellsColumnButton.enable(false);

            data.editable.obj.find('table').each(function () {
                var registry = TablePlugin.TableRegistry;
                for (var i = 0; i < registry.length; i++) {
                    if (registry[i].obj.attr('id') === jQuery(this).attr('id')) {
                        registry[i].activate();
                        return true;
                    }
                }

                // Because table this is a new table that is not yet in the
                // registry.
                createNewTable(this);
            });

        });
0

There are 0 answers