WordPress/wp-admin/js/post-formats.min.js

1 line
2.3 KiB
JavaScript
Raw Normal View History

window.wp=window.wp||{};(function(g){var c,b,a,h,f,e=["standard","chat","status","aside"];function d(i){c.get(0).className=c.get(0).className.replace(/\bwp-format-[^ ]+/,"");c.addClass("wp-format-"+i)}g(function(){var i=g(".post-formats-fields");g(".post-format-options").on("click","a",function(p){p.preventDefault();var o=g(this),l,j,k=o.parent(),n=o.data("wp-format"),m=g(".post-format-description");if(typeof c==="undefined"){c=g("#post-body-content")}if(n===postFormats.currentPostFormat){return}k.find("a.active").removeClass("active");o.addClass("active");g("#icon-edit").removeClass(postFormats.currentPostFormat).addClass(n);g("#post_format").val(n);if(-1<g.inArray(n,e)&&-1<g.inArray(postFormats.currentPostFormat,e)){d(n)}else{i.slideUp(200,function(){d(n);i.slideDown(400)})}g("#title").focus();m.html(o.data("description"));if(m.not(":visible")){m.slideDown("fast")}if(typeof tinymce!="undefined"){l=tinymce.get("content");if(l){j=l.getBody();j.className=j.className.replace(/\bpost-format-[^ ]+/,"");l.dom.addClass(j,"post-format-"+n)}}postFormats.currentPostFormat=n}).on("mouseenter focusin","a",function(){g(".post-format-tip").html(g(this).prop("title"))}).on("mouseleave focusout","a",function(){g(".post-format-tip").html(g(".post-format-options a.active").prop("title"))});g(".wp-format-media-select").click(function(l){l.preventDefault();var j=g(this),n,k,m="image",o="",n=j.closest(".wp-format-media-holder"),k=g("#wp_format_"+n.data("format"));switch(n.data("format")){case"audio":m="audio";break;case"video":m="video";break}if(b&&a===m&&h===o){b.open();return}a=m;h=o;b=wp.media.frames.formatMedia=wp.media({title:j.data("choose"),toolbar:o,library:{type:m},button:{text:j.data("update")}});f=function(r,p,q){g("#"+r+"-preview").remove();n.parent().prepend('<div id="'+r+'-preview" class="wp-format-media-preview"><'+r+' class="wp-'+r+'-shortcode" controls="controls" preload="none"><source type="'+q+'" src="'+p+'" /></'+r+"></div>");g(".wp-"+r+"-shortcode").mediaelementplayer()};b.on("select",function(){var r=b.state().get("selection").first(),q,p,s;s=r.get("id");p=r.get("url");q=r.get("mime");if(0===q.indexOf("audio")){k.val(p);f("audio",p,q)}else{if(0===q.indexOf("video")){k.val(p);f("video",p,q)}else{k.val(s);j.html('<img src="'+p+'" />');n.removeClass("empty").show()}}});b.open()})})})(jQuery);