1 line
5.5 KiB
JavaScript
1 line
5.5 KiB
JavaScript
window.wp=window.wp||{};(function(c){var y,n,k,t,q,j,w,m=/\s?\bwp-format-[^ ]+/g,g=120,s=360,v="standard",b="short-format",e=["status"],i=["status","aside","image","audio","video"],f=["status","aside"],d=["standard","chat","status","aside","gallery"];function x(C,A){var B=c("#"+C.settings.drop_element+" .media-progress-bar div");B.width(A.percent+"%")}function a(A){c("#"+A.settings.drop_element+" .wp-format-media-select").append('<div class="media-progress-bar"><div></div></div>')}function r(){c(".media-progress-bar",c(".wp-format-media-holder[data-format=image]")).remove()}function l(D){var C,B,A=wp.media.string.image({size:"full",align:false,link:"none"},D.attributes);C=c(".wp-format-media-holder[data-format=image]");c(".media-progress-bar",C).remove();if("image"!==D.attributes.type){return}B=c("#wp_format_"+C.data("format"));B.val(A);c("#image-preview").remove();C.parent().prepend(['<div id="image-preview" class="wp-format-media-preview">','<img src="',D.get("url"),'"',D.get("width")?' width="'+D.get("width")+'"':"",D.get("height")?' height="'+D.get("height")+'"':""," />","</div>"].join(""))}function u(B,A){c.each(A,function(D,C){if(D>0){B.removeFile(C)}})}var p={dropzone:c(".wp-format-media-holder[data-format=image]"),success:l,error:r,plupload:{runtimes:"html5",filters:[{title:"Image",extensions:"jpg,jpeg,gif,png"}]},params:{}};p=new wp.Uploader(p);p.uploader.bind("BeforeUpload",a);p.uploader.bind("UploadProgress",x);p.uploader.bind("FilesAdded",u);function z(A){q.val(A);c.each([k,t,j],function(C,B){B.prop("className",B.prop("className").replace(m,"")).addClass("wp-format-"+A)})}function h(D,B){var A,C=c("#content, #content_ifr");A=C.outerHeight();if(g<A){s=A}if(-1<c.inArray(D,f)){if(!C.hasClass(b)){C.addClass(b);_(C).each(function(E){c(E)[B?"css":"animate"]({height:g})})}}else{C.removeClass(b).animate({height:s})}}function o(A){var G,E,B,D,I=A.data("wp-format"),H=c("#title-prompt-text"),J=c(".post-format-description"),K=c("#title"),C=c(".post-formats-fields"),F=c(".post-format-change span.icon");if(I===postFormats.currentPostFormat){return}A.addClass("active").siblings().removeClass("active");B=-1<c.inArray(I,i);D=-1<c.inArray(postFormats.currentPostFormat,i);if(D?!B:B){n.fadeToggle(200).css("display","inline-block")}B=-1<c.inArray(I,e);D=-1<c.inArray(postFormats.currentPostFormat,e);if(D?!B:B){c("#titlewrap").fadeToggle(200)}B=-1<c.inArray(I,d);D=-1<c.inArray(postFormats.currentPostFormat,d);if(B&&D){z(I);C.hide()}else{if(D){C.hide();z(I);C.slideDown(400)}else{if(B){C.slideUp(200,function(){z(I)})}else{C.slideUp(200,function(){z(I);C.slideDown(400)})}}}h(I);K.focus();if(""===K.val()){H.removeClass("screen-reader-text");K.keydown(function(L){H.addClass("screen-reader-text");c(L.currentTarget).unbind(L)})}J.html(A.data("description"));F.show().prop("className",F.prop("className").replace(m,"")).addClass("wp-format-"+I);if(J.not(":visible")){J.slideDown("fast")}if(typeof tinymce!=="undefined"){G=tinymce.get("content");if(G){E=G.getBody();E.className=E.className.replace(/\bpost-format-[^ ]+/,"");G.dom.addClass(E,"post-format-"+I)}}n.toggleClass("gallery","gallery"===I);postFormats.currentPostFormat=I}c(function(){j=c("body");k=c("#post-body-content");t=c(".icon32");q=c("#post_format");n=c("#insert-media-button").toggleClass("gallery","gallery"===postFormats.currentPostFormat);v=c(".post-format-options .active").data("wp-format");if(-1<c.inArray(v,f)){h(v,true)}c("#show_post_format_ui").on("change",function(){j.toggleClass("wp-post-format-show-ui",this.checked);n.css("display","");c("#titlewrap").css("display","");c.post(ajaxurl,{action:"show-post-format-ui",post_type:c("#post_type").val(),show:this.checked?1:0,nonce:c("#show_post_format_ui_nonce").val()})});c(".post-format-options").on("click","a",function(A){A.preventDefault();o(c(A.currentTarget))});c(".use-url-or-html").on("click","a",function(A){A.preventDefault();c(".wp-format-media-holder, .wp-format-image-textarea").toggle();c(this).closest("p").find("span").toggle()});c(".wp-format-media-select").click(function(F){F.preventDefault();var A=c(F.currentTarget),C,E="image",D,B;D=A.closest(".wp-format-media-holder");B=c("#wp_format_"+D.data("format"));E=D.data("format");if(y&&w===E){y.open();return}w=E;y=wp.media.frames.formatMedia=wp.media({button:{text:A.data("update")},states:[new wp.media.controller.Library({library:wp.media.query({type:E}),title:A.data("choose"),displaySettings:"image"===E})]});C=function(M){var G,I,J="",H=M.url,K=M.mime,L=M.type;if("video"===L){if(M.width){G=M.width;if(G>600){G=600}J+=' width="'+G+'"'}if(M.height){I=M.height;if(M.width&&G<M.width){I=Math.round((I*G)/M.width)}J+=' height="'+I+'"'}}c("#"+L+"-preview").remove();D.parent().prepend('<div id="'+L+'-preview" class="wp-format-media-preview"><'+L+J+' class="wp-'+L+'-shortcode" controls="controls" preload="none"><source type="'+K+'" src="'+H+'" /></'+L+"></div>");c(".wp-"+L+"-shortcode").mediaelementplayer()};y.on("select",function(){var G=0,I=0,H,J=y.state().get("selection").first().toJSON();if(0===J.mime.indexOf("audio")){B.val(J.url);C(J)}else{if(0===J.mime.indexOf("video")){J.src=J.url;B.val(wp.shortcode.string({tag:"video",attrs:_.pick(J,"src","width","height")}));C(J)}else{H=wp.media.string.image({size:"full",align:false,link:"none"},J);B.val(H);c("#image-preview").remove();if(J.width){G=J.width>600?600:J.width}if(J.height){I=J.height}if(G<J.width){I=Math.round((I*G)/J.width)}D.parent().prepend(['<div id="image-preview" class="wp-format-media-preview">','<img src="',J.url,'"',G?' width="'+G+'"':"",I?' height="'+I+'"':""," />","</div>"].join(""))}}});y.open()})})}(jQuery)); |