mirror of
https://github.com/WordPress/WordPress.git
synced 2024-09-10 22:58:33 +02:00
* Keyboard navigation. * History and routes for single items and search results. props adamsilverstein. see #24716. Built from https://develop.svn.wordpress.org/trunk@29057 git-svn-id: http://core.svn.wordpress.org/trunk@28845 1a063a9b-81f0-0310-95a4-ce76da25c4cd
1 line
10 KiB
JavaScript
1 line
10 KiB
JavaScript
!function(a,b,c,d){var e,f=d.media;f.view.l10n?e=f.view.l10n:(e=f.view.l10n="undefined"==typeof _wpMediaViewsL10n?{}:_wpMediaViewsL10n,delete e.settings),f.controller.EditImageNoFrame=f.controller._State.extend({defaults:{id:"edit-attachment",title:e.editImage,menu:!1,router:"edit-metadata",content:"edit-metadata",url:""},initialize:function(){f.controller._State.prototype.initialize.apply(this,arguments)},_postActivate:function(){this._content(),this._router()},deactivate:function(){this.stopListening(this.frame)},_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()))},_content:function(){var a=this.get("content");a&&this.frame.content.render(a)}}),f.view.MediaFrame.Manage=f.view.MediaFrame.extend({initialize:function(){var g=this;b.defaults(this.options,{title:e.mediaLibraryTitle,modal:!1,selection:[],library:{},multiple:"add",state:"library",uploader:!0,mode:["grid","edit"]}),a(document).on("click",".add-new-h2",b.bind(this.addNewClickHandler,this)),this.$el.addClass("wp-core-ui media-grid-view"),(d.Uploader.limitExceeded||!d.Uploader.browser.supported)&&(this.options.uploader=!1),this.options.uploader&&(this.uploader=new f.view.UploaderWindow({controller:this,uploader:{dropzone:a("body"),container:a("body")}}).render(),this.uploader.ready(),a("body").append(this.uploader.el),this.options.uploader=!1),f.view.MediaFrame.prototype.initialize.apply(this,arguments),this.$el.appendTo(this.options.container),this.createSelection(),this.createStates(),this.bindHandlers(),this.render(),b.delay(function(){d.media.mediarouter=new f.view.Frame.Router(g),window.history&&window.history.pushState&&c.history.start({root:mediaGridSettings.adminUrl,pushState:!0})},250),a("#media-search-input").on("input",b.debounce(function(){var b=a(this).val();d.media.mediarouter.navigate(d.media.mediarouter.baseUrl(""===b?"":"?search="+b))},1e3))},createSelection:function(){var a=this.options.selection;a instanceof f.model.Selection||(this.options.selection=new f.model.Selection(a,{multiple:this.options.multiple})),this._selection={attachments:new f.model.Attachments,difference:[]}},createStates:function(){var a,b=this.options;this.options.states||(a=new f.controller.Library({library:f.query(b.library),multiple:b.multiple,title:b.title,priority:20,toolbar:!1,router:!1,content:"browse",filterable:"mime-types"}),a._renderTitle=function(a){var b=this.get("title")||"";a.$el.addClass("wrap"),b+='<a class="add-new-h2">Add New</a>',a.$el.html(b)},this.states.add([a]))},bindHandlers:function(){this.on("content:create:browse",this.browseContent,this),this.on("content:render:edit-image",this.editImageContent,this),this.on("edit:attachment",this.editAttachment,this),this.on("edit:attachment:next",this.editNextAttachment,this),this.on("edit:attachment:previous",this.editPreviousAttachment,this)},addNewClickHandler:function(){this.trigger("show:upload:attachment")},editPreviousAttachment:function(a){var b=this.state().get("library"),c=b.indexOf(a);this.trigger("edit:attachment",b.at(c-1))},editNextAttachment:function(a){var b=this.state().get("library"),c=b.indexOf(a);this.trigger("edit:attachment",b.at(c+1))},editAttachment:function(b){var c=this,d=this.state().get("library");this.editAttachmentFrame=new f.view.Frame.EditAttachments({library:d,model:b}),this.listenTo(this.editAttachmentFrame,"edit:attachment:next",this.editNextAttachment),this.listenTo(this.editAttachmentFrame,"edit:attachment:previous",this.editPreviousAttachment),a("body").on("keydown.media-modal",function(a){c.editAttachmentFrame.keyEvent(a)})},browseContent:function(a){var b=this.state();a.view=new f.view.AttachmentsBrowser({controller:this,collection:b.get("library"),selection:b.get("selection"),model:b,sortable:b.get("sortable"),search:b.get("searchable"),filters:b.get("filterable"),display:b.get("displaySettings"),dragInfo:b.get("dragInfo"),bulkEdit:!0,sidebar:!1,suggestedWidth:b.get("suggestedWidth"),suggestedHeight:b.get("suggestedHeight"),AttachmentView:b.get("AttachmentView")})},editImageContent:function(){var a=this.state().get("image"),b=new f.view.EditImage({model:a,controller:this}).render();this.content.set(b),b.loadEditor()}}),f.view.Attachment.Details.TwoColumn=f.view.Attachment.Details.extend({template:d.template("attachment-details-two-column"),initialize:function(){this.$el.attr("aria-label",this.model.attributes.title).attr("aria-checked",!1),this.model.on("change:sizes change:uploading",this.render,this),this.model.on("change:title",this._syncTitle,this),this.model.on("change:caption",this._syncCaption,this),this.model.on("change:percent",this.progress,this),this.model.on("add",this.select,this),this.model.on("remove",this.deselect,this)},render:function(){f.view.Attachment.Details.prototype.render.apply(this,arguments),f.mixin.removeAllPlayers(),a("audio, video",this.$el).each(function(a,b){var c=f.view.MediaDetails.prepareSrc(b);new MediaElementPlayer(c,f.mixin.mejsSettings)})}}),f.view.Frame.Router=c.Router.extend({mediaFrame:"",initialize:function(a){this.mediaFrame=a},routes:{"upload.php?item=:slug":"showitem","upload.php?search=:query":"search",":default":"defaultRoute"},baseUrl:function(a){return"upload.php"+a},search:function(b){this.closeModal(),a("#media-search-input").val(b).trigger("input")},showitem:function(a){var b=this.mediaFrame.state().get("library");this.closeModal(),this.mediaFrame.trigger("edit:attachment",b.findWhere({id:parseInt(a,10)}))},closeModal:function(){"undefined"!=typeof this.mediaFrame.editAttachmentFrame&&this.mediaFrame.editAttachmentFrame.modal.close()},defaultRoute:function(){this.closeModal(),a("#media-search-input").val("").trigger("input")}}),f.view.Frame.EditAttachments=f.view.Frame.extend({className:"edit-attachment-frame",template:f.template("edit-attachment-frame"),regions:["router","content"],events:{click:"collapse","click .delete-media-item":"deleteMediaItem","click .left":"previousMediaItem","click .right":"nextMediaItem"},initialize:function(){var c=this;f.view.Frame.prototype.initialize.apply(this,arguments),b.defaults(this.options,{modal:!0,state:"edit-attachment"}),this.library=this.options.library,this.model=this.options.model?this.options.model:this.library.at(0),this.createStates(),this.on("content:render:edit-metadata",this.editMetadataContent,this),this.on("content:render:edit-image",this.editImageContentUgh,this),"undefined"!=typeof this.model&&"image"===this.model.get("type")&&(this.on("router:create",this.createRouter,this),this.on("router:render",this.browseRouter,this)),this.options.hasPrevious=this.options.library.indexOf(this.options.model)>0?!0:!1,this.options.hasNext=this.options.library.indexOf(this.options.model)<this.options.library.length-1?!0:!1,this.options.modal&&(this.modal=new f.view.Modal({controller:this,title:this.options.title}),this.modal.close=function(){c.modal.remove(),a("body").off("keydown.media-modal")},this.modal.content(this),this.modal.open())},createStates:function(){this.states.add([new f.controller.EditImageNoFrame({model:this.model})])},render:function(){return!this.state()&&this.options.state&&this.setState(this.options.state),f.view.Frame.prototype.render.apply(this,arguments)},editMetadataContent:function(){var a=new f.view.Attachment.Details.TwoColumn({controller:this,model:this.model});this.content.set(a),d.media.mediarouter.navigate(d.media.mediarouter.baseUrl("?item="+this.model.id))},editImageContentUgh:function(){b.defer(b.bind(this.editImageContent,this))},editImageContent:function(){var a=new f.view.EditImage({model:this.model,controller:this}).render();this.content.set(a),a.loadEditor()},createRouter:function(a){a.view=new f.view.Router({controller:this})},browseRouter:function(a){a.set({"edit-metadata":{text:"Edit Metadata",priority:20},"edit-image":{text:"Edit Image",priority:40}})},previousMediaItem:function(){this.options.hasPrevious&&(this.modal.close(),this.trigger("edit:attachment:previous",this.model))},nextMediaItem:function(){this.options.hasNext&&(this.modal.close(),this.trigger("edit:attachment:next",this.model))},getCurrentIndex:function(){return this.library.indexOf(this.model)},hasNext:function(){return this.getCurrentIndex()+1<this.library.length},hasPrevious:function(){return this.getCurrentIndex()-1>-1},keyEvent:function(c){var d=a(c.target);if(27===c.keyCode)return this.resetRoute(),c;if(d.is("input")||d.is("textarea"))return c;if(39===c.keyCode){if(!this.hasNext)return;b.debounce(this.nextMediaItem(),250)}if(37===c.keyCode){if(!this.hasPrevious)return;b.debounce(this.previousMediaItem(),250)}},resetRoute:function(){d.media.mediarouter.navigate(d.media.mediarouter.baseUrl(""))}}),f.view.GridFieldOptions=f.View.extend({className:"media-grid-field-options",template:f.template("media-grid-field-options"),events:{"change input":"toggleFields"},toggleFields:function(b){var c,d,e=a(b.currentTarget);d=e.data("setting"),c=a(".data-"+d,".data-fields"),e.is(":checked")?(c.show(),deleteUserSetting("hidegrid"+d)):(c.hide(),setUserSetting("hidegrid"+d,1)),a(":checked",this.$el).length?c.parent().show():c.parent().hide()}}),f.view.BulkSelectionToggleButton=f.view.Button.extend({initialize:function(){f.view.Button.prototype.initialize.apply(this,arguments),this.listenTo(this.controller,"bulk-edit:activate bulk-edit:deactivate",b.bind(this.toggleBulkEditHandler,this))},click:function(){var a=this.controller.activeModes.where({id:"bulk-edit"}).length;f.view.Button.prototype.click.apply(this,arguments),a?(this.controller.deactivateMode("bulk-edit"),this.controller.activateMode("edit")):(this.controller.deactivateMode("edit"),this.controller.activateMode("bulk-edit"))},toggleBulkEditHandler:function(){var a=this.controller.activeModes.where({id:"bulk-edit"}).length;a?this.$el.addClass("button-primary"):(this.$el.removeClass("button-primary"),this.controller.state().get("selection").reset())}}),f.view.BulkDeleteButton=f.view.Button.extend({initialize:function(){f.view.Button.prototype.initialize.apply(this,arguments),this.$el.hide(),this.listenTo(this.controller,"bulk-edit:activate bulk-edit:deactivate",b.bind(this.visibility,this))},click:function(){for(f.view.Button.prototype.click.apply(this,arguments);this.controller.state().get("selection").length>0;)this.controller.state().get("selection").at(0).destroy()},visibility:function(){var a=this.controller.activeModes.where({id:"bulk-edit"}).length;a?this.$el.show():this.$el.hide()}})}(jQuery,_,Backbone,wp); |