UNPKG

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 2.03 kB
import{jsPanel}from"../../jspanel.js";jsPanel.layout||(jsPanel.layout={version:"1.4.1",date:"2021-01-19 10:50",storage:localStorage,save(e={}){let t=e.selector?e.selector:".jsPanel-standard",s=e.storagename?e.storagename:"jspanels";const i=document.querySelectorAll(t);let a=[];i.forEach(e=>{let t=e.currentData;t.status=e.status,t.zIndex=e.style.zIndex,t.id=e.id,t.data=e.options.data||void 0,a.push(t)}),a.sort(function(e,t){return e.zIndex-t.zIndex}),this.storage.removeItem(s);let r=JSON.stringify(a);return this.storage.setItem(s,r),r},getAll(e="jspanels"){return!!this.storage[e]&&JSON.parse(this.storage[e])},getDataset(e,t="id",s="jspanels",i=!1){if(this.storage[s]){let a,r=this.getAll(s);return i&&(a=[]),r.forEach(s=>{let i=typeof s[t];if("string"===i||"number"===i)s[t]===e&&(a?a.push(s):a=s);else if(Array.isArray(s[t]))s[t].includes(e)&&(a?a.push(s):a=s);else if("object"==typeof s[t])for(const i in s[t])if(s[t][i]===e){if(!a){a=s;break}a.push(s)}}),a||!1}return!1},restoreId(e={}){let t,s,i;if(!e.id||!e.config)return console.error("Id or predefined panel configuration is missing!"),!1;t=e.id,s=e.config,i=e.storagename?e.storagename:"jspanels";let a=this.getDataset(t,"id",i);if(a){let e={id:a.id,panelSize:{width:a.width,height:a.height},position:`left-top ${a.left} ${a.top}`,zIndex:a.zIndex},t=Object.assign({},s,e);return jsPanel.create(t,t=>{t.style.zIndex=e.zIndex,t.saveCurrentDimensions(),t.saveCurrentPosition(),t.calcSizeFactors(),"normalized"!==a.status&&("minimized"===a.status?t.minimize():"maximized"===a.status?t.maximize():"smallified"===a.status?t.smallify():"smallifiedmax"===a.status&&t.maximize().smallify())})}},restore(e={}){let t,s;if(!e.configs)return console.error("Object with predefined panel configurations is missing!"),!1;if(t=e.configs,s=e.storagename?e.storagename:"jspanels",!this.storage[s])return!1;this.getAll(s).forEach(function(e){let i=e.id;for(let e in t)Object.prototype.hasOwnProperty.call(t,e)&&t[e].id===i&&jsPanel.layout.restoreId({id:i,config:t[e],storagename:s})})}});