!function(e){"use strict";function t(){e(".mediabay_be_loader").addClass("active")}function a(t,a){if((t=parseInt(t))!==(a=parseInt(a))){if(t){var i=e('ul li.category_item[data-id="'+t+'"] .cc_count').text();(i=parseInt(i)-1)?e('ul li.category_item[data-id="'+t+'"] .cc_count').text(i):e('ul li.category_item[data-id="'+t+'"] .cc_count').text(0)}else{var o=e('ul li.category_item[data-id="all"]'),c=o.find(".cc_count").text();c=parseInt(c)+1,o.find(".cc_count").text(c)}if(a){var n=e('ul li.category_item[data-id="'+a+'"] .cc_count').text();n=parseInt(n)+1,e('ul li.category_item[data-id="'+a+'"] .cc_count').text(n)}}}function i(a){t(),e(".wpmediacategory-filter").val(a),e(".wpmediacategory-filter").trigger("change");var i=e(".cc_mediabay_sidebar"),c=o(i);if(c.browser.length>0&&"object"==typeof c.view)try{c.view.collection.props.set({ignore:+new Date})}catch(e){console.log(e)}else if((c=o(i=e(".media-modal-content"))).browser.length>0&&"object"==typeof c.view)try{c.view.collection.props.set({ignore:+new Date})}catch(e){console.log(e)}e(".attachments").css("height","auto"),e(".mediabay_be_loader").removeClass("active")}function o(t){var a,i,o=t.parents(".media-modal");return i=(a=o.length>0?o.find(".attachments-browser"):e("#wpbody-content .attachments-browser")).data("backboneView"),{browser:a,view:i}}function c(){var t=e(".mediabay-editcategory-filter"),a=t.val();localStorage.setItem("mediabayModalActiveFolder",a),"menu-item-browse"===e(".media-frame-content").attr("aria-labelledby")&&(a=e(".wpmediacategory-filter").val(),localStorage.setItem("mediabayModalActiveFolder",a)),t.on("change",function(){a=this.value,localStorage.setItem("mediabayModalActiveFolder",a)}),e(".wpmediacategory-filter").on("change",function(){a=this.value,"menu-item-browse"===e(".media-frame-content").attr("aria-labelledby")&&localStorage.setItem("mediabayModalActiveFolder",a)})}e(document).ready(function(){var o=window.wp;localStorage.setItem("mediabayModalActiveFolder",""),o.media&&o.media.view.Modal.prototype.on("open",function(){e(".media-menu-item").on("click",function(){setTimeout(function(){c()},3)}),c()}),void 0!==o&&"function"==typeof o.Uploader&&e.extend(o.Uploader.prototype,{progress:function(){},init:function(){this.uploader&&(this.uploader.bind("FileFiltered",function(e,t){}),this.uploader.bind("BeforeUpload",function(t,a){var i;i=""!==localStorage.getItem("mediabayModalActiveFolder")?Number(localStorage.getItem("mediabayModalActiveFolder")):Number(e(".wpmediacategory-filter").val()),t.settings.multipart_params.ccFolder=i}),this.uploader.bind("UploadProgress",function(a,i){e(".uploader-window").hide().css("opacity",0),t()}),this.uploader.bind("UploadComplete",function(t,a){""!==localStorage.getItem("mediabayModalActiveFolder")?(i(localStorage.getItem("mediabayModalActiveFolder")),c()):i(e(".wpmediacategory-filter").val())}),this.uploader.bind("FilesAdded",function(t,i){var o;o=""!==localStorage.getItem("mediabayModalActiveFolder")?localStorage.getItem("mediabayModalActiveFolder"):(e(".media-frame-content").attr("aria-labelledby"),e(".wpmediacategory-filter").val()),i.forEach(function(e){"all"===o?a(null,-1):-1===Number(o)?a(null,-1):a(null,o)})}))}})}),jQuery(document).ajaxSend(function(t,a,i){try{if(i.data.indexOf("action=delete-post")>-1){var o={attachmentID:i.context.id,action:"mediabayAjaxCheckDeletingMedia",ajaxNonce:mediabayConfig.nonce};jQuery.ajax({type:"POST",data:o,url:ajaxurl,success:function(t){var a=jQuery.parseJSON(t),i=a.terms,o=a.error,c="";"no"===o&&(i.length&&(e.each(i,function(e,t){c+=t.term_id+","}),c=c.slice(0,c.length-1)),e("#mediabay_hidden_terms").val(c))}})}}catch(t){}}.bind(this)),jQuery(document).ajaxComplete(function(t,a,i){try{if(i.data.indexOf("action=delete-post")>-1){var o=e("#mediabay_hidden_terms").val();if(o){var c=o.split(",");e.each(c,function(t,a){!function(t){var a=e('ul li.category_item[data-id="'+t+'"] .cc_count').text();a=parseInt(a)-1,e('ul li.category_item[data-id="'+t+'"] .cc_count').text(a);var i=e('ul li.category_item[data-id="all"] .cc_count').text();i=parseInt(i)-1,e('ul li.category_item[data-id="all"] .cc_count').text(i)}(a)})}}}catch(t){}}.bind(this))}(jQuery),function(e){"use strict";var t={uploadMedia:function(){e("body").hasClass("media-new-php")&&setTimeout(function(){uploader&&uploader.bind("BeforeUpload",function(t,a){t.settings.multipart_params.ccFolder=e(".mediabay-editcategory-filter").val()})}.bind(this),500)}};e(document).ready(function(){window.wp;t.uploadMedia()})}(jQuery);