Plugin Editor – Breaks when switching between visual and text

I have developed a plugin that inserts a shortcode, now I want to reverse the process.
I have it to find and replace the shortcode with an image. So I have it when you hover over the image, it places a link overlay to open an editor window to edit, and so on. which only works on the load (the switch between Visual and Text and vice versa) adds nothing. the superposition.

j & # 39; uses

            editor.on (& # 39; BeforeSetContent & # 39; function (event) {
event.content = replaceShortcodes (event.content);
generateOverlay (editor)
});

editor.on (& # 39; PostProcess & # 39; function (event) {
if (event.get) {
event.content = restoreShortcodes (event.content);
}
});

I use JQuery to generate hover flyover (unless someone else does it)
using

function generateOverlay (publisher) {
//event.preventDefault ();
if (! $ ("# content_ifr"). content (). find (".wp-ip-image"). parent (). hasClass ("wp-ip-container")) {
$ ("# content_ifr"). contents (). find (& # 39; .wp-ip-image & # 39;). parent (). wrap (& # 39;
& # 39;) } var wp_ip_img = $ ("# content_ifr"). happy (). find (& # 39 ;. wp-ip-image & # 39;) wp_ip_img.hover ( a function () { post_id = $ (this) .data (& # 39; post-id & # 39;); blog_id = $ (this) .data (& # 39; blog-id & # 39;); $ (this) .css ('cursor', 'pointer'); $ (this) .before (& # 39;
& # 39;) $ (this) .parent (). find ("# wp-ip-div -" + blog_id + "-" + post_id) .hover ( a function () { $ (this) .css ('cursor', 'pointer'); $ (this) .html (getPostData (post_id, blog_id)) $ (this) .find (& # 39 ;. wp-preview-ip & # 39;). unbind (). click (function (e) { postContent (editor, $ (this) .data (& # 39; url & # 39;)); }); $ (this) .find (& # 39 ;. wp-remove-ip & # 39;). unbind (). click (function (e) { $ ("# content_ifr"). contents (). find ("# wp-ip-div -" + id_blog + "-" + post_id) .parent (). remove () }); $ (this) .find (& # 39 ;. wp-edit-ip & # 39;). unbind (). click (function (e) { insertPosts (editor, blog_id, post_id, wp_ip_img.data ('wp-insert-post')) }); } a function () { $ (this) .remove () $ (this) .css ('cursor', 'default'); } ) } a function () { $ (this) .css ('cursor', 'default'); } ) } `

when I switch to Visual, it replaces the shortcode and then executes generateOverlay (editor) it happens to wp_ip_img.hover (... and do not run beyond even if he can find wp_ip_img

if someone has any ideas