/*! * file : layx.js * gitee : https://gitee.com/monksoul/LayX * github : https://github.com/MonkSoul/Layx/ * author : 百小僧/MonkSoul * version : v2.5.4 * create time : 2018.05.11 * update time : 2018.11.03 */ ; !(function (over, win, slf) { var Layx = { version: '2.5.4', defaults: { id: '', icon: true, title: '', width: 800, height: 600, minWidth: 200, minHeight: 200, position: 'ct', storeStatus: true, control: true, style: '', controlStyle: '', existFlicker: true, bgColor: "#fff", shadow: true, border: true, borderRadius: '3px', skin: 'default', type: 'html', focusToReveal: true, enableDomainFocus: true, dialogType: '', frames: [], frameIndex: 0, preload: 1, mergeTitle: true, content: '', dialogIcon: false, cloneElementContent: true, url: '', useFrameTitle: false, opacity: 1, escKey: true, floatTarget: false, floatDirection: 'bottom', shadable: false, shadeDestroy: false, readonly: false, loadingText: '内容正在加载中,请稍后', dragInTopToMax: true, isOverToMax: true, stickMenu: false, stickable: true, minMenu: true, minable: true, maxMenu: true, maxable: true, closeMenu: true, closable: true, debugMenu: false, restorable: true, resizable: true, autodestroy: false, autodestroyText: '此窗口将在 {second} 秒内自动关闭.', resizeLimit: { t: false, r: false, b: false, l: false, lt: false, rt: false, lb: false, rb: false }, buttonKey: 'enter', buttons: [], movable: true, moveLimit: { vertical: false, horizontal: false, leftOut: true, rightOut: true, topOut: true, bottomOut: true }, focusable: true, alwaysOnTop: false, allowControlDbclick: true, statusBar: false, statusBarStyle: '', event: { onload: { before: function (layxWindow, winform) { }, after: function (layxWindow, winform) { } }, onmin: { before: function (layxWindow, winform) { }, after: function (layxWindow, winform) { } }, onmax: { before: function (layxWindow, winform) { }, after: function (layxWindow, winform) { } }, onrestore: { before: function (layxWindow, winform) { }, after: function (layxWindow, winform) { } }, ondestroy: { before: function (layxWindow, winform, params, inside, escKey) { }, after: function () { } }, onvisual: { before: function (layxWindow, winform, params, inside, status) { }, after: function (layxWindow, winform, status) { } }, onmove: { before: function (layxWindow, winform) { }, progress: function (layxWindow, winform) { }, after: function (layxWindow, winform) { } }, onresize: { before: function (layxWindow, winform) { }, progress: function (layxWindow, winform) { }, after: function (layxWindow, winform) { } }, onfocus: function (layxWindow, winform) { }, onexist: function (layxWindow, winform) { }, onswitch: { before: function (layxWindow, winform, frameId) { }, after: function (layxWindow, winform, frameId) { } }, onstick: { before: function (layxWindow, winform) { }, after: function (layxWindow, winform) { } } } }, defaultButtons: { label: '确定', callback: function (id, button, event) { }, id: '', classes: [], style: '' }, defaultFrames: { id: '', title: '', type: 'html', url: '', content: '', useFrameTitle: false, cloneElementContent: true, bgColor: "#fff" }, zIndex: 10000000, windows: {}, stickZIndex: 20000000, prevFocusId: null, focusId: null, create: function (options) { var that = this, config = layxDeepClone({}, that.defaults, options || {}), winform = {}; if (!config.id) { console.error("窗口id不能为空且唯一"); return; } Layx.prevFocusId = Layx.focusId; Layx.focusId = config.id; var _winform = that.windows[config.id]; if (_winform) { if (_winform.status === "min") { that.restore(_winform.id); } if (_winform.existFlicker === true) { that.flicker(config.id); } if (Utils.isFunction(config.event.onexist)) { config.event.onexist(_winform.layxWindow, _winform); } var fixFocus = setInterval(function () { if (config.id !== Layx.focusId) { that.updateZIndex(config.id); } else { clearInterval(fixFocus); } }, 0); return _winform; } if (Utils.isArray(config.frames)) { for (var i = 0; i < config.frames.length; i++) { config.frames[i] = layxDeepClone({}, that.defaultFrames, config.frames[i]); if (!config.frames[i].id) { console.error("窗口组窗口id不能为空且窗口组内唯一"); return; } } } if (Utils.isArray(config.buttons)) { for (var i = 0; i < config.buttons.length; i++) { config.buttons[i] = layxDeepClone({}, that.defaultButtons, config.buttons[i]); } } if (config.shadable === true || /^(0(\.[0-9])?$)|(1)$/.test(config.shadable)) { var layxShade = document.createElement("div"); layxShade.setAttribute("id", "layx-" + config.id + "-shade"); layxShade.classList.add("layx-shade"); layxShade.style.zIndex = config.alwaysOnTop === true ? (++that.stickZIndex) : (++that.zIndex); if (/^(0(\.[0-9])?$)|(1)$/.test(config.shadable)) { layxShade.style.backgroundColor = "rgba(0,0,0," + config.shadable + ")"; } layxShade.oncontextmenu = function (e) { e = e || window.event; e.returnValue = false; return false; }; layxShade.onclick = function (e) { e = e || window.event; if (config.shadeDestroy === true) { that.destroy(config.id, null, true); } else { if (config.existFlicker === true) { that.flicker(config.id); } } e.stopPropagation(); }; document.body.appendChild(layxShade); } if (config.style) { var style = document.getElementById("layx-style"); if (style) { style.innerHTML += config.style; } else { style = document.createElement("style"); style.setAttribute("id", "layx-style"); style.type = "text/css"; style.innerHTML = config.style; document.getElementsByTagName("HEAD").item(0).appendChild(style); } } var layxWindow = document.createElement("div"); layxWindow.setAttribute("id", "layx-" + config.id); layxWindow.classList.add("layx-window"); layxWindow.classList.add("layx-flexbox"); layxWindow.classList.add("layx-skin-" + config.skin); if (config.shadow === true) { layxWindow.style.setProperty("box-shadow", "1px 1px 24px rgba(0, 0, 0, .3)"); layxWindow.style.setProperty("-moz-box-shadow", "1px 1px 24px rgba(0, 0, 0, .3)"); layxWindow.style.setProperty("-webkit-box-shadow", "1px 1px 24px rgba(0, 0, 0, .3)"); } var _minWidth, _minHeight, _width, _height, _top, _left; _minWidth = Utils.compileLayxWidthOrHeight("width", config.minWidth, that.defaults.minWidth); _minHeight = Utils.compileLayxWidthOrHeight("height", config.minHeight, that.defaults.minHeight); _width = Utils.compileLayxWidthOrHeight("width", config.width, that.defaults.width); _height = Utils.compileLayxWidthOrHeight("height", config.height, that.defaults.height); _width = Math.max(_width, _minWidth); _height = Math.max(_height, _minHeight); var _position = Utils.compileLayxPosition(_width, _height, config.position); _top = _position.top; _left = _position.left; _top = Math.max(_top, 0); _top = Math.min(win.innerHeight - 15, _top); _left = Math.max(_left, -(_width - 15)); _left = Math.min(_left, win.innerWidth - 15); if (config.storeStatus === true && config.floatTarget === false) { var _areaInfo = that.getStoreWindowAreaInfo(config.id); if (_areaInfo) { _width = _areaInfo.width; _height = _areaInfo.height; _top = _areaInfo.top; _left = _areaInfo.left; } else { that.storeWindowAreaInfo(config.id, { width: _width, height: _height, top: _top, left: _left }); } } else { that.removeStoreWindowAreaInfo(config.id); } if (Utils.isDom(config.floatTarget)) { layxWindow.classList.add("layx-bubble-type"); var bubble = document.createElement("div"); bubble.classList.add("layx-bubble"); bubble.classList.add("layx-bubble-" + config.floatDirection); layxWindow.appendChild(bubble); var bubbleInlay = document.createElement("div"); bubbleInlay.classList.add("layx-bubble-inlay"); bubbleInlay.classList.add("layx-bubble-inlay-" + config.floatDirection); bubble.appendChild(bubbleInlay); } layxWindow.style.zIndex = config.alwaysOnTop === true ? (++that.stickZIndex) : (++that.zIndex); layxWindow.style.width = _width + "px"; layxWindow.style.height = _height + "px"; layxWindow.style.minWidth = _minWidth + "px"; layxWindow.style.minHeight = _minHeight + "px"; layxWindow.style.top = _top + "px"; layxWindow.style.left = _left + "px"; layxWindow.style.setProperty("border", Utils.isBoolean(config.border) ? (config.skin === "default" && config.border === true ? "" : "none") : config.border); layxWindow.style.backgroundColor = config.bgColor; layxWindow.style.setProperty("border-radius", config.borderRadius); layxWindow.style.setProperty("-moz-border-radius", config.borderRadius); layxWindow.style.setProperty("-webkit-border-radius", config.borderRadius); layxWindow.style.opacity = /^(0(\.[0-9])?$)|(1)$/.test(config.opacity) ? config.opacity : 1; if (config.focusable === true) { layxWindow.onclick = function (e) { e = e || window.event; if (Utils.isFunction(config.event.onfocus)) { var revel = Utils.isFunction(config.event.onfocus); if (revel === false) { return; } config.event.onfocus(layxWindow, winform); } that.updateZIndex(config.id); }; } document.body.appendChild(layxWindow); var layxWindowStyle = layxWindow.currentStyle ? layxWindow.currentStyle : win.getComputedStyle(layxWindow, null); winform.id = config.id; winform.title = config.title; winform.layxWindowId = layxWindow.getAttribute("id"); winform.layxWindow = layxWindow; winform.createDate = new Date(); winform.status = "normal"; winform.type = config.type; winform.buttons = config.buttons; winform.frames = config.frames; winform.useFrameTitle = config.useFrameTitle; winform.cloneElementContent = config.cloneElementContent; winform.storeStatus = config.storeStatus; winform.url = config.url; winform.content = config.content; winform.escKey = config.escKey; winform.focusToReveal = config.focusToReveal; winform.dialogType = config.dialogType; winform.enableDomainFocus = config.enableDomainFocus; winform.buttonKey = config.buttonKey; winform.existFlicker = config.existFlicker; winform.groupCurrentId = (Utils.isArray(config.frames) && config.frames.length > 0 && config.frames[config.frameIndex]) ? config.frames[config.frameIndex].id : null; winform.area = { width: _width, height: _height, minWidth: _minWidth, minHeight: _minHeight, top: _top, left: _left }; winform.border = config.border; winform.control = config.control; winform.isFloatTarget = Utils.isDom(config.floatTarget); winform.floatTarget = config.floatTarget; winform.floatDirection = config.floatDirection; winform.loadingText = config.loadingText; winform.focusable = config.focusable; winform.isStick = config.alwaysOnTop === true; winform.zIndex = config.alwaysOnTop === true ? that.stickZIndex : that.zIndex; winform.movable = config.movable; winform.moveLimit = config.moveLimit; winform.resizable = config.resizable; winform.resizeLimit = config.resizeLimit; winform.stickable = config.stickable; winform.minable = config.minable; winform.maxable = config.maxable; winform.restorable = config.restorable; winform.closable = config.closable; winform.skin = config.skin; winform.event = config.event; winform.dragInTopToMax = config.dragInTopToMax; that.windows[config.id] = winform; if (config.control === true) { var controlBar = document.createElement("div"); controlBar.classList.add("layx-control-bar"); controlBar.classList.add("layx-flexbox"); controlBar.style.setProperty("border-radius", layxWindowStyle.borderRadius + " " + layxWindowStyle.borderRadius + " " + "0 0"); controlBar.style.setProperty("-moz-border-radius", layxWindowStyle.borderRadius + " " + layxWindowStyle.borderRadius + " " + "0 0"); controlBar.style.setProperty("-webkit-border-radius", layxWindowStyle.borderRadius + " " + layxWindowStyle.borderRadius + " " + "0 0"); config.controlStyle && controlBar.setAttribute("style", config.controlStyle); if (config.type === "group" && config.mergeTitle === true) { controlBar.classList.add("layx-type-group"); } layxWindow.appendChild(controlBar); if (config.icon !== false) { var leftBar = document.createElement("div"); leftBar.classList.add("layx-left-bar"); leftBar.classList.add("layx-flexbox"); leftBar.classList.add("layx-flex-vertical"); controlBar.appendChild(leftBar); var windowIcon = document.createElement("div"); windowIcon.classList.add("layx-icon"); windowIcon.classList.add("layx-window-icon"); windowIcon.innerHTML = config.icon === true ? '' : config.icon; if (config.icon === true) { windowIcon.ondblclick = function (e) { e = e || window.event; that.destroy(config.id, null, true); e.stopPropagation(); }; } leftBar.appendChild(windowIcon); } var title = document.createElement("div"); title.classList.add("layx-title"); title.classList.add("layx-flexauto"); title.classList.add("layx-flexbox"); title.classList.add("layx-flex-vertical"); if (config.type === "group" && config.mergeTitle === true) { title.classList.add("layx-type-group"); } if (config.allowControlDbclick === true) { title.ondblclick = function (e) { e = e || window.event; if (config.restorable === true) { that.restore(config.id); } e.stopPropagation(); }; } if (config.movable === true && Utils.isDom(config.floatTarget) == false) { new LayxDrag(title); } controlBar.appendChild(title); if (config.type !== "group") { var label = document.createElement("label"); label.classList.add("layx-label"); label.innerHTML = config.useFrameTitle === true ? "" : config.title; title.setAttribute("title", label.innerText); title.appendChild(label); } else { if (Utils.isArray(config.frames)) { if (config.mergeTitle === false) { var groupTab = document.createElement("div"); groupTab.classList.add("layx-group-tab"); groupTab.classList.add("layx-flexbox"); groupTab.classList.add("layx-type-group"); layxWindow.appendChild(groupTab); var label = document.createElement("label"); label.classList.add("layx-label"); label.innerHTML = config.useFrameTitle === true ? "" : config.title; title.setAttribute("title", label.innerText); title.appendChild(label); } for (var i = 0; i < config.frames.length; i++) { var frameConfig = layxDeepClone({}, that.defaultFrames, config.frames[i]); var frameTitle = document.createElement("div"); frameTitle.setAttribute("data-frameId", frameConfig.id); frameTitle.classList.add("layx-group-title"); frameTitle.classList.add("layx-flexauto"); frameTitle.classList.add("layx-flex-vertical"); if (i === config.frameIndex) { frameTitle.setAttribute("data-enable", "1"); } if (Utils.isSupportTouch) { frameTitle.ontouchstart = function (e) { e = e || window.event; that._setGroupIndex(config.id, this); }; if (Utils.IsPC()) { frameTitle.onclick = function (e) { e = e || window.event; that._setGroupIndex(config.id, this); e.stopPropagation(); }; } } else { frameTitle.onclick = function (e) { e = e || window.event; that._setGroupIndex(config.id, this); e.stopPropagation(); }; } if (config.mergeTitle === false) { groupTab.appendChild(frameTitle); } else { title.appendChild(frameTitle); } var groupLabel = document.createElement("label"); groupLabel.classList.add("layx-label"); groupLabel.innerHTML = frameConfig.title; frameTitle.setAttribute("title", groupLabel.innerText); frameTitle.appendChild(groupLabel); } } } var rightBar = document.createElement("div"); rightBar.classList.add("layx-right-bar"); rightBar.classList.add("layx-flexbox"); controlBar.appendChild(rightBar); var customMenu = document.createElement("div"); customMenu.classList.add("layx-custom-menus"); customMenu.classList.add("layx-flexbox"); rightBar.appendChild(customMenu); if (config.stickMenu === true || config.minMenu === true || config.maxMenu === true || config.closeMenu === true || config.debugMenu === true) { var inlayMenu = document.createElement("div"); inlayMenu.classList.add("layx-inlay-menus"); inlayMenu.classList.add("layx-flexbox"); rightBar.appendChild(inlayMenu); if (!Utils.isDom(config.floatTarget)) { if (config.debugMenu === true) { var debugMenu = document.createElement("div"); debugMenu.classList.add("layx-icon"); debugMenu.classList.add("layx-flexbox"); debugMenu.classList.add("layx-flex-center"); debugMenu.classList.add("layx-debug-menu"); debugMenu.setAttribute("title", "调试信息"); debugMenu.innerHTML = ''; debugMenu.onclick = function (e) { e = e || window.event; var jsonStr = JSON.stringify(winform, null, 4).replace(//g, ">"); that.create({ id: 'layx-' + config.id + '-debug', title: "窗口调试信息", width: 300, height: 300, content: '
', shadable: true, debugMenu: false, minMenu: false, minable: false, position: [layxWindow.offsetTop + 10, layxWindow.offsetLeft + 10], storeStatus: false }); }; inlayMenu.appendChild(debugMenu); } if (config.stickMenu === true || (config.alwaysOnTop === true && config.stickMenu)) { var stickMenu = document.createElement("div"); stickMenu.classList.add("layx-icon"); stickMenu.classList.add("layx-flexbox"); stickMenu.classList.add("layx-flex-center"); stickMenu.classList.add("layx-stick-menu"); config.alwaysOnTop === true ? stickMenu.setAttribute("title", "取消置顶") : stickMenu.setAttribute("title", "置顶"); config.alwaysOnTop === true && stickMenu.setAttribute("data-enable", "1"); stickMenu.innerHTML = ''; if (config.stickable === true) { stickMenu.onclick = function (e) { e = e || window.event; that.stickToggle(config.id); }; } inlayMenu.appendChild(stickMenu); } if (config.minMenu === true) { var minMenu = document.createElement("div"); minMenu.classList.add("layx-icon"); minMenu.classList.add("layx-flexbox"); minMenu.classList.add("layx-flex-center"); minMenu.classList.add("layx-min-menu"); minMenu.setAttribute("title", "最小化"); minMenu.setAttribute("data-menu", "min"); minMenu.innerHTML = ''; minMenu.onclick = function (e) { e = e || window.event; if (!this.classList.contains("layx-restore-menu")) { if (config.minable === true) { that.min(config.id); } } else { if (config.restorable === true) { that.restore(config.id); } } }; inlayMenu.appendChild(minMenu); } if (config.maxMenu === true) { var maxMenu = document.createElement("div"); maxMenu.classList.add("layx-icon"); maxMenu.classList.add("layx-flexbox"); maxMenu.classList.add("layx-flex-center"); maxMenu.classList.add("layx-max-menu"); maxMenu.setAttribute("title", "最大化"); maxMenu.setAttribute("data-menu", "max"); maxMenu.innerHTML = ''; maxMenu.onclick = function (e) { e = e || window.event; if (!this.classList.contains("layx-restore-menu")) { if (config.maxable === true) { that.max(config.id); } } else { if (config.restorable === true) { that.restore(config.id); } } }; inlayMenu.appendChild(maxMenu); } } if (config.closeMenu === true) { var destroyMenu = document.createElement("div"); destroyMenu.classList.add("layx-icon"); destroyMenu.classList.add("layx-flexbox"); destroyMenu.classList.add("layx-flex-center"); destroyMenu.classList.add("layx-destroy-menu"); destroyMenu.setAttribute("title", "关闭"); destroyMenu.innerHTML = ''; destroyMenu.onclick = function (e) { e = e || window.event; if (config.closable === true) { that.destroy(config.id, null, true); } }; inlayMenu.appendChild(destroyMenu); } } } var main = document.createElement("div"); main.classList.add("layx-main"); main.classList.add("layx-flexauto"); if (!config.statusBar) { main.style.setProperty("border-radius", "0 0 " + layxWindowStyle.borderRadius + " " + layxWindowStyle.borderRadius); main.style.setProperty("-moz-border-radius", "0 0 " + layxWindowStyle.borderRadius + " " + layxWindowStyle.borderRadius); main.style.setProperty("-webkit-border-radius", "0 0 " + layxWindowStyle.borderRadius + " " + layxWindowStyle.borderRadius); } layxWindow.appendChild(main); if (config.readonly === true) { var readonlyPanel = document.createElement("div"); readonlyPanel.classList.add("layx-readonly"); readonlyPanel.oncontextmenu = function (e) { e = e || window.event; e.returnValue = false; return false; }; if (config.focusable === true) { readonlyPanel.onclick = function (e) { e = e || window.event; if (Utils.isFunction(config.event.onfocus)) { var revel = Utils.isFunction(config.event.onfocus); if (revel === false) { return; } config.event.onfocus(layxWindow, winform); } that.updateZIndex(config.id); e.stopPropagation(); }; } main.appendChild(readonlyPanel); } switch (config.type) { case "html": default: if (Utils.isFunction(config.event.onload.before)) { var revel = config.event.onload.before(layxWindow, winform); if (revel === false) { return; } } var contentShade = that.createContenLoadAnimate(main, config.loadingText, winform); that.createHtmlBody(main, config, config.content); contentShade && main.removeChild(contentShade); if (winform.loadingTextTimer) { clearInterval(winform.loadingTextTimer); delete winform.loadingTextTimer; } if (Utils.isFunction(config.event.onload.after)) { config.event.onload.after(layxWindow, winform); } break; case "url": if (Utils.isFunction(config.event.onload.before)) { var revel = config.event.onload.before(layxWindow, winform); if (revel === false) { return; } } var contentShade = that.createContenLoadAnimate(main, config.loadingText, winform); that.createFrameBody(main, config, layxWindow, winform); break; case "group": if (Utils.isArray(config.frames)) { if (Utils.isFunction(config.event.onload.before)) { var revel = config.event.onload.before(layxWindow, winform); if (revel === false) { return; } } var contentShade = that.createContenLoadAnimate(main, config.loadingText, winform); config.preload = (/(^[1-9]\d*$)/.test(config.preload) === false) ? true : Math.min(config.preload, config.frames.length); var groupLoadCompleteListener = setInterval(function () { var loadComplteMains = layxWindow.querySelectorAll(".layx-group-main[data-complete='1']"); if (loadComplteMains.length === Utils.isBoolean(config.preload) ? config.frames.length : config.preload) { clearInterval(groupLoadCompleteListener); if (winform.loadingTextTimer) { clearInterval(winform.loadingTextTimer); delete winform.loadingTextTimer; } layxWindow.setAttribute("data-group-init", "1"); contentShade && main.removeChild(contentShade); if (Utils.isFunction(config.event.onload.after)) { config.event.onload.after(layxWindow, winform); } } }, 100); for (var i = 0; i < config.frames.length; i++) { var frameConfig = layxDeepClone({}, that.defaultFrames, config.frames[i]); var frameBody = document.createElement("div"); frameBody.classList.add("layx-group-main"); frameBody.style.backgroundColor = frameConfig.bgColor; frameBody.setAttribute("data-frameId", frameConfig.id); if (i === config.frameIndex) { frameBody.setAttribute("data-enable", "1"); } main.appendChild(frameBody); var isNeedLoad = (i === config.frameIndex) ? true : (Utils.isBoolean(config.preload) ? true : (i + 1 <= config.preload)); if (frameConfig.type === "html") { that.createHtmlBody(frameBody, config, frameConfig.content, "group", frameConfig, isNeedLoad); if (isNeedLoad) { frameBody.setAttribute("data-complete", "1"); } } else if (frameConfig.type === "url") { that.createFrameBody(frameBody, config, layxWindow, winform, "group", frameConfig, isNeedLoad); } } } break; } if (/(^[1-9]\d*$)/.test(config.autodestroy)) { var second = config.autodestroy / 1000; if (config.autodestroyText !== false) { var autodestroyTip = document.createElement("div"); autodestroyTip.classList.add("layx-auto-destroy-tip"); autodestroyTip.innerHTML = config.autodestroyText.replace("{second}", second); layxWindow.appendChild(autodestroyTip); } winform.destroyTimer = setInterval(function () { --second; if (config.autodestroyText !== false) { autodestroyTip.innerHTML = config.autodestroyText.replace("{second}", second); } if (second <= 0) { clearInterval(winform.destroyTimer); that.destroy(config.id, null, true); } }, 1000); } var resize = document.createElement("div"); resize.classList.add("layx-resizes"); if (config.resizable === false) { resize.setAttribute("data-enable", "0"); } layxWindow.appendChild(resize); var resizeTop = document.createElement("div"); resizeTop.classList.add("layx-resize-top"); if (Utils.isSupportTouch) { resizeTop.classList.add("layx-reisize-touch"); } if (config.resizeLimit.t === true) { resizeTop.setAttribute("data-enable", "0"); } new LayxResize(resizeTop, true, false, true, false); resize.appendChild(resizeTop); var resizeLeft = document.createElement("div"); resizeLeft.classList.add("layx-resize-left"); if (Utils.isSupportTouch) { resizeLeft.classList.add("layx-reisize-touch"); } if (config.resizeLimit.l === true) { resizeLeft.setAttribute("data-enable", "0"); } new LayxResize(resizeLeft, false, true, false, true); resize.appendChild(resizeLeft); var resizeLeftTop = document.createElement("div"); resizeLeftTop.classList.add("layx-resize-left-top"); if (Utils.isSupportTouch) { resizeLeftTop.classList.add("layx-reisize-touch"); } if (config.resizeLimit.lt === true) { resizeLeftTop.setAttribute("data-enable", "0"); } new LayxResize(resizeLeftTop, true, true, false, false); resize.appendChild(resizeLeftTop); var resizeRightTop = document.createElement("div"); resizeRightTop.classList.add("layx-resize-right-top"); if (Utils.isSupportTouch) { resizeRightTop.classList.add("layx-reisize-touch"); } if (config.resizeLimit.rt === true) { resizeRightTop.setAttribute("data-enable", "0"); } new LayxResize(resizeRightTop, true, false, false, false); resize.appendChild(resizeRightTop); var resizeLeftBottom = document.createElement("div"); resizeLeftBottom.classList.add("layx-resize-left-bottom"); if (Utils.isSupportTouch) { resizeLeftBottom.classList.add("layx-reisize-touch"); } if (config.resizeLimit.lb === true) { resizeLeftBottom.setAttribute("data-enable", "0"); } new LayxResize(resizeLeftBottom, false, true, false, false); resize.appendChild(resizeLeftBottom); var resizeRight = document.createElement("div"); resizeRight.classList.add("layx-resize-right"); if (Utils.isSupportTouch) { resizeRight.classList.add("layx-reisize-touch"); } if (config.resizeLimit.r === true) { resizeRight.setAttribute("data-enable", "0"); } new LayxResize(resizeRight, false, false, false, true); resize.appendChild(resizeRight); var resizeBottom = document.createElement("div"); resizeBottom.classList.add("layx-resize-bottom"); if (Utils.isSupportTouch) { resizeBottom.classList.add("layx-reisize-touch"); } if (config.resizeLimit.b === true) { resizeBottom.setAttribute("data-enable", "0"); } new LayxResize(resizeBottom, false, false, true, false); resize.appendChild(resizeBottom); var resizeRightBottom = document.createElement("div"); resizeRightBottom.classList.add("layx-resize-right-bottom"); if (Utils.isSupportTouch) { resizeRightBottom.classList.add("layx-reisize-touch"); } if (config.resizeLimit.rb === true) { resizeRightBottom.setAttribute("data-enable", "0"); } new LayxResize(resizeRightBottom, false, false, false, false); resize.appendChild(resizeRightBottom); if (config.statusBar) { var statusBar = document.createElement("div"); statusBar.classList.add("layx-statu-bar"); statusBar.style.setProperty("border-radius", "0 0 " + layxWindowStyle.borderRadius + " " + layxWindowStyle.borderRadius); statusBar.style.setProperty("-moz-border-radius", "0 0 " + layxWindowStyle.borderRadius + " " + layxWindowStyle.borderRadius); statusBar.style.setProperty("-webkit-border-radius", "0 0 " + layxWindowStyle.borderRadius + " " + layxWindowStyle.borderRadius); config.statusBarStyle && statusBar.setAttribute("style", config.statusBarStyle); if (config.statusBar === true && Utils.isArray(config.buttons)) { var btnElement = that.createLayxButtons(config.buttons, config.id, config.dialogType === "prompt" ? true : false); btnElement && statusBar.appendChild(btnElement); } else { if (Utils.isDom(config.statusBar)) { statusBar.appendChild(config.statusBar); } else { statusBar.innerHTML = config.statusBar; } } layxWindow.appendChild(statusBar); } if (Utils.isDom(config.floatTarget)) { that.updateFloatWinPosition(config.id, config.floatDirection); } if (config.isOverToMax === true && (Utils.isDom(config.floatTarget) === false)) { if (_width > window.innerWidth || _height > window.innerHeight) { that.max(config.id); } } var fixFocus = setInterval(function () { if (config.id !== Layx.focusId) { that.updateZIndex(config.id); } else { clearInterval(fixFocus); } }, 0); return winform; }, updateFloatWinPosition: function (id, direction) { var that = this, windowId = "layx-" + id, layxWindow = document.getElementById(windowId), winform = that.windows[id], bubbleDirectionOptions = ['top', 'bottom', 'left', 'right']; if (layxWindow && winform && winform.isFloatTarget === true) { direction = bubbleDirectionOptions.indexOf(direction) > -1 ? direction : winform.floatDirection; var bubble = layxWindow.querySelector(".layx-bubble"); var bubbleInlay = layxWindow.querySelector(".layx-bubble-inlay"); if (bubble && bubbleInlay) { bubble.classList.remove("layx-bubble-" + winform.floatDirection); bubble.style["border" + winform.floatDirection.toFirstUpperCase() + "Color"] = "transparent"; bubbleInlay.classList.remove("layx-bubble-inlay-" + winform.floatDirection); bubbleInlay.style["border" + winform.floatDirection.toFirstUpperCase() + "Color"] = "transparent"; bubble.classList.add("layx-bubble-" + direction); bubbleInlay.classList.add("layx-bubble-inlay-" + direction); var layxWindowStyle = layxWindow.currentStyle ? layxWindow.currentStyle : win.getComputedStyle(layxWindow, null); var _controlBar = layxWindow.querySelector(".layx-control-bar"); var controlStyle = _controlBar && (_controlBar.currentStyle ? _controlBar.currentStyle : win.getComputedStyle(_controlBar, null)); if (winform.control === true && _controlBar && controlStyle) { bubble.style["border" + direction.toFirstUpperCase() + "Color"] = (layxWindowStyle.borderColor === "rgba(0, 0, 0, 0)" || layxWindowStyle.borderColor === "transparent" || (!layxWindowStyle.borderColor) || (Utils.isBoolean(winform.border))) ? ((winform.skin === "default") ? "#3baced" : controlStyle.backgroundColor) : layxWindowStyle.borderColor; bubbleInlay.style["border" + direction.toFirstUpperCase() + "Color"] = controlStyle.backgroundColor; } else { bubble.style["border" + direction.toFirstUpperCase() + "Color"] = (layxWindowStyle.borderColor === "rgba(0, 0, 0, 0)" || layxWindowStyle.borderColor === "transparent" || (!layxWindowStyle.borderColor) || (Utils.isBoolean(winform.border))) ? ((winform.skin === "default") ? "#3baced" : "#fff") : layxWindowStyle.borderColor; bubbleInlay.style["border" + direction.toFirstUpperCase() + "Color"] = layxWindowStyle.backgroundColor; } var bubblePosition = Utils.compilebubbleDirection(direction, winform.floatTarget, winform.area.width, winform.area.height); that.setPosition(id, { top: bubblePosition.top, left: bubblePosition.left }, true); var floatPos = Utils.getElementPos(winform.floatTarget); if (direction === "top" || direction === "bottom") { bubble.style.left = Math.abs(floatPos.x + winform.floatTarget.offsetWidth / 2 - winform.layxWindow.offsetLeft - 9) + "px"; } if (direction === "left" || direction === "right") { bubble.style.top = Math.abs(floatPos.y + winform.floatTarget.offsetHeight / 2 - winform.layxWindow.offsetTop - 9) + "px"; } if ((direction === "top") || ((direction === "right" || direction === "left") && (winform.control === true && _controlBar && controlStyle && bubble.offsetTop > _controlBar.offsetHeight))) { bubble.style["border" + direction.toFirstUpperCase() + "Color"] = (layxWindowStyle.borderColor === "rgba(0, 0, 0, 0)" || layxWindowStyle.borderColor === "transparent" || (!layxWindowStyle.borderColor) || (Utils.isBoolean(winform.border))) ? ((winform.skin === "default") ? "#3baced" : "#fff") : layxWindowStyle.borderColor; bubbleInlay.style["border" + direction.toFirstUpperCase() + "Color"] = layxWindowStyle.backgroundColor; } winform.floatDirection = direction; that.updateFloatWinResize(id, direction); } } }, updateFloatWinResize: function (id, direction) { var that = this, windowId = "layx-" + id, layxWindow = document.getElementById(windowId), winform = that.windows[id], bubbleDirectionOptions = ['top', 'bottom', 'left', 'right']; if (layxWindow && winform && winform.isFloatTarget === true) { direction = bubbleDirectionOptions.indexOf(direction) > -1 ? direction : winform.floatDirection; switch (direction) { case "bottom": layxWindow.querySelector(".layx-resize-left").setAttribute("data-enable", "0"); layxWindow.querySelector(".layx-resize-top").setAttribute("data-enable", "0"); layxWindow.querySelector(".layx-resize-left-top").setAttribute("data-enable", "0"); layxWindow.querySelector(".layx-resize-left-bottom").setAttribute("data-enable", "0"); layxWindow.querySelector(".layx-resize-right-top").setAttribute("data-enable", "0"); if (winform.resizeLimit.r === false) { layxWindow.querySelector(".layx-resize-right").removeAttribute("data-enable"); } if (winform.resizeLimit.b === false) { layxWindow.querySelector(".layx-resize-bottom").removeAttribute("data-enable"); } if (winform.resizeLimit.rb === false) { layxWindow.querySelector(".layx-resize-right-bottom").removeAttribute("data-enable"); } break; case "top": layxWindow.querySelector(".layx-resize-left").setAttribute("data-enable", "0"); layxWindow.querySelector(".layx-resize-left-top").setAttribute("data-enable", "0"); layxWindow.querySelector(".layx-resize-bottom").setAttribute("data-enable", "0"); layxWindow.querySelector(".layx-resize-left-bottom").setAttribute("data-enable", "0"); layxWindow.querySelector(".layx-resize-right-bottom").setAttribute("data-enable", "0"); if (winform.resizeLimit.r === false) { layxWindow.querySelector(".layx-resize-right").removeAttribute("data-enable"); } if (winform.resizeLimit.t === false) { layxWindow.querySelector(".layx-resize-top").removeAttribute("data-enable"); } if (winform.resizeLimit.rt === false) { layxWindow.querySelector(".layx-resize-right-top").removeAttribute("data-enable"); } break; case "right": layxWindow.querySelector(".layx-resize-left").setAttribute("data-enable", "0"); layxWindow.querySelector(".layx-resize-top").setAttribute("data-enable", "0"); layxWindow.querySelector(".layx-resize-left-top").setAttribute("data-enable", "0"); layxWindow.querySelector(".layx-resize-left-bottom").setAttribute("data-enable", "0"); layxWindow.querySelector(".layx-resize-right-top").setAttribute("data-enable", "0"); if (winform.resizeLimit.r === false) { layxWindow.querySelector(".layx-resize-right").removeAttribute("data-enable"); } if (winform.resizeLimit.b === false) { layxWindow.querySelector(".layx-resize-bottom").removeAttribute("data-enable"); } if (winform.resizeLimit.rb === false) { layxWindow.querySelector(".layx-resize-right-bottom").removeAttribute("data-enable"); } break; case "left": layxWindow.querySelector(".layx-resize-top").setAttribute("data-enable", "0"); layxWindow.querySelector(".layx-resize-right").setAttribute("data-enable", "0"); layxWindow.querySelector(".layx-resize-left-top").setAttribute("data-enable", "0"); layxWindow.querySelector(".layx-resize-right-top").setAttribute("data-enable", "0"); layxWindow.querySelector(".layx-resize-right-bottom").setAttribute("data-enable", "0"); if (winform.resizeLimit.l === false) { layxWindow.querySelector(".layx-resize-left").removeAttribute("data-enable"); } if (winform.resizeLimit.b === false) { layxWindow.querySelector(".layx-resize-bottom").removeAttribute("data-enable"); } if (winform.resizeLimit.lb === false) { layxWindow.querySelector(".layx-resize-left-bottom").removeAttribute("data-enable"); } break; } } }, removeStoreWindowAreaInfo: function (id) { var that = this, windowId = "layx-" + id, storeAreaInfo = (typeof (Storage) !== "undefined") && !(win.location.protocol.indexOf("file:") > -1) && localStorage.getItem(windowId); if (storeAreaInfo) { localStorage.removeItem(windowId); } }, storeWindowAreaInfo: function (id, area) { var that = this, windowId = "layx-" + id; (typeof (Storage) !== "undefined") && !(win.location.protocol.indexOf("file:") > -1) && localStorage.setItem(windowId, JSON.stringify(area)); }, getStoreWindowAreaInfo: function (id) { var that = this, windowId = "layx-" + id, storeAreaInfo = (typeof (Storage) !== "undefined") && !(win.location.protocol.indexOf("file:") > -1) && localStorage.getItem(windowId); if (storeAreaInfo) { return JSON.parse(storeAreaInfo); } return null; }, _setGroupIndex: function (id, target) { var that = this, windowId = "layx-" + id, layxWindow = document.getElementById(windowId), winform = that.windows[id]; if (layxWindow && winform && winform.type === "group") { var prevSelectTitle = layxWindow.querySelector(".layx-group-title[data-enable='1']"); if (prevSelectTitle !== target) { if (Utils.isFunction(winform.event.onswitch.before)) { var revel = winform.event.onswitch.before(layxWindow, winform, prevSelectTitle.getAttribute("data-frameId")); if (revel === false) { return; } } prevSelectTitle.removeAttribute("data-enable"); target.setAttribute("data-enable", "1"); var frameId = target.getAttribute("data-frameId"); var prevGroupMain = layxWindow.querySelector(".layx-group-main[data-enable='1']"); var currentGroupMain = layxWindow.querySelector(".layx-group-main[data-frameId='" + frameId + "']"); if (currentGroupMain !== prevGroupMain) { prevGroupMain.removeAttribute("data-enable"); currentGroupMain.setAttribute("data-enable", "1"); winform.groupCurrentId = frameId; if (currentGroupMain.getAttribute("data-preload") === "1") { var frameform = that.getGroupFrame(winform.frames, frameId); if (frameform.type === "url") { that.setGroupUrl(id, frameId, frameform.url); currentGroupMain.removeAttribute("data-preload"); } if (frameform.type === "html") { that.setGroupContent(id, frameId, frameform.content, frameform.cloneElementContent); currentGroupMain.removeAttribute("data-preload"); } } } if (Utils.isFunction(winform.event.onswitch.after)) { winform.event.onswitch.after(layxWindow, winform, target.getAttribute("data-frameId")); } } } }, setGroupIndex: function (id, frameId) { var that = this, windowId = "layx-" + id, layxWindow = document.getElementById(windowId), winform = that.windows[id]; if (layxWindow && winform) { var title = layxWindow.querySelector(".layx-group-title[data-frameId='" + frameId + "']"); title.click(); } }, cloneStore: {}, createHtmlBody: function (main, config, content, type, frameConfig, isLoad) { var that = this; var html = document.createElement("div"); html.classList.add("layx-html"); html.setAttribute("id", "layx-" + config.id + (type === "group" ? "-" + frameConfig.id + "-" : "-") + "html"); var newContent; if (isLoad !== false) { if (Utils.isDom(content)) { var _ctStyle = content.currentStyle ? content.currentStyle : win.getComputedStyle(content, null); if (type !== "group" && config.cloneElementContent === false) { Layx.cloneStore[config.id] = { prev: content.previousSibling, parent: content.parentNode, next: content.nextSibling, display: _ctStyle.display }; } if (type === "group" && frameConfig.cloneElementContent === false) { if (!Layx.cloneStore[config.id]) { Layx.cloneStore[config.id] = { frames: {} }; } Layx.cloneStore[config.id].frames[frameConfig.id] = { prev: content.previousSibling, parent: content.parentNode, next: content.nextSibling, display: _ctStyle.display }; } newContent = html.appendChild((type === "group" ? frameConfig : config).cloneElementContent === true ? content.cloneNode(true) : content); } else { html.innerHTML = content; } } else { main.setAttribute("data-preload", "1"); } main.appendChild(html); if (Utils.isDom(newContent)) { var contentStyle = newContent.currentStyle ? newContent.currentStyle : win.getComputedStyle(newContent, null); if (contentStyle.display === "none") { newContent.style.display = ""; } } }, frameLoadHandle: function (iframe, main, config, layxWindow, winform, type, frameConfig, isLoad) { var that = this; var contentShade = (type === "group" ? iframe.parentNode.parentNode : iframe.parentNode).querySelector(".layx-content-shade"); try { if (config.focusable === true && config.enableDomainFocus === true) { if (!iframe.getAttribute("data-focus")) { IframeOnClick.track(iframe, function () { if (Utils.isFunction(config.event.onfocus)) { var revel = Utils.isFunction(config.event.onfocus); if (revel === false) { return; } config.event.onfocus(layxWindow, winform); } that.updateZIndex(config.id); }); iframe.setAttribute("data-focus", "true"); } } var iframeTitle = config.title; if (type === "group") { if (frameConfig.useFrameTitle === true) { iframeTitle = iframe.contentWindow.document.querySelector("title").innerText; that.setGroupTitle(config.id, frameConfig.id, iframeTitle); } } else { if (config.useFrameTitle === true) { iframeTitle = iframe.contentWindow.document.querySelector("title").innerText; that.setTitle(config.id, iframeTitle); } } iframe.contentWindow.document.addEventListener("click", function (event) { var e = event || window.event || arguments.callee.caller.arguments[0]; if (config.focusable === true) { if (Utils.isFunction(config.event.onfocus)) { var revel = Utils.isFunction(config.event.onfocus); if (revel === false) { return; } config.event.onfocus(layxWindow, winform); } that.updateZIndex(config.id); } }, false); iframe.contentWindow.document.addEventListener("keydown", function (event) { var e = event || window.event || arguments.callee.caller.arguments[0]; var focusWindow = Layx.windows[Layx.focusId]; if (e && e.keyCode == 27) { if (focusWindow) { Layx.destroy(Layx.focusId, {}, false, true); } } if (e && e.keyCode === 13) { if (focusWindow && focusWindow.buttons.length > 0) { if (focusWindow.buttonKey.toLowerCase() === "enter" && !e.ctrlKey) { if (focusWindow.dialogType !== "prompt") { focusWindow.buttons[0].callback(focusWindow.id, Layx.getButton(focusWindow.id, focusWindow.buttons[0].id, e)); } else { var textarea = Layx.getPromptTextArea(focusWindow.id); focusWindow.buttons[0].callback(focusWindow.id, (textarea ? textarea.value : "").replace(/(^\s*)|(\s*$)/g, ""), textarea, Layx.getButton(focusWindow.id, focusWindow.buttons[0].id, e)); } } else if (focusWindow.buttonKey.toLowerCase() === "ctrl+enter" && e.ctrlKey) { if (focusWindow.dialogType !== "prompt") { focusWindow.buttons[0].callback(focusWindow.id, Layx.getButton(focusWindow.id, focusWindow.buttons[0].id, e)); } else { var textarea = Layx.getPromptTextArea(focusWindow.id); focusWindow.buttons[0].callback(focusWindow.id, (textarea ? textarea.value : "").replace(/(^\s*)|(\s*$)/g, ""), textarea, Layx.getButton(focusWindow.id, focusWindow.buttons[0].id, e)); } } } } }, false); } catch (e) { if (type === "group") { contentShade && contentShade.parentNode.removeChild(contentShade); } console.warn(e); } finally { if (type === "group") { if (isLoad) { main.setAttribute("data-complete", "1"); } if (layxWindow.getAttribute("data-group-init") === "1") { if (winform.loadingTextTimer) { clearInterval(winform.loadingTextTimer); delete winform.loadingTextTimer; } contentShade && contentShade.parentNode.removeChild(contentShade); if (Utils.isFunction(config.event.onload.after)) { config.event.onload.after(layxWindow, winform); } } } else { contentShade && contentShade.parentNode.removeChild(contentShade); if (winform.loadingTextTimer) { clearInterval(winform.loadingTextTimer); delete winform.loadingTextTimer; } if (Utils.isFunction(config.event.onload.after)) { config.event.onload.after(layxWindow, winform); } } } }, createFrameBody: function (main, config, layxWindow, winform, type, frameConfig, isLoad) { var that = this; var iframe = document.createElement("iframe"); iframe.setAttribute("id", "layx-" + config.id + (type === "group" ? "-" + frameConfig.id + "-" : "-") + "iframe"); iframe.classList.add("layx-iframe"); iframe.classList.add("layx-flexbox"); iframe.setAttribute("allowtransparency", "true"); iframe.setAttribute("frameborder", "0"); if (win.navigator.userAgent.toLowerCase().indexOf('iphone') > -1 || (!!navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/))) { iframe.setAttribute("scrolling", "no"); } else { iframe.setAttribute("scrolling", "auto"); } iframe.setAttribute("allowfullscreen", ""); iframe.setAttribute("mozallowfullscreen", ""); iframe.setAttribute("webkitallowfullscreen", ""); iframe.src = isLoad !== false ? ((type === "group" ? frameConfig.url : config.url) || 'about:blank') : 'about:blank'; if (iframe.attachEvent) { iframe.attachEvent("onreadystatechange", function () { if (iframe.readyState === "complete" || iframe.readyState == "loaded") { iframe.detachEvent("onreadystatechange", arguments.callee); that.frameLoadHandle(iframe, main, config, layxWindow, winform, type, frameConfig, isLoad); } }); } else { iframe.addEventListener("load", function () { this.removeEventListener("load", arguments.call, false); that.frameLoadHandle(iframe, main, config, layxWindow, winform, type, frameConfig, isLoad); }, false); } if (isLoad === false) { main.setAttribute("data-preload", "1"); } main.appendChild(iframe); }, setContent: function (id, content, cloneElementContent) { var that = this, windowId = "layx-" + id, layxWindow = document.getElementById(windowId), winform = that.windows[id]; if (layxWindow && winform) { if (winform.type === "html") { var html = layxWindow.querySelector("#layx-" + id + "-html"); if (html) { if (Utils.isFunction(winform.event.onload.before)) { var revel = winform.event.onload.before(layxWindow, winform); if (revel === false) { return; } } try { var contentShade = that.createContenLoadAnimate(html.parentNode, winform.loadingText, winform); cloneElementContent = Utils.isBoolean(cloneElementContent) ? cloneElementContent : winform.cloneElementContent; var newContent; if (Utils.isDom(content)) { var _ctStyle = content.currentStyle ? content.currentStyle : win.getComputedStyle(content, null); if (cloneElementContent === false) { Layx.cloneStore[id] = { prev: content.previousSibling, parent: content.parentNode, next: content.nextSibling, display: _ctStyle.display }; } html.innerHTML = ""; newContent = html.appendChild(cloneElementContent === true ? content.cloneNode(true) : content); } else { html.innerHTML = content; } if (Utils.isDom(newContent)) { var contentStyle = newContent.currentStyle ? newContent.currentStyle : window.getComputedStyle(newContent, null); if (contentStyle.display === "none") { newContent.style.display = ""; } } winform.content = content; } finally { contentShade && html.parentNode.removeChild(contentShade); if (winform.loadingTextTimer) { clearInterval(winform.loadingTextTimer); delete winform.loadingTextTimer; } if (Utils.isFunction(winform.event.onload.after)) { winform.event.onload.after(layxWindow, winform); } } } } } }, getGroupFrame: function (frames, frameId) { var frm = {}; for (var i = 0; i < frames.length; i++) { if (frames[i].id === frameId) { frm = frames[i]; break; } } return frm; }, reloadGroupFrame: function (id, frameId) { var that = this, windowId = "layx-" + id, layxWindow = document.getElementById(windowId), winform = that.windows[id]; if (layxWindow && winform && winform.type === "group") { var frameform = that.getGroupFrame(winform.frames, frameId); if (frameform.type === "url") { var iframe = layxWindow.querySelector("#layx-" + id + "-" + frameId + "-" + "iframe"); if (iframe) { var url = iframe.getAttribute("src"); that.setGroupUrl(id, frameId, url); } } } }, setGroupContent: function (id, frameId, content, cloneElementContent) { var that = this, windowId = "layx-" + id, layxWindow = document.getElementById(windowId), winform = that.windows[id]; if (layxWindow && winform && winform.type === "group") { var frameform = that.getGroupFrame(winform.frames, frameId); if (frameform.type === "html") { var html = layxWindow.querySelector("#layx-" + id + "-" + frameId + "-" + "html"); if (html) { if (Utils.isFunction(winform.event.onload.before)) { var revel = winform.event.onload.before(layxWindow, winform); if (revel === false) { return; } } try { var contentShade = that.createContenLoadAnimate(html.parentNode.parentNode, winform.loadingText, winform); cloneElementContent = Utils.isBoolean(cloneElementContent) ? cloneElementContent : frameform.cloneElementContent; var newContent; if (Utils.isDom(content)) { var _ctStyle = content.currentStyle ? content.currentStyle : win.getComputedStyle(content, null); if (cloneElementContent === false) { if (!Layx.cloneStore[id]) { Layx.cloneStore[id] = { frames: {} }; } Layx.cloneStore[id].frames[frameId] = { prev: content.previousSibling, parent: content.parentNode, next: content.nextSibling, display: _ctStyle.display }; } html.innerHTML = ""; newContent = html.appendChild(cloneElementContent === true ? content.cloneNode(true) : content); } else { html.innerHTML = content; } if (Utils.isDom(newContent)) { var contentStyle = newContent.currentStyle ? newContent.currentStyle : window.getComputedStyle(newContent, null); if (contentStyle.display === "none") { newContent.style.display = ""; } } frameform.content = content; } finally { contentShade && html.parentNode.parentNode.removeChild(contentShade); if (winform.loadingTextTimer) { clearInterval(winform.loadingTextTimer); delete winform.loadingTextTimer; } if (Utils.isFunction(winform.event.onload.after)) { winform.event.onload.after(layxWindow, winform); } } } } } }, createContenLoadAnimate: function (pEle, loadingText, winform, isCreateLoadAnimate) { var that = this; if (loadingText !== false) { if (Utils.isArray(loadingText) && loadingText.length === 2 && loadingText[0] === true) { return that.createContenLoadAnimate(pEle, loadingText[1], winform, false); } var contentShade = document.createElement("div"); contentShade.classList.add("layx-content-shade"); contentShade.classList.add("layx-flexbox"); contentShade.classList.add("layx-flex-center"); if (Utils.isDom(loadingText)) { contentShade.appendChild(loadingText); } else { if (isCreateLoadAnimate !== false) { contentShade.appendChild(that.createLoadAnimate()); } var msgContent = document.createElement("div"); msgContent.classList.add("layx-load-content-msg"); msgContent.innerHTML = loadingText; contentShade.appendChild(msgContent); var span = document.createElement("span"); span.classList.add("layx-dot"); msgContent.appendChild(span); var dotCount = 0; winform.loadingTextTimer = setInterval(function () { if (dotCount === 5) { dotCount = 0; } ++dotCount; var dotHtml = ""; for (var i = 0; i < dotCount; i++) { dotHtml += "."; } span.innerHTML = dotHtml; }, 200); } return pEle.appendChild(contentShade); } }, setUrl: function (id, url) { url = url || 'about:blank'; var that = this, windowId = "layx-" + id, layxWindow = document.getElementById(windowId), winform = that.windows[id]; if (layxWindow && winform) { if (winform.type === "url") { var iframe = layxWindow.querySelector("#layx-" + id + "-iframe"); if (iframe) { if (Utils.isFunction(winform.event.onload.before)) { var revel = winform.event.onload.before(layxWindow, winform); if (revel === false) { return; } } var contentShade = that.createContenLoadAnimate(iframe.parentNode, winform.loadingText, winform); iframe.setAttribute("src", url); } } } }, setGroupUrl: function (id, frameId, url) { url = url || 'about:blank'; var that = this, windowId = "layx-" + id, layxWindow = document.getElementById(windowId), winform = that.windows[id]; if (layxWindow && winform && winform.type === "group") { var frameform = that.getGroupFrame(winform.frames, frameId); if (frameform.type === "url") { var iframe = layxWindow.querySelector("#layx-" + id + "-" + frameId + "-" + "iframe"); if (iframe) { if (Utils.isFunction(winform.event.onload.before)) { var revel = winform.event.onload.before(layxWindow, winform); if (revel === false) { return; } } iframe.parentNode.removeAttribute("data-complete"); var contentShade = that.createContenLoadAnimate(iframe.parentNode.parentNode, winform.loadingText, winform); iframe.setAttribute("src", url); } } } }, setGroupTitle: function (id, frameId, content, useFrameTitle) { var that = this, windowId = "layx-" + id, layxWindow = document.getElementById(windowId), winform = that.windows[id]; if (layxWindow && winform && winform.type === "group") { var title = layxWindow.querySelector(".layx-group-title[data-frameId='" + frameId + "']"); if (title) { var frameform = that.getGroupFrame(winform.frames, frameId); if (useFrameTitle === true && frameform.type === "url") { var iframe = layxWindow.querySelector("#layx-" + id + "-" + frameId + "-" + "iframe"); try { content = iframe.contentDocument.querySelector("title").innerText; } catch (e) { } } var label = title.querySelector(".layx-label"); if (label) { label.innerHTML = content; title.setAttribute("title", label.innerHTML); frameform.title = content; } } } }, setTitle: function (id, content, useFrameTitle) { var that = this, windowId = "layx-" + id, layxWindow = document.getElementById(windowId), winform = that.windows[id]; if (layxWindow && winform) { var title = layxWindow.querySelector(".layx-title"); if (title) { if (useFrameTitle === true && winform.type === "url") { var iframe = layxWindow.querySelector("#layx-" + id + "-iframe"); try { content = iframe.contentDocument.querySelector("title").innerText; } catch (e) { } } var label = title.querySelector(".layx-label"); if (label) { label.innerHTML = content; title.setAttribute("title", label.innerHTML); winform.title = content; } } } }, stickToggle: function (id) { var that = this, windowId = "layx-" + id, layxWindow = document.getElementById(windowId), winform = that.windows[id]; if (layxWindow && winform) { that.updateZIndex(id); if (Utils.isFunction(winform.event.onstick.before)) { var revel = winform.event.onstick.before(layxWindow, winform); if (revel === false) { return; } } winform.isStick = !winform.isStick; var stickMenu = layxWindow.querySelector(".layx-stick-menu"); if (stickMenu) { stickMenu.setAttribute("data-enable", winform.isStick ? "1" : "0"); winform.isStick ? stickMenu.setAttribute("title", "取消置顶") : stickMenu.setAttribute("title", "置顶"); } that.updateZIndex(id); if (Utils.isFunction(winform.event.onstick.after)) { winform.event.onstick.after(layxWindow, winform); } } }, reloadFrame: function (id) { var that = this, windowId = "layx-" + id, layxWindow = document.getElementById(windowId), winform = that.windows[id]; if (layxWindow && winform) { if (winform.type === "url") { var iframe = layxWindow.querySelector("#layx-" + id + "-iframe"); if (iframe) { var url = iframe.getAttribute("src"); that.setUrl(id, url); } } } }, restore: function (id) { var that = this, windowId = "layx-" + id, layxWindow = document.getElementById(windowId), winform = that.windows[id]; if (layxWindow && winform) { if (winform.restorable !== true) return; that.updateZIndex(id); if (Utils.isFunction(winform.event.onrestore.before)) { var revel = winform.event.onrestore.before(layxWindow, winform); if (revel === false) { return; } } var area = winform.area; if (winform.status === "normal") { that.max(id); } else if (winform.status === "max") { if (document.body.classList.contains("ilayx-body")) { document.body.classList.remove('ilayx-body'); } layxWindow.style.top = area.top + "px"; layxWindow.style.left = area.left + "px"; layxWindow.style.width = area.width + "px"; layxWindow.style.height = area.height + "px"; layxWindow.classList.remove("layx-max-statu"); winform.status = "normal"; var restoreMenu = layxWindow.querySelector(".layx-restore-menu[data-menu='max']"); if (restoreMenu) { restoreMenu.classList.remove("layx-restore-menu"); restoreMenu.classList.add("layx-max-menu"); restoreMenu.setAttribute("title", "最大化"); restoreMenu.innerHTML = ''; } var resizePanel = layxWindow.querySelector(".layx-resizes"); if (resizePanel) { resizePanel.removeAttribute("data-enable"); } } if (winform.status === "min") { if (winform.minBefore === "normal") { layxWindow.style.top = area.top + "px"; layxWindow.style.left = area.left + "px"; layxWindow.style.width = area.width + "px"; layxWindow.style.height = area.height + "px"; winform.status = "normal"; var restoreMenu = layxWindow.querySelector(".layx-restore-menu[data-menu='min']"); if (restoreMenu) { restoreMenu.classList.remove("layx-restore-menu"); restoreMenu.classList.add("layx-min-menu"); restoreMenu.setAttribute("title", "最小化"); restoreMenu.innerHTML = ''; } var resizePanel = layxWindow.querySelector(".layx-resizes"); if (resizePanel) { resizePanel.removeAttribute("data-enable"); } } else if (winform.minBefore === "max") { that.max(id); } that.updateMinLayout(); } var _winform = layxDeepClone({}, {}, winform); delete that.windows[id]; that.windows[id] = _winform; that.updateMinLayout(); if (layxWindow.classList.contains("layx-min-statu")) { layxWindow.classList.remove("layx-min-statu"); } if (Utils.isFunction(_winform.event.onrestore.after)) { _winform.event.onrestore.after(layxWindow, _winform); } } }, min: function (id) { var that = this, windowId = "layx-" + id, layxWindow = document.getElementById(windowId), winform = that.windows[id]; if (layxWindow && winform && winform.isFloatTarget === false) { if (winform.minable !== true || winform.status === "min") return; that.updateZIndex(id); if (Utils.isFunction(winform.event.onmin.before)) { var revel = winform.event.onmin.before(layxWindow, winform); if (revel === false) { return; } } var innertArea = Utils.innerArea(); winform.minBefore = winform.status; winform.status = "min"; var minMenu = layxWindow.querySelector(".layx-min-menu"); if (minMenu) { minMenu.classList.remove("layx-max-menu"); minMenu.classList.add("layx-restore-menu"); minMenu.setAttribute("title", "还原"); minMenu.innerHTML = ''; } var resizePanel = layxWindow.querySelector(".layx-resizes"); if (resizePanel) { resizePanel.setAttribute("data-enable", "0"); } var restoreMenu = layxWindow.querySelector(".layx-restore-menu[data-menu='max']"); if (restoreMenu) { restoreMenu.classList.remove("layx-restore-menu"); restoreMenu.classList.add("layx-max-menu"); restoreMenu.setAttribute("title", "最大化"); restoreMenu.innerHTML = ''; } if (layxWindow.classList.contains("layx-max-statu")) { layxWindow.classList.remove("layx-max-statu"); } var _winform = layxDeepClone({}, winform); delete that.windows[id]; that.windows[id] = _winform; that.updateMinLayout(); if (document.body.classList.contains("ilayx-body")) { document.body.classList.remove('ilayx-body'); } if (Utils.isFunction(winform.event.onmin.after)) { winform.event.onmin.after(layxWindow, winform); } } }, updateZIndex: function (id) { var that = this, windowId = "layx-" + id, layxWindow = document.getElementById(windowId), winform = that.windows[id]; if (layxWindow && winform) { if (winform.dialogType !== "load" && winform.dialogType !== "msg") { Layx.focusId = id; } if (winform.focusToReveal === true) { var layxShade = document.getElementById("layx-" + id + "-shade"); if (layxShade) { layxShade.style.zIndex = (winform.isStick === true ? (++that.stickZIndex) : (++that.zIndex)); } if (winform.isStick === true) { winform.zIndex = (++that.stickZIndex) + 1; } else { winform.zIndex = (++that.zIndex) + 1; } layxWindow.style.zIndex = winform.zIndex; } } }, updateMinLayout: function () { var that = this, windows = that.windows, innertArea = Utils.innerArea(), paddingLeft = 10, paddingBottom = 10, widthByMinStatu = 240, stepIndex = 0, lineMaxCount = Math.floor(innertArea.width / (widthByMinStatu + paddingLeft)); for (var id in windows) { var winform = windows[id], layxWindow = document.getElementById("layx-" + id); if (layxWindow && winform.status === "min") { var control = layxWindow.querySelector(".layx-control-bar"); if (control) { var heightByMinStatus = control.offsetHeight; layxWindow.classList.add("layx-min-statu"); layxWindow.style.width = widthByMinStatu + 'px'; layxWindow.style.height = heightByMinStatus + 'px'; layxWindow.style.top = innertArea.height - (Math.floor(stepIndex / lineMaxCount) + 1) * (heightByMinStatus + paddingBottom) + 'px'; layxWindow.style.left = stepIndex % lineMaxCount * (widthByMinStatu + paddingLeft) + paddingLeft + 'px'; stepIndex++; } } } }, max: function (id) { var that = this, windowId = "layx-" + id, layxWindow = document.getElementById(windowId), winform = that.windows[id], innertArea = Utils.innerArea(); if (layxWindow && winform && winform.isFloatTarget === false) { if (winform.maxable !== true) return; if (winform.status === "max") { layxWindow.style.top = 0; layxWindow.style.left = 0; layxWindow.style.width = innertArea.width + "px"; layxWindow.style.height = innertArea.height + "px"; } else { that.updateZIndex(id); if (Utils.isFunction(winform.event.onmax.before)) { var revel = winform.event.onmax.before(layxWindow, winform); if (revel === false) { return; } } document.body.classList.add('ilayx-body'); layxWindow.style.top = 0; layxWindow.style.left = 0; layxWindow.style.width = innertArea.width + "px"; layxWindow.style.height = innertArea.height + "px"; layxWindow.classList.add("layx-max-statu"); winform.status = "max"; var maxMenu = layxWindow.querySelector(".layx-max-menu"); if (maxMenu) { maxMenu.classList.remove("layx-max-menu"); maxMenu.classList.add("layx-restore-menu"); maxMenu.setAttribute("title", "还原"); maxMenu.innerHTML = ''; } var resizePanel = layxWindow.querySelector(".layx-resizes"); if (resizePanel) { resizePanel.setAttribute("data-enable", "0"); } var restoreMenu = layxWindow.querySelector(".layx-restore-menu[data-menu='min']"); if (restoreMenu) { restoreMenu.classList.remove("layx-restore-menu"); restoreMenu.classList.add("layx-min-menu"); restoreMenu.setAttribute("title", "最小化"); restoreMenu.innerHTML = ''; } var _winform = layxDeepClone({}, winform); delete that.windows[id]; that.windows[id] = _winform; that.updateMinLayout(); if (layxWindow.classList.contains("layx-min-statu")) { layxWindow.classList.remove("layx-min-statu"); } if (Utils.isFunction(winform.event.onmax.after)) { winform.event.onmax.after(layxWindow, winform); } } } }, visual: function (id, status, params, inside) { var that = this, windowId = "layx-" + id, layxWindow = document.getElementById(windowId), layxShade = document.getElementById(windowId + '-shade'), winform = that.windows[id]; if (layxWindow && winform) { if (Utils.isFunction(winform.event.onvisual.before)) { var revel = winform.event.onvisual.before(layxWindow, winform, params || {}, inside === true, status !== false); if (revel === false) { return; } } if (status !== false) { layxWindow.classList.remove("layx-hide-statu"); } else { layxWindow.classList.add("layx-hide-statu"); } that.updateMinLayout(); if (Utils.isFunction(winform.event.onvisual.after)) { winform.event.onvisual.after(layxWindow, winform, status !== false); } } }, destroyInlay: function (id) { var that = this; that.destroy(id, null, true); }, destroy: function (id, params, inside, escKey, force) { var that = this, windowId = "layx-" + id, layxWindow = document.getElementById(windowId), layxShade = document.getElementById(windowId + '-shade'), winform = that.windows[id]; if (layxWindow && winform) { if (winform.escKey === false && escKey === true) return; that.updateZIndex(id); if (Utils.isFunction(winform.event.ondestroy.before)) { var revel = winform.event.ondestroy.before(layxWindow, winform, params || {}, inside === true, escKey === true); if (force === true) { } else { if (revel === false) { return; } } } if (winform.closable !== true) return; var oldNodeInfo = that.cloneStore[id]; if (winform.type === "html" && oldNodeInfo) { var html = layxWindow.querySelector("#layx-" + id + "-html"); if (html) { var child = html.children[0]; if (child && child.style) { child.style.display = oldNodeInfo.display; } if (oldNodeInfo.prev) { setTimeout(function () { Utils.insertAfter(child, oldNodeInfo.prev); }, 0); } else { setTimeout(function () { oldNodeInfo.parent && oldNodeInfo.parent.insertBefore(child, oldNodeInfo.next); }, 0); } } } if (winform.type === "group" && oldNodeInfo) { if (oldNodeInfo && oldNodeInfo.frames) { for (var frameId in oldNodeInfo.frames) { var frameInfo = oldNodeInfo.frames[frameId]; var html = layxWindow.querySelector("#layx-" + id + "-" + frameId + "-html"); if (html) { var child = html.children[0]; if (child && child.style) { child.style.display = frameInfo.display; } if (frameInfo.prev) { setTimeout(function () { Utils.insertAfter(child, frameInfo.prev); }, 0); } else { setTimeout(function () { frameInfo.parent && frameInfo.parent.insertBefore(child, frameInfo.next); }, 0); } } } } } Layx.focusId = Layx.prevFocusId; delete that.cloneStore[id]; delete that.windows[id]; if (document.body.classList.contains("ilayx-body")) { document.body.classList.remove('ilayx-body'); } layxWindow.parentNode.removeChild(layxWindow); if (layxShade) { layxShade.parentNode.removeChild(layxShade); } that.updateMinLayout(); if (Utils.isFunction(winform.event.ondestroy.after)) { winform.event.ondestroy.after(); } if (winform.destroyTimer) clearInterval(winform.destroyTimer); if (winform.loadTimer) clearInterval(winform.loadTimer); if (winform.loadingTextTimer) clearInterval(winform.loadingTextTimer); for (var key in winform) { delete winform[key]; } winform = undefined; } }, destroyAll: function () { var that = this; for (var id in Layx.windows) { that.destroy(id); } }, flicker: function (id) { var that = this, flickerTimer, windowId = "layx-" + id, layxWindow = document.getElementById(windowId), winform = that.windows[id]; if (layxWindow && winform) { that.updateZIndex(id); if (layxWindow.classList.contains('layx-flicker')) { layxWindow.classList.remove('layx-flicker'); } layxWindow.classList.add('layx-flicker'); flickerTimer = setTimeout(function () { layxWindow.classList.remove('layx-flicker'); clearTimeout(flickerTimer); }, 120 * 8); } }, setPosition: function (id, position, isFloatTarget) { var that = this, windowId = "layx-" + id, layxWindow = document.getElementById(windowId), winform = that.windows[id]; if (layxWindow && winform) { var _position = isFloatTarget === true ? position : Utils.compileLayxPosition(winform.area.width, winform.area.height, position); winform.area.left = _position.left; winform.area.top = _position.top; if (winform.storeStatus === true) { that.storeWindowAreaInfo(id, winform.area); } layxWindow.style.left = _position.left + "px"; layxWindow.style.top = _position.top + "px"; } }, setSize: function (id, area) { var that = this, windowId = "layx-" + id, layxWindow = document.getElementById(windowId), winform = that.windows[id]; if (layxWindow && winform) { if (area) { if (area["width"]) { var _width = Utils.compileLayxWidthOrHeight("width", area["width"], that.defaults.width); winform.area.width = _width; layxWindow.style.width = _width + "px"; } if (area["height"]) { var _height = Utils.compileLayxWidthOrHeight("height", area["height"], that.defaults.height); winform.area.height = _height; layxWindow.style.height = _height + "px"; } if (winform.storeStatus === true) { that.storeWindowAreaInfo(id, winform.area); } } } }, getFrameContext: function (id) { var that = this, windowId = "layx-" + id, layxWindow = document.getElementById(windowId), winform = that.windows[id], iframeWindow = null; if (layxWindow && winform && winform.type === "url") { var iframe = layxWindow.querySelector(".layx-iframe"); if (iframe) { try { iframeWindow = iframe.contentWindow; } catch (e) { } } } return iframeWindow; }, getParentContext: function (id) { var that = this; var iframeWindow = that.getFrameContext(id); if (iframeWindow) { return iframeWindow.parent; } else { return null; } }, getGroupFrameContext: function (id, frameId) { var that = this, windowId = "layx-" + id, layxWindow = document.getElementById(windowId), winform = that.windows[id], iframeWindow = null; if (layxWindow && winform && winform.type === "group") { var frameform = that.getGroupFrame(winform.frames, frameId); if (frameform.type === "url") { var iframe = layxWindow.querySelector("#layx-" + id + "-" + frameId + "-" + "iframe"); if (iframe) { try { iframeWindow = iframe.contentWindow; } catch (e) { } } } } return iframeWindow; }, createLayxButtons: function (buttons, id, isPrompt) { var that = this; var buttonPanel = document.createElement("div"); buttonPanel.classList.add("layx-buttons"); for (var i = 0; i < buttons.length; i++) { var buttonItem = document.createElement("button"); var buttonConfig = layxDeepClone({}, that.defaultButtons, buttons[i]); buttonItem.classList.add("layx-button-item"); buttonItem.setAttribute("title", buttonConfig.label); buttonItem.innerText = buttonConfig.label; buttonConfig.id && buttonItem.setAttribute("id", "layx-" + id + "-button-" + buttonConfig.id); if (Utils.isArray(buttonConfig.classes)) { for (var n = 0; n < buttonConfig.classes.length; n++) { buttonItem.classList.add(buttonConfig.classes[n]); } } else { buttonConfig.classes && buttonItem.classList.add(buttonConfig.classes.toString()); } buttonConfig.style && buttonItem.setAttribute("style", buttonConfig.style); buttonItem.callback = buttons[i].callback; buttonItem.onclick = function (e) { e = e || window.event || arguments.callee.caller.arguments[0]; if (Utils.isFunction(this.callback)) { if (isPrompt === true) { var textarea = that.getPromptTextArea(id); that.updateZIndex(id); this.callback(id, (textarea ? textarea.value : "").replace(/(^\s*)|(\s*$)/g, ""), textarea, this, e); } else { that.updateZIndex(id); this.callback(id, this, e); } } }; buttonPanel.appendChild(buttonItem); } return buttonPanel; }, setButtonStatus: function (id, buttonId, isEnable) { var that = this, windowId = "layx-" + id, layxWindow = document.getElementById(windowId), winform = that.windows[id]; if (layxWindow && winform) { var button = layxWindow.querySelector("#layx-" + id + "-button-" + buttonId); if (button) { if (isEnable === false) { button.setAttribute("disabled", "disabled"); } else { button.removeAttribute("disabled"); } } } }, getStrSizeRange: function (str, minWidth, minHeight, maxWidth, maxHeight, dialogIcon) { var width = 0, height = 0, span = document.createElement("span"); span.innerHTML = str; span.classList.add("layx-calc-text"); span.style.visibility = 'hidden'; span.style.display = 'inline-block'; span.style.minWidth = minWidth + "px"; span.style.minHeight = minHeight + "px"; span.style.maxWidth = maxWidth + "px"; span.style.maxHeight = maxHeight + "px"; span.style.paddingLeft = 10 + 'px'; span.style.paddingRight = 10 + 'px'; span.style.paddingTop = 10 + 'px'; span.style.paddingBottom = 10 + 'px'; span.style.margin = "0"; span.style.border = "none"; span.style.lineHeight = 1.5; document.body.appendChild(span); width = span.offsetWidth; height = span.offsetHeight + 1; document.body.removeChild(span); return { width: width + (dialogIcon === true ? 45 : 0), height: height }; }, getButton: function (id, buttonId) { var that = this, windowId = "layx-" + id, layxWindow = document.getElementById(windowId), winform = that.windows[id]; if (layxWindow && winform) { return layxWindow.querySelector("#layx-" + id + "-button" + (buttonId ? "-" + buttonId : "")); } return null; }, tip: function (msg, target, direction, options) { var that = this; if (Utils.isDom(target)) { var _id = (options && options.id) ? options.id : 'layx-dialog-tip-' + Utils.rndNum(8); target.addEventListener("mouseover", function (e) { var msgSizeRange = that.getStrSizeRange(msg, 20, 20, 320, 90, ((options && options.dialogIcon) ? true : false)); that.create(layxDeepClone({}, { id: _id, type: 'html', control: false, content: that.createDialogContent("tip", msg, ((options && options.dialogIcon) ? options.dialogIcon : false)), width: msgSizeRange.width, height: msgSizeRange.height, minHeight: msgSizeRange.height, minWidth: msgSizeRange.width, stickMenu: false, minMenu: false, floatTarget: target, floatDirection: direction || 'bottom', maxMenu: false, closeMenu: false, alwaysOnTop: true, resizable: false, movable: false, allowControlDbclick: false, autodestroyText: false, loadingText: false, storeStatus: false }, options)); }, false); target.addEventListener("mouseout", function (e) { that.destroy(_id, null, true); }, false); } }, msg: function (msg, options) { var that = this; var msgSizeRange = that.getStrSizeRange(msg, 120, 20, 320, 90, ((options && options.dialogIcon) ? true : false)); var winform = that.create(layxDeepClone({}, { id: (options && options.id) ? options.id : 'layx-dialog-msg-' + Utils.rndNum(8), type: 'html', control: false, content: that.createDialogContent("msg", msg, ((options && options.dialogIcon) ? options.dialogIcon : false)), autodestroy: 5000, width: msgSizeRange.width, height: msgSizeRange.height, minHeight: msgSizeRange.height, stickMenu: false, minMenu: false, maxMenu: false, closeMenu: false, alwaysOnTop: true, resizable: false, movable: false, allowControlDbclick: false, position: [10, 'tc'], autodestroyText: false, loadingText: false, storeStatus: false, dialogType: 'msg' }, options)); that.flicker(winform.id); return winform; }, createDialogContent: function (type, content, iconType) { var that = this; var dialog = document.createElement("div"); dialog.classList.add("layx-dialog-" + type); dialog.classList.add("layx-flexbox"); if (iconType) { var dialogIcon = document.createElement("div"); dialogIcon.classList.add("layx-dialog-icon"); var iconWrap = document.createElement("div"); iconWrap.classList.add("layx-icon"); iconWrap.classList.add("layx-dialog-icon-" + iconType); switch (iconType) { case "success": iconWrap.innerHTML = ''; break; case "warn": iconWrap.innerHTML = ''; break; case "error": iconWrap.innerHTML = ''; break; case "help": iconWrap.innerHTML = ''; break; } dialogIcon.appendChild(iconWrap); dialog.appendChild(dialogIcon); } var dialogContent = document.createElement("div"); dialogContent.classList.add("layx-dialog-content"); dialogContent.classList.add("layx-flexauto"); dialogContent.innerHTML = content; dialog.appendChild(dialogContent); return dialog; }, alert: function (title, msg, yes, options) { var that = this; var msgSizeRange = that.getStrSizeRange(msg, 137, 66, 352, 157, ((options && options.dialogIcon) ? true : false)); var winform = that.create(layxDeepClone({}, { id: (options && options.id) ? options.id : 'layx-dialog-alert-' + Utils.rndNum(8), title: title || "提示消息", icon: false, type: 'html', content: that.createDialogContent("alert", msg, ((options && options.dialogIcon) ? options.dialogIcon : false)), width: msgSizeRange.width + 20, height: msgSizeRange.height + 73, minHeight: msgSizeRange.height + 73, stickMenu: false, dialogType: "alert", minMenu: false, minable: false, maxMenu: false, maxable: false, alwaysOnTop: true, resizable: false, allowControlDbclick: false, shadable: true, statusBar: true, buttons: [{ label: '确定', callback: function (id, button, event) { event = event || window.event || arguments.callee.caller.arguments[0]; event.stopPropagation(); if (Utils.isFunction(yes)) { var reval = yes(id, button, event); if (reval !== false) { Layx.destroy(id); } } else { Layx.destroy(id); } } }], position: 'ct', loadingText: false, storeStatus: false }, options)); return winform; }, confirm: function (title, msg, yes, options) { var that = this; var msgSizeRange = that.getStrSizeRange(msg, 180, 137, 352, 180, ((options && options.dialogIcon) ? true : false)); var winform = that.create(layxDeepClone({}, { id: (options && options.id) ? options.id : 'layx-dialog-confirm-' + Utils.rndNum(8), title: title || "询问消息", icon: false, type: 'html', content: that.createDialogContent("confirm", msg, ((options && options.dialogIcon) ? options.dialogIcon : false)), width: msgSizeRange.width + 20, height: msgSizeRange.height, minHeight: msgSizeRange.height, stickMenu: false, dialogType: "confirm", minMenu: false, minable: false, maxMenu: false, maxable: false, alwaysOnTop: true, resizable: false, allowControlDbclick: false, shadable: true, buttons: [{ label: '确定', callback: function (id, button, event) { event = event || window.event || arguments.callee.caller.arguments[0]; event.stopPropagation(); if (Utils.isFunction(yes)) { var reval = yes(id, button); if (reval !== false) { Layx.destroy(id); } } } }, { label: '取消', callback: function (id, button, event) { event = event || window.event; event.stopPropagation(); Layx.destroy(id); } }], statusBar: true, position: 'ct', loadingText: false, storeStatus: false }, options)); return winform; }, getPromptTextArea: function (id) { var that = this, windowId = "layx-" + id, layxWindow = document.getElementById(windowId), winform = that.windows[id]; if (layxWindow && winform && winform.type === "html") { var promptPanel = layxWindow.querySelector(".layx-dialog-prompt"); if (promptPanel) { var textarea = promptPanel.querySelector(".layx-textarea"); if (textarea) { return textarea; } } } return null; }, prompt: function (title, msg, yes, defaultValue, options) { var that = this; var msgSizeRange = that.getStrSizeRange(msg, 200, 184, 352, 200); var winform = that.create(layxDeepClone({}, { id: (options && options.id) ? options.id : 'layx-dialog-prompt-' + Utils.rndNum(8), title: title || "请输入信息", icon: false, type: 'html', content: that.createDialogContent("prompt", ""), width: msgSizeRange.width + 20, height: msgSizeRange.height, minHeight: msgSizeRange.height, stickMenu: false, dialogType: "prompt", minMenu: false, minable: false, maxMenu: false, maxable: false, alwaysOnTop: true, resizable: false, allowControlDbclick: false, shadable: true, statusBar: true, buttonKey: 'ctrl+enter', buttons: [{ label: '确定', callback: function (id, value, textarea, button, event) { event = event || window.event || arguments.callee.caller.arguments[0]; event.stopPropagation(); if (textarea && value.length === 0) { textarea.focus(); } else { if (Utils.isFunction(yes)) { var reval = yes(id, value, textarea, button, event); if (reval !== false) { Layx.destroy(id); } } } } }, { label: '取消', callback: function (id, value, textarea, button, event) { event = event || window.event; event.stopPropagation(); Layx.destroy(id); } }], position: 'ct', loadingText: false, storeStatus: false }, options)); return winform; }, createLoadAnimate: function () { var animate = document.createElement("div"); animate.classList.add("layx-load-animate"); var inner = document.createElement("div"); inner.classList.add("layx-load-inner"); var spiner = document.createElement("div"); spiner.classList.add("layx-load-spiner"); inner.appendChild(spiner); var filler = document.createElement("div"); filler.classList.add("layx-load-filler"); inner.appendChild(filler); var masker = document.createElement("div"); masker.classList.add("layx-load-masker"); inner.appendChild(masker); animate.appendChild(inner); var inner2 = inner.cloneNode(true); inner2.classList.remove("layx-load-inner"); inner2.classList.add("layx-load-inner2"); animate.appendChild(inner2); return animate; }, load: function (id, msg, options) { var that = this; var msgSizeRange = that.getStrSizeRange(msg, 120, 53, 320, 90); var loadElement = document.createElement("div"); loadElement.classList.add("layx-dialog-load"); loadElement.classList.add("layx-flexbox"); loadElement.classList.add("layx-flex-center"); loadElement.appendChild(that.createLoadAnimate()); var msgContent = document.createElement("div"); msgContent.classList.add("layx-load-msg"); msgContent.innerHTML = msg; loadElement.appendChild(msgContent); var span = document.createElement("span"); span.classList.add("layx-dot"); msgContent.appendChild(span); var dotCount = 0; var loadTimer = setInterval(function () { if (dotCount === 5) { dotCount = 0; } ++dotCount; var dotHtml = ""; for (var i = 0; i < dotCount; i++) { dotHtml += "."; } span.innerHTML = dotHtml; }, 200); var winform = that.create(layxDeepClone({}, { id: id ? id : 'layx-dialog-load-' + Utils.rndNum(8), type: 'html', control: false, shadable: true, content: loadElement, cloneElementContent: false, width: msgSizeRange.width + 70, height: msgSizeRange.height, minHeight: msgSizeRange.height, stickMenu: false, minMenu: false, maxMenu: false, closeMenu: false, escKey: false, alwaysOnTop: true, resizable: false, movable: false, allowControlDbclick: false, position: 'ct', loadingText: false, storeStatus: false, dialogType: 'load' }, options)); winform.loadTimer = loadTimer; return winform; } }; String.prototype.toFirstUpperCase = function () { return this.replace(/^\S/, function (s) { return s.toUpperCase(); }); }; if (!("classList" in document.documentElement)) { Object.defineProperty(HTMLElement.prototype, 'classList', { get: function () { var self = this; function update(fn) { return function (value) { var classes = self.className.split(/\s+/g), index = classes.indexOf(value); fn(classes, index, value); self.className = classes.join(" "); }; } return { add: update(function (classes, index, value) { if (!~index) classes.push(value); }), remove: update(function (classes, index) { if (~index) classes.splice(index, 1); }), toggle: update(function (classes, index, value) { if (~index) classes.splice(index, 1); else classes.push(value); }), contains: function (value) { return !!~self.className.split(/\s+/g).indexOf(value); }, item: function (i) { return self.className.split(/\s+/g)[i] || null; } }; } }); } var IframeOnClick = { resolution: 0, iframes: [], interval: null, Iframe: function () { this.element = arguments[0]; this.cb = arguments[1]; this.hasTracked = false; }, track: function (element, cb) { this.iframes.push(new this.Iframe(element, cb)); if (!this.interval) { var _this = this; this.interval = setInterval(function () { _this.checkClick(); }, this.resolution); } }, checkClick: function () { if (document.activeElement) { var activeElement = document.activeElement; for (var i in this.iframes) { if (activeElement === this.iframes[i].element) { if (this.iframes[i].hasTracked == false) { this.iframes[i].cb.apply(win, []); this.iframes[i].hasTracked = true; } } else { this.iframes[i].hasTracked = false; } } } } }; var Utils = { isSupportTouch: "ontouchstart" in document ? true : false, isSupportMouse: "onmouseup" in document ? true : false, IsPC: function () { var userAgentInfo = navigator.userAgent; var Agents = ["Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod"]; var flag = true; for (var v = 0; v < Agents.length; v++) { if (userAgentInfo.indexOf(Agents[v]) > 0) { flag = false; break; } } return flag; }, isBoolean: function (obj) { return typeof obj === "boolean"; }, isString: function (obj) { return typeof obj === "string"; }, isNumber: function (obj) { return typeof obj === "number"; }, isArray: function (o) { return Object.prototype.toString.call(o) == '[object Array]'; }, isFunction: function (func) { return func && Object.prototype.toString.call(func) === '[object Function]'; }, isDom: function (obj) { return !!(obj && typeof window !== 'undefined' && (obj === window || obj.nodeType)); }, insertAfter: function (newEl, targetEl) { var parentEl = targetEl.parentNode; if (newEl) { if (parentEl.lastChild == targetEl) { parentEl.appendChild(newEl); } else { parentEl.insertBefore(newEl, targetEl.nextSibling); } } }, innerArea: function () { return { width: win.innerWidth, height: win.innerHeight }; }, getCross: function (p1, p2, p) { return (p2.x - p1.x) * (p.y - p1.y) - (p.x - p1.x) * (p2.y - p1.y); }, IsPointInMatrix: function (area, p) { var that = this; var p1 = area.p1; var p2 = area.p2; var p3 = area.p3; var p4 = area.p4; return that.getCross(p1, p2, p) * that.getCross(p3, p4, p) >= 0 && that.getCross(p2, p3, p) * that.getCross(p4, p1, p) >= 0; }, checkElementIsVisual: function (pEle, ele, allContain) { var that = this; var innerArea = that.innerArea(); var pEleStartPos = that.getElementPos(pEle); var pEleEndPos = { x: pEleStartPos.x + pEle.offsetWidth, y: pEleStartPos.y + pEle.offsetHeight }; var eleStartPos = that.getElementPos(ele); var eleEndPos = { x: eleStartPos.x + ele.offsetWidth, y: eleStartPos.y + ele.offsetHeight }; if (allContain === false) { var pleArea = { p1: { x: pEleStartPos.x, y: pEleEndPos.y }, p2: { x: pEleStartPos.x, y: pEleStartPos.y }, p3: { x: pEleEndPos.x, y: pEleStartPos.y }, p4: { x: pEleEndPos.x, y: pEleEndPos.y } }; var winArea = { p1: { x: 0, y: innerArea.height }, p2: { x: 0, y: 0 }, p3: { x: innerArea.width, y: 0 }, p4: { x: innerArea.width, y: innerArea.height } }; var ltPoint = that.IsPointInMatrix(pleArea, { x: eleStartPos.x, y: eleStartPos.y }); var rtPoint = that.IsPointInMatrix(pleArea, { x: eleEndPos.x, y: eleStartPos.y }); var lbPoint = that.IsPointInMatrix(pleArea, { x: eleStartPos.x, y: eleEndPos.y }); var rbPoint = that.IsPointInMatrix(pleArea, { x: eleEndPos.x, y: eleEndPos.y }); var wltPoint = that.IsPointInMatrix(winArea, { x: eleStartPos.x, y: eleStartPos.y }); var wrtPoint = that.IsPointInMatrix(winArea, { x: eleEndPos.x, y: eleStartPos.y }); var wlbPoint = that.IsPointInMatrix(winArea, { x: eleStartPos.x, y: eleEndPos.y }); var wrbPoint = that.IsPointInMatrix(winArea, { x: eleEndPos.x, y: eleEndPos.y }); return (ltPoint || rtPoint || lbPoint || rbPoint) && (wltPoint || wrtPoint || wlbPoint || wrbPoint); } return (eleStartPos.x >= pEleStartPos.x) && (eleEndPos.x <= pEleEndPos.x) && (eleStartPos.y >= pEleStartPos.y) && (eleEndPos.y <= pEleEndPos.y) && (eleStartPos.x >= 0) && (eleEndPos.x <= innerArea.width) && (eleStartPos.y >= 0) && (eleEndPos.y <= innerArea.height); }, compilebubbleDirection: function (direction, target, width, height) { var that = this, bubbleDirectionOptions = ['top', 'bottom', 'left', 'right'], targetPos = that.getElementPos(target), innerArea = that.innerArea(), bubbleSize = 11, pos = { top: 0, left: 0 }; direction = bubbleDirectionOptions.indexOf(direction) > -1 ? direction : 'bottom'; switch (direction) { case "bottom": pos.top = targetPos.y + target.offsetHeight + bubbleSize; pos.left = targetPos.x; if (targetPos.x + width >= innerArea.width) { pos.left = innerArea.width - width; } break; case "top": pos.top = targetPos.y - (height + bubbleSize); pos.left = targetPos.x; if (targetPos.x + width >= innerArea.width) { pos.left = innerArea.width - width; } break; case "right": pos.top = targetPos.y; pos.left = targetPos.x + target.offsetWidth + bubbleSize; if (targetPos.y + height >= innerArea.height) { pos.top = innerArea.height - height; } break; case "left": pos.top = targetPos.y; pos.left = targetPos.x - (width + bubbleSize); if (targetPos.y + height >= innerArea.height) { pos.top = innerArea.height - height; } break; } return pos; }, compileLayxPosition: function (width, height, position) { var that = this, postionOptions = ['ct', 'lt', 'rt', 'lb', 'rb', 'lc', 'tc', 'rc', 'bc'], innerArea = that.innerArea(); var pos = { top: 0, left: 0 }; if (that.isArray(position) && position.length === 2) { pos.top = that.isNumber(position[0]) ? position[0] : that.compileLayxPosition(width, height, position[0]).top; pos.left = that.isNumber(position[1]) ? position[1] : that.compileLayxPosition(width, height, position[1]).left; } else { position = postionOptions.indexOf(position.toString()) > -1 ? position.toString() : 'ct'; switch (position) { case 'ct': pos.top = (innerArea.height - height) / 2; pos.left = (innerArea.width - width) / 2; break; case 'lt': pos.top = 0; pos.left = 0; break; case 'rt': pos.top = 0; pos.left = innerArea.width - width; break; case 'lb': pos.top = innerArea.height - height; pos.left = 0; break; case 'rb': pos.top = innerArea.height - height; pos.left = innerArea.width - width; break; case 'lc': pos.left = 0; pos.top = (innerArea.height - height) / 2; break; case 'tc': pos.top = 0; pos.left = (innerArea.width - width) / 2; break; case 'rc': pos.left = innerArea.width - width; pos.top = (innerArea.height - height) / 2; break; case 'bc': pos.top = innerArea.height - height; pos.left = (innerArea.width - width) / 2; break; } } return pos; }, rndNum: function (n) { var rnd = ""; for (var i = 0; i < n; i++) rnd += Math.floor(Math.random() * 10); return rnd; }, compileLayxWidthOrHeight: function (type, widthOrHeight, errorValue) { var that = this, innerArea = that.innerArea(); if (/(^[1-9]\d*$)/.test(widthOrHeight)) { return Number(widthOrHeight); } if (/^(100|[1-9]?\d(\.\d\d?)?)%$/.test(widthOrHeight)) { var value = Number(widthOrHeight.toString().replace('%', '')); if (type === "width") { return innerArea.width * (value / 100); } if (type === "height") { return innerArea.height * (value / 100); } } if (/^[1-9]\d*v[hw]$/.test(widthOrHeight)) { if (type === "width") { return innerArea.width * parseFloat(widthOrHeight) / 100; } if (type === "height") { return innerArea.height * parseFloat(widthOrHeight) / 100; } } return errorValue; }, getNodeByClassName: function (node, className, parentWindow) { parentWindow = parentWindow || win; var that = this; if (node === parentWindow.document.body) { return null; } var cls = node.classList; if (cls.contains(className)) { return node; } else { return that.getNodeByClassName(node.parentNode, className); } }, getMousePosition: function (e) { e = e || window.event; if (e.touches) { if (Utils.IsPC()) { var button = e.button || e.which; if (button == 1 && e.shiftKey == false) { var scrollX = document.documentElement.scrollLeft || document.body.scrollLeft; var scrollY = document.documentElement.scrollTop || document.body.scrollTop; var x = e.pageX || e.clientX + scrollX; var y = e.pageY || e.clientY + scrollY; return { x: x, y: y }; } } return { x: e.touches[0].clientX, y: e.touches[0].clientY }; } else { var scrollX = document.documentElement.scrollLeft || document.body.scrollLeft; var scrollY = document.documentElement.scrollTop || document.body.scrollTop; var x = e.pageX || e.clientX + scrollX; var y = e.pageY || e.clientY + scrollY; return { x: x, y: y }; } }, getElementPos: function (el) { var ua = navigator.userAgent.toLowerCase(); var isOpera = (ua.indexOf('opera') != -1); var isIE = (ua.indexOf('msie') != -1 && !isOpera); if (el.parentNode === null || el.style.display == 'none') { return false; } var parent = null; var pos = []; var box; if (el.getBoundingClientRect) { box = el.getBoundingClientRect(); var scrollTop = Math.max(document.documentElement.scrollTop, document.body.scrollTop); var scrollLeft = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft); return { x: box.left + scrollLeft, y: box.top + scrollTop }; } else if (document.getBoxObjectFor) { box = document.getBoxObjectFor(el); var borderLeft = (el.style.borderLeftWidth) ? parseInt(el.style.borderLeftWidth) : 0; var borderTop = (el.style.borderTopWidth) ? parseInt(el.style.borderTopWidth) : 0; pos = [box.x - borderLeft, box.y - borderTop]; } else { pos = [el.offsetLeft, el.offsetTop]; parent = el.offsetParent; if (parent != el) { while (parent) { pos[0] += parent.offsetLeft; pos[1] += parent.offsetTop; parent = parent.offsetParent; } } if (ua.indexOf('opera') != -1 || (ua.indexOf('safari') != -1 && el.style.position == 'absolute')) { pos[0] -= document.body.offsetLeft; pos[1] -= document.body.offsetTop; } } if (el.parentNode) { parent = el.parentNode; } else { parent = null; } while (parent && parent.tagName != 'BODY' && parent.tagName != 'HTML') { pos[0] -= parent.scrollLeft; pos[1] -= parent.scrollTop; if (parent.parentNode) { parent = parent.parentNode; } else { parent = null; } } return { x: pos[0], y: pos[1] }; } }; var LayxResize = function (handle, isTop, isLeft, lockX, lockY) { LayxResize.isResizing = false; LayxResize.isFirstResizing = true; var drag = function (e) { e = e || window.event; var moveMouseCoord = Utils.getMousePosition(e), distX = moveMouseCoord.x - handle.mouseStartCoord.x, distY = moveMouseCoord.y - handle.mouseStartCoord.y; if (Utils.isSupportTouch) { if (e.cancelable) { if (!e.defaultPrevented) { e.preventDefault(); } } if (((distX !== 0 || distY !== 0) && (new Date() - handle.touchDate > 100)) === false) return; if (Utils.IsPC()) { var button = e.button || e.which; if ((button == 1 && e.shiftKey == false) === false) return; if (!e.defaultPrevented) { e.preventDefault(); } if ((distX !== 0 || distY !== 0) === false) return; } } else { var button = e.button || e.which; if ((button == 1 && e.shiftKey == false) === false) return; if (!e.defaultPrevented) { e.preventDefault(); } if ((distX !== 0 || distY !== 0) === false) return; } var _top = handle.winform.area.top + distY, _left = handle.winform.area.left + distX, _height = isTop ? handle.winform.area.height - distY : handle.winform.area.height + distY, _width = isLeft ? handle.winform.area.width - distX : handle.winform.area.width + distX; LayxResize.isResizing = true; if (LayxResize.isFirstResizing === true) { LayxResize.isFirstResizing = false; if (Utils.isFunction(handle.winform.event.onresize.before)) { var reval = handle.winform.event.onresize.before(handle.layxWindow, handle.winform); if (reval === false) { LayxResize.isResizing = false; LayxResize.isFirstResizing = true; if (Utils.isSupportTouch) { document.ontouchend = null; document.ontouchmove = null; if (Utils.IsPC()) { document.onmouseup = null; document.onmousemove = null; } } else { document.onmouseup = null; document.onmousemove = null; } return; } } } _width = Math.max(_width, handle.winform.area.minWidth); if (isLeft) { _left = Math.min(_left, handle.winform.area.left + handle.winform.area.width - handle.winform.area.minWidth); _left = Math.max(0, _left); _width = Math.min(_width, handle.winform.area.left + handle.winform.area.width); } else { _left = Math.min(_left, handle.winform.area.left); _left = Math.max(handle.winform.area.left, _left); _width = Math.min(_width, handle.innerArea.width - handle.winform.area.left); } _height = Math.max(_height, handle.winform.area.minHeight); if (isTop) { _top = Math.min(_top, handle.winform.area.top + handle.winform.area.height - handle.winform.area.minHeight); _top = Math.max(0, _top); _height = Math.min(_height, handle.winform.area.top + handle.winform.area.height); } else { _top = Math.min(_top, handle.winform.area.top); _top = Math.max(handle.winform.area.top, _top); _height = Math.min(_height, handle.innerArea.height - handle.winform.area.top); } if (lockY) { handle.layxWindow.style.width = _width + 'px'; handle.layxWindow.style.left = _left + 'px'; } if (lockX) { handle.layxWindow.style.top = _top + 'px'; handle.layxWindow.style.height = _height + 'px'; } if (lockY === false && lockX === false) { handle.layxWindow.style.width = _width + 'px'; handle.layxWindow.style.left = _left + 'px'; handle.layxWindow.style.top = _top + 'px'; handle.layxWindow.style.height = _height + 'px'; } if (Utils.isFunction(handle.winform.event.onresize.progress)) { handle.winform.event.onresize.progress(handle.layxWindow, handle.winform); } }; var dragend = function (e) { e = e || window.event; if (Utils.isSupportTouch) { document.ontouchend = null; document.ontouchmove = null; if (Utils.IsPC()) { var button = e.button || e.which; if (button == 1 && e.shiftKey == false) { var resizeList = handle.layxWindow.querySelectorAll(".layx-resizes > div"); for (var i = 0; i < resizeList.length; i++) { resizeList[i].classList.add("layx-reisize-touch"); } } document.onmouseup = null; document.onmousemove = null; } } else { document.onmouseup = null; document.onmousemove = null; } var mousePreventDefault = handle.layxWindow.querySelector(".layx-mouse-preventDefault"); if (mousePreventDefault) { mousePreventDefault.parentNode.removeChild(mousePreventDefault); } var layxMove = document.getElementById("layx-window-move"); if (layxMove) { layxMove.parentNode.removeChild(layxMove); } if (LayxResize.isResizing === true) { LayxResize.isResizing = false; LayxResize.isFirstResizing = true; handle.winform.area.top = handle.layxWindow.offsetTop; handle.winform.area.left = handle.layxWindow.offsetLeft; handle.winform.area.width = handle.layxWindow.offsetWidth; handle.winform.area.height = handle.layxWindow.offsetHeight; if (handle.winform.storeStatus === true) { Layx.storeWindowAreaInfo(handle.winform.id, { top: handle.winform.area.top, left: handle.winform.area.left, width: handle.winform.area.width, height: handle.winform.area.height }); } if (Utils.isFunction(handle.winform.event.onresize.after)) { handle.winform.event.onresize.after(handle.layxWindow, handle.winform); } } }; var dragstart = function (e) { e = e || window.event; var layxWindow = Utils.getNodeByClassName(handle, 'layx-window', win); if (layxWindow) { var id = layxWindow.getAttribute("id").substr(5), winform = Layx.windows[id]; if (winform) { if (winform.status !== "min" && winform.resizable === true) { var layxMove = document.getElementById("layx-window-move"); if (!layxMove) { layxMove = document.createElement("div"); layxMove.setAttribute("id", "layx-window-move"); document.body.appendChild(layxMove); } Layx.updateZIndex(id); layxMove.style.zIndex = winform.zIndex - 1; var mouseCoord = Utils.getMousePosition(e); handle.mouseStartCoord = mouseCoord; handle.layxWindow = layxWindow; handle.winform = winform; handle.innerArea = Utils.innerArea(); handle.touchDate = new Date(); var mousePreventDefault = layxWindow.querySelector(".layx-mouse-preventDefault"); if (!mousePreventDefault) { mousePreventDefault = document.createElement("div"); mousePreventDefault.classList.add("layx-mouse-preventDefault"); var main = layxWindow.querySelector(".layx-main"); if (main) { main.appendChild(mousePreventDefault); } } if (Utils.isSupportTouch) { document.ontouchend = dragend; document.ontouchmove = drag; if (Utils.IsPC()) { var button = e.button || e.which; if (button == 1 && e.shiftKey == false) { var resizeList = layxWindow.querySelectorAll(".layx-resizes > div"); for (var i = 0; i < resizeList.length; i++) { resizeList[i].classList.remove("layx-reisize-touch"); } } document.onmouseup = dragend; document.onmousemove = drag; } } else { document.onmouseup = dragend; document.onmousemove = drag; } } else { Layx.restore(id); } } } return false; }; if (Utils.isSupportTouch) { handle.ontouchstart = dragstart; if (Utils.IsPC()) { handle.onmousedown = dragstart; } } else { handle.onmousedown = dragstart; } }; var LayxDrag = function (handle) { LayxDrag.isMoveing = false; LayxDrag.isFirstMoveing = true; var drag = function (e) { e = e || window.event; var moveMouseCoord = Utils.getMousePosition(e), distX = moveMouseCoord.x - handle.mouseStartCoord.x, distY = moveMouseCoord.y - handle.mouseStartCoord.y; if (Utils.isSupportTouch) { if (e.cancelable) { if (!e.defaultPrevented) { e.preventDefault(); } } if (((distX !== 0 || distY !== 0) && (new Date() - handle.touchDate > 100)) === false) return; if (Utils.IsPC()) { var button = e.button || e.which; if ((button == 1 && e.shiftKey == false) === false) return; if (!e.defaultPrevented) { e.preventDefault(); } if ((distX !== 0 || distY !== 0) === false) return; } } else { var button = e.button || e.which; if ((button == 1 && e.shiftKey == false) === false) return; if (!e.defaultPrevented) { e.preventDefault(); } if ((distX !== 0 || distY !== 0) === false) return; } LayxDrag.isMoveing = true; if (LayxDrag.isFirstMoveing === true) { LayxDrag.isFirstMoveing = false; if (Utils.isFunction(handle.winform.event.onmove.before)) { var reval = handle.winform.event.onmove.before(handle.layxWindow, handle.winform); if (reval === false) { LayxDrag.isMoveing = false; LayxDrag.isFirstMoveing = true; if (Utils.isSupportTouch) { document.ontouchend = null; document.ontouchmove = null; } else { document.onmouseup = null; document.onmousemove = null; } return; } } } var _left = handle.winform.area.left + distX; var _top = handle.winform.area.top + distY; if (handle.winform.status === "max" && handle.winform.resizable === true) { if (moveMouseCoord.x < handle.winform.area.width / 2) { _left = 0; } else if (moveMouseCoord.x > handle.winform.area.width / 2 && moveMouseCoord.x < handle.innerArea.width - handle.winform.area.width) { _left = moveMouseCoord.x - handle.winform.area.width / 2; } else if (handle.innerArea.width - moveMouseCoord.x < handle.winform.area.width / 2) { _left = handle.innerArea.width - handle.winform.area.width; } else if (handle.innerArea.width - moveMouseCoord.x > handle.winform.area.width / 2 && moveMouseCoord.x >= handle.innerArea.width - handle.winform.area.width) { _left = moveMouseCoord.x - handle.winform.area.width / 2; } _top = 0; handle.winform.area.top = 0; handle.winform.area.left = _left; Layx.restore(handle.winform.id); } handle.winform.moveLimit.horizontal === true && (_left = handle.winform.area.left); handle.winform.moveLimit.vertical === true && (_top = handle.winform.area.top); handle.winform.moveLimit.leftOut === false && (_left = Math.max(_left, 0)); handle.winform.moveLimit.rightOut === false && (_left = Math.min(_left, handle.innerArea.width - handle.winform.area.width)); handle.winform.moveLimit.bottomOut === false && (_top = Math.min(_top, handle.innerArea.height - handle.winform.area.height)); _top = Math.max(_top, 0); _top = Math.min(handle.innerArea.height - 15, _top); _left = Math.max(_left, -(handle.winform.area.width - 15)); _left = Math.min(_left, handle.innerArea.width - 15); handle.layxWindow.style.left = _left + "px"; handle.layxWindow.style.top = _top + "px"; if (Utils.isFunction(handle.winform.event.onmove.progress)) { handle.winform.event.onmove.progress(handle.layxWindow, handle.winform); } }; var dragend = function (e) { e = e || window.event; if (Utils.isSupportTouch) { document.ontouchend = null; document.ontouchmove = null; if (Utils.IsPC()) { var button = e.button || e.which; if (button == 1 && e.shiftKey == false) { var resizeList = handle.layxWindow.querySelectorAll(".layx-resizes > div"); for (var i = 0; i < resizeList.length; i++) { resizeList[i].classList.add("layx-reisize-touch"); } } document.onmouseup = null; document.onmousemove = null; } } else { document.onmouseup = null; document.onmousemove = null; } var mousePreventDefault = handle.layxWindow.querySelector(".layx-mouse-preventDefault"); if (mousePreventDefault) { mousePreventDefault.parentNode.removeChild(mousePreventDefault); } var layxMove = document.getElementById("layx-window-move"); if (layxMove) { layxMove.parentNode.removeChild(layxMove); } if (LayxDrag.isMoveing === true) { LayxDrag.isMoveing = false; LayxDrag.isFirstMoveing = true; handle.winform.area.top = handle.layxWindow.offsetTop; handle.winform.area.left = handle.layxWindow.offsetLeft; if (handle.winform.storeStatus === true) { Layx.storeWindowAreaInfo(handle.winform.id, { top: handle.winform.area.top, left: handle.winform.area.left, width: handle.winform.area.width, height: handle.winform.area.height }); } if (handle.winform.area.top === 0 && handle.winform.status === "normal" && handle.winform.maxable === true && handle.winform.resizable === true && handle.winform.dragInTopToMax === true) { handle.winform.area.top = handle.defaultArea.top; handle.winform.area.left = handle.defaultArea.left; if (handle.winform.storeStatus === true) { Layx.storeWindowAreaInfo(handle.winform.id, { top: handle.winform.area.top, left: handle.winform.area.left, width: handle.winform.area.width, height: handle.winform.area.height }); } Layx.max(handle.winform.id); } if (Utils.isFunction(handle.winform.event.onmove.after)) { handle.winform.event.onmove.after(handle.layxWindow, handle.winform); } } }; var dragstart = function (e) { e = e || window.event; var layxWindow = Utils.getNodeByClassName(handle, 'layx-window', win); if (layxWindow) { var id = layxWindow.getAttribute("id").substr(5), winform = Layx.windows[id]; if (winform) { if (winform.status !== "min" && winform.movable === true) { var layxMove = document.getElementById("layx-window-move"); if (!layxMove) { layxMove = document.createElement("div"); layxMove.setAttribute("id", "layx-window-move"); document.body.appendChild(layxMove); } Layx.updateZIndex(id); layxMove.style.zIndex = winform.zIndex - 1; var mouseCoord = Utils.getMousePosition(e); handle.mouseStartCoord = mouseCoord; handle.layxWindow = layxWindow; handle.winform = winform; handle.innerArea = Utils.innerArea(); handle.defaultArea = layxDeepClone({}, winform.area); handle.touchDate = new Date(); var mousePreventDefault = layxWindow.querySelector(".layx-mouse-preventDefault"); if (!mousePreventDefault) { mousePreventDefault = document.createElement("div"); mousePreventDefault.classList.add("layx-mouse-preventDefault"); var main = layxWindow.querySelector(".layx-main"); if (main) { main.appendChild(mousePreventDefault); } } if (Utils.isSupportTouch) { document.ontouchend = dragend; document.ontouchmove = drag; if (Utils.IsPC()) { var button = e.button || e.which; if (button == 1 && e.shiftKey == false) { var resizeList = layxWindow.querySelectorAll(".layx-resizes > div"); for (var i = 0; i < resizeList.length; i++) { resizeList[i].classList.remove("layx-reisize-touch"); } } document.onmouseup = dragend; document.onmousemove = drag; } } else { document.onmouseup = dragend; document.onmousemove = drag; } } else { Layx.restore(id); } } } return false; }; if (Utils.isSupportTouch) { handle.ontouchstart = dragstart; if (Utils.IsPC()) { handle.onmousedown = dragstart; } } else { handle.onmousedown = dragstart; } }; win.layx = { v: (function () { return Layx.version; })(), open: function (options) { var winform = Layx.create(options); return winform; }, html: function (id, title, content, options) { var winform = Layx.create(layxDeepClone({}, { id: id, title: title, type: 'html', content: content }, options || {})); return winform; }, iframe: function (id, title, url, options) { var winform = Layx.create(layxDeepClone({}, { id: id, title: title, type: 'url', url: url, useFrameTitle: title === true ? true : false }, options || {})); return winform; }, group: function (id, frames, frameIndex, options) { var winform = Layx.create(layxDeepClone({}, { id: id, type: 'group', frames: frames, frameIndex: typeof frameIndex === "number" ? (frameIndex > frames.length ? 0 : frameIndex) : 0 }, options || {})); return winform; }, windows: function () { return Layx.windows; }, getWindow: function (id) { return Layx.windows[id]; }, destroy: function (id, params, force) { Layx.destroy(id, params, false, false, force); }, visual: function (id, status, params) { Layx.visual(id, status, params); }, min: function (id) { Layx.min(id); }, max: function (id) { Layx.max(id); }, setTitle: function (id, title, useFrameTitle) { Layx.setTitle(id, title, useFrameTitle); }, flicker: function (id) { Layx.flicker(id); }, restore: function (id) { Layx.restore(id); }, updateZIndex: function (id) { Layx.updateZIndex(id); }, updateMinLayout: function () { Layx.updateMinLayout(); }, stickToggle: function (id) { Layx.stickToggle(id); }, setPosition: function (id, position) { Layx.setPosition(id, position); }, getFrameContext: function (id) { return Layx.getFrameContext(id); }, getParentContext: function (id) { return Layx.getParentContext(id); }, setContent: function (id, content, cloneElementContent) { Layx.setContent(id, content, cloneElementContent); }, setUrl: function (id, url) { Layx.setUrl(id, url); }, setGroupContent: function (id, frameId, content, cloneElementContent) { Layx.setGroupContent(id, frameId, content, cloneElementContent); }, setGroupTitle: function (id, frameId, title, useFrameTitle) { Layx.setGroupTitle(id, frameId, title, useFrameTitle); }, setGroupUrl: function (id, frameId, url) { Layx.setGroupUrl(id, frameId, url); }, setGroupIndex: function (id, frameId) { Layx.setGroupIndex(id, frameId); }, getGroupFrameContext: function (id, frameId) { return Layx.getGroupFrameContext(id, frameId); }, destroyAll: function () { Layx.destroyAll(); }, tip: function (msg, target, direction, options) { Layx.tip(msg, target, direction, options); }, msg: function (msg, options) { return Layx.msg(msg, options); }, alert: function (title, msg, yes, options) { return Layx.alert(title, msg, yes, options); }, confirm: function (title, msg, yes, options) { return Layx.confirm(title, msg, yes, options); }, getPromptTextArea: function (id) { return Layx.getPromptTextArea(id); }, prompt: function (title, msg, yes, defaultValue, options) { return Layx.prompt(title, msg, yes, defaultValue, options); }, load: function (id, msg, options) { return Layx.load(id, msg, options); }, multiLine: function (f) { return f.toString().replace(/^[^\/]+\/\*!?\s?/, '').replace(/\*\/[^\/]+$/, ''); }, reloadFrame: function (id) { Layx.reloadFrame(id); }, reloadGroupFrame: function (id, frameId) { Layx.reloadGroupFrame(id, frameId); }, setButtonStatus: function (id, buttonId, isEnable) { Layx.setButtonStatus(id, buttonId, isEnable); }, updateFloatWinPosition: function (id, direction) { Layx.updateFloatWinPosition(id, direction); }, getElementPos: function (ele) { return Utils.getElementPos(ele); }, destroyInlay: function (id) { Layx.destroyInlay(id); }, checkVisual: function (pEle, ele, allContain) { return Utils.checkElementIsVisual(pEle, ele, allContain); }, getButton: function (id, buttonId) { return Layx.getButton(id, buttonId); }, setSize: function (id, area) { Layx.setSize(id, area); } }; win.document.addEventListener("keydown", function (event) { var e = event || window.event || arguments.callee.caller.arguments[0]; var focusWindow = Layx.windows[Layx.focusId]; if (e && e.keyCode == 27) { if (focusWindow) { Layx.destroy(Layx.focusId, {}, false, true); } } if (e && e.keyCode === 13) { if (focusWindow && focusWindow.buttons.length > 0) { if (focusWindow.buttonKey.toLowerCase() === "enter" && !e.ctrlKey) { if (focusWindow.dialogType !== "prompt") { focusWindow.buttons[0].callback(focusWindow.id, Layx.getButton(focusWindow.id, focusWindow.buttons[0].id, e)); } else { var textarea = Layx.getPromptTextArea(focusWindow.id); focusWindow.buttons[0].callback(focusWindow.id, (textarea ? textarea.value : "").replace(/(^\s*)|(\s*$)/g, ""), textarea, Layx.getButton(focusWindow.id, focusWindow.buttons[0].id, e)); } } else if (focusWindow.buttonKey.toLowerCase() === "ctrl+enter" && e.ctrlKey) { if (focusWindow.dialogType !== "prompt") { focusWindow.buttons[0].callback(focusWindow.id, Layx.getButton(focusWindow.id, focusWindow.buttons[0].id, e)); } else { var textarea = Layx.getPromptTextArea(focusWindow.id); focusWindow.buttons[0].callback(focusWindow.id, (textarea ? textarea.value : "").replace(/(^\s*)|(\s*$)/g, ""), textarea, Layx.getButton(focusWindow.id, focusWindow.buttons[0].id, e)); } } } } }, false); })(top, window, self); ; !(function (global) { var extend, _extend, _isObject; _isObject = function (o) { return Object.prototype.toString.call(o) === '[object Object]'; }; _extend = function self(destination, source) { var property; for (property in destination) { if (destination.hasOwnProperty(property)) { if (_isObject(destination[property]) && _isObject(source[property])) { self(destination[property], source[property]); } if (source.hasOwnProperty(property)) { continue; } else { source[property] = destination[property]; } } } }; extend = function () { var arr = arguments, result = {}, i; if (!arr.length) return {}; for (i = arr.length - 1; i >= 0; i--) { if (_isObject(arr[i])) { _extend(arr[i], result); } } arr[0] = result; return result; }; global.layxDeepClone = extend; })(window); ; !(function (window) { var svgSprite = ''; var script = function () { var scripts = document.getElementsByTagName("script"); return scripts[scripts.length - 1]; }(); var shouldInjectCss = script.getAttribute("data-injectcss"); var ready = function (fn) { if (document.addEventListener) { if (~["complete", "loaded", "interactive"].indexOf(document.readyState)) { setTimeout(fn, 0); } else { var loadFn = function () { document.removeEventListener("DOMContentLoaded", loadFn, false); fn(); }; document.addEventListener("DOMContentLoaded", loadFn, false); } } else if (document.attachEvent) { IEContentLoaded(window, fn); } function IEContentLoaded(w, fn) { var d = w.document, done = false, init = function () { if (!done) { done = true; fn(); } }; var polling = function () { try { d.documentElement.doScroll("left"); } catch (e) { setTimeout(polling, 50); return; } init(); }; polling(); d.onreadystatechange = function () { if (d.readyState == "complete") { d.onreadystatechange = null; init(); } }; } }; var before = function (el, target) { target.parentNode.insertBefore(el, target); }; var prepend = function (el, target) { if (target.firstChild) { before(el, target.firstChild); } else { target.appendChild(el); } }; function appendSvg() { var div, svg; div = document.createElement("div"); div.innerHTML = svgSprite; svgSprite = null; svg = div.getElementsByTagName("svg")[0]; if (svg) { svg.setAttribute("aria-hidden", "true"); svg.style.position = "absolute"; svg.style.width = 0; svg.style.height = 0; svg.style.overflow = "hidden"; prepend(svg, document.body); } } if (shouldInjectCss && !window.__iconfont__svg__cssinject__) { window.__iconfont__svg__cssinject__ = true; try { document.write(""); } catch (e) { console && console.log(e); } } ready(appendSvg); })(window);