window.wp=window.wp||{};var mediaConfig=mediabayConfig;!function(e){"use strict";var i=wp.media,a=i.view.AttachmentFilters.extend({tagName:"select",className:"attachment-filters",id:"mediabay-attachment-filters",events:{change:"change"},keys:[],initialize:function(){this.createFilters(),_.extend(this.filters,this.options.filters),this.$el.html(_.chain(this.filters).map(function(i,a){return{el:e("<option></option>").val(a).html(i.text)[0],priority:i.priority||50}},this).sortBy("priority").pluck("el").value()),this.listenTo(this.model,"change",this.select),this.select()},createFilters:function(){var i={};_.each(mediabayFolders||{},function(a,t){var o=a.folderID,s=e("<div/>").html(a.folderName).text();i[o]={text:s,priority:t},i[o].props={},i[o].props[mediaConfig.mediabayFolder]=o}),i.all={text:mediaConfig.mediabayAllTitle,priority:-1},i.all.props={},i.all.props[mediaConfig.mediabayFolder]=null,this.filters=i},change:function(){var e=this.filters[this.el.value];e&&this.model.set(e.props)},select:function(){var e=this.model,i="all",a=e.toJSON();_.find(this.filters,function(e,t){if(_.all(e.props,function(e,i){return e===(_.isUndefined(a[i])?null:a[i])}))return i=t}),this.$el.val(i)}}),t=i.view.AttachmentsBrowser;if(i.view.AttachmentsBrowser=i.view.AttachmentsBrowser.extend({createToolbar:function(){var e=jQuery.Deferred();this.$el.data("backboneView",this),this._treeLoaded=e,t.prototype.createToolbar.apply(this,arguments);var i=new a({className:"wpmediacategory-filter attachment-filters",controller:this.controller,model:this.collection.props,priority:-75}).render();this.toolbar.set("mediabay-filter",i),i.initialize()}}),void 0!==window.wp&&"function"==typeof window.wp.Uploader){var o=window.wp.media,s=o.view.Modal;o.view.Modal=o.view.Modal.extend({className:"mediabay-modal",initialize:function(){s.prototype.initialize.apply(this,arguments)},open:function(){s.prototype.open.apply(this,arguments)&&(e(".mediabay-modal").length||e(".supports-drag-drop").length&&e(".supports-drag-drop").each(function(){"block"!=e(this).css("display")&&"inline-block"!=e(this).css("display")||(console.log("class added"),e(this).addClass("mediabay-modal"))}),e(".mediabay-modal").length?(e(".mediabay-custom-menu").remove(),e(".mediabay-custom-menu-trigger").remove(),e(".mediabay-modal .media-frame-menu").removeClass("has-mediabay-menu"),e(".mediabay-modal .media-frame").length&&(e(".mediabay-custom-menu").length||(e(".mediabay-modal .media-frame-menu").addClass("has-mediabay-menu"),e(".mediabay-modal .media-modal-content").append('<div class="mediabay-custom-menu-trigger" title="'+mediaConfig.showhideTrigger+'"><img class="mediabay_be_svg" src="'+mediaConfig.assetsURL+'img/menu.svg" alt="" /></div>'),e(".mediabay-modal .media-modal-content").append("<div class='mediabay-custom-menu'></div>"),e(".mediabay-modal .mediabay-custom-menu").load(mediaConfig.uploadURL+" #mediabay_sidebar",function(){e(".media-modal-content #mediabay_sidebar, .media-modal-content .cc_mediabay_sidebar_in").css("width","300px"),MediabayCore.init()})))):setTimeout(function(){},1e3))},close:function(){s.prototype.close.apply(this,arguments),e(".mediabay-modal").removeClass("mediabay-modal")}})}}(jQuery);