tinymce.PluginManager.add("wpgallery",function(d){function t(e){return e.replace(/\[gallery([^\]]*)\]/g,function(e){return function(e,t){return t=window.encodeURIComponent(t),''}("wp-gallery",e)})}function n(e){return e.replace(/(?:]+)?>)*(]+>)(?:<\/p>)*/g,function(e,t){var n=function(e,t){return(t=new RegExp(t+'="([^"]+)"').exec(e))?window.decodeURIComponent(t[1]):""}(t,"data-wp-media");return n?"

"+n+"

":e})}function o(n){var a,o,e;"IMG"===n.nodeName&&"undefined"!=typeof wp&&wp.media&&(e=window.decodeURIComponent(d.dom.getAttrib(n,"data-wp-media")),d.dom.hasClass(n,"wp-gallery")&&wp.media.gallery&&(a=wp.media.gallery,(o=a.edit(e)).state("gallery-edit").on("update",function(e){var t=a.shortcode(e).string();d.dom.setAttrib(n,"data-wp-media",window.encodeURIComponent(t)),o.detach()})))}d.addCommand("WP_Gallery",function(){o(d.selection.getNode())}),d.on("mouseup",function(e){var t=d.dom,n=e.target;function a(){t.removeClass(t.select("img.wp-media-selected"),"wp-media-selected")}"IMG"===n.nodeName&&t.getAttrib(n,"data-wp-media")?2!==e.button&&(t.hasClass(n,"wp-media-selected")?o(n):(a(),t.addClass(n,"wp-media-selected"))):a()}),d.on("ResolveName",function(e){var t=d.dom,n=e.target;"IMG"===n.nodeName&&t.getAttrib(n,"data-wp-media")&&t.hasClass(n,"wp-gallery")&&(e.name="gallery")}),d.on("BeforeSetContent",function(e){d.plugins.wpview&&"undefined"!=typeof wp&&wp.mce||(e.content=t(e.content))}),d.on("PostProcess",function(e){e.get&&(e.content=n(e.content))})});