table.js
18.4 KB
(()=>{var t={968:t=>{function e(t,e){if(!t)throw new Error(e||"AssertionError")}e.notEqual=function(t,n,i){e(t!=n,i)},e.notOk=function(t,n){e(!t,n)},e.equal=function(t,n,i){e(t==n,i)},e.ok=e,t.exports=e},821:(t,e,n)=>{var i=n(250),s=n(715),r=n(968);function o(t){if(!(this instanceof o))return new o(t);this._name=t||"nanobus",this._starListeners=[],this._listeners={}}t.exports=o,o.prototype.emit=function(t){r.ok("string"==typeof t||"symbol"==typeof t,"nanobus.emit: eventName should be type string or symbol");for(var e=[],n=1,i=arguments.length;n<i;n++)e.push(arguments[n]);var o=s(this._name+"('"+t.toString()+"')"),u=this._listeners[t];return u&&u.length>0&&this._emit(this._listeners[t],e),this._starListeners.length>0&&this._emit(this._starListeners,t,e,o.uuid),o(),this},o.prototype.on=o.prototype.addListener=function(t,e){return r.ok("string"==typeof t||"symbol"==typeof t,"nanobus.on: eventName should be type string or symbol"),r.equal(typeof e,"function","nanobus.on: listener should be type function"),"*"===t?this._starListeners.push(e):(this._listeners[t]||(this._listeners[t]=[]),this._listeners[t].push(e)),this},o.prototype.prependListener=function(t,e){return r.ok("string"==typeof t||"symbol"==typeof t,"nanobus.prependListener: eventName should be type string or symbol"),r.equal(typeof e,"function","nanobus.prependListener: listener should be type function"),"*"===t?this._starListeners.unshift(e):(this._listeners[t]||(this._listeners[t]=[]),this._listeners[t].unshift(e)),this},o.prototype.once=function(t,e){r.ok("string"==typeof t||"symbol"==typeof t,"nanobus.once: eventName should be type string or symbol"),r.equal(typeof e,"function","nanobus.once: listener should be type function");var n=this;return this.on(t,(function i(){e.apply(n,arguments),n.removeListener(t,i)})),this},o.prototype.prependOnceListener=function(t,e){r.ok("string"==typeof t||"symbol"==typeof t,"nanobus.prependOnceListener: eventName should be type string or symbol"),r.equal(typeof e,"function","nanobus.prependOnceListener: listener should be type function");var n=this;return this.prependListener(t,(function i(){e.apply(n,arguments),n.removeListener(t,i)})),this},o.prototype.removeListener=function(t,e){return r.ok("string"==typeof t||"symbol"==typeof t,"nanobus.removeListener: eventName should be type string or symbol"),r.equal(typeof e,"function","nanobus.removeListener: listener should be type function"),"*"===t?(this._starListeners=this._starListeners.slice(),n(this._starListeners,e)):(void 0!==this._listeners[t]&&(this._listeners[t]=this._listeners[t].slice()),n(this._listeners[t],e));function n(t,e){if(t){var n=t.indexOf(e);return-1!==n?(i(t,n,1),!0):void 0}}},o.prototype.removeAllListeners=function(t){return t?"*"===t?this._starListeners=[]:this._listeners[t]=[]:(this._starListeners=[],this._listeners={}),this},o.prototype.listeners=function(t){var e="*"!==t?this._listeners[t]:this._starListeners,n=[];if(e)for(var i=e.length,s=0;s<i;s++)n.push(e[s]);return n},o.prototype._emit=function(t,e,n,i){if(void 0!==t&&0!==t.length){void 0===n&&(n=e,e=null),e&&(n=void 0!==i?[e].concat(n,i):[e].concat(n));for(var s=t.length,r=0;r<s;r++){var o=t[r];o.apply(o,n)}}}},706:(t,e,n)=>{var i=n(968),s="undefined"!=typeof window;function r(t){this.hasWindow=t,this.hasIdle=this.hasWindow&&window.requestIdleCallback,this.method=this.hasIdle?window.requestIdleCallback.bind(window):this.setTimeout,this.scheduled=!1,this.queue=[]}r.prototype.push=function(t){i.equal(typeof t,"function","nanoscheduler.push: cb should be type function"),this.queue.push(t),this.schedule()},r.prototype.schedule=function(){if(!this.scheduled){this.scheduled=!0;var t=this;this.method((function(e){for(;t.queue.length&&e.timeRemaining()>0;)t.queue.shift()(e);t.scheduled=!1,t.queue.length&&t.schedule()}))}},r.prototype.setTimeout=function(t){setTimeout(t,0,{timeRemaining:function(){return 1}})},t.exports=function(){var t;return s?(window._nanoScheduler||(window._nanoScheduler=new r(!0)),t=window._nanoScheduler):t=new r,t}},715:(t,e,n)=>{var i,s=n(706)(),r=n(968);o.disabled=!0;try{i=window.performance,o.disabled="true"===window.localStorage.DISABLE_NANOTIMING||!i.mark}catch(t){}function o(t){if(r.equal(typeof t,"string","nanotiming: name should be type string"),o.disabled)return u;var e=(1e4*i.now()).toFixed()%Number.MAX_SAFE_INTEGER,n="start-"+e+"-"+t;function a(r){var o="end-"+e+"-"+t;i.mark(o),s.push((function(){var s=null;try{var u=t+" ["+e+"]";i.measure(u,n,o),i.clearMarks(n),i.clearMarks(o)}catch(t){s=t}r&&r(s,t)}))}return i.mark(n),a.uuid=e,a}function u(t){t&&s.push((function(){t(new Error("nanotiming: performance API unavailable"))}))}t.exports=o},250:t=>{"use strict";t.exports=function(t,e,n){var i,s=t.length;if(!(e>=s||0===n)){var r=s-(n=e+n>s?s-e:n);for(i=e;i<r;++i)t[i]=t[i+n];t.length=r}}},513:t=>{function e(t,e){if(!t)throw new Error(e||"AssertionError")}e.notEqual=function(t,n,i){e(t!=n,i)},e.notOk=function(t,n){e(!t,n)},e.equal=function(t,n,i){e(t==n,i)},e.ok=e,t.exports=e},891:(t,e,n)=>{var i=n(212),s=n(595),r=n(513);function o(t){if(!(this instanceof o))return new o(t);this._name=t||"nanobus",this._starListeners=[],this._listeners={}}t.exports=o,o.prototype.emit=function(t){r.ok("string"==typeof t||"symbol"==typeof t,"nanobus.emit: eventName should be type string or symbol");for(var e=[],n=1,i=arguments.length;n<i;n++)e.push(arguments[n]);var o=s(this._name+"('"+t.toString()+"')"),u=this._listeners[t];return u&&u.length>0&&this._emit(this._listeners[t],e),this._starListeners.length>0&&this._emit(this._starListeners,t,e,o.uuid),o(),this},o.prototype.on=o.prototype.addListener=function(t,e){return r.ok("string"==typeof t||"symbol"==typeof t,"nanobus.on: eventName should be type string or symbol"),r.equal(typeof e,"function","nanobus.on: listener should be type function"),"*"===t?this._starListeners.push(e):(this._listeners[t]||(this._listeners[t]=[]),this._listeners[t].push(e)),this},o.prototype.prependListener=function(t,e){return r.ok("string"==typeof t||"symbol"==typeof t,"nanobus.prependListener: eventName should be type string or symbol"),r.equal(typeof e,"function","nanobus.prependListener: listener should be type function"),"*"===t?this._starListeners.unshift(e):(this._listeners[t]||(this._listeners[t]=[]),this._listeners[t].unshift(e)),this},o.prototype.once=function(t,e){r.ok("string"==typeof t||"symbol"==typeof t,"nanobus.once: eventName should be type string or symbol"),r.equal(typeof e,"function","nanobus.once: listener should be type function");var n=this;return this.on(t,(function i(){e.apply(n,arguments),n.removeListener(t,i)})),this},o.prototype.prependOnceListener=function(t,e){r.ok("string"==typeof t||"symbol"==typeof t,"nanobus.prependOnceListener: eventName should be type string or symbol"),r.equal(typeof e,"function","nanobus.prependOnceListener: listener should be type function");var n=this;return this.prependListener(t,(function i(){e.apply(n,arguments),n.removeListener(t,i)})),this},o.prototype.removeListener=function(t,e){return r.ok("string"==typeof t||"symbol"==typeof t,"nanobus.removeListener: eventName should be type string or symbol"),r.equal(typeof e,"function","nanobus.removeListener: listener should be type function"),"*"===t?(this._starListeners=this._starListeners.slice(),n(this._starListeners,e)):(void 0!==this._listeners[t]&&(this._listeners[t]=this._listeners[t].slice()),n(this._listeners[t],e));function n(t,e){if(t){var n=t.indexOf(e);return-1!==n?(i(t,n,1),!0):void 0}}},o.prototype.removeAllListeners=function(t){return t?"*"===t?this._starListeners=[]:this._listeners[t]=[]:(this._starListeners=[],this._listeners={}),this},o.prototype.listeners=function(t){var e="*"!==t?this._listeners[t]:this._starListeners,n=[];if(e)for(var i=e.length,s=0;s<i;s++)n.push(e[s]);return n},o.prototype._emit=function(t,e,n,i){if(void 0!==t&&0!==t.length){void 0===n&&(n=e,e=null),e&&(n=void 0!==i?[e].concat(n,i):[e].concat(n));for(var s=t.length,r=0;r<s;r++){var o=t[r];o.apply(o,n)}}}},746:(t,e,n)=>{var i=n(513),s="undefined"!=typeof window;function r(t){this.hasWindow=t,this.hasIdle=this.hasWindow&&window.requestIdleCallback,this.method=this.hasIdle?window.requestIdleCallback.bind(window):this.setTimeout,this.scheduled=!1,this.queue=[]}r.prototype.push=function(t){i.equal(typeof t,"function","nanoscheduler.push: cb should be type function"),this.queue.push(t),this.schedule()},r.prototype.schedule=function(){if(!this.scheduled){this.scheduled=!0;var t=this;this.method((function(e){for(;t.queue.length&&e.timeRemaining()>0;)t.queue.shift()(e);t.scheduled=!1,t.queue.length&&t.schedule()}))}},r.prototype.setTimeout=function(t){setTimeout(t,0,{timeRemaining:function(){return 1}})},t.exports=function(){var t;return s?(window._nanoScheduler||(window._nanoScheduler=new r(!0)),t=window._nanoScheduler):t=new r,t}},595:(t,e,n)=>{var i,s=n(746)(),r=n(513);o.disabled=!0;try{i=window.performance,o.disabled="true"===window.localStorage.DISABLE_NANOTIMING||!i.mark}catch(t){}function o(t){if(r.equal(typeof t,"string","nanotiming: name should be type string"),o.disabled)return u;var e=(1e4*i.now()).toFixed()%Number.MAX_SAFE_INTEGER,n="start-"+e+"-"+t;function a(r){var o="end-"+e+"-"+t;i.mark(o),s.push((function(){var s=null;try{var u=t+" ["+e+"]";i.measure(u,n,o),i.clearMarks(n),i.clearMarks(o)}catch(t){s=t}r&&r(s,t)}))}return i.mark(n),a.uuid=e,a}function u(t){t&&s.push((function(){t(new Error("nanotiming: performance API unavailable"))}))}t.exports=o},212:t=>{"use strict";t.exports=function(t,e,n){var i,s=t.length;if(!(e>=s||0===n)){var r=s-(n=e+n>s?s-e:n);for(i=e;i<r;++i)t[i]=t[i+n];t.length=r}}}},e={};function n(i){var s=e[i];if(void 0!==s)return s.exports;var r=e[i]={exports:{}};return t[i](r,r.exports,n),r.exports}n.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return n.d(e,{a:e}),e},n.d=(t,e)=>{for(var i in e)n.o(e,i)&&!n.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:e[i]})},n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),(()=>{"use strict";var t=n(891),e=n.n(t);const i=function(){function t(t){this.element=t,this.state=!1,this.events=new(e()),this.init()}return t.prototype.init=function(){var t=this;this.determinScreenOptionState(),this.element.addEventListener("click",(function(){t.determinScreenOptionState(),t.persist()}))},t.prototype.isEnabled=function(){return this.element.checked},t.prototype.determinScreenOptionState=function(){this.isEnabled()?this.enable():this.disable()},t.prototype.enable=function(){this.state=!0,this.events.emit("changeState",!0)},t.prototype.disable=function(){this.state=!1,this.events.emit("changeState",!1)},t.prototype.persist=function(){jQuery.post(ajaxurl,{action:"acp_new_inline_show_button",value:this.state,layout:AC.layout,list_screen:AC.list_screen,_ajax_nonce:AC.ajax_nonce})},t}(),s=function(){function t(t){this.element=t}return t.find=function(e){var n=document.querySelector(e);return null===n?null:new t(n)},t.create=function(e){return new t(document.createElement(e))},t.prototype.getElement=function(){return this.element},t.prototype.addId=function(t){return this.element.id=t,this},t.prototype.toggleClass=function(t,e){return void 0===e&&(e=null),null===e?this.element.classList.contains(t)?this.removeClass(t):this.addClass(t):e?this.addClass(t):this.removeClasses(t)},t.prototype.addClass=function(t){return this.element.classList.add(t),this},t.prototype.addClasses=function(){for(var t=this,e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return e.forEach((function(e){return t.addClass(e)})),this},t.prototype.removeClasses=function(){for(var t=this,e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return e.forEach((function(e){return t.removeClass(e)})),this},t.prototype.removeClass=function(t){return this.element.classList.remove(t),this},t.prototype.setAttribute=function(t,e){return this.element.setAttribute(t,e),this},t.prototype.setAttributes=function(t){var e=this;return Object.keys(t).forEach((function(n){return e.setAttribute(n,t[n])})),this},t.prototype.addHtml=function(t){return this.element.innerHTML=t,this},t.prototype.append=function(t){return this.element.appendChild(t),this},t.prototype.appendSelfTo=function(t){return t.append(this.element),this},t.prototype.prepend=function(t){return this.element.prepend(t),this},t.prototype.prependSelfTo=function(t){return t.prepend(this.element),this},t.prototype.css=function(t,e){return this.element.style[t]=e,this},t.prototype.insertAfter=function(t){var e;try{null===(e=this.element.parentElement)||void 0===e||e.insertBefore(t,this.element.nextElementSibling)}catch(t){console.error("Not able to insert element after current node",this.element)}},t.prototype.insertSelfBefore=function(t){var e;try{null===(e=t.parentElement)||void 0===e||e.insertBefore(this.element,t)}catch(t){console.error("Not able to insert element before current node",this.element)}return this},t.prototype.insertBefore=function(t){var e;try{null===(e=this.element.parentElement)||void 0===e||e.insertBefore(t,this.element)}catch(t){console.error("Not able to insert element before current node",this.element)}return this},t.prototype.addEventListener=function(t,e){return this.element.addEventListener(t,e),this},t.prototype.addEventListeners=function(t,e){var n=this;return t.forEach((function(t){return n.addEventListener(t,e)})),this},t}();var r=function(){function t(t){this.el=t,this.visible=!0}return t.prototype.toggle=function(t){return this.visible=t,this},t.prototype.isHidden=function(){return!this.visible},t.prototype.getElement=function(){return new s(this.el)},t.prototype.setTooltip=function(t){return this.el.dataset.acTip=t,this},t.createWithMarkup=function(e,n){return new t(s.create("a").setAttribute("data-slug",e).addClasses("ac-table-button").addHtml(n).getElement())},t}(),o=function(){function t(t){this.data=t}return t.prototype.add=function(t,e){e in this.data||(this.data[e]=[]),this.data[e].push(t)},t.prototype.getById=function(t){this.getButtons().find((function(e){return e.getElement().getElement().id===t}))},t.prototype.getButtons=function(){var t=this,e=[];return Object.keys(this.data).forEach((function(n){t.data[parseInt(n)].forEach((function(t){e.push(t)}))})),e},t.prototype.getReversedButtons=function(){return this.getButtons().reverse()},t}();!function(){function t(t){this.container=t,this.buttons=new o({}),this.init()}t.prototype.getButton=function(t){return this.buttons.getById(t)},t.prototype.addButton=function(t,e){this.buttons.add(t,e)},t.prototype.init=function(){var t=this;this.container.addEventListener("update",(function(){t.refresh()})),document.querySelectorAll(".tablenav.top .actions").forEach((function(e){var n,i,s;n=t.container,null===(s=null==(i=e)?void 0:i.parentNode)||void 0===s||s.insertBefore(n,i.nextSibling),t.container.classList.add("-init")})),this.container.querySelectorAll(".ac-table-actions-buttons .ac-table-button").forEach((function(e){var n,i,s=new r(e);e.offsetParent||(s.toggle(!1),s.getElement().getElement().remove()),t.addButton(s,parseInt(null!==(i=null===(n=e.dataset)||void 0===n?void 0:n.priority)&&void 0!==i?i:"10"))}))},t.prototype.getElement=function(){return this.container},t.prototype.refresh=function(){var t=this;this.buttons.getButtons().forEach((function(e){var n;e.isHidden()?e.getElement().getElement().remove():null===(n=t.container.querySelector(".ac-table-actions-buttons"))||void 0===n||n.append(e.getElement().getElement())}))}}();const u=function(){function t(t){this.actions=t,this.element=this.createElement(),this.state=!0,this.events=new(e()),this.initEvents(),this.placeElement()}return t.prototype.placeElement=function(){this.actions.addButton(new r(this.element),5),this.actions.refresh()},t.prototype.initEvents=function(){var t=this;this.element.addEventListener("click",(function(e){e.preventDefault(),t.state&&t.events.emit("click")}))},t.prototype.getElement=function(){return this.element},t.prototype.hide=function(){this.getElement().style.display="none",this.actions.refresh()},t.prototype.show=function(){this.getElement().style.display="inline-block",this.actions.refresh()},t.prototype.enable=function(){this.show(),this.state=!0},t.prototype.disable=function(){this.hide(),this.state=!1},t.prototype.createElement=function(){var t=document.createElement("a");return t.classList.add("ac-table-button"),t.classList.add("ac-add-new-inline"),t.id="ac-button-add-new-inline",t.innerText=ACP_ADD_NEW_INLINE.i18n.add_new,t},t}();var a=n(821),l=n.n(a);const h=function(){function t(){this.filters={}}return t.prototype.addFilter=function(t,e,n){void 0===n&&(n=10),this.filters.hasOwnProperty(t)||(this.filters[t]={}),this.filters[t].hasOwnProperty(n)||(this.filters[t][n]=[]),this.filters[t][n].push(e)},t.prototype.applyFilters=function(t,e,n){var i=this;return void 0===n&&(n={}),this.filters.hasOwnProperty(t)?(Object.keys(this.filters[t]).forEach((function(s){i.filters[t][parseInt(s)].forEach((function(t){e=t(e,n)}))})),e):e},t}(),c=function(){function t(){this.services={},this.events=new(l()),this.filters=new h,this.$=s}return t.prototype.registerService=function(t,e){return this.services[t]=e,this.events.emit("Service.Registered."+t,e),this},t.prototype.getService=function(t){return this.hasService(t)?this.services[t]:null},t.prototype.hasService=function(t){return this.services.hasOwnProperty(t)},t.prototype.addListener=function(t,e){this.events.addListener(t,e)},t.prototype.emitEvent=function(t,e){this.events.emit(t,e)},t}();var p=function(){return window.AC_SERVICES||(window.AC_SERVICES=new c),window.AC_SERVICES},d=p();const f=function(){function t(t){this.loading=!1,this.createButton=new u(t),this.screenOption=null;var e=document.getElementById("acp_new_inline_show_button-1");e&&(this.screenOption=new i(e)),this.initEvents()}return t.prototype.initEvents=function(){var t=this;this.screenOption&&!this.screenOption.isEnabled()&&this.createButton.disable(),this.screenOption&&this.screenOption.events.addListener("changeState",(function(e){e?t.createButton.enable():t.createButton.disable()})),this.createButton.events.addListener("click",(function(){t.addNew()}))},t.prototype.addNew=function(){var t=this;this.loading||(this.loading=!0,jQuery.post(window.location.href,{ac_action:"acp_add_new_inline",_ajax_nonce:AC.ajax_nonce,list_screen:AC.list_screen,layout:AC.layout}).done((function(t){if(t&&t.success&&t.data.hasOwnProperty("row")){var e=jQuery(t.data.row);jQuery("table.wp-list-table tbody").prepend(e),e.hide(),e.fadeIn(),d.getService("Table").updateRow(e[0]),d.hasService("Editing")&&d.getService("Editing").hasService("InlineEdit")&&d.getService("Editing").getService("InlineEdit").initRow(t.data.id)}})).always((function(){t.loading=!1})))},t}();var y=p();y.addListener("Table.Ready",(function(t){y.registerService("AddNewInline",new f(t.table.Actions))}))})()})();