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