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

1 line
9.2 KiB
JavaScript

!function(a){var b={},c={};wp.media.string={props:function(a,b){var c,d,e,f,g,h=wp.media.view.settings.defaultProps;return g=function(a){return"image"!==a.type||a.alt||(a.alt=a.caption||a.title||"",a.alt=a.alt.replace(/<\/?[^>]+>/g,""),a.alt=a.alt.replace(/[\r\n]+/g," ")),a},a=a?_.clone(a):{},b&&b.type&&(a.type=b.type),"image"===a.type&&(a=_.defaults(a||{},{align:h.align||getUserSetting("align","none"),size:h.size||getUserSetting("imgsize","medium"),url:"",classes:[]})),b?(a.title=a.title||b.title,c=a.link||h.link||getUserSetting("urlbutton","file"),"file"===c||"embed"===c?d=b.url:"post"===c?d=b.link:"custom"===c&&(d=a.linkUrl),a.linkUrl=d||"","image"===b.type?(a.classes.push("wp-image-"+b.id),f=b.sizes,e=f&&f[a.size]?f[a.size]:b,_.extend(a,_.pick(b,"align","caption","alt"),{width:e.width,height:e.height,src:e.url,captionId:"attachment_"+b.id})):"video"===b.type||"audio"===b.type?_.extend(a,_.pick(b,"title","type","icon","mime")):(a.title=a.title||b.filename,a.rel=a.rel||"attachment wp-att-"+b.id),g(a)):g(a)},link:function(a,b){var c;return a=wp.media.string.props(a,b),c={tag:"a",content:a.title,attrs:{href:a.linkUrl}},a.rel&&(c.attrs.rel=a.rel),wp.html.string(c)},audio:function(a,b){return wp.media.string._audioVideo("audio",a,b)},video:function(a,b){return wp.media.string._audioVideo("video",a,b)},_audioVideo:function(a,b,c){var d,e,f;return b=wp.media.string.props(b,c),"embed"!==b.link?wp.media.string.link(b):(d={},"video"===a&&(c.width&&(d.width=c.width),c.height&&(d.height=c.height)),f=c.filename.split(".").pop(),_.contains(wp.media.view.settings.embedExts,f)?(d[f]=c.url,e=wp.shortcode.string({tag:a,attrs:d})):wp.media.string.link(b))},image:function(a,b){var c,d,e,f,g={};return a=wp.media.string.props(a,b),d=a.classes||[],g.src="undefined"!=typeof b?b.url:a.url,_.extend(g,_.pick(a,"width","height","alt")),a.align&&!a.caption&&d.push("align"+a.align),a.size&&d.push("size-"+a.size),g["class"]=_.compact(d).join(" "),c={tag:"img",attrs:g,single:!0},a.linkUrl&&(c={tag:"a",attrs:{href:a.linkUrl},content:c}),f=wp.html.string(c),a.caption&&(e={},g.width&&(e.width=g.width),a.captionId&&(e.id=a.captionId),a.align&&(e.align="align"+a.align),f=wp.shortcode.string({tag:"caption",attrs:e,content:f+" "+a.caption})),f}},wp.media.collection={attachments:function(a,b){return function(d){var e,f,g,h,i=d.string(),j=c[i];return delete c[i],j?j:(e=_.defaults(d.attrs.named,this.defaults),f=_.pick(e,"orderby","order"),f.type=b,f.perPage=-1,void 0!==e.orderby&&(e._orderByField=e.orderby),"rand"===e.orderby&&(e._orderbyRandom=!0),-1!==jQuery.inArray(a,["playlist","video-playlist"])&&_.each(["tracknumbers","tracklist","images"],function(b){"undefined"==typeof e[b]?e["_"+b]=wp.media[a].defaults[b]:("true"===e[b]||!0===e[b])&&(e["_"+b]=!0)}),(!e.orderby||/^menu_order(?: ID)?$/i.test(e.orderby))&&(f.orderby="menuOrder"),e.ids?(f.post__in=e.ids.split(","),f.orderby="post__in"):e.include&&(f.post__in=e.include.split(",")),e.exclude&&(f.post__not_in=e.exclude.split(",")),f.post__in||(f.uploadedTo=e.id),h=_.omit(e,"id","ids","include","exclude","orderby","order"),g=wp.media.query(f),g[a]=new Backbone.Model(h),g)}},shortcodeAttrs:function(a,b){var c=b.props.toJSON(),d=_.pick(c,"orderby","order","style");return b[a]&&_.extend(d,b[a].toJSON()),d.ids=b.pluck("id"),c.uploadedTo&&(d.id=c.uploadedTo),delete d.orderby,d._orderbyRandom?d.orderby="rand":d._orderByField&&"rand"!=d._orderByField&&(d.orderby=d._orderByField),delete d._orderbyRandom,delete d._orderByField,d.ids&&"post__in"===d.orderby&&delete d.orderby,-1!==jQuery.inArray(a,["playlist","video-playlist"])&&_.each(["tracknumbers","tracklist","images"],function(a){d[a]=d["_"+a]?!0:!1,delete d["_"+a]}),_.each(this.defaults,function(a,b){a===d[b]&&delete d[b]}),d},editSelection:function(a,b){var c,d,e=wp.media[a].defaults.id;return b=b.shortcode,_.isUndefined(b.get("id"))&&!_.isUndefined(e)&&b.set("id",e),c=wp.media[a].attachments(b),d=new wp.media.model.Selection(c.models,{props:c.props.toJSON(),multiple:!0}),d[a]=c[a],d.more().done(function(){d.props.set({query:!1}),d.unmirror(),d.props.unset("orderby")}),d},cacheShortcode:function(a,b,d){var e=new wp.media.model.Attachments(b.models,{props:b.props.toJSON()});return e[a]=b[a],c[d.string()]=e,d},getEditFrame:function(a){return this.frame&&this.frame.dispose(),this.frame=wp.media(_.extend({frame:"post",editing:!0,multiple:!0},a)).open(),this.frame},instance:function(a,b){return{attachments:this.attachments(a,b.type),shortcode:function(b){var c=new wp.shortcode({tag:a,attrs:wp.media.collection.shortcodeAttrs(a,b),type:"single"});return wp.media.collection.cacheShortcode(a,b,c)},edit:function(c){var d=wp.shortcode.next(a,c);if(d&&d.content===c)return wp.media.collection.getEditFrame({title:b.title,state:a+"-edit",selection:wp.media.collection.editSelection(a,d)})}}}},wp.media.gallery=function(){var a={defaults:{itemtag:"dl",icontag:"dt",captiontag:"dd",columns:"3",link:"post",size:"thumbnail",order:"ASC",id:wp.media.view.settings.post.id,orderby:"menu_order ID"}};return _.extend(a,wp.media.collection.instance("gallery",{type:"image",title:wp.media.view.l10n.editGalleryTitle}))}(),wp.media.featuredImage={get:function(){return wp.media.view.settings.post.featuredImageId},set:function(b){var c=wp.media.view.settings;c.post.featuredImageId=b,wp.media.post("set-post-thumbnail",{json:!0,post_id:c.post.id,thumbnail_id:c.post.featuredImageId,_wpnonce:c.post.nonce}).done(function(b){a(".inside","#postimagediv").html(b)})},frame:function(){return this._frame?this._frame:(this._frame=wp.media({state:"featured-image",states:[new wp.media.controller.FeaturedImage]}),this._frame.on("toolbar:create:featured-image",function(a){this.createSelectToolbar(a,{text:wp.media.view.l10n.setFeaturedImage})},this._frame),this._frame.state("featured-image").on("select",this.select),this._frame)},select:function(){var a=this.get("selection").single();wp.media.view.settings.post.featuredImageId&&wp.media.featuredImage.set(a?a.id:-1)},init:function(){a("#postimagediv").on("click","#set-post-thumbnail",function(a){a.preventDefault(),a.stopPropagation(),wp.media.featuredImage.frame().open()}).on("click","#remove-post-thumbnail",function(){wp.media.view.settings.post.featuredImageId=-1})}},a(wp.media.featuredImage.init),wp.media.editor={insert:function(a){var b,c="undefined"!=typeof tinymce,d="undefined"!=typeof QTags,e=window.wpActiveEditor;if(window.send_to_editor)return window.send_to_editor.apply(this,arguments);if(e)c&&(b=tinymce.get(e));else if(c&&tinymce.activeEditor)b=tinymce.activeEditor,e=window.wpActiveEditor=b.id;else if(!d)return!1;if(b&&!b.isHidden()?b.execCommand("mceInsertContent",!1,a):d?QTags.insertContent(a):document.getElementById(e).value+=a,window.tb_remove)try{window.tb_remove()}catch(f){}},add:function(c,d){var e=this.get(c);return e?e:(e=b[c]=wp.media(_.defaults(d||{},{frame:"post",state:"insert",title:wp.media.view.l10n.addMedia,multiple:!0})),e.on("insert",function(b){var c=e.state();b=b||c.get("selection"),b&&a.when.apply(a,b.map(function(a){var b=c.display(a).toJSON();return this.send.attachment(b,a.toJSON())},this)).done(function(){wp.media.editor.insert(_.toArray(arguments).join("\n\n"))})},this),e.state("gallery-edit").on("update",function(a){this.insert(wp.media.gallery.shortcode(a).string())},this),e.state("embed").on("select",function(){var a=e.state(),b=a.get("type"),c=a.props.toJSON();c.url=c.url||"","link"===b?(_.defaults(c,{title:c.url,linkUrl:c.url}),this.send.link(c).done(function(a){wp.media.editor.insert(a)})):"image"===b&&(_.defaults(c,{title:c.url,linkUrl:"",align:"none",link:"none"}),"none"===c.link?c.linkUrl="":"file"===c.link&&(c.linkUrl=c.url),this.insert(wp.media.string.image(c)))},this),e.state("featured-image").on("select",wp.media.featuredImage.select),e.setState(e.options.state),e)},id:function(a){return a?a:(a=wpActiveEditor,!a&&"undefined"!=typeof tinymce&&tinymce.activeEditor&&(a=tinymce.activeEditor.id),a=a||"")},get:function(a){return a=this.id(a),b[a]},remove:function(a){a=this.id(a),delete b[a]},send:{attachment:function(a,b){var c,d,e=b.caption;return wp.media.view.settings.captions||delete b.caption,a=wp.media.string.props(a,b),c={id:b.id,post_content:b.description,post_excerpt:e},a.linkUrl&&(c.url=a.linkUrl),"image"===b.type?(d=wp.media.string.image(a),_.each({align:"align",size:"image-size",alt:"image_alt"},function(b,d){a[d]&&(c[b]=a[d])})):"video"===b.type?d=wp.media.string.video(a,b):"audio"===b.type?d=wp.media.string.audio(a,b):(d=wp.media.string.link(a),c.post_title=a.title),wp.media.post("send-attachment-to-editor",{nonce:wp.media.view.settings.nonce.sendToEditor,attachment:c,html:d,post_id:wp.media.view.settings.post.id})},link:function(a){return wp.media.post("send-link-to-editor",{nonce:wp.media.view.settings.nonce.sendToEditor,src:a.linkUrl,title:a.title,html:wp.media.string.link(a),post_id:wp.media.view.settings.post.id})}},open:function(a,b){var c;return b=b||{},a=this.id(a),c=this.get(a),(!c||c.options&&b.state!==c.options.state)&&(c=this.add(a,b)),c.open()},init:function(){a(document.body).on("click",".insert-media",function(b){var c=a(b.currentTarget),d=c.data("editor"),e={frame:"post",state:"insert",title:wp.media.view.l10n.addMedia,multiple:!0};b.preventDefault(),c.blur(),c.hasClass("gallery")&&(e.state="gallery",e.title=wp.media.view.l10n.createGalleryTitle),wp.media.editor.open(d,e)})}},_.bindAll(wp.media.editor,"open"),a(wp.media.editor.init)}(jQuery);