2014-02-13 06:10:11 +01:00
|
|
|
tinymce.PluginManager.add("wpgallery",function(a){function b(a){return a.replace(/\[gallery([^\]]*)\]/g,function(a){var b=window.encodeURIComponent(a);return'<img src="'+tinymce.Env.transparentSrc+'" class="wp-media wp-gallery mceItem" data-wp-media="'+b+'" data-mce-resize="false" data-mce-placeholder="1" />'})}function c(a){return a.replace(/\[(audio|video)[^\]]*\][\s\S]*?\[\/\1\]/g,function(a,b){var c=window.encodeURIComponent(a),d="wp-media mceItem wp-"+b;return'<img src="'+tinymce.Env.transparentSrc+'" class="'+d+'" data-wp-media="'+c+'" data-mce-resize="false" data-mce-placeholder="1" />'})}function d(a){function b(a,b){return b=new RegExp(b+'="([^"]+)"').exec(a),b?window.decodeURIComponent(b[1]):""}return a.replace(/(?:<p(?: [^>]+)?>)*(<img [^>]+>)(?:<\/p>)*/g,function(a,c){var d=b(c,"data-wp-media");return d?"<p>"+d+"</p>":a})}function e(b){var c,d,e;"IMG"===b.nodeName&&"undefined"!=typeof wp&&wp.media&&wp.media.gallery&&(a.dom.hasClass(b,"wp-gallery")?(c=wp.media.gallery,e=window.decodeURIComponent(a.dom.getAttrib(b,"data-wp-media")),d=c.edit(e),d.state("gallery-edit").on("update",function(d){var e=c.shortcode(d).string();a.dom.setAttrib(b,"data-wp-media",window.encodeURIComponent(e))})):window.console&&console.log("Edit AV shortcode "+window.decodeURIComponent(a.dom.getAttrib(b,"data-wp-media"))))}a.addCommand("WP_Gallery",function(){e(a.selection.getNode())}),a.on("mouseup",function(b){var c=a.dom,d=b.target;"IMG"===d.nodeName&&c.getAttrib(d,"data-wp-media")?2!==b.button&&(c.hasClass(d,"wp-media-selected")?(e(d),c.removeClass(d,"wp-media-selected")):c.addClass(d,"wp-media-selected")):c.removeClass(c.select("img.wp-media-selected"),"wp-media-selected")}),a.on("ResolveName",function(b){var c=a.dom,d=b.target;"IMG"===d.nodeName&&c.getAttrib(d,"data-wp-media")&&(c.hasClass(d,"wp-gallery")?b.name="gallery":c.hasClass(d,"wp-video")?b.name="video":c.hasClass(d,"wp-audio")&&(b.name="audio"))}),a.on("BeforeSetContent",function(a){a.content=b(a.content),a.content=c(a.content)}),a.on("PostProcess",function(a){a.get&&(a.content=d(a.content))})});
|