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

1 line
2.5 KiB
JavaScript

window.wp=window.wp||{};(function(g){var c,b,a,h,f,e=["standard","chat","status","aside","gallery"];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(t){var q="",p=t.url,r=t.mime,s=t.type;if("video"===s){if(t.width){q+=' width="'+t.width+'"'}if(t.height){q+=' height="'+t.height+'"'}}g("#"+s+"-preview").remove();n.parent().prepend('<div id="'+s+'-preview" class="wp-format-media-preview"><'+s+q+' class="wp-'+s+'-shortcode" controls="controls" preload="none"><source type="'+r+'" src="'+p+'" /></'+s+"></div>");g(".wp-"+s+"-shortcode").mediaelementplayer()};b.on("select",function(){var p=b.state().get("selection").first().toJSON();if(0===p.mime.indexOf("audio")){k.val(p.url);f(p)}else{if(0===p.mime.indexOf("video")){p.src=p.url;k.val(wp.shortcode.string({tag:"video",attrs:_.pick(p,"src","width","height")}));f(p)}else{k.val(p.id);j.html('<img src="'+p.url+'" />');n.removeClass("empty").show()}}});b.open()})})})(jQuery);