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

3 lines
75 KiB
JavaScript
Raw Normal View History

!function(a,b){var c,d=wp.media;c=d.view.l10n="undefined"==typeof _wpMediaViewsL10n?{}:_wpMediaViewsL10n,d.view.settings=c.settings||{},delete c.settings,d.model.settings.post=d.view.settings.post,a.support.transition=function(){var a,c=document.documentElement.style,d={WebkitTransition:"webkitTransitionEnd",MozTransition:"transitionend",OTransition:"oTransitionEnd otransitionend",transition:"transitionend"};return a=b.find(b.keys(d),function(a){return!b.isUndefined(c[a])}),a&&{end:d[a]}}(),d.transition=function(c,d){var e=a.Deferred();return d=d||2e3,a.support.transition?(c instanceof a||(c=a(c)),c.first().one(a.support.transition.end,e.resolve),b.delay(e.resolve,d)):e.resolve(),e.promise()},d.controller.Region=function(a){b.extend(this,b.pick(a||{},"id","view","selector"))},d.controller.Region.extend=Backbone.Model.extend,b.extend(d.controller.Region.prototype,{mode:function(a){return a?a===this._mode?this:(this.trigger("deactivate"),this._mode=a,this.render(a),this.trigger("activate"),this):this._mode},render:function(a){if(a&&a!==this._mode)return this.mode(a);var b,c={view:null};return this.trigger("create",c),b=c.view,this.trigger("render",b),b&&this.set(b),this},get:function(){return this.view.views.first(this.selector)},set:function(a,b){return b&&(b.add=!1),this.view.views.set(this.selector,a,b)},trigger:function(a){var c,d;if(this._mode)return d=b.toArray(arguments),c=this.id+":"+a,d[0]=c+":"+this._mode,this.view.trigger.apply(this.view,d),d[0]=c,this.view.trigger.apply(this.view,d),this}}),d.controller.StateMachine=function(a){this.states=new Backbone.Collection(a)},d.controller.StateMachine.extend=Backbone.Model.extend,b.extend(d.controller.StateMachine.prototype,Backbone.Events,{state:function(a){return this.states=this.states||new Backbone.Collection,a=a||this._state,a&&!this.states.get(a)&&this.states.add({id:a}),this.states.get(a)},setState:function(a){var b=this.state();return b&&a===b.id||!this.states||!this.states.get(a)?this:(b&&(b.trigger("deactivate"),this._lastState=b.id),this._state=a,this.state().trigger("activate"),this)},lastState:function(){return this._lastState?this.state(this._lastState):void 0}}),b.each(["on","off","trigger"],function(a){d.controller.StateMachine.prototype[a]=function(){return this.states=this.states||new Backbone.Collection,this.states[a].apply(this.states,arguments),this}}),d.controller.State=Backbone.Model.extend({constructor:function(){this.on("activate",this._preActivate,this),this.on("activate",this.activate,this),this.on("activate",this._postActivate,this),this.on("deactivate",this._deactivate,this),this.on("deactivate",this.deactivate,this),this.on("reset",this.reset,this),this.on("ready",this._ready,this),this.on("ready",this.ready,this),Backbone.Model.apply(this,arguments),this.on("change:menu",this._updateMenu,this)},ready:function(){},activate:function(){},deactivate:function(){},reset:function(){},_ready:function(){this._updateMenu()},_preActivate:function(){this.active=!0},_postActivate:function(){this.on("change:menu",this._menu,this),this.on("change:titleMode",this._title,this),this.on("change:content",this._content,this),this.on("change:toolbar",this._toolbar,this),this.frame.on("title:render:default",this._renderTitle,this),this._title(),this._menu(),this._toolbar(),this._content(),this._router()},_deactivate:function(){this.active=!1,this.frame.off("title:render:default",this._renderTitle,this),this.off("change:menu",this._menu,this),this.off("change:titleMode",this._title,this),this.off("change:content",this._content,this),this.off("change:toolbar",this._toolbar,this)},_title:function(){this.frame.title.render(this.get("titleMode")||"default")},_renderTitle:function(a){a.$el.text(this.get("title")||"")},_router:function(){var a,b=this.frame.router,c=this.get("router");this.frame.$el.toggleClass("hide-router",!c),c&&(this.frame.router.render(c),a=b.get(),a&&a.select&&a.select(this.frame.content.mode()))},_menu:function(){var a,b=this.frame.menu,c=this.get("menu");c&&(b.mode(c),a=b.get(),a&&a.select&&a.select(this.id))},_updateMenu:function(){var a=this.
}}}}))}}),d.view.MediaFrame.ImageDetails=d.view.MediaFrame.Select.extend({defaults:{id:"image",url:"",menu:"image-details",content:"image-details",toolbar:"image-details",type:"link",title:c.imageDetailsTitle,priority:120},initialize:function(a){this.image=new d.model.PostImage(a.metadata),this.options.selection=new d.model.Selection(this.image.attachment,{multiple:!1}),d.view.MediaFrame.Select.prototype.initialize.apply(this,arguments)},bindHandlers:function(){d.view.MediaFrame.Select.prototype.bindHandlers.apply(this,arguments),this.on("menu:create:image-details",this.createMenu,this),this.on("content:render:image-details",this.renderImageDetailsContent,this),this.on("content:render:edit-image",this.editImageContent,this),this.on("menu:render:image-details",this.renderMenu,this),this.on("toolbar:render:image-details",this.renderImageDetailsToolbar,this),this.on("toolbar:render:replace",this.renderReplaceImageToolbar,this)},createStates:function(){this.states.add([new d.controller.ImageDetails({image:this.image,editable:!1,menu:"image-details"}),new d.controller.ReplaceImage({id:"replace-image",library:d.query({type:"image"}),image:this.image,multiple:!1,title:c.imageReplaceTitle,menu:"image-details",toolbar:"replace",priority:80,displaySettings:!0}),new d.controller.EditImage({image:this.image,selection:this.options.selection})])},renderImageDetailsContent:function(){var a=new d.view.ImageDetails({controller:this,model:this.state().image,attachment:this.state().image.attachment}).render();this.content.set(a)},editImageContent:function(){var a,b=this.state(),c=b.get("image");c&&(a=new d.view.EditImage({model:c,controller:this}).render(),this.content.set(a),a.loadEditor())},renderMenu:function(a){var b=this.lastState(),e=b&&b.id,f=this;a.set({cancel:{text:c.imageDetailsCancel,priority:20,click:function(){e?f.setState(e):f.close()}},separateCancel:new d.View({className:"separator",priority:40})})},renderImageDetailsToolbar:function(){this.toolbar.set(new d.view.Toolbar({controller:this,items:{select:{style:"primary",text:c.update,priority:80,click:function(){var a=this.controller,b=a.state();a.close(),b.trigger("update",a.image.toJSON()),a.setState(a.options.state),a.reset()}}}}))},renderReplaceImageToolbar:function(){var a=this,b=a.lastState(),e=b&&b.id;this.toolbar.set(new d.view.Toolbar({controller:this,items:{back:{text:c.back,priority:20,click:function(){e?a.setState(e):a.close()}},replace:{style:"primary",text:c.replace,priority:80,click:function(){var a=this.controller,b=a.state(),c=b.get("selection"),d=c.single();a.close(),a.image.changeAttachment(d,b.display(d)),b.trigger("replace",a.image.toJSON()),a.setState(a.options.state),a.reset()}}}}))}}),d.view.Modal=d.View.extend({tagName:"div",template:d.template("media-modal"),attributes:{tabindex:0},events:{"click .media-modal-backdrop, .media-modal-close":"escapeHandler",keydown:"keydown"},initialize:function(){b.defaults(this.options,{container:document.body,title:"",propagate:!0,freeze:!0})},prepare:function(){return{title:this.options.title}},attach:function(){return this.views.attached?this:(this.views.rendered||this.render(),this.$el.appendTo(this.options.container),this.views.attached=!0,this.views.ready(),this.propagate("attach"))},detach:function(){return this.$el.is(":visible")&&this.close(),this.$el.detach(),this.views.attached=!1,this.propagate("detach")},open:function(){var b=this.$el,c=this.options;return b.is(":visible")?this:(this.views.attached||this.attach(),c.freeze&&(this._freeze={scrollTop:a(window).scrollTop()}),b.show().focus(),this.propagate("open"))},close:function(b){var c=this._freeze;return this.views.attached&&this.$el.is(":visible")?(this.$el.hide(),this.propagate("close"),c&&a(window).scrollTop(c.scrollTop),b&&b.escape&&this.propagate("escape"),this):this},escape:function(){return this.close({escape:!0})},escapeHandler:function(a){a.preventDefault(),this.escape()},content:function(a){return this.views.set(".media-modal-content",a),this},propagate:function(a){return this.trigger(a),this.options.propagate&&this.controller.trigger(a),this}
},ready:function(){this.refresh()},refresh:function(){if(this.$el.children().length){var a=this.collection,b="edit-selection"===this.controller.content.mode();this.$el.toggleClass("empty",!a.length),this.$el.toggleClass("one",1===a.length),this.$el.toggleClass("editing",b),this.$(".count").text(c.selected.replace("%d",a.length))}},edit:function(a){a.preventDefault(),this.options.editable&&this.options.editable.call(this,this.collection)},clear:function(a){a.preventDefault(),this.collection.reset()}}),d.view.Attachment.Selection=d.view.Attachment.extend({className:"attachment selection",toggleSelection:function(){this.options.selection.single(this.model)}}),d.view.Attachments.Selection=d.view.Attachments.extend({events:{},initialize:function(){return b.defaults(this.options,{sortable:!0,resize:!1,AttachmentView:d.view.Attachment.Selection}),d.view.Attachments.prototype.initialize.apply(this,arguments)}}),d.view.Attachment.EditSelection=d.view.Attachment.Selection.extend({buttons:{close:!0}}),d.view.Settings=d.View.extend({events:{"click button":"updateHandler","change input":"updateHandler","change select":"updateHandler","change textarea":"updateHandler"},initialize:function(){this.model=this.model||new Backbone.Model,this.model.on("change",this.updateChanges,this)},prepare:function(){return b.defaults({model:this.model.toJSON()},this.options)},render:function(){return d.View.prototype.render.apply(this,arguments),b(this.model.attributes).chain().keys().each(this.update,this),this},update:function(a){var b,c,d=this.model.get(a),e=this.$('[data-setting="'+a+'"]');e.length&&(e.is("select")?(c=e.find('[value="'+d+'"]'),c.length?(e.find("option").prop("selected",!1),c.prop("selected",!0)):this.model.set(a,e.find(":selected").val())):e.hasClass("button-group")?(b=e.find("button").removeClass("active"),b.filter('[value="'+d+'"]').addClass("active")):e.is('input[type="text"], textarea')?e.is(":focus")||e.val(d):e.is('input[type="checkbox"]')&&e.prop("checked",!!d))},updateHandler:function(b){var c,d=a(b.target).closest("[data-setting]"),e=b.target.value;b.preventDefault(),d.length&&(d.is('input[type="checkbox"]')&&(e=d[0].checked),this.model.set(d.data("setting"),e),(c=d.data("userSetting"))&&setUserSetting(c,e))},updateChanges:function(a){a.hasChanged()&&b(a.changed).chain().keys().each(this.update,this)}}),d.view.Settings.AttachmentDisplay=d.view.Settings.extend({className:"attachment-display-settings",template:d.template("attachment-display-settings"),initialize:function(){var a=this.options.attachment;b.defaults(this.options,{userSettings:!1}),d.view.Settings.prototype.initialize.apply(this,arguments),this.model.on("change:link",this.updateLinkTo,this),a&&a.on("change:uploading",this.render,this)},dispose:function(){var a=this.options.attachment;a&&a.off(null,null,this),d.view.Settings.prototype.dispose.apply(this,arguments)},render:function(){var a=this.options.attachment;return a&&b.extend(this.options,{sizes:a.get("sizes"),type:a.get("type")}),d.view.Settings.prototype.render.call(this),this.updateLinkTo(),this},updateLinkTo:function(){var a=this.model.get("link"),b=this.$(".link-to-custom"),c=this.options.attachment;return"none"===a||"embed"===a||!c&&"custom"!==a?void b.addClass("hidden"):(c&&("post"===a?b.val(c.get("link")):"file"===a?b.val(c.get("url")):this.model.get("linkUrl")||b.val("http://"),b.prop("readonly","custom"!==a)),b.removeClass("hidden"),void(b.is(":visible")&&b.focus()[0].select()))}}),d.view.Settings.Gallery=d.view.Settings.extend({className:"collection-settings gallery-settings",template:d.template("gallery-settings")}),d.view.Settings.Playlist=d.view.Settings.extend({className:"collection-settings playlist-settings",template:d.template("playlist-settings")}),d.view.Attachment.Details=d.view.Attachment.extend({tagName:"div",className:"attachment-details",template:d.template("attachment-details"),events:{"change [data-setting]":"updateSetting","change [data-setting] input":"updateSetting","change [data-setting] select":"updateSetting","change [data-setting] textarea":"updateSetting","click .delete-at