(function(h,a,t,e){"use strict";var c=function(t){this.$table=t,this.id=t.attr("id"),this.$filters=[],this.$tableWrapper=[],this.$pagination=[],this.hasAdminBar=0<h("#wpadminbar").length,this.ajaxData=[],this.buildConfig=this.buildConfig.bind(this),this.getDataTable=this.getDataTable.bind(this),this.initClickSearch=this.initClickSearch.bind(this),this.initFilters=this.initFilters.bind(this),this.initPhotoswipe=this.initPhotoswipe.bind(this),this.initResetButton=this.initResetButton.bind(this),this.processAjaxData=this.processAjaxData.bind(this),this.scrollToTop=this.scrollToTop.bind(this),this.showHidePagination=this.showHidePagination.bind(this),t.on("draw.dt",{table:this},this.onDraw),t.on("init.dt",{table:this},this.onInit),t.on("page.dt",{table:this},this.onPage),t.on("processing.dt",{table:this},this.onProcessing),t.on("responsive-display.dt",{table:this},this.onResponsiveDisplay),t.on("xhr.dt",{table:this},this.onAjaxLoad),h(a).on("load",{table:this},this.onWindowLoad),t.addClass("loading").css("visibility","visible"),this.getDataTable()};c.blockConfig={message:null,overlayCSS:{background:"#fff",opacity:.6}},c.addRowAttributes=function(e){return function(t,a){"class"===t?e.addClass(a):e.attr(t,a)}},c.appendFilterOptions=function(s,t,r){r=void 0!==r?r:0,h.each(t,function(t,a){var e=a.name,i="slug"in a?a.slug:e,n="";r&&(n=Array(2*r+1).join(" ")+"– "),s.append('<option value="'+i+'">'+n+e+"</option>"),"children"in a&&c.appendFilterOptions(s,a.children,r+1)})},c.initMedia=function(t){t&&t.length&&("undefined"!=typeof WPPlaylistView&&t.find(".wp-playlist").filter(function(){return 0===h(".mejs-container",this).length}).each(function(){return new WPPlaylistView({el:this})}),"wp"in a&&"mediaelement"in a.wp&&h(a.wp.mediaelement.initialize),h.fn.fitVids&&t.fitVids())},c.responsiveRendererTableAll=function(e,t,a){var i="",n=h.map(a,function(t,a){return i=t.title?t.title+":":"",e.column(t.columnIndex).visible()?'<tr data-dt-row="'+t.rowIndex+'" data-dt-column="'+t.columnIndex+'"><td>'+i+'</td><td class="child">'+t.data+"</td></tr>":""}).join("");if(n){var s=h('<table class="posts-data-table modal-table" />').append(n);return c.initMedia(s),s}return!1},c.prototype.buildConfig=function(){if(this.config)return this.config;var t={retrieve:!0,responsive:!0,processing:!0,orderMulti:!1,language:posts_table_params.language},a=this.$table.data("config");return a&&(t=h.extend(!0,{},t,a)),t.serverSide&&"ajax_url"in posts_table_params&&(t.deferRender=!0,t.ajax={url:posts_table_params.ajax_url,type:"POST",data:{table_id:this.id,action:"ptp_load_posts",_ajax_nonce:posts_table_params.ajax_nonce},xhrFields:{withCredentials:!0}}),"object"==typeof t.responsive.details&&"display"in t.responsive.details&&("child_row_visible"===t.responsive.details.display&&(t.responsive.details.display=h.fn.dataTable.Responsive.display.childRowImmediate,t.responsive.details.renderer=h.fn.dataTable.Responsive.renderer.listHidden()),"modal"===t.responsive.details.display&&(t.responsive.details.display=h.fn.dataTable.Responsive.display.modal(),t.responsive.details.renderer=c.responsiveRendererTableAll)),"lang_url"in posts_table_params&&(t.language={url:posts_table_params.lang_url}),t},c.prototype.getDataTable=function(){return this.dataTable||(this.config=this.buildConfig(),this.dataTable=this.$table.DataTable(this.config)),this.dataTable},c.prototype.initFilters=function(){var t=this,a=t.$table.data("filters");if(!a)return t;var e=t.getDataTable(),i=0,n=h('<div class="posts-table-select-filters" id="'+t.id+'_select_filters"><label class="filter-label">'+posts_table_params.language.filterBy+"</label></div>");for(var s in a){var r=h('<select name="ptp_filter_'+s+'" data-column="'+s+'" data-tax="'+a[s].taxonomy+'" data-search-column="'+s+'_hfilter" aria-label="'+a[s].heading+'"></select>').append('<option value="">'+a[s].heading+"</option>").on("change",{table:t},t.onFilterChange),l=a[s].terms;if(!t.config.serverSide){var o=e.column(r.data("searchColumn")+":name").data();if(o.any()){var d=o.join(" ").split(" ");l=h.grep(l,function(t,a){return"children"in t||-1<d.indexOf(t.slug)})}}l.length&&(c.appendFilterOptions(r,l),r.appendTo(n),i++)}if(0<i){var p=t.$tableWrapper.find(".dataTables_filter");p.length?n.prependTo(p.closest(".posts-table-controls")):n.prependTo(t.$tableWrapper.children(".posts-table-above"))}return t.$filters=t.$tableWrapper.find(".posts-table-select-filters select"),t},c.prototype.initPhotoswipe=function(){return this.$table.on("click",".posts-table-gallery__image a",this.onOpenPhotoswipe),this},c.prototype.initResetButton=function(){var t=this;if(!t.config.resetButton)return t;t.getDataTable();var a=h('<span class="posts-table-reset"><a class="reset" href="#">'+posts_table_params.language.resetButton+"</a></span>").on("click","a",{table:t},this.onReset),e=t.$tableWrapper.find(".dataTables_filter");if(t.$filters.length)a.appendTo(t.$tableWrapper.find(".posts-table-select-filters"));else if(e.length)a.prependTo(e);else{var i=t.$tableWrapper.children("div.posts-table-above").children(".dataTables_length,.dataTables_info").eq(0);i.length?a.appendTo(i):a.prependTo(t.$tableWrapper.children("div.posts-table-above"))}return t},c.prototype.processAjaxData=function(){var t=this;if(t.config.serverSide&&t.ajaxData.length){for(var a=t.$table.find("tbody tr"),e=0;e<t.ajaxData.length;e++)"__attributes"in t.ajaxData[e]&&a.eq(e).length&&h.each(t.ajaxData[e].__attributes,c.addRowAttributes(a.eq(e)));return t}},c.prototype.initClickSearch=function(){return this.config.clickFilter&&this.$table.on("click","a",{table:this},this.onClickSearch),this},c.prototype.scrollToTop=function(){var t=this.config.scrollOffset;if(!1!==t&&!isNaN(t)){var a=this.$tableWrapper.offset().top-t;this.hasAdminBar&&(a-=32),h("html,body").animate({scrollTop:a},300)}return this},c.prototype.showHidePagination=function(){if(this.$pagination.length){var t=this.getDataTable().page.info();t&&t.pages<=1?this.$pagination.hide(0):this.$pagination.show()}return this},c.prototype.onAjaxLoad=function(t,a,e,i){var n=t.data.table;null!==e&&"data"in e&&h.isArray(e.data)&&(n.ajaxData=e.data),n.$table.trigger("lazyload.ptp",[n])},c.prototype.onClickSearch=function(t){var a=h(this),e=t.data.table,i=e.getDataTable(),n=a.closest("td");n.hasClass("child")&&(n=a.closest("li[data-dt-row]",n));var s=i.column(n.get(0));if(s.any()&&h(s.header()).data("clickFilter")){t.stopImmediatePropagation();var r=a.text(),l=h(s.header()).data("name"),o=e.$filters?e.$filters.filter('[data-column="'+l+'"]'):[];o.length&&(i.column(o.data("searchColumn")+":name").search(""),h("option",o).filter(function(){return h.trim(h(this).text().replace("–",""))===r}).prop("selected",!0));var d=h.fn.dataTable.util.escapeRegex(r);return e.config.serverSide||(d=d?"(^|,)"+d+"(, |$)":""),s.search(d,!0,!1).draw(),t.data.table.scrollToTop(),!1}return!0},c.prototype.onDraw=function(t){var a=t.data.table;a.config.serverSide&&a.processAjaxData(),!a.config.serverSide&&a.$table.hasClass("loading")||c.initMedia(a.$table),a.showHidePagination(),a.$table.trigger("draw.ptp",[a])},c.prototype.onFilterChange=function(t){var a=t.data.table,e=h(this).val();a.config.serverSide||(e=e?"(^|)"+e+"(|$)":""),a.getDataTable().column(h(this).data("column")+":name").search("").column(h(this).data("searchColumn")+":name").search(e,!0,!1).draw()},c.prototype.onInit=function(t){var a=t.data.table;a.$tableWrapper=a.$table.parent(),a.$pagination=a.$tableWrapper.find(".dataTables_paginate"),a.initClickSearch().initFilters().initResetButton().initPhotoswipe().showHidePagination(),!a.config.serverSide&&h.fn.fitVids&&a.$table.fitVids(),a.$table.removeClass("loading").trigger("init.ptp",[a])},c.prototype.onOpenPhotoswipe=function(t){t.preventDefault();var a=h(".pswp")[0],e=h(t.target).closest(".posts-table-gallery__image"),n=[];0<e.length&&e.each(function(t,a){var e=h(a).find("img"),i={src:e.attr("data-large_image"),w:e.attr("data-large_image_width"),h:e.attr("data-large_image_height"),title:e.attr("data-caption")&&e.attr("data-caption").length?e.attr("data-caption"):e.attr("title")};n.push(i)});new PhotoSwipe(a,PhotoSwipeUI_Default,n,{index:0,shareEl:!1,closeOnScroll:!1,history:!1,hideAnimationDuration:0,showAnimationDuration:0}).init()},c.prototype.onPage=function(t){t.data.table.scrollToTop()},c.prototype.onProcessing=function(t,a,e){e?t.data.table.$table.block(c.blockConfig):t.data.table.$table.unblock()},c.prototype.onReset=function(t){t.preventDefault();var a=t.data.table,e=a.getDataTable();a.$table.find("tr.child").remove(),a.$table.find("tr.parent").removeClass("parent"),a.$filters.length&&a.$filters.val(""),e.columns('th[data-searchable="true"]').search("");var i=a.$table.attr("data-order");if(i.length){var n=i.replace(/[\[\]\" ]+/g,"").split(",");2===n.length&&e.order(n)}var s="search"in a.config&&"search"in a.config.search?a.config.search.search:"";return e.search(s).page.len(a.config.pageLength).draw(),!1},c.prototype.onResponsiveDisplay=function(t,a,e,i,n){if(i&&void 0!==e.child()){c.initMedia(e.child());var s=t.data.table;s.$table.trigger("responsive-display.ptp",[s,e.child()])}},c.prototype.onWindowLoad=function(t){var a=t.data.table;a.getDataTable().columns.adjust().responsive.recalc(),a.$table.trigger("load.ptp",[a])},h.fn.posts_table=function(){return new c(this),this},h.fn.postsTable=function(){return this.each(function(){new c(h(this))})},h(t).ready(function(){"DataTable"in h.fn&&h.fn.DataTable.ext&&(h.fn.DataTable.ext.errMode="throw"),h(".posts-data-table").postsTable()})})(jQuery,window,document);