12 |
- /* Tabulator v4.8.2 (c) Oliver Folkerd */
- var Menu=function(e){this.table=e,this.menuEl=!1,this.blurEvent=this.hideMenu.bind(this),this.escEvent=this.escMenu.bind(this),this.nestedMenuBlock=!1};Menu.prototype.initializeColumnHeader=function(e){var t,n=this;e.definition.headerContextMenu&&(e.getElement().addEventListener("contextmenu",this.LoadMenuEvent.bind(this,e,e.definition.headerContextMenu)),this.tapHold(e,e.definition.headerContextMenu)),e.definition.headerMenu&&(t=document.createElement("span"),t.classList.add("tabulator-header-menu-button"),t.innerHTML="⋮",t.addEventListener("click",function(t){var i="function"==typeof e.definition.headerMenu?e.definition.headerMenu(e.getComponent(),t):e.definition.headerMenu;t.stopPropagation(),t.preventDefault(),n.loadMenu(t,e,i)}),e.titleElement.insertBefore(t,e.titleElement.firstChild))},Menu.prototype.LoadMenuEvent=function(e,t,n){t="function"==typeof t?t(e.getComponent(),n):t,this.loadMenu(n,e,t)},Menu.prototype.tapHold=function(e,t){var n=this,i=e.getElement(),o=null,u=!1;i.addEventListener("touchstart",function(i){clearTimeout(o),u=!1,o=setTimeout(function(){clearTimeout(o),o=null,u=!0,n.LoadMenuEvent(e,t,i)},1e3)},{passive:!0}),i.addEventListener("touchend",function(e){clearTimeout(o),o=null,u&&e.preventDefault()})},Menu.prototype.initializeCell=function(e){e.column.definition.contextMenu&&(e.getElement().addEventListener("contextmenu",this.LoadMenuEvent.bind(this,e,e.column.definition.contextMenu)),this.tapHold(e,e.column.definition.contextMenu)),e.column.definition.clickMenu&&e.getElement().addEventListener("click",this.LoadMenuEvent.bind(this,e,e.column.definition.clickMenu))},Menu.prototype.initializeRow=function(e){this.table.options.rowContextMenu&&(e.getElement().addEventListener("contextmenu",this.LoadMenuEvent.bind(this,e,this.table.options.rowContextMenu)),this.tapHold(e,this.table.options.rowContextMenu)),this.table.options.rowClickMenu&&e.getElement().addEventListener("click",this.LoadMenuEvent.bind(this,e,this.table.options.rowClickMenu))},Menu.prototype.initializeGroup=function(e){this.table.options.groupContextMenu&&(e.getElement().addEventListener("contextmenu",this.LoadMenuEvent.bind(this,e,this.table.options.groupContextMenu)),this.tapHold(e,this.table.options.groupContextMenu)),this.table.options.groupClickMenu&&e.getElement().addEventListener("click",this.LoadMenuEvent.bind(this,e,this.table.options.groupClickMenu))},Menu.prototype.loadMenu=function(e,t,n){var i=this,o=Math.max(document.body.offsetHeight,window.innerHeight),u=!(e instanceof MouseEvent);if(u||e.preventDefault(),n&&n.length){if(this.nestedMenuBlock){if(this.isOpen())return}else this.nestedMenuBlock=setTimeout(function(){i.nestedMenuBlock=!1},100);this.hideMenu(),this.menuEl=document.createElement("div"),this.menuEl.classList.add("tabulator-menu"),n.forEach(function(e){var n=document.createElement("div"),o=e.label,u=e.disabled;e.separator?n.classList.add("tabulator-menu-separator"):(n.classList.add("tabulator-menu-item"),"function"==typeof o&&(o=o(t.getComponent())),o instanceof Node?n.appendChild(o):n.innerHTML=o,"function"==typeof u&&(u=u(t.getComponent())),u?(n.classList.add("tabulator-menu-item-disabled"),n.addEventListener("click",function(e){e.stopPropagation()})):n.addEventListener("click",function(n){i.hideMenu(),e.action(n,t.getComponent())})),i.menuEl.appendChild(n)}),this.menuEl.style.top=(u?e.touches[0].pageY:e.pageY)+"px",this.menuEl.style.left=(u?e.touches[0].pageX:e.pageX)+"px",setTimeout(function(){i.table.rowManager.element.addEventListener("scroll",i.blurEvent),document.body.addEventListener("click",i.blurEvent),document.body.addEventListener("contextmenu",i.blurEvent),document.body.addEventListener("keydown",i.escEvent)},100),document.body.appendChild(this.menuEl),e.pageX+this.menuEl.offsetWidth>=document.body.offsetWidth&&(this.menuEl.style.left="",this.menuEl.style.right=document.body.offsetWidth-e.pageX+"px"),e.pageY+this.menuEl.offsetHeight>=o&&(this.menuEl.style.top="",this.menuEl.style.bottom=o-e.pageY+"px")}},Menu.prototype.isOpen=function(){return!!this.menuEl.parentNode},Menu.prototype.escMenu=function(e){27==e.keyCode&&this.hideMenu()},Menu.prototype.hideMenu=function(){this.menuEl.parentNode&&this.menuEl.parentNode.removeChild(this.menuEl),this.escEvent&&document.body.removeEventListener("keydown",this.escEvent),this.blurEvent&&(document.body.removeEventListener("click",this.blurEvent),document.body.removeEventListener("contextmenu",this.blurEvent),this.table.rowManager.element.removeEventListener("scroll",this.blurEvent))},Menu.prototype.menus={},Tabulator.prototype.registerModule("menu",Menu);
|