window.wp=window.wp||{},window.wpmlc=window.wpmlc||{l10n:{}},function(n,a){var s=wp.media,c=s.view.l10n,d=s.view.settings.mediaTrash,i={};a.extend(wpmlc.l10n,wpmlcp_media_views_l10n),a.defaults(wpmlc.l10n,{media_orderby:"date",media_order:"DESC"}),i.controllerLibrary={activate:s.controller.Library.prototype.activate},a.extend(s.controller.Library.prototype.defaults,{idealColumnWidth:n(window).width()<640?120:135}),a.extend(s.controller.Library.prototype,{activate:function(){i.controllerLibrary.activate.apply(this,arguments),wp.Uploader.queue.on("add",this.beforeUpload,this),wp.Uploader.queue.on("reset",this.afterUpload,this)},beforeUpload:function(){1==wp.Uploader.queue.length&&n('.attachment-filters:has(option[value!="all"]:selected)').val("all").change()},afterUpload:function(){var e=this.get("library"),t=this.get("selection");"menuOrder"===e.props.get("orderby")&&e.saveMenuOrder(),e.reset(e.models),t.trigger("selection:unsingle",t.model,t),t.trigger("selection:single",t.model,t)},uploading:function(e){var t=this.frame.content,i=this.get("selection");"upload"===t.mode()&&this.frame.content.mode("browse"),this.get("autoSelect")&&(1==wp.Uploader.queue.length&&i.length&&i.reset(),i.add(e),i.trigger("selection:unsingle",i.model,i),i.trigger("selection:single",i.model,i))}}),a.extend(s.view.AttachmentCompat.prototype,{save:function(e){var t,i={};e&&e.preventDefault(),this.controller.isModeActive("wpmlc-grid")&&(t=this.controller.browserView.toolbar.get("spinner")),a.each(this.$el.serializeArray(),function(e){i[e.name]=e.value}),n("input",this.$el).prop("disabled",!0),t&&t.show(),this.noRender=!0,this.controller.trigger("attachment:compat:waiting",["waiting"]),this.model.saveCompat(i).done(a.bind(this.postSave,this,1)).fail(a.bind(this.postSave,this,0))},postSave:function(e){var t,i;"edit-attachment"!==this.controller._state&&(t=this.controller.toolbar.get()),this.controller.isModeActive("wpmlc-grid")&&(i=this.controller.browserView.toolbar.get("spinner")),n("input",this.$el).prop("disabled",!1),i&&i.hide(),t&&(e?t.get("wpmlcAttachmentSuccess"):t.get("wpmlcAttachmentError")),this.controller.trigger("attachment:compat:ready",["ready"])},render:function(){var e=this.model.get("compat"),t=(this.$el,this.model.get("tcount"));if(a.each(t,function(e,t){var i=n('.wpmlc-taxonomy-filter option[value="'+t+'"]'),r=i.text();r=r.replace(/\(.*?\)/,"("+e+")"),i.text(r)}),e&&e.item)return this.noRender||(this.views.detach(),this.$el.html(e.item),this.views.render()),this}}),a.extend(s.view.AttachmentFilters.prototype,{change:function(){var e=this.filters[this.el.value],t=this.controller.state().get("selection"),i=this.controller.content.get().toolbar.get("resetFilterButton"),r=n(".attachment-filters").length,l=n(".attachment-filters").map(function(){return this.value}).get().filter(function(e){return"all"===e}).length;e&&this.model.set(e.props),e&&t&&t.length&&1!==wp.Uploader.queue.length&&t.reset(),e&&d&&!a.isUndefined(this.controller.toolbar)&&this.controller.toolbar.get().$(".media-selection").toggleClass("trash","trash"===e.props.status),a.isUndefined(i)||i.model.set("disabled",r===l)},select:function(){var e=this.model,r="all",l=e.toJSON();l=a.omit(l,"orderby","order"),a.find(this.filters,function(e,t){var i=a.omit(e.props,"orderby","order");if(a.all(i,function(e,t){return e===(a.isUndefined(l[t])?null:l[t])}))return r=t}),this.$el.val(r)}}),i.AttachmentFilters={All:{createFilters:s.view.AttachmentFilters.All.prototype.createFilters},Uploaded:{createFilters:s.view.AttachmentFilters.Uploaded.prototype.createFilters}},a.extend(s.view.AttachmentFilters.All.prototype,{createFilters:function(){var t,e=a.intersection(a.keys(wpmlc.l10n.taxonomies),wpmlc.l10n.filter_taxonomies);i.AttachmentFilters.All.createFilters.apply(this,arguments),a.each(this.filters,function(e,t){e.props.uncategorized=null,e.props.orderby=wpmlc.l10n.media_orderby,e.props.order=wpmlc.l10n.media_order}),this.filters.uncategorized={text:wpmlc.l10n.uncategorized,props:{uploadedTo:null,uncategorized:!0,status:null,type:null,orderby:wpmlc.l10n.media_orderby,order:wpmlc.l10n.media_order},priority:60},t=this.filters.uncategorized.props,a.each(e,function(e){t[e]=null}),d&&(this.controller.isModeActive("grid")||this.controller.isModeActive("wpmlc-grid"))&&(this.filters.trash={text:c.trash,props:{uploadedTo:null,status:"trash",type:null,orderby:"date",order:"DESC"},priority:70})}}),a.extend(s.view.AttachmentFilters.Uploaded.prototype,{createFilters:function(){a.intersection(a.keys(wpmlc.l10n.taxonomies),wpmlc.l10n.filter_taxonomies);i.AttachmentFilters.Uploaded.createFilters.apply(this,arguments),a.each(this.filters,function(e,t){e.props.orderby=wpmlc.l10n.media_orderby,e.props.order=wpmlc.l10n.media_order})}}),s.view.AttachmentFilters.Taxonomy=s.view.AttachmentFilters.extend({id:function(){return"media-attachment-"+this.options.taxonomy+"-filters"},className:function(){return"attachment-filters wpmlc-taxonomy-filter attachment-"+this.options.taxonomy+"-filter"},createFilters:function(){var l={},o=this;a.each(o.options.termList||{},function(e,t){var i=e.term_id,r=n("<div/>").html(e.term_row).text();l[i]={text:r,props:{uncategorized:null,orderby:wpmlc.l10n.media_orderby,order:wpmlc.l10n.media_order},priority:t+4},l[i].props[o.options.taxonomy]=i}),l.all={text:wpmlc.l10n.filter_by,props:{uncategorized:null,orderby:wpmlc.l10n.media_orderby,order:wpmlc.l10n.media_order},priority:1},l.all.props[o.options.taxonomy]=null,l.not_in={text:wpmlc.l10n.not_in,props:{uncategorized:null,orderby:wpmlc.l10n.media_orderby,order:wpmlc.l10n.media_order},priority:2},l.not_in.props[o.options.taxonomy]="not_in",this.filters=l}}),s.view.AttachmentFilters.Authors=s.view.AttachmentFilters.extend({createFilters:function(){var l={};a.each(this.options.users||{},function(e,t){var i=e.user_id,r=e.user_name;l[i]={text:r,props:{author:i,orderby:wpmlc.l10n.media_orderby,order:wpmlc.l10n.media_order},priority:t+2}}),l.all={text:wpmlc.l10n.in+" "+wpmlc.l10n.authors,props:{author:null,orderby:wpmlc.l10n.media_orderby,order:wpmlc.l10n.media_order},priority:1},this.filters=l}}),s.view.Button.resetFilters=s.view.Button.extend({id:"reset-all-filters",initialize:function(){s.view.Button.prototype.initialize.apply(this,arguments),this.controller.on("select:activate select:deactivate",this.toogleResetFilters,this)},click:function(e){"#"===this.attributes.href&&e.preventDefault(),n('.attachment-filters:has(option[value!="all"]:selected)').each(function(e){n(this).val("all").change()})},toogleResetFilters:function(){this.$el.toggleClass("hidden")}}),s.view.wpmlcAttachmentDetailsEditMessage=s.View.extend({tagName:"div",id:"wpmlc-save-changes-message",initialize:function(){this.text=this.options.text,this.class=this.options.class},render:function(){return this.$el.addClass(this.class),this.$el.html("<p><strong>"+this.text+"</strong></p>"),this}}),a.extend(s.view.Attachment.Details.prototype,{deleteAttachment:function(e){e.preventDefault(),window.confirm(c.warnDelete)&&(this.model.destroy(),this.controller.modal&&this.controller.modal.focusManager.focus())}}),i.AttachmentsBrowser={initialize:s.view.AttachmentsBrowser.prototype.initialize,createToolbar:s.view.AttachmentsBrowser.prototype.createToolbar,createSidebar:s.view.AttachmentsBrowser.prototype.createSidebar,createSingle:s.view.AttachmentsBrowser.prototype.createSingle,disposeSingle:s.view.AttachmentsBrowser.prototype.disposeSingle},a.extend(s.view.AttachmentsBrowser.prototype,{initialize:function(){i.AttachmentsBrowser.initialize.apply(this,arguments),this.on("ready",this.fixLayout,this),this.$window=n(window),this.$window.on("resize",a.debounce(a.bind(this.fixLayout,this),15)),n(".notice-dismiss").length&&n(document).on("click",".notice-dismiss",a.debounce(a.bind(this.fixLayout,this),250))},fixLayout:function(){var e=this.$el,t=e.find(".attachments"),i=e.find(".uploader-inline"),r=e.find(".media-toolbar"),l=n(".wpmlc-media-css .updated:visible, .wpmlc-media-css .error:visible, .wpmlc-media-css .notice:visible, .wpmlc-media-css .notice-error:visible, .wpmlc-media-css .notice-warning:visible, .wpmlc-media-css .notice-success:visible, .wpmlc-media-css .notice-info:visible"),o=n(".wpmlc-media-css .update-nag");if(o.length&&(o.css("margin-left","15px"),e.closest(".wrap").css("top",o.outerHeight()+25+"px")),(this.controller.isModeActive("select")||this.controller.isModeActive("wpmlc-grid"))&&(this.controller.isModeActive("select")&&(t.css("top",r.height()+10+"px"),i.css("top",r.height()+10+"px"),e.find(".wpmlc-loader").css("top",r.height()+10+"px"),r.find(".media-toolbar-secondary").prepend(r.find(".instructions"))),this.controller.isModeActive("wpmlc-grid"))){var s=0;a.isUndefined(l)||(l.each(function(){s+=n(this).outerHeight(!0)}),s=s?s-15:0),e.css("top",r.outerHeight()+s+15+"px"),r.css("top",-r.outerHeight()-25+"px")}},createToolbar:function(){var e,t,i,r=this,l=1;if(i={controller:this.controller},(this.controller.isModeActive("grid")||this.controller.isModeActive("wpmlc-grid"))&&(i.className="media-toolbar wp-filter"),this.toolbar=new s.view.Toolbar(i),this.views.add(this.toolbar),this.toolbar.set("spinner",new s.view.Spinner({priority:-40})),(this.controller.isModeActive("grid")||this.controller.isModeActive("wpmlc-grid"))&&(e=s.View.extend({className:"view-switch media-grid-view-switch",template:s.template("media-library-view-switcher")}),this.toolbar.set("libraryViewSwitcher",new e({controller:this.controller,priority:-90}).render())),(-1!==n.inArray(this.options.filters,["uploaded","all"])||parseInt(wpmlc.l10n.force_filters)&&!this.controller.isModeActive("wpmlc-bulk-edit")&&"gallery-edit"!==this.controller._state&&"playlist-edit"!==this.controller._state&&"video-playlist-edit"!==this.controller._state||"customize"===wpmlc.l10n.current_screen||"widgets"===wpmlc.l10n.current_screen)&&("5.3"<=wpmlc.l10n.wp_version&&this.toolbar.set("filters-heading",new wp.media.view.Heading({priority:-100,text:c.filterAttachments,level:"h2",className:"media-attachments-filter-heading"}).render()),-1!==n.inArray("types",wpmlc.l10n.filters_to_show)&&(this.toolbar.set("filtersLabel",new s.view.Label({value:c.filterByType,attributes:{for:"media-attachment-filters"},priority:-80}).render()),"uploaded"===this.options.filters?this.toolbar.set("filters",new s.view.AttachmentFilters.Uploaded({controller:this.controller,model:this.collection.props,priority:-80}).render()):(t=new s.view.AttachmentFilters.All({controller:this.controller,model:this.collection.props,priority:-80}),this.toolbar.set("filters",t.render()))),"4.0"<=wpmlc.l10n.wp_version&&-1!==n.inArray("dates",wpmlc.l10n.filters_to_show)&&s.view.settings.months.length&&(this.toolbar.set("dateFilterLabel",new s.view.Label({value:c.filterByDate,attributes:{for:"media-attachment-date-filters"},priority:-75}).render()),this.toolbar.set("dateFilter",new s.view.DateFilter({controller:this.controller,model:this.collection.props,priority:-75}).render())),1<wpmlc.l10n.users.length&&-1!==n.inArray("authors",wpmlc.l10n.filters_to_show)&&(this.toolbar.set("authorFilterLabel",new s.view.Label({value:wpmlc.l10n.filter_by+" "+wpmlc.l10n.author,attributes:{for:"author-filter"},priority:l++-70}).render()),this.toolbar.set("author-filter",new s.view.AttachmentFilters.Authors({controller:this.controller,model:this.collection.props,priority:l++-70,users:wpmlc.l10n.users}).render())),-1!==n.inArray("taxonomies",wpmlc.l10n.filters_to_show)&&n.each(wpmlc.l10n.taxonomies,function(e,t){-1!==a.indexOf(wpmlc.l10n.filter_taxonomies,e)&&t.term_list.length&&(r.toolbar.set(e+"FilterLabel",new s.view.Label({value:wpmlc.l10n.filter_by,attributes:{for:"media-attachment-"+e+"-filters"},priority:l++-70}).render()),r.toolbar.set(e+"-filter",new s.view.AttachmentFilters.Taxonomy({controller:r.controller,model:r.collection.props,priority:l++-70,taxonomy:e,termList:t.term_list}).render()))}),1<this.toolbar.$el.find(".attachment-filters").length&&this.toolbar.set("resetFilterButton",new s.view.Button.resetFilters({controller:this.controller,text:wpmlc.l10n.reset_filters,disabled:!0,priority:l++-70}).render())),this.controller.isModeActive("wpmlc-grid")){var o=this.controller.toolbar.get();n("body").hasClass("wpmlc-pro-media-css")&&o.set("wpmlcSelectAllButton",new s.view.wpmlcSelectAllButton({filters:t,disabled:!0,text:wpmlc.l10n.select_all,controller:this.controller,priority:-80}).render()),o.set("wpmlcDeselectButton",new s.view.wpmlcDeselectButton({filters:t,disabled:!0,text:c.cancelSelection,controller:this.controller,priority:-70}).render()),o.set("wpmlcDeleteSelectedButton",new s.view.wpmlcDeleteSelectedButton({filters:t,style:"primary",disabled:!0,text:d?c.trashSelected:c.deletePermanently,controller:this.controller,priority:-60}).render()),d&&o.set("wpmlcDeleteSelectedPermanentlyButton",new s.view.wpmlcDeleteSelectedPermanentlyButton({filters:t,style:"primary",disabled:!0,text:c.deleteSelected,controller:this.controller,priority:-50}).render())}this.controller.isModeActive("grid")&&(this.toolbar.set("selectModeToggleButton",new s.view.SelectModeToggleButton({text:c.bulkSelect,controller:this.controller,priority:-70}).render()),this.toolbar.set("deleteSelectedButton",new s.view.DeleteSelectedButton({filters:t,style:"primary",disabled:!0,text:d?c.trashSelected:c.deletePermanently,controller:this.controller,priority:-80,click:function(){var t=[],i=[],e=this.controller.state().get("selection"),r=this.controller.state().get("library");e.length&&(d||window.confirm(c.warnBulkDelete))&&(d&&"trash"!==e.at(0).get("status")&&!window.confirm(c.warnBulkTrash)||(e.each(function(e){e.get("nonces").delete?d&&"trash"===e.get("status")?(e.set("status","inherit"),t.push(e.save()),i.push(e)):d?(e.set("status","trash"),t.push(e.save()),i.push(e)):e.destroy({wait:!0}):i.push(e)}),t.length?(e.remove(i),n.when.apply(null,t).then(a.bind(function(){r._requery(!0),this.controller.trigger("selection:action:done")},this))):this.controller.trigger("selection:action:done")))}}).render()),d&&this.toolbar.set("deleteSelectedPermanentlyButton",new wp.media.view.DeleteSelectedPermanentlyButton({filters:t,style:"primary",disabled:!0,text:c.deleteSelected,controller:this.controller,priority:-55,click:function(){var t=[],e=this.controller.state().get("selection");e.length&&window.confirm(c.warnBulkDelete)&&(e.each(function(e){e.get("nonces").delete?e.destroy({wait:!0}):t.push(e)}),this.controller.trigger("selection:action:done"))}}).render())),this.options.search&&(this.toolbar.set("searchLabel",new s.view.Label({value:c.searchMediaLabel,attributes:{for:"media-search-input"},priority:-30}).render()),this.toolbar.set("search",new s.view.Search({controller:this.controller,model:this.collection.props,attributes:{type:"search",value:c.searchMediaLabel,placeholder:c.searchMediaPlaceholder},priority:-30}).render())),this.options.dragInfo&&this.toolbar.set("dragInfo",new s.View({el:n('<div class="instructions">'+c.dragInfo+"</div>")[0],priority:-40}))},createSidebar:function(){i.AttachmentsBrowser.createSidebar.apply(this,arguments),this.controller.isModeActive("wpmlc-grid")&&this.toggleSidebar()},toggleSidebar:function(){this.controller.state().get("selection").length?(this.sidebar.$el.removeClass("hidden"),this.$el.children(".attachments").css("right","300px"),this.$el.children(".uploader-inline").css("right","310px")):(this.sidebar.$el.addClass("hidden"),this.$el.children(".attachments").css("right",0),this.$el.children(".uploader-inline").css("right","10px"))},createSingle:function(){if(void 0!==arguments[1]&&0<arguments[1].models.length&&i.AttachmentsBrowser.createSingle.apply(this,arguments),this.controller.isModeActive("wpmlc-grid")){var e=this.sidebar,t=this.options.selection.single();"trash"!==this.options.selection.at(0).get("status")&&e.set("details",new wp.media.view.wpmlcGridAttachmentDetails({controller:this.controller,model:t,priority:80})),this.toggleSidebar()}},disposeSingle:function(){i.AttachmentsBrowser.disposeSingle.apply(this,arguments),this.controller.isModeActive("wpmlc-grid")&&this.toggleSidebar()},updateContent:function(){var e,t=this;e=this.controller.isModeActive("grid")||this.controller.isModeActive("wpmlc-grid")?t.attachmentsNoResults:t.uploader,this.collection.length?(e.$el.addClass("hidden"),t.toolbar.get("spinner").hide()):(this.toolbar.get("spinner").show(),this.dfd=this.collection.more().done(function(){t.collection.length?e.$el.addClass("hidden"):e.$el.removeClass("hidden"),t.toolbar.get("spinner").hide()}))},createUploader:function(){this.uploader=new s.view.UploaderInline({controller:this.controller,status:!1,message:this.controller.isModeActive("grid")||this.controller.isModeActive("wpmlc-grid")?"":c.noItemsFound,canClose:this.controller.isModeActive("grid")||this.controller.isModeActive("wpmlc-grid")}),this.uploader.$el.addClass("hidden"),this.views.add(this.uploader)}}),i.MediaFrame={Post:{activate:s.view.MediaFrame.Post.prototype.activate}},a.extend(s.view.MediaFrame.Post.prototype,{activate:function(){var e=this.content.get();i.MediaFrame.Post.activate.apply(this,arguments),this.on("open",e.fixLayout,e),"undefined"!=typeof acf&&n(".acf-expand-details").length&&n(document).on("click",".acf-expand-details",a.debounce(a.bind(e.fixLayout,e),250))}}),n(document).ready(function(){n(document).on("mousedown",".media-frame .attachments-browser .attachments li",function(e){(e.ctrlKey||e.shiftKey)&&e.preventDefault()})}),n("body").addClass("wpmlc-media-css")}(jQuery,_);