WordPress/wp-includes/js/media-editor.min.js

1 line
9.7 KiB
JavaScript
Raw Normal View History

(function(b){var a={};wp.media.string={props:function(f,i){var h,c,e,g,d,j=wp.media.view.settings.defaultProps;d=function(k){if("image"===k.type&&!k.alt){k.alt=k.caption||k.title||"";k.alt=k.alt.replace(/<\/?[^>]+>/g,"");k.alt=k.alt.replace(/[\r\n]+/g," ")}return k};f=f?_.clone(f):{};if(i&&i.type){f.type=i.type}if("image"===f.type){f=_.defaults(f||{},{align:j.align||getUserSetting("align","none"),size:j.size||getUserSetting("imgsize","medium"),url:"",classes:[]})}if(!i){return d(f)}f.title=f.title||i.title;h=f.link||j.link||getUserSetting("urlbutton","file");if("file"===h){c=i.url}else{if("post"===h){c=i.link}else{if("custom"===h){c=f.linkUrl}}}f.linkUrl=c||"";if("image"===i.type){f.classes.push("wp-image-"+i.id);g=i.sizes;e=g&&g[f.size]?g[f.size]:i;_.extend(f,_.pick(i,"align","caption","alt"),{width:e.width,height:e.height,src:e.url,captionId:"attachment_"+i.id})}else{if("video"===i.type||"audio"===i.type){_.extend(f,_.pick(i,"title","type","icon","mime"))}else{f.title=f.title||i.filename;f.rel=f.rel||"attachment wp-att-"+i.id}}return d(f)},link:function(d,e){var c;d=wp.media.string.props(d,e);c={tag:"a",content:d.title,attrs:{href:d.linkUrl}};if(d.rel){c.attrs.rel=d.rel}return wp.html.string(c)},audio:function(d,f){var e,c;d=wp.media.string.props(d,f);e={};if(d.mime){switch(d.mime){case"audio/mpeg":if(f.url.indexOf("mp3")){e.mp3=f.url}else{if(f.url.indexOf("m4a")){e.m4a=f.url}}break;case"audio/mp3":e.mp3=f.url;break;case"audio/m4a":e.m4a=f.url;break;case"audio/wav":e.wav=f.url;break;case"audio/ogg":e.ogg=f.url;break;case"audio/x-ms-wma":case"audio/wma":e.wma=f.url;break;default:return wp.media.string.link(d)}}c=wp.shortcode.string({tag:"audio",attrs:e});return c},video:function(d,f){var e,c;d=wp.media.string.props(d,f);e={};if(f.width){e.width=f.width}if(f.height){e.height=f.height}if(d.mime){switch(d.mime){case"video/mp4":e.mp4=f.url;break;case"video/m4v":e.m4v=f.url;break;case"video/webm":e.webm=f.url;break;case"video/ogg":e.ogv=f.url;break;case"video/x-ms-wmv":case"video/wmv":case"video/asf":e.wmv=f.url;break;case"video/flv":case"video/x-flv":e.flv=f.url;break}}c=wp.shortcode.string({tag:"video",attrs:e});return c},image:function(g,i){var c={},d,f,h,e;g=wp.media.string.props(g,i);f=g.classes||[];c.src=typeof i!=="undefined"?i.url:g.url;_.extend(c,_.pick(g,"width","height","alt"));if(g.align&&!g.caption){f.push("align"+g.align)}if(g.size){f.push("size-"+g.size)}c["class"]=_.compact(f).join(" ");d={tag:"img",attrs:c,single:true};if(g.linkUrl){d={tag:"a",attrs:{href:g.linkUrl},content:d}}e=wp.html.string(d);if(g.caption){h={};if(c.width){h.width=c.width}if(g.captionId){h.id=g.captionId}if(g.align){h.align="align"+g.align}e=wp.shortcode.string({tag:"caption",attrs:h,content:e+" "+g.caption})}return e}};wp.media.gallery=(function(){var c={};return{defaults:{order:"ASC",id:wp.media.view.settings.post.id,itemtag:"dl",icontag:"dt",captiontag:"dd",columns:"3",link:"post",size:"thumbnail",orderby:"menu_order ID"},attachments:function(h){var j=h.string(),d=c[j],f,e,i,g;delete c[j];if(d){return d}f=_.defaults(h.attrs.named,wp.media.gallery.defaults);e=_.pick(f,"orderby","order");e.type="image";e.perPage=-1;if("rand"===f.orderby){f._orderbyRandom=true}if(!f.orderby||/^menu_order(?: ID)?$/i.test(f.orderby)){e.orderby="menuOrder"}if(f.ids){e.post__in=f.ids.split(",");e.orderby="post__in"}else{if(f.include){e.post__in=f.include.split(",")}}if(f.exclude){e.post__not_in=f.exclude.split(",")}if(!e.post__in){e.uploadedTo=f.id}g=_.omit(f,"id","ids","include","exclude","orderby","order");i=wp.media.query(e);i.gallery=new Backbone.Model(g);return i},shortcode:function(d){var f=d.props.toJSON(),e=_.pick(f,"orderby","order"),g,h;if(d.gallery){_.extend(e,d.gallery.toJSON())}e.ids=d.pluck("id");if(f.uploadedTo){e.id=f.uploadedTo}if(e._orderbyRandom){e.orderby="rand"}delete e._orderbyRandom;if(e.ids&&"post__in"===e.orderby){delete e.orderby}_.each(wp.media.gallery.defaults,function(j,i){if(j===e[i]){delete e[i]}});g=new wp.shortcode({tag:"gallery",attrs:e,type:"single"});h=new wp.media.model.Attachments(d.models,{props:f});h.gallery=d.gallery