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

3 lines
72 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.
},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(){this.toolbar.set(new d.view.Toolbar({controller:this,items:{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},keydown:function(a){27===a.which&&this.$el.is(":visible")&&(this.escape(),a.stopImmediatePropagation())}}),d.view.FocusManager=d.View.extend({events:{keydown:"recordTab",focusin:"updateIndex"},focus:function(){b.isUndefined(this.index)||(this.$tabbables=this.$(":tabbable"),this.$tabbables.eq(this.index).focus())},recordTab:function(a){if(9===a.keyCode&&(b.isUndefined(this.index)&&this.updateIndex(a),!b.isUndefined(this.index))){var c=this.index+(a.shiftKey?-1:1);c>=0&&c<this.$tabbables.length?this.index=c:delete this.index}},updateIndex:function(a){this.$tabbables=this.$(":tabbable");var b=this.$tabbables.index(a.target);-1===b?delete this.index:this.index=b}}),d.view.UploaderWindow=d.View.extend({tagName:"div",className:"uploader-window",template:d.template("uploader-window"),initialize:function(){var c;this.$browser=a('<a href="#" class="browser" />').hide().appendTo("body"),c=this.options.uploader=b.defaults(this.options.uploader||{},{dropzone:this.$el,browser:this.$browser,params:{}}),!c.dropzone||c.dropzone instanceof a||(c.dro
},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-attachment":"deleteAttachment","click .trash-attachment":"trashAttachment","click .edit-attachment":"editAttachment","click .refresh-attachment":"refreshAttachment"},initialize:function(){this.focusManager=new d.view.FocusManager({el:this.el}),d.view.Attachment.prototype.initialize.apply(this,arguments)},render:function(){return d.view.Attachment.prototype.render.apply(this,arguments),this.focusManager.focus(),this},deleteAttachment:function(a){a.preventDefault(),confirm(c.warnDelete)&&this.model.destroy()},trashAttachment:function(a){a.preventDefault(),this.model.destroy()},editAttachment:function(a){var b=this.controller.states.get("edit-image");window.imageEdit&&b?(a.preventDefault(),b.set("image",this.model),this.controller.setState("edit-image")):this.$el.addClass("needs-refresh")},refreshAttachment:function(a){this.$el.removeClass("needs-refresh"),a.preventDefault(),this.model.fetch()}}),d.view.AttachmentCompat=d.View.extend({tagName:"form",className:"compat-item",events:{submit:"preventDefault","change input":"save","change select":"save","change textarea":"save"},initialize:function(){this.focusManager=new d.view.FocusManager({el:this.el}),this.model.on("change:compat",this.render,this)},dispose:function(){return this.$(":focus").length&&this.save(),d.View.pr