2013-12-30 02:54:11 +01:00
|
|
|
tinymce.PluginManager.add("wpgallery",function(a){function b(a){return a.replace(/\[gallery([^\]]*)\]/g,function(a,b){var c=tinymce.DOM.encode(b);return'<img src="'+tinymce.Env.transparentSrc+'" class="wp-gallery mceItem" '+'title="gallery'+c+'" data-mce-resize="false" data-mce-placeholder="1" />'})}function c(a){function b(a,b){return b=new RegExp(b+'="([^"]+)"',"g").exec(a),b?tinymce.DOM.decode(b[1]):""}return a.replace(/(?:<p[^>]*>)*(<img[^>]+>)(?:<\/p>)*/g,function(a,c){var d=b(c,"class");return-1!==d.indexOf("wp-gallery")?"<p>["+tinymce.trim(b(c,"title"))+"]</p>":a})}return a.addCommand("WP_Gallery",function(){var b,c,d;"undefined"!=typeof wp&&wp.media&&wp.media.gallery&&(d=a.selection.getNode(),b=wp.media.gallery,"IMG"===d.nodeName&&a.dom.hasClass(d,"wp-gallery")&&(c=b.edit("["+a.dom.getAttrib(d,"title")+"]"),c.state("gallery-edit").on("update",function(c){var e=b.shortcode(c).string().slice(1,-1);a.dom.setAttrib(d,"title",e)})))}),a.on("mouseup",function(b){"IMG"===b.target.nodeName&&a.dom.hasClass(b.target,"wp-gallery")?2!==b.button&&(a.dom.hasClass(b.target,"wp-gallery-selected")?(a.execCommand("WP_Gallery"),a.dom.removeClass(b.target,"wp-gallery-selected")):a.dom.addClass(b.target,"wp-gallery-selected")):a.dom.removeClass(a.dom.select("img.wp-gallery-selected"),"wp-gallery-selected")}),a.on("ResolveName",function(b){var c=a.dom,d=b.target;"IMG"===d.nodeName&&c.hasClass(d,"wp-gallery")&&(b.name="gallery")}),a.on("BeforeSetContent",function(a){a.content=b(a.content)}),a.on("PostProcess",function(a){a.get&&(a.content=c(a.content))}),{_do_gallery:b,_get_gallery:c}});
|