/* jspanel.js - License MIT, copyright 2013 - 2018 Stefan Straesser (http://jspanel.de) */ /* global jsPanel, $ */ 'use strict'; // .append() polyfill needed for EDGE - https://developer.mozilla.org/en-US/docs/Web/API/ParentNode/append var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } (function (arr) { arr.forEach(function (item) { item.append = item.append || function () { var argArr = Array.prototype.slice.call(arguments), docFrag = document.createDocumentFragment(); argArr.forEach(function (argItem) { var isNode = argItem instanceof Node; docFrag.appendChild(isNode ? argItem : document.createTextNode(String(argItem))); }); this.appendChild(docFrag); }; }); })([Element.prototype, Document.prototype, DocumentFragment.prototype]); // Element.closest() polyfill needed for EDGE - https://developer.mozilla.org/en-US/docs/Web/API/Element/closest if (window.Element && !Element.prototype.closest) { Element.prototype.closest = function (s) { var matches = (this.document || this.ownerDocument).querySelectorAll(s), i = void 0, el = this; do { i = matches.length; while (--i >= 0 && matches.item(i) !== el) {}; } while (i < 0 && (el = el.parentElement)); return el; }; } // NodeList.prototype.forEach() polyfill needed for IE11 and Android mobile - https://developer.mozilla.org/en-US/docs/Web/API/NodeList/forEach if (window.NodeList && !NodeList.prototype.forEach) { NodeList.prototype.forEach = function (callback, thisArg) { thisArg = thisArg || window; for (var i = 0; i < this.length; i++) { callback.call(thisArg, this[i], i, this); } }; } // Object.assign Polyfill needed for mobiles - https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Object/assign if (!Object.assign) { Object.defineProperty(Object, 'assign', { enumerable: false, configurable: true, writable: true, value: function value(target) { if (target === undefined || target === null) { throw new TypeError('Cannot convert first argument to object'); } var to = Object(target); for (var i = 1; i < arguments.length; i++) { var nextSource = arguments[i]; if (nextSource === undefined || nextSource === null) { continue; } nextSource = Object(nextSource); var keysArray = Object.keys(Object(nextSource)); for (var nextIndex = 0, len = keysArray.length; nextIndex < len; nextIndex++) { var nextKey = keysArray[nextIndex]; var desc = Object.getOwnPropertyDescriptor(nextSource, nextKey); if (desc !== undefined && desc.enumerable) { to[nextKey] = nextSource[nextKey]; } } } return to; } }); } // Polyfills for IE11 only // CustomEvent - https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent (function () { if (typeof window.CustomEvent === "function") return false; function CustomEvent(event, params) { params = params || { bubbles: false, cancelable: false, detail: undefined }; var evt = document.createEvent('CustomEvent'); evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail); return evt; } CustomEvent.prototype = window.Event.prototype; window.CustomEvent = CustomEvent; })(); // String.prototype.endsWith() - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith if (!String.prototype.endsWith) { String.prototype.endsWith = function (searchStr, Position) { // This works much better than >= because // it compensates for NaN: if (!(Position < this.length)) Position = this.length;else Position |= 0; // round position return this.substr(Position - searchStr.length, searchStr.length) === searchStr; }; } // String.prototype.startsWith() - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith if (!String.prototype.startsWith) { String.prototype.startsWith = function (searchString, position) { return this.substr(position || 0, searchString.length) === searchString; }; } // Create a new object, that prototypically inherits from the Error constructor function jsPanelError(message) { this.name = 'jsPanelError'; this.message = message || ''; this.stack = new Error().stack; } jsPanelError.prototype = Object.create(Error.prototype); jsPanelError.prototype.constructor = jsPanelError; var jsPanel = { version: '4.0.0-beta.1.18', date: '2017-12-28 13:01', idCounter: 0, ziBase: 100, themes: ['default', 'primary', 'info', 'success', 'warning', 'danger'], mdbthemes: ['secondary', 'elegant', 'stylish', 'unique', 'special'], autopositionSpacing: 4, isIE: function () { return navigator.appVersion.match(/Trident/); }(), defaults: { boxShadow: 3, container: document.body, contentSize: { width: '400px', height: '200px' }, // must be object dragit: { cursor: 'move', handles: '.jsPanel-headerlogo, .jsPanel-titlebar, .jsPanel-ftr', // do not use .jsPanel-headerbar opacity: 0.8, disableOnMaximized: true }, headerTitle: 'jsPanel', headerControls: 'all', iconfont: 'jsglyph', maximizedMargin: 0, minimizeTo: 'default', paneltype: 'standard', position: 'center', resizeit: { handles: 'n, e, s, w, ne, se, sw, nw', minWidth: 40, minHeight: 40 }, theme: 'default' }, defaultSnapConfig: { sensitivity: 70, trigger: 'panel' }, ajaxAlwaysCallbacks: [], extensions: {}, ajax: function ajax(obj) { var conf = obj.options.contentAjax, configDefaults = { method: 'GET', async: true, user: '', pwd: '', done: function done() { obj.content.innerHTML = this.responseText; }, autoresize: true, autoreposition: true }; var config = void 0; if (typeof conf === 'string') { config = Object.assign({}, configDefaults, { url: encodeURI(conf), evalscripttags: true }); } else if ((typeof conf === 'undefined' ? 'undefined' : _typeof(conf)) === 'object' && conf.url) { config = Object.assign({}, configDefaults, conf); config.url = encodeURI(conf.url); // reset timeout to 0, withCredentials & responseType to false if request is synchronous if (config.async === false) { config.timeout = 0; if (config.withCredentials) { config.withCredentials = undefined; } if (config.responseType) { config.responseType = undefined; } } } else { console.info('XMLHttpRequest seems to miss the request url!'); return obj; } var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function () { if (xhr.readyState === 4) { if (xhr.status === 200) { config.done.call(xhr, obj); // extract and eval content of script tags if "evalscripttags" if (config.evalscripttags) { // get all script tags within responseText var scripttags = xhr.responseText.match(/]*>([\s\S]*?)<\/script>/gi); if (scripttags) { scripttags.forEach(function (tag) { // remove tags from string and trim it var js = tag.replace(/]*>/i, '').replace(/<\/script>/i, '').trim(); // execute javascript eval(js); }); } } } else { if (config.fail) { config.fail.call(xhr, obj); } } if (config.always) { config.always.call(xhr, obj); } // resize and reposition panel if either width or height is set to 'auto' var oContentSize = obj.options.contentSize; if (typeof oContentSize === 'string' && oContentSize.match(/auto/i)) { var parts = oContentSize.split(' '); var sizes = Object.assign({}, { width: parts[0], height: parts[1] }); if (config.autoresize) { obj.resize(sizes); } if (!obj.classList.contains('jsPanel-contextmenu')) { if (config.autoreposition) { obj.reposition(); } } } else if ((typeof oContentSize === 'undefined' ? 'undefined' : _typeof(oContentSize)) === 'object' && (oContentSize.width === 'auto' || oContentSize.height === 'auto')) { var _sizes = Object.assign({}, oContentSize); if (config.autoresize) { obj.resize(_sizes); } if (!obj.classList.contains('jsPanel-contextmenu')) { if (config.autoreposition) { obj.reposition(); } } } // allows plugins to add callback functions to the ajax always callback if (jsPanel.ajaxAlwaysCallbacks.length) { jsPanel.ajaxAlwaysCallbacks.forEach(function (item) { item.call(obj, obj); }); } } }; xhr.open(config.method, config.url, config.async, config.user, config.pwd); xhr.timeout = config.timeout || 0; if (config.withCredentials) { xhr.withCredentials = config.withCredentials; } if (config.responseType) { xhr.responseType = config.responseType; } if (config.beforeSend) { config.beforeSend.call(xhr); } if (config.data) { xhr.send(config.data); } else { xhr.send(null); } return obj; }, calcColors: function calcColors(primaryColor) { var primeColor = this.color(primaryColor), secondColor = this.lighten(primaryColor, 0.81), thirdColor = this.darken(primaryColor, 0.5), fontColorForPrimary = this.perceivedBrightness(primaryColor) <= 0.556 ? '#ffffff' : '#000000', fontColorForSecond = this.perceivedBrightness(secondColor) <= 0.556 ? '#ffffff' : '#000000', fontColorForThird = this.perceivedBrightness(thirdColor) <= 0.556 ? '#000000' : '#ffffff'; return [primeColor.hsl.css, secondColor, thirdColor, fontColorForPrimary, fontColorForSecond, fontColorForThird]; }, color: function color(val) { var color = val.toLowerCase(), r = void 0, g = void 0, b = void 0, h = void 0, s = void 0, l = void 0, match = void 0, channels = void 0, hsl = void 0, result = {}; var hexPattern = /^#?([0-9a-f]{3}|[0-9a-f]{6})$/gi, // matches "#123" or "#f05a78" with or without "#" RGBAPattern = /^rgba?\(([0-9]{1,3}),([0-9]{1,3}),([0-9]{1,3}),?(0|1|0\.[0-9]{1,2}|\.[0-9]{1,2})?\)$/gi, // matches rgb/rgba color values, whitespace allowed HSLAPattern = /^hsla?\(([0-9]{1,3}),([0-9]{1,3}%),([0-9]{1,3}%),?(0|1|0\.[0-9]{1,2}|\.[0-9]{1,2})?\)$/gi, namedColors = { aliceblue: 'f0f8ff', antiquewhite: 'faebd7', aqua: '0ff', aquamarine: '7fffd4', azure: 'f0ffff', beige: 'f5f5dc', bisque: 'ffe4c4', black: '000', blanchedalmond: 'ffebcd', blue: '00f', blueviolet: '8a2be2', brown: 'a52a2a', burlywood: 'deb887', cadetblue: '5f9ea0', chartreuse: '7fff00', chocolate: 'd2691e', coral: 'ff7f50', cornflowerblue: '6495ed', cornsilk: 'fff8dc', crimson: 'dc143c', cyan: '0ff', darkblue: '00008b', darkcyan: '008b8b', darkgoldenrod: 'b8860b', darkgray: 'a9a9a9', darkgrey: 'a9a9a9', darkgreen: '006400', darkkhaki: 'bdb76b', darkmagenta: '8b008b', darkolivegreen: '556b2f', darkorange: 'ff8c00', darkorchid: '9932cc', darkred: '8b0000', darksalmon: 'e9967a', darkseagreen: '8fbc8f', darkslateblue: '483d8b', darkslategray: '2f4f4f', darkslategrey: '2f4f4f', darkturquoise: '00ced1', darkviolet: '9400d3', deeppink: 'ff1493', deepskyblue: '00bfff', dimgray: '696969', dimgrey: '696969', dodgerblue: '1e90ff', firebrick: 'b22222', floralwhite: 'fffaf0', forestgreen: '228b22', fuchsia: 'f0f', gainsboro: 'dcdcdc', ghostwhite: 'f8f8ff', gold: 'ffd700', goldenrod: 'daa520', gray: '808080', grey: '808080', green: '008000', greenyellow: 'adff2f', honeydew: 'f0fff0', hotpink: 'ff69b4', indianred: 'cd5c5c', indigo: '4b0082', ivory: 'fffff0', khaki: 'f0e68c', lavender: 'e6e6fa', lavenderblush: 'fff0f5', lawngreen: '7cfc00', lemonchiffon: 'fffacd', lightblue: 'add8e6', lightcoral: 'f08080', lightcyan: 'e0ffff', lightgoldenrodyellow: 'fafad2', lightgray: 'd3d3d3', lightgrey: 'd3d3d3', lightgreen: '90ee90', lightpink: 'ffb6c1', lightsalmon: 'ffa07a', lightseagreen: '20b2aa', lightskyblue: '87cefa', lightslategray: '789', lightslategrey: '789', lightsteelblue: 'b0c4de', lightyellow: 'ffffe0', lime: '0f0', limegreen: '32cd32', linen: 'faf0e6', magenta: 'f0f', maroon: '800000', mediumaquamarine: '66cdaa', mediumblue: '0000cd', mediumorchid: 'ba55d3', mediumpurple: '9370d8', mediumseagreen: '3cb371', mediumslateblue: '7b68ee', mediumspringgreen: '00fa9a', mediumturquoise: '48d1cc', mediumvioletred: 'c71585', midnightblue: '191970', mintcream: 'f5fffa', mistyrose: 'ffe4e1', moccasin: 'ffe4b5', navajowhite: 'ffdead', navy: '000080', oldlace: 'fdf5e6', olive: '808000', olivedrab: '6b8e23', orange: 'ffa500', orangered: 'ff4500', orchid: 'da70d6', palegoldenrod: 'eee8aa', palegreen: '98fb98', paleturquoise: 'afeeee', palevioletred: 'd87093', papayawhip: 'ffefd5', peachpuff: 'ffdab9', peru: 'cd853f', pink: 'ffc0cb', plum: 'dda0dd', powderblue: 'b0e0e6', purple: '800080', rebeccapurple: '639', red: 'f00', rosybrown: 'bc8f8f', royalblue: '4169e1', saddlebrown: '8b4513', salmon: 'fa8072', sandybrown: 'f4a460', seagreen: '2e8b57', seashell: 'fff5ee', sienna: 'a0522d', silver: 'c0c0c0', skyblue: '87ceeb', slateblue: '6a5acd', slategray: '708090', slategrey: '708090', snow: 'fffafa', springgreen: '00ff7f', steelblue: '4682b4', tan: 'd2b48c', teal: '008080', thistle: 'd8bfd8', tomato: 'ff6347', turquoise: '40e0d0', violet: 'ee82ee', wheat: 'f5deb3', white: 'fff', whitesmoke: 'f5f5f5', yellow: 'ff0', yellowgreen: '9acd32' }; // change named color to corresponding hex value if (namedColors[color]) { color = namedColors[color]; } // check val for hex color if (color.match(hexPattern) !== null) { // '#' entfernen wenn vorhanden color = color.replace('#', ''); // color has either 3 or 6 characters if (color.length % 2 === 1) { // color has 3 char -> convert to 6 char // r = color.substr(0,1).repeat(2); // g = color.substr(1,1).repeat(2); // String.prototype.repeat() doesn't work in IE11 // b = color.substr(2,1).repeat(2); r = String(color.substr(0, 1)) + color.substr(0, 1); g = String(color.substr(1, 1)) + color.substr(1, 1); b = String(color.substr(2, 1)) + color.substr(2, 1); result.rgb = { r: parseInt(r, 16), g: parseInt(g, 16), b: parseInt(b, 16) }; result.hex = '#' + r + g + b; } else { // color has 6 char result.rgb = { r: parseInt(color.substr(0, 2), 16), g: parseInt(color.substr(2, 2), 16), b: parseInt(color.substr(4, 2), 16) }; result.hex = '#' + color; } hsl = this.rgbToHsl(result.rgb.r, result.rgb.g, result.rgb.b); result.hsl = hsl; result.rgb.css = 'rgb(' + result.rgb.r + ',' + result.rgb.g + ',' + result.rgb.b + ')'; } // check val for rgb/rgba color else if (color.match(RGBAPattern)) { match = RGBAPattern.exec(color); result.rgb = { css: color, r: match[1], g: match[2], b: match[3] }; result.hex = this.rgbToHex(match[1], match[2], match[3]); hsl = this.rgbToHsl(match[1], match[2], match[3]); result.hsl = hsl; } // check val for hsl/hsla color else if (color.match(HSLAPattern)) { match = HSLAPattern.exec(color); h = match[1] / 360; s = match[2].substr(0, match[2].length - 1) / 100; l = match[3].substr(0, match[3].length - 1) / 100; channels = this.hslToRgb(h, s, l); result.rgb = { css: 'rgb(' + channels[0] + ',' + channels[1] + ',' + channels[2] + ')', r: channels[0], g: channels[1], b: channels[2] }; result.hex = this.rgbToHex(result.rgb.r, result.rgb.g, result.rgb.b); result.hsl = { css: 'hsl(' + match[1] + ',' + match[2] + ',' + match[3] + ')', h: match[1], s: match[2], l: match[3] }; } // or return #f5f5f5 else { result.hex = '#f5f5f5'; result.rgb = { css: 'rgb(245,245,245)', r: 245, g: 245, b: 245 }; result.hsl = { css: 'hsl(0,0%,96.08%)', h: 0, s: '0%', l: '96.08%' }; } return result; }, createPanelTemplate: function createPanelTemplate() { var dataAttr = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true; var panel = document.createElement('div'); panel.className = 'jsPanel'; if (dataAttr) { ['close', 'maximize', 'normalize', 'minimize', 'smallify', 'smallifyrev'].forEach(function (item) { panel.setAttribute('data-btn' + item, 'enabled'); }); } panel.innerHTML = '
\n
\n \n
\n

\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
'; return panel; }, createMinimizedTemplate: function createMinimizedTemplate() { var panel = document.createElement('div'); panel.className = 'jsPanel-replacement'; panel.innerHTML = '
\n
\n \n
\n

\n
\n
\n
\n
\n
\n
\n
\n
'; return panel; }, createSnapArea: function createSnapArea(panel, pos, snapsens) { var el = document.createElement('div'), parent = panel.parentNode; el.className = 'jsPanel-snap-area jsPanel-snap-area-' + pos; if (pos === 'lt' || pos === 'rt' || pos === 'rb' || pos === 'lb') { el.style.width = snapsens + 'px'; el.style.height = snapsens + 'px'; } else if (pos === 'ct' || pos === 'cb') { el.style.height = snapsens + 'px'; } else if (pos === 'lc' || pos === 'rc') { el.style.width = snapsens + 'px'; } if (parent !== document.body) { el.style.position = 'absolute'; } if (!document.querySelector('.jsPanel-snap-area.jsPanel-snap-area-' + pos)) { panel.parentNode.appendChild(el); } }, darken: function darken(val, amount) { // amount is value between 0 and 1 var hsl = this.color(val).hsl, l = parseFloat(hsl.l), lnew = l - l * amount + '%'; return 'hsl(' + hsl.h + ',' + hsl.s + ',' + lnew + ')'; }, dragit: function dragit(elmt) { var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; var dragstarted = void 0, opts = Object.assign({}, this.defaults.dragit, options), dragElmt = void 0, containment = void 0, frames = []; var dragstart = new CustomEvent('dragstart', { detail: elmt.id }), drag = new CustomEvent('drag', { detail: elmt.id }), dragstop = new CustomEvent('dragstop', { detail: elmt.id }); // normalize grid config if (opts.grid && Array.isArray(opts.grid)) { if (opts.grid.length === 1) { opts.grid[1] = opts.grid[0]; } } // normalize containment config containment = this.pOcontainment(opts.containment); // attach handler to each drag handle elmt.querySelectorAll(opts.handles).forEach(function (handle) { handle.style.touchAction = 'none'; handle.style.cursor = opts.cursor; handle.classList.add('jsPanel-dragit-handle'); jsPanel.pointerdown.forEach(function (item) { handle.addEventListener(item, function (e) { // prevent body scroll on drag init e.preventDefault(); // footer elmts with the class "jsPanel-ftr-btn" don't drag a panel // do not compare e.target with e.currentTarget because there might be footer elmts supposed to drag the panel if (e.target.closest('.jsPanel-ftr-btn')) { return; } elmt.controlbar.style.pointerEvents = 'none'; frames = document.querySelectorAll('iframe'); if (frames.length) { frames.forEach(function (item) { item.style.pointerEvents = 'none'; }); } var startStyles = window.getComputedStyle(elmt), startLeft = parseFloat(startStyles.left), startTop = parseFloat(startStyles.top), psx = e.touches ? e.touches[0].clientX : e.clientX, // pointer x on mousedown (don't use pageX, doesn't work on FF for Android) psy = e.touches ? e.touches[0].clientY : e.clientY, // pointer y on mousedown (don't use pageY, doesn't work on FF for Android) parent = elmt.parentNode, parentRect = parent.getBoundingClientRect(), parentStyles = window.getComputedStyle(parent); var startLeftCorrection = 0; // function actually draging the elmt dragElmt = function dragElmt(e) { e.preventDefault(); if (!dragstarted) { document.dispatchEvent(dragstart); elmt.style.opacity = opts.opacity; // if configured restore panel size to values before snap and reposition reasonable before drag actually starts if (elmt.snapped && opts.snap.resizeToPreSnap && elmt.currentData.beforeSnap) { elmt.resize(elmt.currentData.beforeSnap.width + ' ' + elmt.currentData.beforeSnap.height); var intermediateStyles = elmt.getBoundingClientRect(), delta = psx - (intermediateStyles.left + intermediateStyles.width), wHalf = intermediateStyles.width / 2; if (delta > -wHalf) { startLeftCorrection = delta + wHalf; } } // dragstart callback if (typeof opts.start === 'function') { opts.start.call(elmt, elmt, { left: startLeft, top: startTop }); } jsPanel.front(elmt); elmt.snapped = false; } dragstarted = 1; if (opts.disableOnMaximized && elmt.status === 'maximized') { return false; } var elmtL = void 0, elmtL2 = void 0, elmtT = void 0, elmtT2 = void 0, elmtR = void 0, elmtR2 = void 0, elmtB = void 0, elmtB2 = void 0; var pmx = e.touches ? e.touches[0].clientX : e.clientX, // current pointer x while pointer moves (don't use pageX, doesn't work on FF for Android) pmy = e.touches ? e.touches[0].clientY : e.clientY, // current pointer y while pointer moves (don't use pageY, doesn't work on FF for Android) dragStyles = window.getComputedStyle(elmt); // get current styles while draging if (opts.snap) { if (opts.snap.trigger === 'panel') { elmtL = parseFloat(dragStyles.left); elmtL2 = Math.pow(elmtL, 2); elmtT = parseFloat(dragStyles.top); elmtT2 = Math.pow(elmtT, 2); elmtR = parseFloat(dragStyles.right); elmtR2 = Math.pow(elmtR, 2); elmtB = parseFloat(dragStyles.bottom); elmtB2 = Math.pow(elmtB, 2); } else if (opts.snap.trigger === 'pointer') { elmtL = pmx; elmtL2 = Math.pow(pmx, 2); elmtT = pmy; elmtT2 = Math.pow(elmtT, 2); elmtR = window.innerWidth - pmx; elmtR2 = Math.pow(elmtR, 2); elmtB = window.innerHeight - pmy; elmtB2 = Math.pow(elmtB, 2); } } var lefttopVectorDrag = Math.sqrt(elmtL2 + elmtT2), leftbottomVectorDrag = Math.sqrt(elmtL2 + elmtB2), righttopVectorDrag = Math.sqrt(elmtR2 + elmtT2), rightbottomVectorDrag = Math.sqrt(elmtR2 + elmtB2), horizontalDeltaDrag = Math.abs(elmtL - elmtR) / 2, verticalDeltaDrag = Math.abs(elmtT - elmtB) / 2, leftVectorDrag = Math.sqrt(elmtL2 + Math.pow(verticalDeltaDrag, 2)), topVectorDrag = Math.sqrt(elmtT2 + Math.pow(horizontalDeltaDrag, 2)), rightVectorDrag = Math.sqrt(elmtR2 + Math.pow(verticalDeltaDrag, 2)), bottomVectorDrag = Math.sqrt(elmtB2 + Math.pow(horizontalDeltaDrag, 2)); // prevent selctions while draging window.getSelection().removeAllRanges(); // trigger drag permanently while draging document.dispatchEvent(drag); // move elmt if (!opts.axis || opts.axis === 'x') { elmt.style.left = startLeft + (pmx - psx) + startLeftCorrection + 'px'; // set new css left of elmt depending on opts.axis } if (!opts.axis || opts.axis === 'y') { elmt.style.top = startTop + (pmy - psy) + 'px'; // set new css top of elmt depending on opts.axis } // apply grid option if (opts.grid) { var cx = parseFloat(dragStyles.left), cy = parseFloat(dragStyles.top), modX = cx % opts.grid[0], modY = cy % opts.grid[1]; if (modX < opts.grid[0] / 2) { elmt.style.left = cx - modX + 'px'; } else { elmt.style.left = cx + (opts.grid[0] - modX) + 'px'; } if (modY < opts.grid[1] / 2) { elmt.style.top = cy - modY + 'px'; } else { elmt.style.top = cy + (opts.grid[1] - modY) + 'px'; } } // apply containment option if (opts.containment || opts.containment === 0) { var maxLeft = void 0, maxTop = void 0; // calc maxLeft and maxTop (minLeft and MinTop is equal to containment setting) if (elmt.options.container === document.body) { maxLeft = window.innerWidth - parseFloat(dragStyles.width) - containment[1]; maxTop = window.innerHeight - parseFloat(dragStyles.height) - containment[2]; } else { var xCorr = parseFloat(parentStyles.borderLeftWidth) + parseFloat(parentStyles.borderRightWidth); var yCorr = parseFloat(parentStyles.borderTopWidth) + parseFloat(parentStyles.borderBottomWidth); maxLeft = parentRect.width - parseFloat(dragStyles.width) - containment[1] - xCorr; maxTop = parentRect.height - parseFloat(dragStyles.height) - containment[2] - yCorr; } if (parseFloat(elmt.style.left) <= containment[3]) { elmt.style.left = containment[3] + 'px'; } if (parseFloat(elmt.style.top) <= containment[0]) { elmt.style.top = containment[0] + 'px'; } if (parseFloat(elmt.style.left) >= maxLeft) { elmt.style.left = maxLeft + 'px'; } if (parseFloat(elmt.style.top) >= maxTop) { elmt.style.top = maxTop + 'px'; } } // callback while dragging if (typeof opts.drag === 'function') { opts.drag.call(elmt, elmt, { left: elmtL, top: elmtT, right: elmtR, bottom: elmtB }); } // apply snap options if (opts.snap) { var snapSens = opts.snap.sensitivity, topSensAreaLength = parent === document.body ? window.innerWidth / 8 : parentRect.width / 8, sideSensAreaLength = parent === document.body ? window.innerHeight / 8 : parentRect.height / 8; elmt.snappableTo = false; jsPanel.removeSnapAreas(elmt); if (lefttopVectorDrag < snapSens) { elmt.snappableTo = 'left-top'; if (opts.snap.snapLeftTop !== false) { jsPanel.createSnapArea(elmt, 'lt', snapSens); } } else if (leftbottomVectorDrag < snapSens) { elmt.snappableTo = 'left-bottom'; if (opts.snap.snapLeftBottom !== false) { jsPanel.createSnapArea(elmt, 'lb', snapSens); } } else if (righttopVectorDrag < snapSens) { elmt.snappableTo = 'right-top'; if (opts.snap.snapRightTop !== false) { jsPanel.createSnapArea(elmt, 'rt', snapSens); } } else if (rightbottomVectorDrag < snapSens) { elmt.snappableTo = 'right-bottom'; if (opts.snap.snapRightBottom !== false) { jsPanel.createSnapArea(elmt, 'rb', snapSens); } } else if (elmtT < snapSens && topVectorDrag < topSensAreaLength) { elmt.snappableTo = 'center-top'; if (opts.snap.snapCenterTop !== false) { jsPanel.createSnapArea(elmt, 'ct', snapSens); } } else if (elmtL < snapSens && leftVectorDrag < sideSensAreaLength) { elmt.snappableTo = 'left-center'; if (opts.snap.snapLeftCenter !== false) { jsPanel.createSnapArea(elmt, 'lc', snapSens); } } else if (elmtR < snapSens && rightVectorDrag < sideSensAreaLength) { elmt.snappableTo = 'right-center'; if (opts.snap.snapRightCenter !== false) { jsPanel.createSnapArea(elmt, 'rc', snapSens); } } else if (elmtB < snapSens && bottomVectorDrag < topSensAreaLength) { elmt.snappableTo = 'center-bottom'; if (opts.snap.snapCenterBottom !== false) { jsPanel.createSnapArea(elmt, 'cb', snapSens); } } } }; jsPanel.pointermove.forEach(function (item) { document.addEventListener(item, dragElmt); }); }); }); jsPanel.pointerup.forEach(function (item) { document.addEventListener(item, function () { jsPanel.pointermove.forEach(function (item) { document.removeEventListener(item, dragElmt); }); document.body.style.overflow = 'inherit'; jsPanel.removeSnapAreas(elmt); if (dragstarted) { document.dispatchEvent(dragstop); elmt.style.opacity = 1; dragstarted = undefined; elmt.saveCurrentPosition(); if (opts.snap) { if (elmt.snappableTo === 'left-top') { jsPanel.snapPanel(elmt, opts.snap.snapLeftTop); } else if (elmt.snappableTo === 'center-top') { jsPanel.snapPanel(elmt, opts.snap.snapCenterTop); } else if (elmt.snappableTo === 'right-top') { jsPanel.snapPanel(elmt, opts.snap.snapRightTop); } else if (elmt.snappableTo === 'right-center') { jsPanel.snapPanel(elmt, opts.snap.snapRightCenter); } else if (elmt.snappableTo === 'right-bottom') { jsPanel.snapPanel(elmt, opts.snap.snapRightBottom); } else if (elmt.snappableTo === 'center-bottom') { jsPanel.snapPanel(elmt, opts.snap.snapCenterBottom); } else if (elmt.snappableTo === 'left-bottom') { jsPanel.snapPanel(elmt, opts.snap.snapLeftBottom); } else if (elmt.snappableTo === 'left-center') { jsPanel.snapPanel(elmt, opts.snap.snapLeftCenter); } if (opts.snap.callback && elmt.snappableTo && typeof opts.snap.callback === 'function') { opts.snap.callback.call(elmt, elmt); } if (elmt.snappableTo && opts.snap.repositionOnSnap) { elmt.repositionOnSnap(elmt.snappableTo); } } if (typeof opts.stop === 'function') { opts.stop.call(elmt, elmt, { left: parseFloat(elmt.style.left), top: parseFloat(elmt.style.top) }); } } elmt.controlbar.style.pointerEvents = 'inherit'; if (frames.length) { frames.forEach(function (item) { item.style.pointerEvents = 'inherit'; }); } }); }); // dragit is initialized - now disable if set if (opts.disable) { handle.style.pointerEvents = 'none'; } }); return elmt; }, emptyNode: function emptyNode(node) { while (node.firstChild) { node.removeChild(node.firstChild); } return node; }, extend: function extend(obj) { // obj needs to be a plain object if (Object.prototype.toString.call(obj) === '[object Object]') { for (var ext in obj) { if (obj.hasOwnProperty(ext)) { this.extensions[ext] = obj[ext]; } } } }, fetch: function (_fetch) { function fetch(_x3) { return _fetch.apply(this, arguments); } fetch.toString = function () { return _fetch.toString(); }; return fetch; }(function (obj) { var conf = obj.options.contentFetch; var confDefaults = { bodyMethod: 'text', evalscripttags: true, autoresize: true, autoreposition: true, done: function done(obj, response) { obj.content.innerHTML = response; } }; if (typeof conf === 'string') { conf = Object.assign({ resource: obj.options.contentFetch }, confDefaults); } else { conf = Object.assign(confDefaults, conf); } var fetchInit = conf.fetchInit || {}; if (conf.beforeSend) { conf.beforeSend.call(obj, obj); } fetch(conf.resource, fetchInit).then(function (response) { if (response.ok) { return response[conf.bodyMethod](); } throw new Error('Network response was not ok.'); }).then(function (response) { conf.done.call(obj, obj, response); // extract and eval content of script tags if "evalscripttags" if (conf.evalscripttags) { // get all script tags within responseText var scripttags = response.match(/]*>([\s\S]*?)<\/script>/gi); if (scripttags) { scripttags.forEach(function (tag) { // remove tags from string and trim it var js = tag.replace(/]*>/i, '').replace(/<\/script>/i, '').trim(); // execute javascript eval(js); }); } } // resize and reposition panel if either width or height is set to 'auto' var oContentSize = obj.options.contentSize; if (conf.autoresize || conf.autoreposition) { if (typeof oContentSize === 'string' && oContentSize.match(/auto/i)) { var parts = oContentSize.split(' '); var sizes = Object.assign({}, { width: parts[0], height: parts[1] }); if (conf.autoresize) { obj.resize(sizes); } if (!obj.classList.contains('jsPanel-contextmenu')) { if (conf.autoreposition) { obj.reposition(); } } } else if ((typeof oContentSize === 'undefined' ? 'undefined' : _typeof(oContentSize)) === 'object' && (oContentSize.width === 'auto' || oContentSize.height === 'auto')) { var _sizes2 = Object.assign({}, oContentSize); if (conf.autoresize) { obj.resize(_sizes2); } if (!obj.classList.contains('jsPanel-contextmenu')) { if (conf.autoreposition) { obj.reposition(); } } } } }).catch(function (error) { console.error('There has been a problem with your fetch operation: ' + error.message); }); }), front: function front(obj) { if (obj.status === 'minimized') { if (obj.statusBefore === 'maximized') { obj.maximize(); } else { obj.normalize(); } } else { var newArr = Array.prototype.slice.call(document.querySelectorAll('.jsPanel-standard')).map(function (panel) { return panel.style.zIndex; }); if (Math.max.apply(Math, _toConsumableArray(newArr)) > obj.style.zIndex) { obj.style.zIndex = jsPanel.zi.next(); } this.resetZi(); } }, getPanels: function getPanels() { var condition = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () { return this.classList.contains('jsPanel-standard'); }; return Array.prototype.slice.call(document.querySelectorAll('.jsPanel')).filter(function (value) { return condition.call(value, value); }).sort(function (a, b) { return b.style.zIndex - a.style.zIndex; }); }, hslToRgb: function hslToRgb(h, s, l) { // h, s and l must be values between 0 and 1 var r = void 0, g = void 0, b = void 0; if (s === 0) { r = g = b = l; // achromatic } else { var hue2rgb = function hue2rgb(p, q, t) { if (t < 0) { t += 1; } if (t > 1) { t -= 1; } if (t < 1 / 6) { return p + (q - p) * 6 * t; } if (t < 1 / 2) { return q; } if (t < 2 / 3) { return p + (q - p) * (2 / 3 - t) * 6; } return p; }; var q = l < 0.5 ? l * (1 + s) : l + s - l * s, p = 2 * l - q; r = hue2rgb(p, q, h + 1 / 3); g = hue2rgb(p, q, h); b = hue2rgb(p, q, h - 1 / 3); } return [Math.round(r * 255), Math.round(g * 255), Math.round(b * 255)]; }, lighten: function lighten(val, amount) { // amount is value between 0 and 1 var hsl = this.color(val).hsl, l = parseFloat(hsl.l), lnew = l + (100 - l) * amount + '%'; return 'hsl(' + hsl.h + ',' + hsl.s + ',' + lnew + ')'; }, perceivedBrightness: function perceivedBrightness(val) { var rgb = this.color(val).rgb; // return value is in the range 0 - 1 and input rgb values must also be in the range 0 - 1 // algorithm from: https://en.wikipedia.org/wiki/Rec._2020 return rgb.r / 255 * 0.2627 + rgb.g / 255 * 0.6780 + rgb.b / 255 * 0.0593; }, pOcontainer: function pOcontainer(container, cb) { if (container) { var box = void 0; if (typeof container === 'string') { box = document.querySelector(container); } else if (container.nodeType === 1) { box = container; } else if (container.length) { box = container[0]; } if (box && box.nodeType === 1) { return box; } } var error = new jsPanelError('\nNO NEW PANEL CREATED!\nThe container to append the panel to does not exist or a container was not specified!'); try { throw error; } catch (e) { if (cb) { cb.call(e, e); } } return error; }, // normalizes values for option.maximizedMargin and containment of dragit/resizeit pOcontainment: function pOcontainment(arg) { if (typeof arg === 'number') { // arg: 20 => arg: [20, 20, 20, 20] return [arg, arg, arg, arg]; } else if (Array.isArray(arg)) { if (arg.length === 1) { // arg: [20] => arg: [20, 20, 20, 20] return [arg[0], arg[0], arg[0], arg[0]]; } else if (arg.length === 2) { // arg: [20, 40] => arg: [20, 40, 20, 40] return arg.concat(arg); } else if (arg.length === 3) { arg[3] = arg[1]; } } return arg; // assumed to be array with 4 values }, pOsize: function pOsize(panel, size) { var values = size || this.defaults.contentSize, parent = panel.parentNode; if (typeof values === 'string') { var nums = values.trim().split(' '); values = {}; values.width = nums[0]; nums.length === 2 ? values.height = nums[1] : values.height = nums[0]; } else { if (values.width && !values.height) { values.height = values.width; } else if (values.height && !values.width) { values.width = values.height; } } if (String(values.width).match(/^[0-9]+$/gi)) { // if number only values.width += 'px'; } else if (typeof values.width === 'string' && values.width.endsWith('%')) { if (parent === document.body) { values.width = window.innerWidth * (parseFloat(values.width) / 100) + 'px'; } else { var prtStyles = window.getComputedStyle(parent), border = parseFloat(prtStyles.borderLeftWidth) + parseFloat(prtStyles.borderRightWidth); values.width = (parseFloat(prtStyles.width) - border) * (parseFloat(values.width) / 100) + 'px'; } } else if (typeof values.width === 'function') { values.width = values.width(); if (typeof values.width === 'number') { values.width += 'px'; } else if (typeof values.width === 'string' && values.width.match(/^[0-9]+$/gi)) { values.width += 'px'; } } if (String(values.height).match(/^[0-9]+$/gi)) { // if number only values.height += 'px'; } else if (typeof values.height === 'string' && values.height.endsWith('%')) { if (parent === document.body) { values.height = window.innerHeight * (parseFloat(values.height) / 100) + 'px'; } else { var _prtStyles = window.getComputedStyle(parent), _border = parseFloat(_prtStyles.borderTopWidth) + parseFloat(_prtStyles.borderBottomWidth); values.height = (parseFloat(_prtStyles.height) - _border) * (parseFloat(values.height) / 100) + 'px'; } } else if (typeof values.height === 'function') { values.height = values.height(); if (typeof values.height === 'number') { values.height += 'px'; } else if (typeof values.height === 'string' && values.height.match(/^[0-9]+$/gi)) { values.height += 'px'; } } return values; // return value must be object {width: xxx, height: xxx} }, position: function position(elmt, _position) { var elmtToPosition = void 0, posSettings = void 0, elmtToPositionAgainst = void 0, calculatedPosition = { left: 0, top: 0 }, myXcorrection = 0, myYcorrection = 0, atXcorrection = 0, atYcorrection = 0; var defaults = { my: 'center', at: 'center', of: 'window', offsetX: '0px', offsetY: '0px' }, windowRect = { width: document.documentElement.clientWidth, height: window.innerHeight }, scrollX = pageXOffset, scrollY = pageYOffset; if (typeof elmt === 'string') { // arg elmt is assumed to be a selector string elmtToPosition = document.querySelector(elmt); } else { // otherwise arg elmt is assumed to be a node object elmtToPosition = elmt; } // do not position elmt when parameter position is set to boolean false if (!_position) { elmtToPosition.style.opacity = 1; return elmtToPosition; } var elmtToPositionRect = elmtToPosition.getBoundingClientRect(); // contains read-only left, top, right, bottom, x, y, width, height describing the !! border-box !! in pixels // Properties other than width and height are relative to the top-left of the viewport!! // translate shorthand string to object - "top-left 50 50 down" if (typeof _position === 'string') { var posValue = _position.match(/\b[a-z]{4,6}-{1}[a-z]{3,6}\b/i), autoposValue = _position.match(/down|up|right([^-]|$)|left([^-]|$)/i), offsetValue = _position.match(/[+-]?\d?\.?\d+([a-z%]{2,4}\b|%?)/gi); var settings = void 0; if (posValue) { settings = { my: posValue[0].toLowerCase(), at: posValue[0].toLowerCase() }; } else { settings = { my: 'center', at: 'center' }; } if (autoposValue) { settings.autoposition = autoposValue[0].toLowerCase(); } if (offsetValue) { // convert strings with only numbers to a number value offsetValue.forEach(function (item, index) { if (item.match(/^[+-]?[0-9]*$/)) { offsetValue[index] += 'px'; } offsetValue[index] = offsetValue[index].toLowerCase(); }); // only one passed offset is used for both offsetX and offsetY if (offsetValue.length === 1) { settings.offsetX = offsetValue[0]; settings.offsetY = offsetValue[0]; } else { settings.offsetX = offsetValue[0]; settings.offsetY = offsetValue[1]; } } posSettings = Object.assign({}, defaults, settings); } else { posSettings = Object.assign({}, defaults, _position); } var parentContainer = elmtToPosition.parentElement; var parentContainerStyles = window.getComputedStyle(parentContainer); var parentContainerRect = parentContainer.getBoundingClientRect(); var parentContainerTagName = parentContainer.tagName.toLowerCase(); if (posSettings.of && posSettings.of !== 'window') { if (typeof posSettings.of === 'string') { // posSettings.of is assumed to be a selector string elmtToPositionAgainst = document.querySelector(posSettings.of); } else { // otherwise posSettings.of is assumed to be a node object elmtToPositionAgainst = posSettings.of; } } // calc left corrections due to panel size, should be the same for all scenarios if (posSettings.my.match(/^center-top$|^center$|^center-bottom$/i)) { myXcorrection = elmtToPositionRect.width / 2; } else if (posSettings.my.match(/right/i)) { myXcorrection = elmtToPositionRect.width; } // calc top corrections due to panel size if (posSettings.my.match(/^left-center$|^center$|^right-center$/i)) { myYcorrection = elmtToPositionRect.height / 2; } else if (posSettings.my.match(/bottom/i)) { myYcorrection = elmtToPositionRect.height; } // SCENARIO 1 - panel appended to body and positioned relative to window -> make fixed if (parentContainerTagName === 'body' && posSettings.of === 'window') { // calc left corrections due to window size if (posSettings.at.match(/^center-top$|^center$|^center-bottom$/i)) { atXcorrection = windowRect.width / 2; } else if (posSettings.at.match(/right/i)) { atXcorrection = windowRect.width; } // calc top corrections due to window size if (posSettings.at.match(/^left-center$|^center$|^right-center$/i)) { atYcorrection = windowRect.height / 2; } else if (posSettings.at.match(/bottom/i)) { atYcorrection = windowRect.height; } calculatedPosition.left = atXcorrection - myXcorrection - parseFloat(parentContainerStyles.borderLeftWidth); calculatedPosition.top = atYcorrection - myYcorrection - parseFloat(parentContainerStyles.borderTopWidth); // panel appended to body and positioned relative to window is always fixed elmtToPosition.style.position = 'fixed'; } // SCENARIO 2 - panel appended to body and positioned relative to another element in document else if (parentContainerTagName === 'body' && posSettings.of !== 'window') { var elmtToPositionAgainstRect = elmtToPositionAgainst.getBoundingClientRect(); // calc left corrections due to position and size of elmtToPositionAgainst if (posSettings.at.match(/^center-top$|^center$|^center-bottom$/i)) { atXcorrection = elmtToPositionAgainstRect.width / 2 + elmtToPositionAgainstRect.left + scrollX; } else if (posSettings.at.match(/right/i)) { atXcorrection = elmtToPositionAgainstRect.width + elmtToPositionAgainstRect.left + scrollX; } else { atXcorrection = elmtToPositionAgainstRect.left + scrollX; } // calc top corrections due to position and size of elmtToPositionAgainst if (posSettings.at.match(/^left-center$|^center$|^right-center$/i)) { atYcorrection = elmtToPositionAgainstRect.height / 2 + elmtToPositionAgainstRect.top + scrollY; } else if (posSettings.at.match(/bottom/i)) { atYcorrection = elmtToPositionAgainstRect.height + elmtToPositionAgainstRect.top + scrollY; } else { atYcorrection = elmtToPositionAgainstRect.top + scrollY; } calculatedPosition.left = atXcorrection - myXcorrection - parseFloat(parentContainerStyles.borderLeftWidth); calculatedPosition.top = atYcorrection - myYcorrection - parseFloat(parentContainerStyles.borderTopWidth); } // SCENARIO 3 - // panel appended to other element than body and positioned relative to its container else if (parentContainerTagName !== 'body' && (posSettings.of === 'window' || !posSettings.of)) { // calc corrections to position panel relative to parentContainer content-box, not border-box var pContainerLRBorderWidth = parseFloat(parentContainerStyles.borderLeftWidth) + parseFloat(parentContainerStyles.borderRightWidth), pContainerTBBorderWidth = parseFloat(parentContainerStyles.borderTopWidth) + parseFloat(parentContainerStyles.borderBottomWidth); // calc left corrections due to parent container width if (posSettings.at.match(/^center-top$|^center$|^center-bottom$/i)) { atXcorrection = parentContainerRect.width / 2 - pContainerLRBorderWidth / 2; } else if (posSettings.at.match(/right/i)) { atXcorrection = parentContainerRect.width - pContainerLRBorderWidth; } // calc top corrections due to parent container height if (posSettings.at.match(/^left-center$|^center$|^right-center$/i)) { atYcorrection = parentContainerRect.height / 2 - pContainerTBBorderWidth / 2; } else if (posSettings.at.match(/bottom/i)) { atYcorrection = parentContainerRect.height - pContainerTBBorderWidth; } calculatedPosition.left = atXcorrection - myXcorrection; calculatedPosition.top = atYcorrection - myYcorrection; } // SCENARIO 4 - panel appended to other element than body and positioned relative to an element within its container else if (parentContainerTagName !== 'body' && parentContainer.contains(elmtToPositionAgainst)) { var _elmtToPositionAgainstRect = elmtToPositionAgainst.getBoundingClientRect(); // calc left corrections due to position and size of elmtToPositionAgainst if (posSettings.at.match(/^center-top$|^center$|^center-bottom$/i)) { atXcorrection = _elmtToPositionAgainstRect.left - parentContainerRect.left + _elmtToPositionAgainstRect.width / 2; } else if (posSettings.at.match(/right/i)) { atXcorrection = _elmtToPositionAgainstRect.left - parentContainerRect.left + _elmtToPositionAgainstRect.width; } else { atXcorrection = _elmtToPositionAgainstRect.left - parentContainerRect.left; } // calc top corrections due to position and size of elmtToPositionAgainst if (posSettings.at.match(/^left-center$|^center$|^right-center$/i)) { atYcorrection = _elmtToPositionAgainstRect.top - parentContainerRect.top + _elmtToPositionAgainstRect.height / 2; } else if (posSettings.at.match(/bottom/i)) { atYcorrection = _elmtToPositionAgainstRect.top - parentContainerRect.top + _elmtToPositionAgainstRect.height; } else { atYcorrection = _elmtToPositionAgainstRect.top - parentContainerRect.top; } calculatedPosition.left = atXcorrection - myXcorrection - parseFloat(parentContainerStyles.borderLeftWidth); calculatedPosition.top = atYcorrection - myYcorrection - parseFloat(parentContainerStyles.borderTopWidth); } // autoposition panels only if ... if (posSettings.autoposition && posSettings.my === posSettings.at && ['left-top', 'center-top', 'right-top', 'left-bottom', 'center-bottom', 'right-bottom'].indexOf(posSettings.my) >= 0) { // add class with position and autoposition direction var newClass = posSettings.my + '-' + posSettings.autoposition.toLowerCase(); elmtToPosition.classList.add(newClass); // get all panels with same class var newClassAll = Array.prototype.slice.call(document.querySelectorAll('.' + newClass)), ownIndex = newClassAll.indexOf(elmtToPosition); // if more than 1 position new panel if (newClassAll.length > 1) { if (posSettings.autoposition === 'down') { // collect heights of all elmts to calc new top position newClassAll.forEach(function (item, index) { if (index > 0 && index <= ownIndex) { calculatedPosition.top += newClassAll[--index].getBoundingClientRect().height + jsPanel.autopositionSpacing; } }); } else if (posSettings.autoposition === 'up') { newClassAll.forEach(function (item, index) { if (index > 0 && index <= ownIndex) { calculatedPosition.top -= newClassAll[--index].getBoundingClientRect().height + jsPanel.autopositionSpacing; } }); } else if (posSettings.autoposition === 'right') { // collect widths of all elmts to calc new left position newClassAll.forEach(function (item, index) { if (index > 0 && index <= ownIndex) { calculatedPosition.left += newClassAll[--index].getBoundingClientRect().width + jsPanel.autopositionSpacing; } }); } else if (posSettings.autoposition === 'left') { newClassAll.forEach(function (item, index) { if (index > 0 && index <= ownIndex) { calculatedPosition.left -= newClassAll[--index].getBoundingClientRect().width + jsPanel.autopositionSpacing; } }); } } } // apply minLeft, minTop, maxLeft and maxTop values (need to be numbers) if ((posSettings.minLeft || posSettings.minLeft === 0) && typeof posSettings.minLeft === 'number' && calculatedPosition.left < posSettings.minLeft) { calculatedPosition.left = posSettings.minLeft; } if ((posSettings.maxLeft || posSettings.maxLeft === 0) && typeof posSettings.maxLeft === 'number' && calculatedPosition.left > posSettings.maxLeft) { calculatedPosition.left = posSettings.maxLeft; } if ((posSettings.minTop || posSettings.minTop === 0) && typeof posSettings.minTop === 'number' && calculatedPosition.top < posSettings.minTop) { calculatedPosition.top = posSettings.minTop; } if ((posSettings.maxTop || posSettings.maxTop === 0) && typeof posSettings.maxTop === 'number' && calculatedPosition.top > posSettings.maxTop) { calculatedPosition.top = posSettings.maxTop; } if (typeof posSettings.modify === 'function') { calculatedPosition = posSettings.modify.call(calculatedPosition, calculatedPosition); // inside the function 'this' refers to the object 'newCoords' // option.modify is optional. If present has to be a function returning an object with the keys 'left' and 'top' and values have to be numbers } // finally apply offsets and position panel if (typeof posSettings.offsetX === 'number') { posSettings.offsetX += 'px'; } if (typeof posSettings.offsetY === 'number') { posSettings.offsetY += 'px'; } elmtToPosition.style.left = 'calc(' + calculatedPosition.left + 'px + ' + posSettings.offsetX + ')'; elmtToPosition.style.top = 'calc(' + calculatedPosition.top + 'px + ' + posSettings.offsetY + ')'; elmtToPosition.style.opacity = 1; // convert css calc values to pixel values - this is required by dragit and resizeit elmtToPosition.style.left = window.getComputedStyle(elmtToPosition).left; elmtToPosition.style.top = window.getComputedStyle(elmtToPosition).top; return elmtToPosition; }, rgbToHsl: function rgbToHsl(r, g, b) { r /= 255, g /= 255, b /= 255; var max = Math.max(r, g, b), min = Math.min(r, g, b), h = void 0, s = void 0, l = (max + min) / 2; if (max === min) { h = s = 0; // achromatic } else { var d = max - min; s = l > 0.5 ? d / (2 - max - min) : d / (max + min); switch (max) { case r: h = (g - b) / d + (g < b ? 6 : 0); break; case g: h = (b - r) / d + 2; break; case b: h = (r - g) / d + 4; break; } h /= 6; } //return [ h, s, l ]; h = h * 360; s = s * 100 + '%'; l = l * 100 + '%'; return { css: 'hsl(' + h + ',' + s + ',' + l + ')', h: h, s: s, l: l }; }, rgbToHex: function rgbToHex(r, g, b) { var red = Number(r).toString(16), green = Number(g).toString(16), blue = Number(b).toString(16); if (red.length === 1) { red = '0' + red; } if (green.length === 1) { green = '0' + green; } if (blue.length === 1) { blue = '0' + blue; } return '#' + red + green + blue; }, removeSnapAreas: function removeSnapAreas(panel) { document.querySelectorAll('.jsPanel-snap-area').forEach(function (el) { if (panel.parentNode) { panel.parentNode.removeChild(el); } }); }, resetZi: function resetZi() { this.zi = function () { var startValue = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : jsPanel.ziBase; var val = startValue; return { next: function next() { return val++; } }; }(); Array.prototype.slice.call(document.querySelectorAll('.jsPanel-standard')).sort(function (a, b) { return a.style.zIndex - b.style.zIndex; }).forEach(function (panel) { panel.style.zIndex = jsPanel.zi.next(); }); }, resizeit: function resizeit(elmt) { var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; var opts = Object.assign({}, this.defaults.resizeit, options), elmtParent = elmt.parentElement, elmtParentTagName = elmtParent.tagName.toLowerCase(), maxWidth = typeof opts.maxWidth === 'function' ? opts.maxWidth() : opts.maxWidth || 10000, maxHeight = typeof opts.maxHeight === 'function' ? opts.maxHeight() : opts.maxHeight || 10000, minWidth = typeof opts.minWidth === 'function' ? opts.minWidth() : opts.minWidth, minHeight = typeof opts.minHeight === 'function' ? opts.minHeight() : opts.minHeight, resizestart = new CustomEvent('resizestart', { detail: elmt.id }), resize = new CustomEvent('resize', { detail: elmt.id }), resizestop = new CustomEvent('resizestop', { detail: elmt.id }); var containment = void 0, resizePanel = void 0, resizestarted = void 0, w = void 0, h = void 0, frames = []; // normalize containment config containment = this.pOcontainment(opts.containment); opts.handles.split(',').forEach(function (item) { var node = document.createElement('DIV'); node.className = 'jsPanel-resizeit-handle jsPanel-resizeit-' + item.trim(); node.style.zIndex = 90; elmt.append(node); }); Array.prototype.slice.call(elmt.getElementsByClassName('jsPanel-resizeit-handle')).forEach(function (handle) { jsPanel.pointerdown.forEach(function (item) { handle.addEventListener(item, function (e) { // prevent window scroll while resizing elmt e.preventDefault(); frames = document.querySelectorAll('iframe'); if (frames.length) { frames.forEach(function (item) { item.style.pointerEvents = 'none'; }); } var elmtRect = elmt.getBoundingClientRect(), /* needs to be calculated on pointerdown!! */ elmtParentRect = elmtParent.getBoundingClientRect(), /* needs to be calculated on pointerdown!! */ elmtParentStyles = window.getComputedStyle(elmtParent, null), elmtParentBLW = parseInt(elmtParentStyles.borderLeftWidth, 10), elmtParentBTW = parseInt(elmtParentStyles.borderTopWidth, 10), elmtParentPosition = elmtParentStyles.getPropertyValue('position'), startX = e.clientX || e.touches[0].clientX, startY = e.clientY || e.touches[0].clientY, startWidth = elmtRect.width, startHeight = elmtRect.height, resizeHandleClassList = e.target.classList; var startLeft = elmtRect.left, startTop = elmtRect.top, maxWidthEast = 10000, maxWidthWest = 10000, maxHeightSouth = 10000, maxHeightNorth = 10000; // important if content contains another document elmt.content.style.pointerEvents = 'none'; if (elmtParentTagName !== 'body') { startLeft = elmtRect.left - elmtParentRect.left + elmtParent.scrollLeft; startTop = elmtRect.top - elmtParentRect.top + elmtParent.scrollTop; } // calc min/max left/top values if containment is set - code from jsDraggable if (elmtParentTagName === 'body' && containment) { maxWidthEast = document.documentElement.clientWidth - elmtRect.left; maxHeightSouth = document.documentElement.clientHeight - elmtRect.top; maxWidthWest = elmtRect.width + elmtRect.left; maxHeightNorth = elmtRect.height + elmtRect.top; } else { // if panel is NOT in body if (containment) { if (elmtParentPosition === 'static') { maxWidthEast = elmtParentRect.width - elmtRect.left + elmtParentBLW; maxHeightSouth = elmtParentRect.height + elmtParentRect.top - elmtRect.top + elmtParentBTW; maxWidthWest = elmtRect.width + (elmtRect.left - elmtParentRect.left) - elmtParentBLW; maxHeightNorth = elmtRect.height + (elmtRect.top - elmtParentRect.top) - elmtParentBTW; } else { maxWidthEast = elmtParent.clientWidth - (elmtRect.left - elmtParentRect.left) + elmtParentBLW; maxHeightSouth = elmtParent.clientHeight - (elmtRect.top - elmtParentRect.top) + elmtParentBTW; maxWidthWest = elmtRect.width + (elmtRect.left - elmtParentRect.left) - elmtParentBLW; maxHeightNorth = elmt.clientHeight + (elmtRect.top - elmtParentRect.top) - elmtParentBTW; } } } // if original opts.containment is array if (containment) { maxWidthWest -= containment[3]; maxHeightNorth -= containment[0]; maxWidthEast -= containment[1]; maxHeightSouth -= containment[2]; } // calculate corrections for rotated panels var computedStyle = window.getComputedStyle(elmt); var wDif = parseFloat(computedStyle.width) - elmtRect.width, hDif = parseFloat(computedStyle.height) - elmtRect.height, xDif = parseFloat(computedStyle.left) - elmtRect.left, yDif = parseFloat(computedStyle.top) - elmtRect.top; if (elmtParent !== document.body) { xDif += elmtParentRect.left; yDif += elmtParentRect.top; } resizePanel = function resizePanel(evt) { // trigger resizestarted only once per resize if (!resizestarted) { document.dispatchEvent(resizestart); if (typeof opts.start === 'function') { opts.start.call(elmt, elmt, { width: startWidth, height: startHeight }); } jsPanel.front(elmt); } resizestarted = 1; // trigger resize permanently while resizing document.dispatchEvent(resize); if (resizeHandleClassList.contains('jsPanel-resizeit-e') || resizeHandleClassList.contains('jsPanel-resizeit-se') || resizeHandleClassList.contains('jsPanel-resizeit-ne')) { w = startWidth + (evt.clientX || evt.touches[0].clientX) - startX + wDif; if (w >= maxWidthEast) { w = maxWidthEast; } if (w >= maxWidth) { w = maxWidth; } else if (w <= minWidth) { w = minWidth; } elmt.style.width = w + 'px'; } if (resizeHandleClassList.contains('jsPanel-resizeit-s') || resizeHandleClassList.contains('jsPanel-resizeit-se') || resizeHandleClassList.contains('jsPanel-resizeit-sw')) { h = startHeight + (evt.clientY || evt.touches[0].clientY) - startY + hDif; if (h >= maxHeightSouth) { h = maxHeightSouth; } if (h >= maxHeight) { h = maxHeight; } else if (h <= minHeight) { h = minHeight; } elmt.style.height = h + 'px'; } if (resizeHandleClassList.contains('jsPanel-resizeit-w') || resizeHandleClassList.contains('jsPanel-resizeit-nw') || resizeHandleClassList.contains('jsPanel-resizeit-sw')) { w = startWidth + startX - (evt.clientX || evt.touches[0].clientX) + wDif; if (w <= maxWidth && w >= minWidth && w <= maxWidthWest) { elmt.style.left = startLeft + (evt.clientX || evt.touches[0].clientX) - startX + xDif + 'px'; } if (w >= maxWidthWest) { w = maxWidthWest; } if (w >= maxWidth) { w = maxWidth; } else if (w <= minWidth) { w = minWidth; } elmt.style.width = w + 'px'; } if (resizeHandleClassList.contains('jsPanel-resizeit-n') || resizeHandleClassList.contains('jsPanel-resizeit-nw') || resizeHandleClassList.contains('jsPanel-resizeit-ne')) { h = startHeight + startY - (evt.clientY || evt.touches[0].clientY) + hDif; if (h <= maxHeight && h >= minHeight && h <= maxHeightNorth) { elmt.style.top = startTop + (evt.clientY || evt.touches[0].clientY) - startY + yDif + 'px'; } if (h >= maxHeightNorth) { h = maxHeightNorth; } if (h >= maxHeight) { h = maxHeight; } else if (h <= minHeight) { h = minHeight; } elmt.style.height = h + 'px'; } if (elmt) { elmt.contentResize(); } window.getSelection().removeAllRanges(); // get current position and size values while resizing var styles = window.getComputedStyle(elmt), values = { left: parseFloat(styles.left), top: parseFloat(styles.top), right: parseFloat(styles.right), bottom: parseFloat(styles.bottom), width: parseFloat(styles.width), height: parseFloat(styles.height) }; // callback while resizing if (typeof opts.resize === 'function') { opts.resize.call(elmt, elmt, values); } }; jsPanel.pointermove.forEach(function (item) { document.addEventListener(item, resizePanel, false); }); // remove resize handler when mouse leaves browser window (mouseleave doesn't work) window.addEventListener('mouseout', function (e) { if (e.relatedTarget === null) { jsPanel.pointermove.forEach(function (item) { document.removeEventListener(item, resizePanel, false); }); } }, false); }); }); }); jsPanel.pointerup.forEach(function (item) { document.addEventListener(item, function (e) { jsPanel.pointermove.forEach(function (item) { document.removeEventListener(item, resizePanel, false); }); if (e.target.classList && e.target.classList.contains('jsPanel-resizeit-handle')) { var isLeftChange = void 0, isTopChange = void 0; var cl = e.target.className; if (cl.match(/jsPanel-resizeit-nw|jsPanel-resizeit-w|jsPanel-resizeit-sw/i)) { isLeftChange = true; } if (cl.match(/jsPanel-resizeit-nw|jsPanel-resizeit-n|jsPanel-resizeit-ne/i)) { isTopChange = true; } // snap panel to grid (doesn't work that well if inside function resizePanel) if (opts.grid && Array.isArray(opts.grid)) { if (opts.grid.length === 1) { opts.grid[1] = opts.grid[0]; } var cw = parseFloat(elmt.style.width), ch = parseFloat(elmt.style.height), modW = cw % opts.grid[0], modH = ch % opts.grid[1], cx = parseFloat(elmt.style.left), cy = parseFloat(elmt.style.top), modX = cx % opts.grid[0], modY = cy % opts.grid[1]; if (modW < opts.grid[0] / 2) { elmt.style.width = cw - modW + 'px'; } else { elmt.style.width = cw + (opts.grid[0] - modW) + 'px'; } if (modH < opts.grid[1] / 2) { elmt.style.height = ch - modH + 'px'; } else { elmt.style.height = ch + (opts.grid[1] - modH) + 'px'; } if (isLeftChange) { if (modX < opts.grid[0] / 2) { elmt.style.left = cx - modX + 'px'; } else { elmt.style.left = cx + (opts.grid[0] - modX) + 'px'; } } if (isTopChange) { if (modY < opts.grid[1] / 2) { elmt.style.top = cy - modY + 'px'; } else { elmt.style.top = cy + (opts.grid[1] - modY) + 'px'; } } } if (elmt) { elmt.contentResize(); } } if (resizestarted) { elmt.content.style.pointerEvents = 'inherit'; document.dispatchEvent(resizestop); resizestarted = undefined; elmt.saveCurrentDimensions(); if (typeof opts.stop === 'function') { opts.stop.call(elmt, elmt, { width: parseFloat(elmt.style.width), height: parseFloat(elmt.style.height) }); } } if (frames.length) { frames.forEach(function (item) { item.style.pointerEvents = 'inherit'; }); } }, false); }); // resizeit is initialized - now disable if set if (opts.disable) { elmt.querySelectorAll('.jsPanel-resizeit-handle').forEach(function (handle) { handle.style.pointerEvents = 'none'; }); } return elmt; }, setClass: function setClass(elmt, classnames) { classnames.split(' ').forEach(function (item) { return elmt.classList.add(item); }); return elmt; }, remClass: function remClass(elmt, classnames) { classnames.split(' ').forEach(function (item) { return elmt.classList.remove(item); }); return elmt; }, setStyle: function setStyle(elmt, stylesobject) { for (var prop in stylesobject) { if (stylesobject.hasOwnProperty(prop)) { var property = String(prop).replace(/-\w/gi, function (match) { return match.substr(-1).toUpperCase(); }); elmt.style[property] = stylesobject[prop]; } } return elmt; }, snapPanel: function snapPanel(panel, pos) { // store panel size before it snaps panel.currentData.beforeSnap = { width: panel.currentData.width, height: panel.currentData.height }; // snap panel if (pos && typeof pos === 'function') { pos.call(panel, panel, panel.snappableTo); } else if (pos !== false) { var offsets = [0, 0]; if (panel.options.dragit.snap.containment) { if (panel.options.dragit.containment) { var containment = this.pOcontainment(panel.options.dragit.containment), position = panel.snappableTo; if (position.startsWith('left')) { offsets[0] = containment[3]; } else if (position.startsWith('right')) { offsets[0] = -containment[1]; } if (position.endsWith('top')) { offsets[1] = containment[0]; } else if (position.endsWith('bottom')) { offsets[1] = -containment[2]; } } } panel.reposition(panel.snappableTo + ' ' + offsets[0] + ' ' + offsets[1]); panel.snapped = panel.snappableTo; } }, // METHOD CREATING THE PANEL --------------------------------------------- create: function create() { var _this = this; var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var cb = arguments[1]; var opts = void 0, closetimer = void 0; if (options.config) { opts = Object.assign({}, this.defaults, options.config, options); delete opts.config; } else { opts = Object.assign({}, this.defaults, options); } if (!opts.id) { opts.id = 'jsPanel-' + (jsPanel.idCounter += 1); } else if (typeof opts.id === 'function') { opts.id = opts.id(); } var p = document.getElementById(opts.id); if (p !== null) { // if a panel with passed id already exists, front it and return error object if (p.classList.contains('jsPanel')) { p.front(); } var error = new jsPanelError('\nNO NEW PANEL CREATED!\nAn element with the ID <' + opts.id + '> already exists in the document.'); try { throw error; } catch (e) { if (cb) { cb.call(e, e); } } return console.error(error.name + ':', error.message); } // check whether container is valid -> if not return and log error var panelContainer = this.pOcontainer(opts.container, cb); if (panelContainer && panelContainer.message) { return console.error(panelContainer.name + ':', panelContainer.message); } // normalize maximizedMargin opts.maximizedMargin = this.pOcontainment(opts.maximizedMargin); // normalize snap config if (opts.dragit && opts.dragit.snap) { if (_typeof(opts.dragit.snap) === 'object') { opts.dragit.snap = Object.assign({}, this.defaultSnapConfig, opts.dragit.snap); } else { opts.dragit.snap = this.defaultSnapConfig; } } opts.template = opts.template || false; var self = opts.template ? opts.template : this.createPanelTemplate(); // Properties self.options = opts; self.status = 'initialized'; self.currentData = {}; self.header = self.querySelector('.jsPanel-hdr'); // complete header section self.headerbar = self.header.querySelector('.jsPanel-headerbar'); // log, title and controls self.titlebar = self.header.querySelector('.jsPanel-titlebar'); // div surrounding title h3 self.headerlogo = self.headerbar.querySelector('.jsPanel-headerlogo'); // logo only self.headertitle = self.headerbar.querySelector('.jsPanel-title'); // title h3 self.controlbar = self.headerbar.querySelector('.jsPanel-controlbar'); // div surrounding all controls self.headertoolbar = self.header.querySelector('.jsPanel-hdr-toolbar'); self.content = self.querySelector('.jsPanel-content'); self.footer = self.querySelector('.jsPanel-ftr'); self.snappableTo = false; self.snapped = false; // Events var jspanelloaded = new CustomEvent('jspanelloaded', { 'detail': opts.id }), jspanelbeforeclose = new CustomEvent('jspanelbeforeclose', { 'detail': opts.id }), jspanelclosed = new CustomEvent('jspanelclosed', { 'detail': opts.id }), jspanelstatuschange = new CustomEvent('jspanelstatuschange', { 'detail': opts.id }), jspanelbeforenormalize = new CustomEvent('jspanelbeforenormalize', { 'detail': opts.id }), jspanelnormalized = new CustomEvent('jspanelnormalized', { 'detail': opts.id }), jspanelbeforemaximize = new CustomEvent('jspanelbeforemaximize', { 'detail': opts.id }), jspanelmaximized = new CustomEvent('jspanelmaximized', { 'detail': opts.id }), jspanelbeforeminimize = new CustomEvent('jspanelbeforeminimize', { 'detail': opts.id }), jspanelminimized = new CustomEvent('jspanelminimized', { 'detail': opts.id }), jspanelbeforesmallify = new CustomEvent('jspanelbeforesmallify', { 'detail': opts.id }), jspanelsmallified = new CustomEvent('jspanelsmallified', { 'detail': opts.id }), jspanelsmallifiedmax = new CustomEvent('jspanelsmallifiedmax', { 'detail': opts.id }), jspanelbeforeunsmallify = new CustomEvent('jspanelbeforeunsmallify', { 'detail': opts.id }), jspanelfronted = new CustomEvent('jspanelfronted', { 'detail': opts.id }); // controls handlers var hasCloseBtn = self.querySelector('.jsPanel-btn-close'), hasMaxBtn = self.querySelector('.jsPanel-btn-maximize'), hasNormBtn = self.querySelector('.jsPanel-btn-normalize'), hasSmallBtn = self.querySelector('.jsPanel-btn-smallify'), hasSmallrevBtn = self.querySelector('.jsPanel-btn-smallifyrev'), hasMinBtn = self.querySelector('.jsPanel-btn-minimize'); if (hasCloseBtn) { jsPanel.pointerup.forEach(function (item) { hasCloseBtn.addEventListener(item, function (e) { e.preventDefault(); self.close(); }); }); } if (hasMaxBtn) { jsPanel.pointerup.forEach(function (item) { hasMaxBtn.addEventListener(item, function (e) { e.preventDefault(); self.maximize(); }); }); } if (hasNormBtn) { jsPanel.pointerup.forEach(function (item) { hasNormBtn.addEventListener(item, function (e) { e.preventDefault(); self.normalize(); }); }); } if (hasSmallBtn) { jsPanel.pointerup.forEach(function (item) { hasSmallBtn.addEventListener(item, function (e) { e.preventDefault(); self.smallify(); }); }); } if (hasSmallrevBtn) { jsPanel.pointerup.forEach(function (item) { hasSmallrevBtn.addEventListener(item, function (e) { e.preventDefault(); self.unsmallify(); }); }); } if (hasMinBtn) { jsPanel.pointerup.forEach(function (item) { hasMinBtn.addEventListener(item, function (e) { e.preventDefault(); self.minimize(); }); }); } // import extensions var extensions = jsPanel.extensions; for (var ext in extensions) { if (extensions.hasOwnProperty(ext)) { self[ext] = extensions[ext]; } } // Methods self.addToolbar = function (place, tb, callback) { if (place === 'header') { place = self.headertoolbar; } else if (place === 'footer') { place = self.footer; } if (typeof tb === 'string') { place.innerHTML = tb; } else if (Array.isArray(tb)) { tb.forEach(function (item) { if (typeof item === 'string') { place.innerHTML += item; } else { place.append(item); } }); } else if (typeof tb === 'function') { var tool = tb.call(self, self); if (typeof tool === 'string') { place.innerHTML = tool; } else { place.append(tool); } } else { place.append(tb); } place.classList.add('active'); if (place === self.footer) { self.content.classList.remove('jsPanel-content-nofooter'); } self.contentResize(); if (callback) { callback.call(self, self); } return self; }; self.applyBuiltInTheme = function (themeDetails) { self.classList.add('jsPanel-theme-' + themeDetails.color); // do not remove theme from jsP self.header.classList.add('jsPanel-theme-' + themeDetails.color); // optionally set theme filling if (themeDetails.filling) { self.content.style.background = ''; self.content.classList.add('jsPanel-content-' + themeDetails.filling); } if (!opts.headerToolbar) { self.content.style.background = ''; self.content.style.borderTop = '1px solid ' + self.headertitle.style.color; } return self; }; self.applyArbitraryTheme = function (themeDetails) { self.header.style.backgroundColor = themeDetails.colors[0]; ['.jsPanel-headerlogo', '.jsPanel-title', '.jsPanel-hdr-toolbar'].forEach(function (item) { self.querySelector(item).style.color = themeDetails.colors[3]; }, self); self.querySelectorAll('.jsPanel-controlbar .jsPanel-btn .jsglyph').forEach(function (item) { item.style.color = themeDetails.colors[3]; }); if (opts.headerToolbar) { jsPanel.setStyle(self.headertoolbar, { boxShadow: '0 0 1px ' + themeDetails.colors[3] + ' inset', width: 'calc(100% + 4px)', marginLeft: '-1px' }); } else { self.content.style.borderTop = '1px solid ' + themeDetails.colors[3]; } if (themeDetails.filling === 'filled') { self.content.style.backgroundColor = themeDetails.colors[0]; self.content.style.color = themeDetails.colors[3]; } else if (themeDetails.filling === 'filledlight') { self.content.style.backgroundColor = themeDetails.colors[1]; } return self; }; self.applyBootstrapTheme = function (themeDetails) { var bsTheme = themeDetails.bstheme, bsVersion = $.fn.button.Constructor.VERSION[0]; if (bsVersion === '4') { self.classList.add('bg-' + bsTheme); } else { ['panel', 'panel-' + bsTheme].forEach(function (item) { self.classList.add(item); }); self.header.classList.add('panel-heading'); } // added support for material-design-for-bootstrap 4.x colors if (themeDetails.bs === 'mdb') { var mdbColor = bsTheme + '-color'; if (themeDetails.mdbStyle) { mdbColor = mdbColor + '-dark'; } self.classList.add(mdbColor); } // get primary theme color var pColor = void 0; if (bsVersion === '4') { pColor = window.getComputedStyle(self).backgroundColor.replace(/\s+/g, ''); } else { pColor = window.getComputedStyle(self.header).backgroundColor.replace(/\s+/g, ''); } if (themeDetails.filling) { self.setTheme(pColor + ' ' + themeDetails.filling); } else { self.setTheme(pColor); } return self; }; self.applyThemeBorder = function (themeDetails) { var bordervalues = opts.border.split(' '); self.style.borderWidth = bordervalues[0]; self.style.borderStyle = bordervalues[1]; self.style.borderColor = bordervalues[2]; self.header.style.borderTopLeftRadius = '1px'; self.header.style.borderTopRightRadius = '1px'; if (!themeDetails.bs) { if (jsPanel.themes.indexOf(themeDetails.color) === -1) { // arbitrary themes only (for built-in themes it's taken from the css file) bordervalues[2] ? self.style.borderColor = bordervalues[2] : self.style.borderColor = themeDetails.colors[0]; } } else { // bootstrap var pColor = void 0; if (window.getComputedStyle(self.header).backgroundColor === 'transparent') { pColor = window.getComputedStyle(self).backgroundColor.replace(/\s+/g, ''); } else { pColor = window.getComputedStyle(self.header).backgroundColor.replace(/\s+/g, ''); } bordervalues[2] ? self.style.borderColor = bordervalues[2] : self.style.borderColor = pColor; } return self; }; self.autopositionRemaining = function () { var autoPos = void 0; ['left-top-down', 'left-top-right', 'center-top-down', 'right-top-down', 'right-top-left', 'left-bottom-up', 'left-bottom-right', 'center-bottom-up', 'right-bottom-up', 'right-bottom-left'].forEach(function (item) { if (self.classList.contains(item)) { autoPos = item; } }); if (autoPos) { opts.container.querySelectorAll('.' + autoPos).forEach(function (item) { item.reposition(); }); } }; self.calcSizeFactors = function () { var styles = window.getComputedStyle(self); if (opts.container === document.body) { self.hf = parseFloat(self.style.left) / (document.body.clientWidth - parseFloat(self.style.width)); self.vf = parseFloat(self.style.top) / (window.innerHeight - parseFloat(styles.height)); } else { var parentStyles = window.getComputedStyle(self.parentElement); self.hf = parseFloat(self.style.left) / (parseFloat(parentStyles.width) - parseFloat(self.style.width)); self.vf = parseFloat(self.style.top) / (parseFloat(parentStyles.height) - parseFloat(styles.height)); } }; self.clearTheme = function (callback) { jsPanel.themes.concat(jsPanel.mdbthemes).forEach(function (value) { ['panel', 'jsPanel-theme-' + value, 'panel-' + value, value + '-color'].forEach(function (item) { self.classList.remove(item); }); self.header.classList.remove('panel-heading', 'jsPanel-theme-' + value); }, self); self.headertitle.classList.remove('panel-title'); self.content.classList.remove('panel-body', 'jsPanel-content-filled', 'jsPanel-content-filledlight'); self.footer.classList.remove('panel-footer'); jsPanel.setStyle(self, { backgroundColor: '', borderWidth: '', borderStyle: '', borderColor: '' }); jsPanel.setStyle(self.content, { background: '', border: '' }); jsPanel.setStyle(self.headertoolbar, { boxShadow: '', width: '', marginLeft: '' }); self.header.style.background = ''; Array.prototype.slice.call(self.controlbar.querySelectorAll('.jsglyph')).concat([self.headerlogo, self.headertitle, self.headertoolbar, self.content]).forEach(function (item) { item.style.color = ''; }); if (callback) { callback.call(self, self); } return self; }; self.close = function (callback) { var doClose = function doClose() { var panelId = opts.id; if (closetimer) { window.clearTimeout(closetimer); } self.closeChildpanels(); if (self.parentNode) { self.parentNode.removeChild(self); } // return false if panel was not removed from dom if (document.getElementById(panelId)) { return false; } self.removeMinimizedReplacement(); document.dispatchEvent(jspanelclosed); if (callback) { callback.call(panelId, panelId); } if (opts.onclosed) { opts.onclosed.call(panelId, panelId); } // if panel is autopositioned reposition remaining autopositioned panels self.autopositionRemaining(); }; document.dispatchEvent(jspanelbeforeclose); if (opts.onbeforeclose && opts.onbeforeclose.call(self, self) === false) { return self; } if (opts.animateOut) { if (opts.animateIn) { jsPanel.remClass(self, opts.animateIn); } jsPanel.setClass(self, opts.animateOut); self.addEventListener('animationend', function () { doClose(); }); } else { doClose(); } }; self.closeChildpanels = function (callback) { self.getChildpanels().forEach(function (item) { return item.close(); }); if (callback) { callback.call(self, self); } return self; }; self.contentRemove = function (callback) { jsPanel.emptyNode(self.content); if (callback) { callback.call(self, self); } return self; }; self.contentResize = function (callback) { var panelStyles = window.getComputedStyle(self), hdrStyles = window.getComputedStyle(self.header), ftrStyles = window.getComputedStyle(self.footer), hdrHeight = !opts.headerRemove ? hdrStyles.height : 0, ftrHeight = ftrStyles.display === 'none' ? 0 : ftrStyles.height; var contentHeight = parseFloat(panelStyles.height) - parseFloat(hdrHeight) - parseFloat(ftrHeight) - parseFloat(panelStyles.borderTopWidth) - parseFloat(panelStyles.borderBottomWidth); self.content.style.height = contentHeight + 'px'; if (callback) { callback.call(self, self); } return self; }; self.createMinimizedReplacement = function () { var tpl = jsPanel.createMinimizedTemplate(), color = window.getComputedStyle(self.headertitle).color, font = opts.iconfont, controlbar = tpl.querySelector('.jsPanel-controlbar'); tpl.style.backgroundColor = window.getComputedStyle(self.header).backgroundColor === 'transparent' ? window.getComputedStyle(self).backgroundColor : window.getComputedStyle(self.header).backgroundColor; tpl.id = self.id + '-min'; tpl.querySelector('.jsPanel-headerbar').replaceChild(self.headerlogo.cloneNode(true), tpl.querySelector('.jsPanel-headerlogo')); tpl.querySelector('.jsPanel-titlebar').replaceChild(self.headertitle.cloneNode(true), tpl.querySelector('.jsPanel-title')); tpl.querySelector('.jsPanel-title').style.color = color; controlbar.style.color = color; // set iconfont self.setIconfont(font, tpl); if (self.dataset.btnnormalize === 'enabled') { jsPanel.pointerup.forEach(function (evt) { tpl.querySelector('.jsPanel-btn-normalize').addEventListener(evt, function () { self.normalize().removeMinimizedReplacement(); }); }); } else { controlbar.querySelector('.jsPanel-btn-normalize').style.display = 'none'; } if (self.dataset.btnmaximize === 'enabled') { jsPanel.pointerup.forEach(function (evt) { tpl.querySelector('.jsPanel-btn-maximize').addEventListener(evt, function () { self.maximize().removeMinimizedReplacement(); }); }); } else { controlbar.querySelector('.jsPanel-btn-maximize').style.display = 'none'; } if (self.dataset.btnclose === 'enabled') { jsPanel.pointerup.forEach(function (evt) { tpl.querySelector('.jsPanel-btn-close').addEventListener(evt, function () { self.removeMinimizedReplacement().close(); }); }); } else { controlbar.querySelector('.jsPanel-btn-close').style.display = 'none'; } return tpl; }; self.front = function (callback) { jsPanel.front(self); document.dispatchEvent(jspanelfronted); if (callback) { callback.call(self, self); } if (opts.onfronted) { opts.onfronted.call(self, self); } return self; }; self.getChildpanels = function () { return Array.prototype.slice.call(self.content.querySelectorAll('.jsPanel')); }; self.getThemeDetails = function (th) { var passedTheme = th.toLowerCase().replace(/ /g, ''), theme = { color: false, colors: false, filling: false, bs: false, bstheme: false }; if (passedTheme.substr(-6, 6) === 'filled') { theme.filling = 'filled'; theme.color = passedTheme.substr(0, passedTheme.length - 6); } else if (passedTheme.substr(-11, 11) === 'filledlight') { theme.filling = 'filledlight'; theme.color = passedTheme.substr(0, passedTheme.length - 11); } else { theme.filling = ''; theme.color = passedTheme; // themeDetails.color is the primary color } theme.colors = jsPanel.calcColors(theme.color); // if first part of theme includes a "-" it's assumed to be a bootstrap theme if (theme.color.match('-')) { var bsVariant = theme.color.split('-'); theme.bs = bsVariant[0]; theme.bstheme = bsVariant[1]; theme.mdbStyle = bsVariant[2] || undefined; } return theme; }; self.isChildpanel = function () { // if panel is childpanel of another panel returns parentpanel var pp = self.closest('.jsPanel-content'); return pp ? pp.parentNode : false; }; self.maximize = function (callback) { // Note: do not disable maximize method for already maximized panels -> onwindowresize wouldn't work if (opts.onbeforemaximize && opts.onbeforemaximize.call(self, self) === false) { return self; } document.dispatchEvent(jspanelbeforemaximize); var parent = self.parentNode, margins = opts.maximizedMargin; if (parent === document.body) { // maximize within window self.style.width = document.documentElement.clientWidth - margins[1] - margins[3] + 'px'; self.style.height = document.documentElement.clientHeight - margins[0] - margins[2] + 'px'; self.style.left = margins[3] + 'px'; self.style.top = margins[0] + 'px'; if (!opts.position.fixed) { self.style.left = window.pageXOffset + margins[3] + 'px'; self.style.top = window.pageYOffset + margins[0] + 'px'; } } else { // maximize within parentNode self.style.width = parent.clientWidth - margins[1] - margins[3] + 'px'; self.style.height = parent.clientHeight - margins[0] - margins[2] + 'px'; self.style.left = margins[3] + 'px'; self.style.top = margins[0] + 'px'; } self.contentResize(); self.removeMinimizedReplacement(); self.status = 'maximized'; self.setControls(['.jsPanel-btn-maximize', '.jsPanel-btn-smallifyrev']); jsPanel.front(self); document.dispatchEvent(jspanelmaximized); document.dispatchEvent(jspanelstatuschange); if (opts.onstatuschange && opts.onstatuschange.call(self, self) === false) { return self; } if (callback) { callback.call(self, self); } if (opts.onmaximized) { opts.onmaximized.call(self, self); } return self; }; self.minimize = function (callback) { if (self.status === 'minimized') { return self; } if (opts.onbeforeminimize && opts.onbeforeminimize.call(self, self) === false) { return self; } document.dispatchEvent(jspanelbeforeminimize); // create container for minimized replacements if not already there if (!document.getElementById('jsPanel-replacement-container')) { var replacementContainer = document.createElement('div'); replacementContainer.id = 'jsPanel-replacement-container'; document.body.append(replacementContainer); } self.style.left = '-9999px'; self.statusBefore = self.status; self.status = 'minimized'; document.dispatchEvent(jspanelminimized); document.dispatchEvent(jspanelstatuschange); if (opts.onstatuschange && opts.onstatuschange.call(self, self) === false) { return self; } if (opts.minimizeTo) { var replacement = self.createMinimizedReplacement(); if (opts.minimizeTo === 'default') { document.getElementById('jsPanel-replacement-container').append(replacement); } else { var container = void 0; if (typeof opts.minimizeTo === 'string') { if (opts.minimizeTo === 'parentpanel') { var parent = self.closest('.jsPanel-content').parentNode, list = parent.querySelectorAll('.jsPanel-minimized-box'); container = list[list.length - 1]; } else { container = document.querySelector(opts.minimizeTo); } } else { container = opts.minimizeTo; } container.append(replacement); } } if (callback) { callback.call(self, self); } if (opts.onminimized) { opts.onminimized.call(self, self); } return self; }; self.normalize = function (callback) { if (self.status === 'normalized') { return self; } if (opts.onbeforenormalize && opts.onbeforenormalize.call(self, self) === false) { return self; } document.dispatchEvent(jspanelbeforenormalize); self.style.width = self.currentData.width; self.style.height = self.currentData.height; self.contentResize(); self.style.left = self.currentData.left; self.style.top = self.currentData.top; self.removeMinimizedReplacement(); self.status = 'normalized'; self.setControls(['.jsPanel-btn-normalize', '.jsPanel-btn-smallifyrev']); jsPanel.front(self); document.dispatchEvent(jspanelnormalized); document.dispatchEvent(jspanelstatuschange); if (opts.onstatuschange && opts.onstatuschange.call(self, self) === false) { return self; } if (callback) { callback.call(self, self); } if (opts.onnormalized) { opts.onnormalized.call(self, self); } return self; }; self.removeMinimizedReplacement = function () { var elmt = document.getElementById(self.id + '-min'); if (elmt) { elmt.parentNode.removeChild(elmt); } return self; }; self.reposition = function () { for (var _len = arguments.length, params = Array(_len), _key = 0; _key < _len; _key++) { params[_key] = arguments[_key]; } var pos = opts.position, updateCache = true, callback = void 0; params.forEach(function (value) { if (typeof value === 'string' || (typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object') { pos = value; } else if (typeof value === 'boolean') { updateCache = value; } else if (typeof value === 'function') { callback = value; } }); jsPanel.position(self, pos); if (updateCache) { self.saveCurrentPosition(); } if (callback) { callback.call(self, self); } return self; }; self.repositionOnSnap = function (pos) { var offsetX = '0', offsetY = '0'; var margins = jsPanel.pOcontainment(opts.dragit.containment); // calculate offsets if (opts.dragit.snap.containment) { if (pos === 'left-top') { offsetX = margins[3]; offsetY = margins[0]; } else if (pos === 'right-top') { offsetX = -margins[1]; offsetY = margins[0]; } else if (pos === 'right-bottom') { offsetX = -margins[1]; offsetY = -margins[2]; } else if (pos === 'left-bottom') { offsetX = margins[3]; offsetY = -margins[2]; } else if (pos === 'center-top') { offsetX = margins[3] / 2 - margins[1] / 2; offsetY = margins[0]; } else if (pos === 'center-bottom') { offsetX = margins[3] / 2 - margins[1] / 2; offsetY = -margins[2]; } else if (pos === 'left-center') { offsetX = margins[3]; offsetY = margins[0] / 2 - margins[2] / 2; } else if (pos === 'right-center') { offsetX = -margins[1]; offsetY = margins[0] / 2 - margins[2] / 2; } } /* jsPanel.position(self, `${pos} ${offsetX} ${offsetY}`); For some reason I could not find the line above does not work (pos and offsets in one string), but only when center-bottom is used with different settings for left/right margin. */ jsPanel.position(self, pos); jsPanel.setStyle(self, { left: 'calc(' + self.style.left + ' + ' + offsetX + 'px)', top: 'calc(' + self.style.top + ' + ' + offsetY + 'px)' }); }; self.resize = function () { for (var _len2 = arguments.length, params = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { params[_key2] = arguments[_key2]; } var dimensions = window.getComputedStyle(self); var size = { width: dimensions.width, height: dimensions.height }, updateCache = true, callback = void 0; params.forEach(function (value) { if (typeof value === 'string') { size = value; } else if ((typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object') { size = Object.assign(size, value); } else if (typeof value === 'boolean') { updateCache = value; } else if (typeof value === 'function') { callback = value; } }); var values = jsPanel.pOsize(self, size); self.style.width = values.width; self.style.height = values.height; self.contentResize(); if (updateCache) { self.saveCurrentDimensions(); } if (callback) { callback.call(self, self); } return self; }; self.saveCurrentDimensions = function () { var normData = window.getComputedStyle(self); self.currentData.width = normData.width; if (self.status === 'normalized') { self.currentData.height = normData.height; } }; self.saveCurrentPosition = function () { var normData = window.getComputedStyle(self); self.currentData.left = normData.left; self.currentData.top = normData.top; }; self.setControls = function (sel, callback) { self.header.querySelectorAll('.jsPanel-btn').forEach(function (item) { item.style.display = 'block'; }); sel.forEach(function (item) { var btn = self.controlbar.querySelector(item); if (btn) { btn.style.display = 'none'; } }); if (callback) { callback.call(self, self); } return self; }; self.setControlStatus = function (ctrl) { var action = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'enable'; var callback = arguments[2]; if (action === 'disable') { if (self.getAttribute('data-btn' + ctrl) !== 'removed') { self.setAttribute('data-btn' + ctrl, 'disabled'); var btn = self.controlbar.querySelector('.jsPanel-btn-' + ctrl); btn.style.pointerEvents = 'none'; btn.style.opacity = 0.4; btn.style.cursor = 'default'; } } else if (action === 'enable') { if (self.getAttribute('data-btn' + ctrl) !== 'removed') { self.setAttribute('data-btn' + ctrl, 'enabled'); var _btn = self.controlbar.querySelector('.jsPanel-btn-' + ctrl); _btn.style.pointerEvents = 'auto'; _btn.style.opacity = 1; _btn.style.cursor = 'pointer'; } } else if (action === 'remove') { var _btn2 = self.controlbar.querySelector('.jsPanel-btn-' + ctrl); self.controlbar.removeChild(_btn2); self.setAttribute('data-btn' + ctrl, 'removed'); } if (callback) { callback.call(self, self); } return self; }; self.setHeaderControls = function (callback) { var controls = ['close', 'maximize', 'normalize', 'minimize', 'smallify', 'smallifyrev'], option = opts.headerControls; if (typeof option === 'string') { if (option === 'none') { controls.forEach(function (item) { self.setControlStatus(item, 'remove'); }); } else if (option === 'closeonly') { controls.forEach(function (item) { if (item !== 'close') { self.setControlStatus(item, 'remove'); } }); } } else { controls.forEach(function (item) { if (option[item]) { self.setControlStatus(item, option[item]); } }); } if (callback) { callback.call(self, self); } return self; }; self.setHeaderLogo = function (hdrLogo, callback) { if (typeof hdrLogo === 'string') { if (hdrLogo.substr(0, 1) !== '<') { // is assumed to be an img url var img = document.createElement('img'); img.style.maxHeight = getComputedStyle(self.headerbar).height; img.src = hdrLogo; jsPanel.emptyNode(self.headerlogo); self.headerlogo.append(img); } else { self.headerlogo.innerHTML = hdrLogo; } } else { // assumed to be a node object jsPanel.emptyNode(self.headerlogo); self.headerlogo.append(hdrLogo); } if (callback) { callback.call(self, self); } return self; }; self.setHeaderRemove = function (callback) { self.removeChild(self.header); self.content.classList.add('jsPanel-content-noheader'); ['close', 'maximize', 'normalize', 'minimize', 'smallify', 'smallifyrev'].forEach(function (item) { self.setAttribute('data-btn' + item, 'removed'); }); if (callback) { callback.call(self, self); } return self; }; self.setHeaderTitle = function (hdrTitle, callback) { if (typeof hdrTitle === 'string') { self.headertitle.innerHTML = hdrTitle; } else if (typeof hdrTitle === 'function') { jsPanel.emptyNode(self.headertitle); self.headertitle.innerHTML = hdrTitle(); } else { // assumed to be a node object jsPanel.emptyNode(self.headertitle); self.headertitle.append(hdrTitle); } if (callback) { callback.call(self, self); } return self; }; self.setIconfont = function () { var font = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'jsglyph'; var panel = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : self; var callback = arguments[2]; if (font !== 'jsglyph') { var classArray = void 0, textArray = void 0; if (font === 'bootstrap' || font === 'glyphicon') { classArray = ['glyphicon glyphicon-remove', 'glyphicon glyphicon-fullscreen', 'glyphicon glyphicon-resize-full', 'glyphicon glyphicon-minus', 'glyphicon glyphicon-chevron-down', 'glyphicon glyphicon-chevron-up']; } else if (font === 'fa' || font === 'far' || font === 'fal' || font === 'fas') { classArray = [font + ' fa-window-close', font + ' fa-window-maximize', font + ' fa-window-restore', font + ' fa-window-minimize', font + ' fa-chevron-down', font + ' fa-chevron-up']; } else if (font === 'material-icons') { classArray = [font, font, font, font, font, font]; textArray = ['close', 'fullscreen', 'fullscreen_exit', 'call_received', 'expand_more', 'expand_less']; } else if (Array.isArray(font)) { classArray = ['custom-control-icon ' + font[5], 'custom-control-icon ' + font[4], 'custom-control-icon ' + font[3], 'custom-control-icon ' + font[2], 'custom-control-icon ' + font[1], 'custom-control-icon ' + font[0]]; } else { return panel; } Array.prototype.slice.call(panel.querySelectorAll('.jsPanel-controlbar .jsPanel-btn > span')).reverse().forEach(function (item, i) { item.className = classArray[i]; if (font === 'material-icons') { item.textContent = textArray[i]; } }); } if (callback) { callback.call(panel, panel); } return panel; }; self.setRtl = function () { [self.header, self.headerbar, self.titlebar, self.controlbar, self.headertoolbar, self.footer].forEach(function (item) { item.classList.add('jsPanel-rtl'); }); [self.headertitle, self.headertoolbar, self.content, self.footer].forEach(function (item) { item.dir = 'rtl'; if (opts.rtl.lang) { item.lang = opts.rtl.lang; } }); }; self.setSize = function () { if (opts.panelSize) { var values = jsPanel.pOsize(self, opts.panelSize); self.style.width = values.width; self.style.height = values.height; self.contentResize(); } else if (opts.contentSize) { var _values = jsPanel.pOsize(self, opts.contentSize); self.content.style.width = _values.width; self.content.style.height = _values.height; // explicitly assign current width/height to panel self.style.width = _values.width; // then set content width to 100% self.content.style.width = '100%'; } return self; }; self.setTheme = function () { var theme = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : opts.theme; var callback = arguments[1]; // first remove all theme related syles self.clearTheme(); if (theme === 'none') { // results in an all white panel without any theme related classes/styles applied // removal of footer background/border is done in jsP.toolbarAdd() self.style.backgroundColor = '#fff'; return self; } var themeDetails = self.getThemeDetails(theme); if (!themeDetails.bs) { if (jsPanel.themes.indexOf(themeDetails.color) !== -1) { self.applyBuiltInTheme(themeDetails); } else { self.applyArbitraryTheme(themeDetails); } } else { self.applyBootstrapTheme(themeDetails); } if (opts.border) { self.applyThemeBorder(themeDetails); } else { self.style.borderWidth = ''; self.style.borderStyle = ''; self.style.borderColor = ''; } if (callback) { callback.call(self, self); } return self; }; self.smallify = function (callback) { if (self.status === 'smallified' || self.status === 'smallifiedmax') { return self; } if (opts.onbeforesmallify && opts.onbeforesmallify.call(self, self) === false) { return self; } document.dispatchEvent(jspanelbeforesmallify); if (self.status === 'normalized') { self.saveCurrentDimensions(); } self.style.overflow = 'hidden'; self.style.height = window.getComputedStyle(self.headerbar).height; if (self.status === 'normalized') { self.setControls(['.jsPanel-btn-normalize', '.jsPanel-btn-smallify']); self.status = 'smallified'; document.dispatchEvent(jspanelsmallified); document.dispatchEvent(jspanelstatuschange); if (opts.onstatuschange && opts.onstatuschange.call(self, self) === false) { return self; } } else if (self.status === 'maximized') { self.setControls(['.jsPanel-btn-maximize', '.jsPanel-btn-smallify']); self.status = 'smallifiedmax'; document.dispatchEvent(jspanelsmallifiedmax); document.dispatchEvent(jspanelstatuschange); if (opts.onstatuschange && opts.onstatuschange.call(self, self) === false) { return self; } } if (callback) { callback.call(self, self); } if (opts.onsmallified) { opts.onsmallified.call(self, self); } return self; }; self.unsmallify = function (callback) { if (self.status === 'smallified' || self.status === 'smallifiedmax') { if (opts.onbeforeunsmallify && opts.onbeforeunsmallify.call(self, self) === false) { return self; } document.dispatchEvent(jspanelbeforeunsmallify); self.style.overflow = 'visible'; jsPanel.front(self); if (self.status === 'smallified') { self.style.height = self.currentData.height; self.setControls(['.jsPanel-btn-normalize', '.jsPanel-btn-smallifyrev']); self.status = 'normalized'; document.dispatchEvent(jspanelnormalized); document.dispatchEvent(jspanelstatuschange); if (opts.onstatuschange && opts.onstatuschange.call(self, self) === false) { return self; } } else if (self.status === 'smallifiedmax') { self.maximize(); } else if (self.status === 'minimized') { self.normalize(); } if (callback) { callback.call(self, self); } if (opts.onunsmallified) { opts.onunsmallified.call(self, self); } } return self; }; self.dragit = function (string) { var dragitOptions = Object.assign({}, jsPanel.defaults.dragit, opts.dragit), handles = self.querySelectorAll(dragitOptions.handles); if (string === 'disable') { handles.forEach(function (handle) { handle.style.pointerEvents = 'none'; }); } else { handles.forEach(function (handle) { handle.style.pointerEvents = 'auto'; }); } return self; }; self.resizeit = function (string) { var handles = self.querySelectorAll('.jsPanel-resizeit-handle'); if (string === 'disable') { handles.forEach(function (handle) { handle.style.pointerEvents = 'none'; }); } else { handles.forEach(function (handle) { handle.style.pointerEvents = 'auto'; }); } return self; }; // option.id self.id = opts.id; // option.paneltype classname self.classList.add('jsPanel-' + opts.paneltype); // set z-index and paneltype class if (opts.paneltype === 'standard') { self.style.zIndex = this.zi.next(); } // option.container panelContainer.append(self); // option.theme self.setTheme(opts.theme); // option.boxShadow if (opts.boxShadow) { self.classList.add('jsPanel-depth-' + opts.boxShadow); } /* option.headerRemove, option.iconfont, option.headerControls, option.headerLogo, option.headerTitle */ if (!opts.headerRemove) { if (opts.headerLogo) { self.setHeaderLogo(opts.headerLogo); } self.setIconfont(opts.iconfont); self.setHeaderTitle(opts.headerTitle); self.setHeaderControls(); } else { self.setHeaderRemove(); } // option.headerToolbar if (opts.headerToolbar) { self.addToolbar(self.headertoolbar, opts.headerToolbar); } // option.footerToolbar if (opts.footerToolbar) { self.addToolbar(self.footer, opts.footerToolbar); } // option.content if (opts.content) { if (typeof opts.content === 'function') { opts.content.call(self, self); } else if (typeof opts.content === 'string') { self.content.innerHTML = opts.content; } else { self.content.append(opts.content); } } // option.contentAjax if (opts.contentAjax) { this.ajax(self); } // option.contentFetch if (opts.contentFetch) { this.fetch(self); } // option.rtl if (opts.rtl) { self.setRtl(); } // option.size -- should be after option.theme self.setSize(); // option.position self.status = 'normalized'; // if option.position evaluates to false panel will not be positioned at all if (opts.position || opts.position !== 'cursor') { this.position(self, opts.position); } else { self.style.opacity = 1; } document.dispatchEvent(jspanelnormalized); document.dispatchEvent(jspanelstatuschange); if (opts.onstatuschange && opts.onstatuschange.call(self, self) === false) { return self; } self.calcSizeFactors(); // option.animateIn if (opts.animateIn) { // remove class again on animationend, otherwise opacity doesn't change when panel is dragged self.addEventListener('animationend', function () { _this.remClass(self, opts.animateIn); }); this.setClass(self, opts.animateIn); } // option.dragit AND option.resizeit AND option.syncMargins if (opts.syncMargins) { var containment = this.pOcontainment(opts.maximizedMargin); if (opts.dragit) { opts.dragit.containment = containment; if (opts.dragit.snap) { opts.dragit.snap.containment = true; } } if (opts.resizeit) { opts.resizeit.containment = containment; } } if (opts.dragit) { this.dragit(self, opts.dragit); document.addEventListener('dragstop', function (e) { if (e.detail === self.id) { self.calcSizeFactors(); } }, false); } else { self.titlebar.style.cursor = 'default'; } if (opts.resizeit) { this.resizeit(self, opts.resizeit); var startstatus = void 0; document.addEventListener('resizestart', function (e) { if (e.detail === self.id) { startstatus = self.status; } }, false); document.addEventListener('resizestop', function (e) { if (e.detail === self.id) { if ((startstatus === 'smallified' || startstatus === 'smallifiedmax' || startstatus === 'maximized') && parseFloat(self.style.height) > parseFloat(window.getComputedStyle(self.header).height)) { self.setControls(['.jsPanel-btn-normalize', '.jsPanel-btn-smallifyrev']); self.status = 'normalized'; document.dispatchEvent(jspanelnormalized); document.dispatchEvent(jspanelstatuschange); if (opts.onstatuschange && opts.onstatuschange.call(self, self) === false) { return self; } self.calcSizeFactors(); } } }, false); } // initialize self.currentData - must be after options position & size self.saveCurrentDimensions(); self.saveCurrentPosition(); // option.setStatus if (opts.setStatus) { var newStatus = opts.setStatus; if (newStatus === 'smallifiedmax') { self.maximize().smallify(); } else if (newStatus === 'smallified') { self.smallify(); } else { var func = newStatus.substr(0, newStatus.length - 1); self[func](); } } // option.autoclose if (opts.autoclose) { closetimer = window.setTimeout(function () { if (self) self.close(); }, opts.autoclose); } // front panel on mousedown this.pointerdown.forEach(function (item) { self.addEventListener(item, function (e) { if (!e.target.closest('.jsPanel-btn-close') && !e.target.closest('.jsPanel-btn-minimize') && opts.paneltype === 'standard') { self.front(); } }, false); }); // option.onwindowresize if (opts.onwindowresize) { window.addEventListener('resize', function (e) { if (e.target === window) { // see https://bugs.jqueryui.com/ticket/7514 var param = opts.onwindowresize, status = self.status, parentStyles = window.getComputedStyle(self.parentNode); if (status === 'maximized' && param === true) { self.maximize(); } else if (status === 'normalized' || status === 'smallified' || status === 'maximized') { if (typeof param === 'function') { param.call(self, e, self); } else { self.style.left = function () { var l = void 0; if (opts.container === document.body) { l = (document.body.clientWidth - parseFloat(self.style.width)) * self.hf; } else { l = (parseFloat(parentStyles.width) - parseFloat(self.style.width)) * self.hf; } return l <= 0 ? 0 : l + 'px'; }(); self.style.top = function () { var t = void 0; if (opts.container === document.body) { t = (window.innerHeight - parseFloat(self.currentData.height)) * self.vf; } else { t = (parseFloat(parentStyles.height) - parseFloat(self.currentData.height)) * self.vf; } return t <= 0 ? 0 : t + 'px'; }(); } } } }, false); } // without this handler content section would have pointerEvents = none when clicking header section (see dragit) this.pointerup.forEach(function (item) { self.addEventListener(item, function () { self.content.style.pointerEvents = 'inherit'; }); }); // option.callback if (opts.callback && Array.isArray(opts.callback)) { opts.callback.forEach(function (item) { item.call(self, self); }); } else if (opts.callback) { opts.callback.call(self, self); } // construtor callback if (cb) { cb.call(self, self); } document.dispatchEvent(jspanelloaded); return self; } }; // initialize z-index generator (needs to be seperate because jsPanel is not defined yet when putting it inside jsPanel = { ... }) jsPanel.zi = function () { var startValue = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : jsPanel.ziBase; var val = startValue; return { next: function next() { return val++; } }; }(); if (window.PointerEvent) { jsPanel.pointerdown = ['pointerdown']; jsPanel.pointermove = ['pointermove']; jsPanel.pointerup = ['pointerup']; } else { if ('ontouchend' in window) { jsPanel.pointerdown = ['touchstart', 'mousedown']; jsPanel.pointermove = ['touchmove', 'mousemove']; jsPanel.pointerup = ['touchend', 'mouseup']; } else { jsPanel.pointerdown = ['mousedown']; jsPanel.pointermove = ['mousemove']; jsPanel.pointerup = ['mouseup']; } } // closeOnEscape document.addEventListener('keydown', function (e) { if (e.key === 'Escape' || e.code === 'Esc' || e.keyCode === 27) { jsPanel.getPanels(function () { return this.classList.contains('jsPanel'); }).some(function (item) { if (item.options.closeOnEscape) { item.close(); return true; } return false; }); } }, false);