jspanel4
Version:
A JavaScript library to create highly configurable multifunctional floating panels that can also be used as modal, tooltip, hint or contextmenu
1 lines • 3.33 kB
JavaScript
import{jsPanel}from"../../jspanel.js";if(!jsPanel.dock){jsPanel.dock={version:"1.1.3",date:"2020-06-04 08:38",defaults:{position:{my:"left-top",at:"right-top"},linkSlaveHeight:!1,linkSlaveWidth:!1,callback:!1}};const e=function(e){let i,s=this;if(this.slaveconfig=Object.assign({},jsPanel.dock.defaults,e),!(i=this.slaveconfig.master&&1===this.slaveconfig.master.nodeType?this.slaveconfig.master:document.querySelector(this.slaveconfig.master))){if(this.errorReporting){let e="◀ COULD NOT DOCK PANEL ►<br>The configured master panel to does not exist";jsPanel.errorpanel(e)}return!1}i.slaves||(i.slaves=new Set),i.handlers||(i.handlers={}),i.handlers.fronted||(i.options.onfronted.push(()=>{let e=i.style.zIndex;return i.slaves.forEach(i=>{i.style.zIndex=e}),!0}),i.handlers.fronted=!0),i.handlers.smallified||(i.options.onsmallified.push(()=>(i.slaves.forEach(e=>{e.smallify().reposition()}),!0)),i.handlers.smallified=!0),i.handlers.unsmallified||(i.options.onunsmallified.push(()=>(i.slaves.forEach(e=>{e.unsmallify().reposition()}),!0)),i.handlers.unsmallified=!0),i.handlers.closed||(i.options.onclosed.push(()=>(i.slaves.forEach(e=>{e.close()}),!0)),i.handlers.closed=!0),i.handlers.minimized||(i.options.onminimized.push(()=>(i.slaves.forEach(e=>{e.minimize()}),!0)),i.handlers.minimized=!0),i.handlers.maximized||(i.options.onmaximized.push(()=>(i.slaves.forEach(e=>{if(e.normalize(),e.slaveconfig.linkSlaveHeight){let s=window.getComputedStyle(i).height;e.resize({height:s})}if(e.slaveconfig.linkSlaveWidth){let s=window.getComputedStyle(i).width;e.resize({width:s})}e.reposition()}),!0)),i.handlers.maximized=!0),i.handlers.normalized||(i.options.onnormalized.push(()=>(i.slaves.forEach(e=>{if(e.normalize(),e.slaveconfig.linkSlaveHeight){let s=window.getComputedStyle(i).height;e.resize({height:s})}if(e.slaveconfig.linkSlaveWidth){let s=window.getComputedStyle(i).width;e.resize({width:s})}e.reposition()}),!0)),i.handlers.normalized=!0);let t=Object.assign({},this.slaveconfig.position,{of:i,minLeft:!1,minTop:!1,maxLeft:!1,maxTop:!1,autoposition:!1,modify:!1});if(t.my||(t.my=jsPanel.dock.defaults.position.my),t.at||(t.at=jsPanel.dock.defaults.position.at),s.options.position=t,["smallify","minimize","normalize","maximize"].forEach(function(e){s.setControlStatus(e,"remove")}),this.slaveconfig.linkSlaveHeight){let e=window.getComputedStyle(i).height;s.resize({height:e})}if(this.slaveconfig.linkSlaveWidth){let e=window.getComputedStyle(i).width;s.resize({width:e})}return s.reposition(t),s.dragit("disable"),s.resizeit("disable"),s.options.minimizeTo=!1,s.options.onclosed.push(()=>{i.slaves.delete(s)}),s.options.onfronted.push(e=>{let s=e.style.zIndex;i.style.zIndex=s,i.slaves.forEach(e=>{e.style.zIndex=s})}),i.reposSlave=function(){document.querySelector("#"+s.id)&&s.reposition()},i.options.dragit&&i.options.dragit.drag.push(i.reposSlave),i.resizeSlave=function(){if(document.querySelector("#"+s.id)){if(s.reposition(),s.slaveconfig.linkSlaveHeight){let e=window.getComputedStyle(i).height;s.resize({height:e})}if(s.slaveconfig.linkSlaveWidth){let e=window.getComputedStyle(i).width;s.resize({width:e})}}},i.options.resizeit&&i.options.resizeit.resize.push(i.resizeSlave),i.slaves.add(s),s.dockedTo=i.id,this.slaveconfig.callback&&this.slaveconfig.callback.call(s,i,s),s};jsPanel.extend({dock:e})}