remove tag below when image will be removed wordpress editor

i hope anybody can help me

With a wordpress filter I’ve modified the image-tag which will be send to the editor. Im using a data-attribute which contains the image-urls for different devices. A js-script sets the image-src from data-attribute. As fallback i´m using a noscript-tag after every img-tag.

Read More

So now i have to remove the noscript-tag when the image will be removed in the wordpress editor.

My init-Array for tiny_mce_before_init filter looks like that:

$initArray['setup'] = <<<JS
[function(ed) {
              ed.on('KeyDown', function (e) {
                var editor = tinyMCE.activeEditor;
                if ((e.keyCode == 8 || e.keyCode == 46) && editor.selection) {

                    var selectedNode = editor.selection.getNode();
                    console.log(selectedNode);
                    if (selectedNode && selectedNode.nodeName == 'IMG') {

                        delete_img_noscript(selectedNode.src); // A callback that will let me invoke the deletion of the image on the server if appropriate for the image source.
                        alert(selectedNode);
                        //selectedNode.next('noscript').remove();
                    }
                }
            });

}][0]
JS;

Related posts