mirror of
https://github.com/modernw/App-Installer-For-Windows-8.x-Reset.git
synced 2026-04-17 21:24:48 +10:00
Update Reader.
This commit is contained in:
117
shared/html/libs/msgbox/contentdlg.css
Normal file
117
shared/html/libs/msgbox/contentdlg.css
Normal file
@@ -0,0 +1,117 @@
|
||||
.win-contentdialog {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
top: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
box-sizing: border-box;
|
||||
background-color: rgba(0, 0, 0, 0.5);
|
||||
transition: all 0.15s linear;
|
||||
opacity: 1;
|
||||
z-index: 100;
|
||||
}
|
||||
|
||||
.win-contentdialog.hide {
|
||||
opacity: 0;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.win-contentdialog .win-contentdialog-dialog {
|
||||
position: absolute;
|
||||
left: 50%;
|
||||
top: 50%;
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
padding: 20px 0;
|
||||
background-color: rgb(31, 0, 104);
|
||||
/*transition: all 0.5s cubic-bezier(0.1, 0.9, 0.2, 1);*/
|
||||
transition: height, max-height, min-height 0.5s cubic-bezier(0.1, 0.9, 0.2, 1);
|
||||
transform: translate(-50%, -50%);
|
||||
}
|
||||
|
||||
.win-contentdialog .win-contentdialog-title {
|
||||
font-size: 20pt;
|
||||
font-weight: normal;
|
||||
padding: 0 172px;
|
||||
box-sizing: border-box;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.win-contentdialog .win-contentdialog-content {
|
||||
padding: 0 172px;
|
||||
overflow-y: auto;
|
||||
box-sizing: border-box;
|
||||
max-height: calc(100vh - 200px);
|
||||
margin: 10px 0 20px 0;
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
.win-contentdialog .win-contentdialog-commands {
|
||||
padding: 0 172px;
|
||||
box-sizing: border-box;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
flex-wrap: wrap;
|
||||
align-content: flex-start;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
.win-contentdialog .win-contentdialog-commands>button {
|
||||
margin-left: 20px;
|
||||
}
|
||||
|
||||
.win-contentdialog .win-contentdialog-content p {
|
||||
margin: 5px 0;
|
||||
}
|
||||
|
||||
.win-contentdialog .win-contentdialog-content dl dt,
|
||||
.win-contentdialog .win-contentdialog-content dl dd {
|
||||
display: inline-block;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
vertical-align: middle;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.win-contentdialog .win-contentdialog-content dl {
|
||||
width: 100%;
|
||||
max-width: 100%;
|
||||
height: auto;
|
||||
box-sizing: border-box;
|
||||
margin: 0px;
|
||||
}
|
||||
|
||||
.win-contentdialog .win-contentdialog-content dl dt {
|
||||
width: 100%;
|
||||
max-width: 100%;
|
||||
text-align: left;
|
||||
padding-right: 8px;
|
||||
}
|
||||
|
||||
.win-contentdialog .win-contentdialog-content dl dd {
|
||||
width: 100%;
|
||||
max-width: 100%;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.win-contentdialog .win-contentdialog-content dl dd * {
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
.win-contentdialog-dialog-template {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.win-contentdialog .win-contentdialog-content .win-contentdialog-dialog-template {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.win-ui-light .win-contentdialog .win-contentdialog-dialog,
|
||||
.win-contentdialog.win-ui-light .win-contentdialog-dialog {
|
||||
background-color: white;
|
||||
}
|
||||
|
||||
.win-ui-dark .win-contentdialog .win-contentdialog-dialog,
|
||||
.win-contentdialog.win-ui-dark .win-contentdialog-dialog {
|
||||
background-color: rgb(31, 0, 104);
|
||||
}
|
||||
317
shared/html/libs/msgbox/contentdlg.js
Normal file
317
shared/html/libs/msgbox/contentdlg.js
Normal file
@@ -0,0 +1,317 @@
|
||||
/// <reference path="//Microsoft.WinJS.2.0/js/base.js" />
|
||||
/// <reference path="//Microsoft.WinJS.2.0/js/ui.js" />
|
||||
|
||||
(function (global) {
|
||||
"use strict";
|
||||
if (typeof global.toStaticHTML === "undefined") global.toStaticHTML = function (str) { return str; };
|
||||
if (typeof global.WinJS === "undefined" || !global.WinJS) global.WinJS = {};
|
||||
if (typeof global.WinJS.UI === "undefined" || !global.WinJS.UI) global.WinJS.UI = {};
|
||||
|
||||
// 事件混入
|
||||
function mixEventMixin(target) {
|
||||
var eventMixin = WinJS.Utilities.eventMixin;
|
||||
target.addEventListener = eventMixin.addEventListener;
|
||||
target.removeEventListener = eventMixin.removeEventListener;
|
||||
target.dispatchEvent = eventMixin.dispatchEvent;
|
||||
target._listeners = target._listeners || {};
|
||||
}
|
||||
|
||||
/**
|
||||
* 表示 ContentDialog 中的一个按钮命令。
|
||||
* @class
|
||||
* @param {string} label 按钮显示文本
|
||||
* @param {function(Event=): (boolean|void)} [handler] 按钮点击处理函数
|
||||
* @param {string} [commandId] 命令唯一标识
|
||||
*/
|
||||
function ContentDialogCommand(label, handler, commandId) {
|
||||
this.label = label;
|
||||
this.handler = handler;
|
||||
this.commandId = commandId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 模拟 WinRT ContentDialog 的对话框
|
||||
* @class
|
||||
* @memberof WinJS.UI
|
||||
* @param {HTMLElement} element 容器
|
||||
* @param {Object} [options] 初始化选项
|
||||
*/
|
||||
function ContentDialog(element, options) {
|
||||
var container = element;
|
||||
container.innerHTML = toStaticHTML('<div class="win-contentdialog-dialog notice-body"><div class="win-contentdialog-title notice-title"></div><div class="win-contentdialog-content notice-text"></div><div class="win-contentdialog-commands notice-controls"></div></div>');
|
||||
container.classList.add("win-contentdialog");
|
||||
container.classList.add("notice-back");
|
||||
container.classList.add("hide");
|
||||
|
||||
var title = container.querySelector(".win-contentdialog-title");
|
||||
var content = container.querySelector(".win-contentdialog-content");
|
||||
var commandContainer = container.querySelector(".win-contentdialog-commands");
|
||||
var _isdisposed = false;
|
||||
|
||||
mixEventMixin(this);
|
||||
var self = this;
|
||||
|
||||
// 命令集合
|
||||
this._commands = new WinJS.Binding.List();
|
||||
var _showAsyncPromise = null;
|
||||
var _showAsyncResolve = null;
|
||||
|
||||
// 渲染按钮
|
||||
function renderCommands() {
|
||||
while (commandContainer.firstChild) {
|
||||
commandContainer.removeChild(commandContainer.firstChild);
|
||||
}
|
||||
self._commands.forEach(function (cmd, index) {
|
||||
var btn = document.createElement("button");
|
||||
btn.classList.add ("notice-btn");
|
||||
btn.textContent = cmd.label;
|
||||
btn.setAttribute("data-command-id", cmd.commandId || index);
|
||||
|
||||
btn.addEventListener("click", function (evt) {
|
||||
handleCommandClick(cmd, evt);
|
||||
});
|
||||
|
||||
commandContainer.appendChild(btn);
|
||||
});
|
||||
if (self._commands.length > 0) {
|
||||
self.primaryCommandIndex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// 按钮点击处理
|
||||
function handleCommandClick(cmd, evt) {
|
||||
var result;
|
||||
|
||||
if (typeof cmd.handler === "function") {
|
||||
result = cmd.handler.call(self, evt);
|
||||
}
|
||||
|
||||
function complete() {
|
||||
self.hide().then(function () {
|
||||
if (_showAsyncResolve) {
|
||||
_showAsyncResolve(cmd.commandId);
|
||||
clearAsyncState();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// handler 返回 false → 不关闭
|
||||
if (result === false) return;
|
||||
|
||||
// handler 返回 Promise → 等待
|
||||
if (result && typeof result.then === "function") {
|
||||
result.then(complete);
|
||||
return;
|
||||
}
|
||||
|
||||
complete();
|
||||
}
|
||||
|
||||
function clearAsyncState() {
|
||||
_showAsyncPromise = null;
|
||||
_showAsyncResolve = null;
|
||||
}
|
||||
|
||||
// 可取消事件
|
||||
function createCancelableEvent(type) {
|
||||
var defaultPrevented = false;
|
||||
return {
|
||||
type: type,
|
||||
target: self,
|
||||
preventDefault: function () { defaultPrevented = true; },
|
||||
get defaultPrevented() { return defaultPrevented; }
|
||||
};
|
||||
}
|
||||
|
||||
function raiseEvent(type, cancelable) {
|
||||
var eventObj = cancelable ? createCancelableEvent(type) : { type: type, target: self };
|
||||
self.dispatchEvent(type, eventObj);
|
||||
var handler = self["on" + type];
|
||||
if (typeof handler === "function") {
|
||||
handler.call(self, eventObj);
|
||||
}
|
||||
return eventObj;
|
||||
}
|
||||
|
||||
// 命令列表事件
|
||||
this._commands.addEventListener("iteminserted", renderCommands);
|
||||
this._commands.addEventListener("itemremoved", renderCommands);
|
||||
this._commands.addEventListener("itemchanged", renderCommands);
|
||||
this._commands.addEventListener("reload", renderCommands);
|
||||
|
||||
// 属性
|
||||
Object.defineProperty(this, "element", { get: function () { return container; }, enumerable: true });
|
||||
Object.defineProperty(this, "hidden", { get: function () { return container.classList.contains("hide"); }, enumerable: true });
|
||||
Object.defineProperty(this, "title", { get: function () { return title.textContent; }, set: function (v) { title.textContent = v; }, enumerable: true });
|
||||
Object.defineProperty(this, "content", {
|
||||
get: function () { return content.firstChild; },
|
||||
set: function (v) {
|
||||
if (typeof v === "string" || typeof v === "number") v = document.createTextNode(v);
|
||||
while (content.firstChild) content.removeChild(content.firstChild);
|
||||
content.appendChild(v);
|
||||
},
|
||||
enumerable: true
|
||||
});
|
||||
Object.defineProperty(this, "commands", { get: function () { return self._commands; }, enumerable: true });
|
||||
Object.defineProperty(this, "primaryCommandIndex", {
|
||||
get: function () {
|
||||
var btns = commandContainer.querySelectorAll("button");
|
||||
for (var i = 0; i < btns.length; i++) {
|
||||
if (btns[i].type === "submit") return i;
|
||||
}
|
||||
return -1;
|
||||
},
|
||||
set: function (value) {
|
||||
var btns = commandContainer.querySelectorAll("button");
|
||||
for (var i = 0; i < btns.length; i++) {
|
||||
btns[i].removeAttribute("type");
|
||||
if (i === value) btns[i].type = "submit";
|
||||
}
|
||||
},
|
||||
enumerable: true
|
||||
});
|
||||
this._darkMode = true;
|
||||
this._backgroundColor = null;
|
||||
this._foregroundColor = null;
|
||||
Object.defineProperty(this, "darkMode", {
|
||||
get: function () {
|
||||
return self._darkMode;
|
||||
},
|
||||
set: function (value) {
|
||||
self._darkMode = !!value;
|
||||
if (self._backgroundColor === null) {
|
||||
if (self._darkMode) {
|
||||
container.classList.add("win-ui-dark");
|
||||
container.classList.remove("win-ui-light");
|
||||
} else {
|
||||
container.classList.add("win-ui-light");
|
||||
container.classList.remove("win-ui-dark");
|
||||
}
|
||||
}
|
||||
},
|
||||
enumerable: true
|
||||
});
|
||||
Object.defineProperty(this, "backgroundColor", {
|
||||
get: function () {
|
||||
return self._backgroundColor;
|
||||
},
|
||||
set: function (value) {
|
||||
self._backgroundColor = value;
|
||||
var dialog = container.querySelector(".win-contentdialog-dialog");
|
||||
if (dialog) {
|
||||
if (value !== null) {
|
||||
dialog.style.backgroundColor = value;
|
||||
} else {
|
||||
// 还原暗/亮模式背景
|
||||
if (self._darkMode) {
|
||||
dialog.style.backgroundColor = "rgb(31, 0, 104)";
|
||||
} else {
|
||||
dialog.style.backgroundColor = "white";
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
enumerable: true
|
||||
});
|
||||
Object.defineProperty(this, "foregroundColor", {
|
||||
get: function () {
|
||||
return self._foregroundColor;
|
||||
},
|
||||
set: function (value) {
|
||||
self._foregroundColor = value;
|
||||
var titleEl = container.querySelector(".win-contentdialog-title");
|
||||
var contentEl = container.querySelector(".win-contentdialog-content");
|
||||
if (titleEl) titleEl.style.color = value || "";
|
||||
if (contentEl) contentEl.style.color = value || "";
|
||||
},
|
||||
enumerable: true
|
||||
});
|
||||
container.classList.add("win-ui-dark");
|
||||
// 显示 / 隐藏
|
||||
this.show = function () {
|
||||
if (!container.classList.contains("hide")) return Promise.as();
|
||||
var ev = raiseEvent("beforeshow", true);
|
||||
if (ev.defaultPrevented) return Promise.as(); // 取消显示时直接返回
|
||||
container.classList.remove("hide");
|
||||
return new WinJS.Promise(function (complete) {
|
||||
setTimeout(function () {
|
||||
raiseEvent("aftershow", false);
|
||||
complete();
|
||||
}, 150);
|
||||
});
|
||||
};
|
||||
|
||||
this.hide = function () {
|
||||
if (container.classList.contains("hide")) return Promise.as();
|
||||
var ev = raiseEvent("beforehide", true);
|
||||
if (ev.defaultPrevented) return Promise.as();
|
||||
container.classList.add("hide");
|
||||
return new WinJS.Promise(function (complete) {
|
||||
setTimeout(function () {
|
||||
raiseEvent("afterhide", false);
|
||||
complete();
|
||||
}, 150);
|
||||
});
|
||||
};
|
||||
|
||||
// 释放资源
|
||||
this.dispose = function () {
|
||||
if (!_isdisposed) {
|
||||
_isdisposed = true;
|
||||
try { container.removeNode(false); } catch (e) { }
|
||||
}
|
||||
};
|
||||
|
||||
// 事件回调
|
||||
this.onbeforeshow = null;
|
||||
this.onaftershow = null;
|
||||
this.onbeforehide = null;
|
||||
this.onafterhide = null;
|
||||
|
||||
// showAsync
|
||||
this.showAsync = function () {
|
||||
if (_showAsyncPromise) return _showAsyncPromise;
|
||||
_showAsyncPromise = new WinJS.Promise(function (resolve) {
|
||||
_showAsyncResolve = resolve;
|
||||
self.show();
|
||||
});
|
||||
return _showAsyncPromise;
|
||||
};
|
||||
|
||||
// 初始化 options
|
||||
if (options) {
|
||||
if (options.title !== undefined) this.title = options.title;
|
||||
if (options.content !== undefined) this.content = options.content;
|
||||
if (options.commands && options.commands.length) {
|
||||
options.commands.forEach(function (c) {
|
||||
if (c instanceof ContentDialogCommand) {
|
||||
self._commands.push(c);
|
||||
} else {
|
||||
self._commands.push(new ContentDialogCommand(c.label, c.handler, c.commandId));
|
||||
}
|
||||
});
|
||||
renderCommands();
|
||||
}
|
||||
if (typeof options.primaryCommandIndex === "number") this.primaryCommandIndex = options.primaryCommandIndex;
|
||||
if (typeof options.onbeforeshow === "function") this.onbeforeshow = options.onbeforeshow;
|
||||
if (typeof options.onaftershow === "function") this.onaftershow = options.onaftershow;
|
||||
if (typeof options.onbeforehide === "function") this.onbeforehide = options.onbeforehide;
|
||||
if (typeof options.onafterhide === "function") this.onafterhide = options.onafterhide;
|
||||
if (options.autoShow === true) this.show();
|
||||
}
|
||||
}
|
||||
|
||||
// 快速创建 ContentDialog
|
||||
ContentDialog.create = function (content, title) {
|
||||
var container = document.createElement("div");
|
||||
document.body.appendChild(container);
|
||||
return new ContentDialog(container, {
|
||||
title: title,
|
||||
content: content
|
||||
});
|
||||
};
|
||||
|
||||
global.WinJS.UI.ContentDialogCommand = ContentDialogCommand;
|
||||
global.WinJS.UI.ContentDialog = ContentDialog;
|
||||
|
||||
})(this);
|
||||
@@ -1,95 +0,0 @@
|
||||
.notice-back {
|
||||
background-color: rgba(0, 0, 0, 0.5);
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
height: auto;
|
||||
width: auto;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
flex-wrap: nowrap;
|
||||
align-content: center;
|
||||
justify-content: center;
|
||||
display: -ms-flexbox;
|
||||
-ms-flex-direction: column;
|
||||
-ms-flex-wrap: nowrap;
|
||||
-ms-flex-line-pack: center;
|
||||
/* align-content: center */
|
||||
-ms-flex-pack: center;
|
||||
/* justify-content: center */
|
||||
transition: all 0.15s linear;
|
||||
opacity: 0;
|
||||
z-index: 100;
|
||||
}
|
||||
|
||||
.notice-body {
|
||||
background: #0078d7;
|
||||
padding: 25px 172px;
|
||||
left: 0;
|
||||
right: 0;
|
||||
top: auto;
|
||||
bottom: auto;
|
||||
max-height: 80%;
|
||||
height: auto;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
flex-wrap: nowrap;
|
||||
display: -ms-flexbox;
|
||||
-ms-flex-direction: column;
|
||||
-ms-flex-wrap: nowrap;
|
||||
min-height: 0 !important;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.notice-body>h1,
|
||||
.notice-body>h2,
|
||||
.notice-body>h3,
|
||||
.notice-body>h4,
|
||||
.notice-body>h5,
|
||||
.notice-body>h6,
|
||||
.notice-body>p,
|
||||
.notice-body>a,
|
||||
.notice-body>span {
|
||||
font-family: "Microsoft YaHei", "Segoe UI", "Ebrima", "Nirmala", "Gadugi", "Segoe UI Emoji", "Segoe UI Symbol", "Meiryo", "Leelawadee", "Microsoft JhengHei", "Malgun Gothic", "Estrangelo Edessa", "Microsoft Himalaya", "Microsoft New Tai Lue", "Microsoft PhagsPa", "Microsoft Tai Le", "Microsoft Yi Baiti", "Mongolian Baiti", "MV Boli", "Myanmar Text", "Javanese Text", "Cambria Math";
|
||||
white-space: pre-wrap;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.notice-title {
|
||||
color: white;
|
||||
font-weight: normal;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
|
||||
.notice-text {
|
||||
color: white;
|
||||
font-weight: normal;
|
||||
white-space: pre-wrap;
|
||||
-ms-overflow-style: -ms-autohiding-scrollbar;
|
||||
}
|
||||
|
||||
.notice-controls {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
flex-wrap: nowrap;
|
||||
align-content: center;
|
||||
justify-content: flex-end;
|
||||
align-items: center;
|
||||
display: -ms-flexbox;
|
||||
-ms-flex-direction: row;
|
||||
-ms-flex-wrap: nowrap;
|
||||
-ms-flex-line-pack: center;
|
||||
/* align-content: center(几乎无效,保留即可) */
|
||||
-ms-flex-pack: end;
|
||||
/* justify-content: flex-end */
|
||||
-ms-flex-align: center;
|
||||
/* align-items: center */
|
||||
margin-top: 10px;
|
||||
/*gap: 20px;*/
|
||||
}
|
||||
|
||||
.notice-btn {
|
||||
margin-left: 20px;
|
||||
}
|
||||
95
shared/html/libs/msgbox/msgbox.elder.css
Normal file
95
shared/html/libs/msgbox/msgbox.elder.css
Normal file
@@ -0,0 +1,95 @@
|
||||
.notice-back {
|
||||
background-color: rgba(0, 0, 0, 0.5);
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
height: auto;
|
||||
width: auto;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
flex-wrap: nowrap;
|
||||
align-content: center;
|
||||
justify-content: center;
|
||||
display: -ms-flexbox;
|
||||
-ms-flex-direction: column;
|
||||
-ms-flex-wrap: nowrap;
|
||||
-ms-flex-line-pack: center;
|
||||
/* align-content: center */
|
||||
-ms-flex-pack: center;
|
||||
/* justify-content: center */
|
||||
transition: all 0.15s linear;
|
||||
opacity: 0;
|
||||
z-index: 100;
|
||||
}
|
||||
|
||||
.notice-body {
|
||||
background: #0078d7;
|
||||
padding: 25px 172px;
|
||||
left: 0;
|
||||
right: 0;
|
||||
top: auto;
|
||||
bottom: auto;
|
||||
max-height: 80%;
|
||||
height: auto;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
flex-wrap: nowrap;
|
||||
display: -ms-flexbox;
|
||||
-ms-flex-direction: column;
|
||||
-ms-flex-wrap: nowrap;
|
||||
min-height: 0 !important;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.notice-body>h1,
|
||||
.notice-body>h2,
|
||||
.notice-body>h3,
|
||||
.notice-body>h4,
|
||||
.notice-body>h5,
|
||||
.notice-body>h6,
|
||||
.notice-body>p,
|
||||
.notice-body>a,
|
||||
.notice-body>span {
|
||||
font-family: "Microsoft YaHei", "Segoe UI", "Ebrima", "Nirmala", "Gadugi", "Segoe UI Emoji", "Segoe UI Symbol", "Meiryo", "Leelawadee", "Microsoft JhengHei", "Malgun Gothic", "Estrangelo Edessa", "Microsoft Himalaya", "Microsoft New Tai Lue", "Microsoft PhagsPa", "Microsoft Tai Le", "Microsoft Yi Baiti", "Mongolian Baiti", "MV Boli", "Myanmar Text", "Javanese Text", "Cambria Math";
|
||||
white-space: pre-wrap;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.notice-title {
|
||||
color: white;
|
||||
font-weight: normal;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
|
||||
.notice-text {
|
||||
color: white;
|
||||
font-weight: normal;
|
||||
white-space: pre-wrap;
|
||||
-ms-overflow-style: -ms-autohiding-scrollbar;
|
||||
}
|
||||
|
||||
.notice-controls {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
flex-wrap: nowrap;
|
||||
align-content: center;
|
||||
justify-content: flex-end;
|
||||
align-items: center;
|
||||
display: -ms-flexbox;
|
||||
-ms-flex-direction: row;
|
||||
-ms-flex-wrap: nowrap;
|
||||
-ms-flex-line-pack: center;
|
||||
/* align-content: center(几乎无效,保留即可) */
|
||||
-ms-flex-pack: end;
|
||||
/* justify-content: flex-end */
|
||||
-ms-flex-align: center;
|
||||
/* align-items: center */
|
||||
margin-top: 10px;
|
||||
/*gap: 20px;*/
|
||||
}
|
||||
|
||||
.notice-btn {
|
||||
margin-left: 20px;
|
||||
}
|
||||
532
shared/html/libs/msgbox/msgbox.elder.js
Normal file
532
shared/html/libs/msgbox/msgbox.elder.js
Normal file
@@ -0,0 +1,532 @@
|
||||
function IsBlackLabel(text) {
|
||||
if (text === null || text === undefined) return true;
|
||||
var trimmed = String(text).replace(/^\s+|\s+$/g, '');
|
||||
return trimmed === '';
|
||||
}
|
||||
|
||||
var MBFLAGS = {
|
||||
MB_OK: 0x00000000,
|
||||
MB_OKCANCEL: 0x00000001,
|
||||
MB_ABORTRETRYIGNORE: 0x00000002,
|
||||
MB_YESNOCANCEL: 0x00000003,
|
||||
MB_YESNO: 0x00000004,
|
||||
MB_RETRYCANCEL: 0x00000005,
|
||||
MB_CANCELTRYCONTINUE: 0x00000006,
|
||||
MB_HELP: 0x00004000,
|
||||
MB_DEFBUTTON1: 0x00000000,
|
||||
MB_DEFBUTTON2: 0x00000100,
|
||||
MB_DEFBUTTON3: 0x00000200,
|
||||
MB_DEFBUTTON4: 0x00000300,
|
||||
MB_ICONERROR: 0x00000010,
|
||||
MB_ICONWARNING: 0x00000030,
|
||||
MB_ICONINFORMATION: 0x00000040
|
||||
};
|
||||
|
||||
var MBRET = {
|
||||
IDOK: 1,
|
||||
IDCANCEL: 2,
|
||||
IDABORT: 3,
|
||||
IDRETRY: 4,
|
||||
IDIGNORE: 5,
|
||||
IDYES: 6,
|
||||
IDNO: 7,
|
||||
IDCLOSE: 8,
|
||||
IDHELP: 9,
|
||||
IDTRYAGAIN: 10,
|
||||
IDCONTINUE: 11
|
||||
};
|
||||
|
||||
Object.freeze(MBFLAGS);
|
||||
Object.freeze(MBRET);
|
||||
|
||||
(function(global) {
|
||||
try {
|
||||
var storage = Bridge.External.Storage;
|
||||
var path = storage.path;
|
||||
var root = path.getDir(path.program);
|
||||
var respath = path.combine(root, "reslib.dll");
|
||||
var res = Bridge.Resources;
|
||||
global.respath = respath;
|
||||
global.getPublicRes = function(resId) {
|
||||
return res.fromfile(respath, resId);
|
||||
}
|
||||
} catch (e) {}
|
||||
})(this);
|
||||
|
||||
function GetLocaleStringFromResId(resId) { try { return getPublicRes(resId); } catch (e) {} }
|
||||
var msgboxResult = {};
|
||||
|
||||
function MessageBox(_lpText, _lpCaption, _uType, _objColor) {
|
||||
var id = MessageBoxForJS(_lpText, _lpCaption, _uType, _objColor, function(valueReturn) {
|
||||
getRes = valueReturn;
|
||||
msgboxResult[id] = valueReturn;
|
||||
});
|
||||
return id;
|
||||
}
|
||||
|
||||
function GetMessageBoxResult(msgboxId) {
|
||||
var result = msgboxResult[msgboxId];
|
||||
if (result === undefined || result === null) return null;
|
||||
msgboxResult[msgboxId] = null;
|
||||
return result;
|
||||
}
|
||||
|
||||
function ClearAllMessageBoxResults() {
|
||||
msgboxResult = null;
|
||||
msgboxResult = {};
|
||||
}
|
||||
|
||||
// 注意:callback 函数无返回值,传入参数:整数型 按下的按钮值。
|
||||
/*
|
||||
使用示例:
|
||||
MessageBoxForJS("请选择一个按钮", "", MBFLAGS.MB_OKCANCEL, "#0078d7", function(value) {
|
||||
console.log("MessageBoxForJS callback value: " + value);
|
||||
})
|
||||
*/
|
||||
function MessageBoxForJS(_lpText, _lpCaption, _uType, _objColor, _callback) {
|
||||
var msgbox = document.createElement("div");
|
||||
msgbox.classList.add("notice-back");
|
||||
msgbox.classList.add("win-ui-dark");
|
||||
var uniqueId = "msgbox_" + new Date().getTime();
|
||||
msgbox.id = uniqueId;
|
||||
var msgbody = document.createElement("div");
|
||||
msgbody.classList.add("notice-body");
|
||||
if (!IsBlackLabel(_objColor)) {
|
||||
msgbody.style.backgroundColor = _objColor;
|
||||
}
|
||||
msgbox.appendChild(msgbody);
|
||||
var msgcontainter = document.createElement("div");
|
||||
msgcontainter.style.height = "100%";
|
||||
msgcontainter.style.width = "100%";
|
||||
msgcontainter.style.maxHeight = "100%";
|
||||
msgcontainter.style.minHeight = "0px";
|
||||
msgcontainter.style.boxSizing = "border-box";
|
||||
msgbody.appendChild(msgcontainter);
|
||||
var msgcaption = document.createElement("div");
|
||||
msgcontainter.appendChild(msgcaption);
|
||||
msgcontainter.style.display = "flex";
|
||||
msgcontainter.style.flexDirection = "column";
|
||||
var msgcontent = document.createElement("div");
|
||||
msgcontent.style.flex = "1 1 auto";
|
||||
msgcontent.style.marginRight = "3px";
|
||||
msgcontent.style.overflowX = "hidden";
|
||||
msgcontent.style.overflowY = "auto";
|
||||
msgcontent.style.minHeight = "0px";
|
||||
msgcontainter.appendChild(msgcontent);
|
||||
if (_lpCaption instanceof HTMLElement) {
|
||||
msgcaption.appendChild(_lpCaption);
|
||||
msgcaption.classList.add("notice-title");
|
||||
} else {
|
||||
if (!IsBlackLabel(_lpCaption)) {
|
||||
var msgtitle = document.createElement("h2");
|
||||
msgtitle.textContent = _lpCaption;
|
||||
msgtitle.classList.add("notice-title");
|
||||
msgcaption.appendChild(msgtitle);
|
||||
} else {
|
||||
var msgtitle = document.createElement("h2");
|
||||
msgtitle.textContent = "";
|
||||
msgtitle.classList.add("notice-title");
|
||||
msgcaption.appendChild(msgtitle);
|
||||
}
|
||||
}
|
||||
if (_lpText instanceof HTMLElement || _lpText instanceof HTMLDivElement || typeof _lpText !== "string") {
|
||||
try {
|
||||
_lpText.classList.add("notice-text");
|
||||
msgcontent.appendChild(_lpText);
|
||||
} catch (e) {
|
||||
if (!IsBlackLabel(_lpText)) {
|
||||
var msgtext = document.createElement("p");
|
||||
msgtext.textContent = _lpText;
|
||||
msgtext.classList.add("notice-text");
|
||||
if (IsBlackLabel(_lpCaption)) {
|
||||
msgtext.style.marginTop = "0";
|
||||
}
|
||||
msgcontent.appendChild(msgtext);
|
||||
} else {
|
||||
var msgtext = document.createElement("p");
|
||||
msgtext.innerText = "";
|
||||
msgtext.classList.add("notice-text");
|
||||
if (IsBlackLabel(_lpCaption)) {
|
||||
msgtext.style.marginTop = "0";
|
||||
}
|
||||
msgcontent.appendChild(msgtext);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!IsBlackLabel(_lpText)) {
|
||||
var msgtext = document.createElement("p");
|
||||
msgtext.textContent = _lpText;
|
||||
msgtext.classList.add("notice-text");
|
||||
if (IsBlackLabel(_lpCaption)) {
|
||||
msgtext.style.marginTop = "0";
|
||||
}
|
||||
msgcontent.appendChild(msgtext);
|
||||
} else {
|
||||
var msgtext = document.createElement("p");
|
||||
msgtext.innerText = "";
|
||||
msgtext.classList.add("notice-text");
|
||||
if (IsBlackLabel(_lpCaption)) {
|
||||
msgtext.style.marginTop = "0";
|
||||
}
|
||||
msgcontent.appendChild(msgtext);
|
||||
}
|
||||
}
|
||||
var msgctrls = document.createElement("div");
|
||||
msgctrls.classList.add("notice-controls");
|
||||
msgcontainter.appendChild(msgctrls);
|
||||
var cnt = 0;
|
||||
var cbFuncPress = function(valueReturn) {
|
||||
getRes = valueReturn;
|
||||
msgbox.style.opacity = 0;
|
||||
setTimeout(function() {
|
||||
document.body.removeChild(msgbox);
|
||||
}, 500);
|
||||
if (_callback) {
|
||||
_callback(valueReturn);
|
||||
}
|
||||
};
|
||||
var pfCreateButton = function(displayNameResId, valueReturn) {
|
||||
var btn = document.createElement("button");
|
||||
btn.innerHTML = GetLocaleStringFromResId(displayNameResId);
|
||||
btn.classList.add("notice-btn");
|
||||
btn.addEventListener("click", function() {
|
||||
cbFuncPress(valueReturn);
|
||||
});
|
||||
msgctrls.appendChild(btn);
|
||||
};
|
||||
if ((_uType & MBFLAGS.MB_HELP) === MBFLAGS.MB_HELP) {
|
||||
pfCreateButton(808, MBRET.IDHELP);
|
||||
}
|
||||
for (cnt = 0; cnt <= MBFLAGS.MB_RETRYCANCEL; cnt++) {
|
||||
if ((_uType & 0xF) === cnt) {
|
||||
switch (cnt) {
|
||||
case MBFLAGS.MB_OK:
|
||||
{
|
||||
pfCreateButton(800, MBRET.IDOK);
|
||||
}
|
||||
break;
|
||||
case MBFLAGS.MB_OKCANCEL:
|
||||
{
|
||||
pfCreateButton(800, MBRET.IDOK);
|
||||
pfCreateButton(801, MBRET.IDCANCEL);
|
||||
}
|
||||
break;
|
||||
case MBFLAGS.MB_ABORTRETRYIGNORE:
|
||||
{
|
||||
pfCreateButton(802, MBRET.IDABORT);
|
||||
pfCreateButton(803, MBRET.IDRETRY);
|
||||
pfCreateButton(804, MBRET.IDIGNORE);
|
||||
}
|
||||
break;
|
||||
case MBFLAGS.MB_YESNOCANCEL:
|
||||
{
|
||||
pfCreateButton(805, MBRET.IDYES);
|
||||
pfCreateButton(806, MBRET.IDNO);
|
||||
pfCreateButton(801, MBRET.IDCANCEL);
|
||||
}
|
||||
break;
|
||||
case MBFLAGS.MB_YESNO:
|
||||
{
|
||||
pfCreateButton(805, MBRET.IDYES);
|
||||
pfCreateButton(806, MBRET.IDNO);
|
||||
}
|
||||
break;
|
||||
case MBFLAGS.MB_RETRYCANCEL:
|
||||
{
|
||||
pfCreateButton(803, MBRET.IDRETRY);
|
||||
pfCreateButton(801, MBRET.IDCANCEL);
|
||||
}
|
||||
break;
|
||||
case MBFLAGS.MB_CANCELTRYCONTINUE:
|
||||
{
|
||||
pfCreateButton(801, MBRET.IDCANCEL);
|
||||
pfCreateButton(803, MBRET.IDRETRY);
|
||||
pfCreateButton(810, MBRET.IDCONTINUE);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
var btns = msgctrls.querySelectorAll("button");
|
||||
var defaultBtnCnt = 0;
|
||||
if ((_uType & MBFLAGS.MB_DEFBUTTON1) === MBFLAGS.MB_DEFBUTTON1) defaultBtnCnt = 0;
|
||||
if ((_uType & MBFLAGS.MB_DEFBUTTON2) === MBFLAGS.MB_DEFBUTTON2) defaultBtnCnt = 1;
|
||||
if ((_uType & MBFLAGS.MB_DEFBUTTON3) === MBFLAGS.MB_DEFBUTTON3) defaultBtnCnt = 2;
|
||||
if ((_uType & MBFLAGS.MB_DEFBUTTON4) === MBFLAGS.MB_DEFBUTTON4) defaultBtnCnt = 3;
|
||||
for (cnt = 0; cnt < btns.length; cnt++) {
|
||||
if (cnt === defaultBtnCnt) {
|
||||
btns[cnt].focus();
|
||||
break;
|
||||
}
|
||||
}
|
||||
document.body.appendChild(msgbox);
|
||||
setTimeout(function() {
|
||||
msgbox.style.opacity = 1;
|
||||
}, 1);
|
||||
return msgbox.id;
|
||||
}
|
||||
|
||||
function MsgBoxObj() {
|
||||
this.elementId = "";
|
||||
this.callback = null;
|
||||
this.type = MBFLAGS.MB_OK;
|
||||
this._boundCallback = this._internalCallback.bind(this);
|
||||
this._text = "";
|
||||
this._title = "";
|
||||
this._color = "#0078d7";
|
||||
this.show = function() {
|
||||
this.elementId = MessageBoxForJS(
|
||||
this._text,
|
||||
this._title,
|
||||
this.type,
|
||||
this._color,
|
||||
this._boundCallback
|
||||
);
|
||||
setTimeout(function() {
|
||||
var element = document.getElementById(this.elementId);
|
||||
if (element) {
|
||||
var bodyElement = element.querySelector(".notice-body");
|
||||
if (bodyElement) {
|
||||
bodyElement.style.transition = "all 0.5s linear";
|
||||
}
|
||||
}
|
||||
}.bind(this), 100);
|
||||
}
|
||||
Object.defineProperty(this, "text", {
|
||||
get: function() {
|
||||
return this._text;
|
||||
},
|
||||
set: function(value) {
|
||||
this._text = value;
|
||||
if (this.elementId) {
|
||||
var element = document.getElementById(this.elementId);
|
||||
if (element) {
|
||||
var textElement = element.querySelector(".notice-text");
|
||||
if (textElement) {
|
||||
if (value instanceof HTMLElement) {
|
||||
value.classList.add("notice-text");
|
||||
textElement.parentNode.replaceChild(value, textElement);
|
||||
} else {
|
||||
textElement.innerHTML = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
Object.defineProperty(this, "title", {
|
||||
get: function() {
|
||||
return this._title;
|
||||
},
|
||||
set: function(value) {
|
||||
this._title = value;
|
||||
if (this.elementId) {
|
||||
var element = document.getElementById(this.elementId);
|
||||
if (element) {
|
||||
var titleElement = element.querySelector(".notice-title");
|
||||
if (titleElement) {
|
||||
titleElement.innerHTML = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
Object.defineProperty(this, "color", {
|
||||
get: function() {
|
||||
return this._color;
|
||||
},
|
||||
set: function(value) {
|
||||
this._color = value;
|
||||
if (this.elementId) {
|
||||
var element = document.getElementById(this.elementId);
|
||||
if (element) {
|
||||
var bodyElement = element.querySelector(".notice-body");
|
||||
if (bodyElement) {
|
||||
bodyElement.style.backgroundColor = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
this.getElement = function() {
|
||||
return document.getElementById(this.elementId);
|
||||
};
|
||||
}
|
||||
|
||||
MsgBoxObj.prototype._internalCallback = function(returnValue) {
|
||||
if (typeof this.callback === "function") {
|
||||
this.callback(returnValue);
|
||||
}
|
||||
};
|
||||
/**
|
||||
* 异步显示消息框,返回一个 Promise 对象。
|
||||
* @param {string | HTMLElement} swText 内容
|
||||
* @param {string} swTitle 标题
|
||||
* @param {MBFLAGS} uType 标志,使用 MBFLAGS 常量
|
||||
* @param {string} swColor 背景颜色文本。
|
||||
* @returns {Promise}
|
||||
*/
|
||||
function messageBoxAsync(swText, swTitle, uType, swColor, pfCallback) {
|
||||
if (typeof Promise === "undefined") {
|
||||
console.error("Promise is not supported in this environment.");
|
||||
MessageBoxForJS(swText, swTitle, uType, swColor, pfCallback);
|
||||
}
|
||||
return new Promise(function(resolve, reject) {
|
||||
try {
|
||||
MessageBoxForJS(swText, swTitle, uType, swColor, function(valueReturn) {
|
||||
if (resolve) resolve(valueReturn);
|
||||
});
|
||||
} catch (ex) {
|
||||
if (reject) reject(ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function MessageBoxButton(swDisplayName, nValueReturn) {
|
||||
this.displayName = swDisplayName;
|
||||
this.value = nValueReturn;
|
||||
}
|
||||
|
||||
function messageBoxAdvance(swText, swCaption, aCommands, swColor, pfCallback) {
|
||||
var _lpText = swText;
|
||||
var _lpCaption = swCaption;
|
||||
var msgbox = document.createElement("div");
|
||||
msgbox.classList.add("notice-back");
|
||||
msgbox.classList.add("win-ui-dark");
|
||||
var uniqueId = "msgbox_" + new Date().getTime();
|
||||
msgbox.id = uniqueId;
|
||||
var msgbody = document.createElement("div");
|
||||
msgbody.classList.add("notice-body");
|
||||
if (!IsBlackLabel(swColor)) {
|
||||
msgbody.style.backgroundColor = swColor;
|
||||
}
|
||||
msgbox.appendChild(msgbody);
|
||||
var msgcontainter = document.createElement("div");
|
||||
msgcontainter.style.height = "100%";
|
||||
msgcontainter.style.width = "100%";
|
||||
msgcontainter.style.maxHeight = "100%";
|
||||
msgcontainter.style.minHeight = "0px";
|
||||
msgcontainter.style.boxSizing = "border-box";
|
||||
msgbody.appendChild(msgcontainter);
|
||||
var msgcaption = document.createElement("div");
|
||||
msgcontainter.appendChild(msgcaption);
|
||||
msgcontainter.style.display = "flex";
|
||||
msgcontainter.style.flexDirection = "column";
|
||||
var msgcontent = document.createElement("div");
|
||||
msgcontent.style.flex = "1 1 auto";
|
||||
msgcontent.style.marginRight = "3px";
|
||||
msgcontent.style.overflowX = "hidden";
|
||||
msgcontent.style.overflowY = "auto";
|
||||
msgcontent.style.minHeight = "0px";
|
||||
msgcontainter.appendChild(msgcontent);
|
||||
if (_lpCaption instanceof HTMLElement) {
|
||||
msgcaption.appendChild(_lpCaption);
|
||||
msgcaption.classList.add("notice-title");
|
||||
} else {
|
||||
if (!IsBlackLabel(_lpCaption)) {
|
||||
var msgtitle = document.createElement("h2");
|
||||
msgtitle.textContent = _lpCaption;
|
||||
msgtitle.classList.add("notice-title");
|
||||
msgcaption.appendChild(msgtitle);
|
||||
} else {
|
||||
var msgtitle = document.createElement("h2");
|
||||
msgtitle.textContent = "";
|
||||
msgtitle.classList.add("notice-title");
|
||||
msgcaption.appendChild(msgtitle);
|
||||
}
|
||||
}
|
||||
if (_lpText instanceof HTMLElement || _lpText instanceof HTMLDivElement || typeof _lpText !== "string") {
|
||||
try {
|
||||
_lpText.classList.add("notice-text");
|
||||
msgcontent.appendChild(_lpText);
|
||||
} catch (e) {
|
||||
if (!IsBlackLabel(_lpText)) {
|
||||
var msgtext = document.createElement("p");
|
||||
msgtext.textContent = _lpText;
|
||||
msgtext.classList.add("notice-text");
|
||||
if (IsBlackLabel(_lpCaption)) {
|
||||
msgtext.style.marginTop = "0";
|
||||
}
|
||||
msgcontent.appendChild(msgtext);
|
||||
} else {
|
||||
var msgtext = document.createElement("p");
|
||||
msgtext.innerText = "";
|
||||
msgtext.classList.add("notice-text");
|
||||
if (IsBlackLabel(_lpCaption)) {
|
||||
msgtext.style.marginTop = "0";
|
||||
}
|
||||
msgcontent.appendChild(msgtext);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!IsBlackLabel(_lpText)) {
|
||||
var msgtext = document.createElement("p");
|
||||
msgtext.textContent = _lpText;
|
||||
msgtext.classList.add("notice-text");
|
||||
if (IsBlackLabel(_lpCaption)) {
|
||||
msgtext.style.marginTop = "0";
|
||||
}
|
||||
msgcontent.appendChild(msgtext);
|
||||
} else {
|
||||
var msgtext = document.createElement("p");
|
||||
msgtext.innerText = "";
|
||||
msgtext.classList.add("notice-text");
|
||||
if (IsBlackLabel(_lpCaption)) {
|
||||
msgtext.style.marginTop = "0";
|
||||
}
|
||||
msgcontent.appendChild(msgtext);
|
||||
}
|
||||
}
|
||||
var msgctrls = document.createElement("div");
|
||||
msgctrls.classList.add("notice-controls");
|
||||
msgcontainter.appendChild(msgctrls);
|
||||
if (aCommands.length <= 0) {
|
||||
aCommands.push(new MessageBoxButton(GetLocaleStringFromResId(800) || "OK", MBRET.IDOK));
|
||||
}
|
||||
for (var i = 0; i < aCommands.length; i++) {
|
||||
var cmd = aCommands[i];
|
||||
var btn = document.createElement("button");
|
||||
btn.textContent = cmd.displayName;
|
||||
btn.setAttribute("data-msgbox-value", cmd.value);
|
||||
Windows.UI.Event.Util.addEvent(btn, "click", function(event) {
|
||||
var btns = this.parentNode.querySelectorAll("button");
|
||||
var lastbtnstatus = [];
|
||||
for (var j = 0; j < btns.length; j++) {
|
||||
lastbtnstatus.push(btns[j].disabled);
|
||||
btns[j].disabled = true;
|
||||
}
|
||||
try {
|
||||
pfCallback(this.getAttribute("data-msgbox-value"));
|
||||
} catch (e) {}
|
||||
msgbox.style.opacity = 0;
|
||||
setTimeout(function(nodes, laststatus) {
|
||||
for (var k = 0; k < nodes.length; k++) {
|
||||
nodes[k].disabled = laststatus[k];
|
||||
}
|
||||
document.body.removeChild(msgbox);
|
||||
}, 500, btns, lastbtnstatus);
|
||||
});
|
||||
msgctrls.appendChild(btn);
|
||||
}
|
||||
document.body.appendChild(msgbox);
|
||||
setTimeout(function() {
|
||||
msgbox.style.opacity = 1;
|
||||
}, 1);
|
||||
return msgbox.id;
|
||||
}
|
||||
|
||||
function messageBoxAdvanceAsync(swText, swCaption, aCommands, swColor) {
|
||||
if (typeof Promise === "undefined") {
|
||||
console.error("Promise is not supported in this environment.");
|
||||
messageBoxAdvance(swText, swCaption, aCommands, swColor);
|
||||
}
|
||||
return new Promise(function(resolve, reject) {
|
||||
try {
|
||||
messageBoxAdvance(swText, swCaption, aCommands, swColor, function(valueReturn) {
|
||||
if (resolve) resolve(valueReturn);
|
||||
});
|
||||
} catch (ex) {
|
||||
if (reject) reject(ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -39,6 +39,7 @@ var MBRET = {
|
||||
Object.freeze(MBFLAGS);
|
||||
Object.freeze(MBRET);
|
||||
|
||||
// ==================== 资源加载部分(保持不变) ====================
|
||||
(function(global) {
|
||||
try {
|
||||
var storage = Bridge.External.Storage;
|
||||
@@ -53,15 +54,197 @@ Object.freeze(MBRET);
|
||||
} catch (e) {}
|
||||
})(this);
|
||||
|
||||
function GetLocaleStringFromResId(resId) { try { return getPublicRes(resId); } catch (e) {} }
|
||||
function GetLocaleStringFromResId(resId) {
|
||||
try { return getPublicRes(resId); } catch (e) { return ""; }
|
||||
}
|
||||
|
||||
// ==================== 全局结果存储 ====================
|
||||
var msgboxResult = {};
|
||||
|
||||
function MessageBox(_lpText, _lpCaption, _uType, _objColor) {
|
||||
var id = MessageBoxForJS(_lpText, _lpCaption, _uType, _objColor, function(valueReturn) {
|
||||
getRes = valueReturn;
|
||||
msgboxResult[id] = valueReturn;
|
||||
function ClearAllMessageBoxResults() {
|
||||
msgboxResult = {};
|
||||
}
|
||||
|
||||
// ==================== 辅助函数 ====================
|
||||
var _msgboxIdCounter = 0;
|
||||
|
||||
function _generateMsgBoxId() {
|
||||
return "msgbox_" + new Date().getTime() + "_" + (++_msgboxIdCounter);
|
||||
}
|
||||
|
||||
// 根据 MBFLAGS 生成命令列表(返回 { commands, defaultIndex })
|
||||
function _buildCommandsFromFlags(uType) {
|
||||
var commands = [];
|
||||
var baseType = uType & 0xF;
|
||||
var defaultIndex = 0;
|
||||
var hasHelp = (uType & MBFLAGS.MB_HELP) === MBFLAGS.MB_HELP;
|
||||
|
||||
// 辅助添加命令
|
||||
function addCommand(resId, returnValue) {
|
||||
var label = GetLocaleStringFromResId(resId);
|
||||
if (!label) label = "Button";
|
||||
commands.push({ label: label, value: returnValue });
|
||||
}
|
||||
|
||||
// 先处理帮助按钮(原实现中帮助按钮总是在最前面)
|
||||
if (hasHelp) {
|
||||
addCommand(808, MBRET.IDHELP);
|
||||
}
|
||||
|
||||
// 根据基础类型添加按钮
|
||||
switch (baseType) {
|
||||
case MBFLAGS.MB_OK:
|
||||
addCommand(800, MBRET.IDOK);
|
||||
break;
|
||||
case MBFLAGS.MB_OKCANCEL:
|
||||
addCommand(800, MBRET.IDOK);
|
||||
addCommand(801, MBRET.IDCANCEL);
|
||||
break;
|
||||
case MBFLAGS.MB_ABORTRETRYIGNORE:
|
||||
addCommand(802, MBRET.IDABORT);
|
||||
addCommand(803, MBRET.IDRETRY);
|
||||
addCommand(804, MBRET.IDIGNORE);
|
||||
break;
|
||||
case MBFLAGS.MB_YESNOCANCEL:
|
||||
addCommand(805, MBRET.IDYES);
|
||||
addCommand(806, MBRET.IDNO);
|
||||
addCommand(801, MBRET.IDCANCEL);
|
||||
break;
|
||||
case MBFLAGS.MB_YESNO:
|
||||
addCommand(805, MBRET.IDYES);
|
||||
addCommand(806, MBRET.IDNO);
|
||||
break;
|
||||
case MBFLAGS.MB_RETRYCANCEL:
|
||||
addCommand(803, MBRET.IDRETRY);
|
||||
addCommand(801, MBRET.IDCANCEL);
|
||||
break;
|
||||
case MBFLAGS.MB_CANCELTRYCONTINUE:
|
||||
addCommand(801, MBRET.IDCANCEL);
|
||||
addCommand(803, MBRET.IDRETRY);
|
||||
addCommand(810, MBRET.IDCONTINUE);
|
||||
break;
|
||||
default:
|
||||
addCommand(800, MBRET.IDOK);
|
||||
break;
|
||||
}
|
||||
|
||||
// 确定默认按钮索引(考虑帮助按钮占位)
|
||||
var defFlag = uType & 0x300; // MB_DEFBUTTON1~4
|
||||
var defButtonNumber = 0;
|
||||
if (defFlag === MBFLAGS.MB_DEFBUTTON2) defButtonNumber = 1;
|
||||
else if (defFlag === MBFLAGS.MB_DEFBUTTON3) defButtonNumber = 2;
|
||||
else if (defFlag === MBFLAGS.MB_DEFBUTTON4) defButtonNumber = 3;
|
||||
else defButtonNumber = 0;
|
||||
|
||||
// 默认索引需要加上帮助按钮的偏移
|
||||
var finalDefaultIndex = (hasHelp ? 1 : 0) + defButtonNumber;
|
||||
if (finalDefaultIndex >= commands.length) finalDefaultIndex = commands.length - 1;
|
||||
if (finalDefaultIndex < 0) finalDefaultIndex = 0;
|
||||
|
||||
return { commands: commands, defaultIndex: finalDefaultIndex };
|
||||
}
|
||||
|
||||
// 创建 ContentDialog 并应用公共属性
|
||||
function _createContentDialog(title, content, bgColor, commands, defaultIndex, callback) {
|
||||
var container = document.createElement("div");
|
||||
document.body.appendChild(container);
|
||||
|
||||
var dialog = new WinJS.UI.ContentDialog(container, {
|
||||
//title: typeof title === "string" ? title : "",
|
||||
//content: typeof content === "string" ? content : "",
|
||||
autoShow: false
|
||||
});
|
||||
return id;
|
||||
dialog.title = title;
|
||||
dialog.content = content;
|
||||
// 处理标题为 HTMLElement
|
||||
if (title instanceof HTMLElement) {
|
||||
var titleContainer = container.querySelector(".win-contentdialog-title");
|
||||
if (titleContainer) {
|
||||
while (titleContainer.firstChild) titleContainer.removeChild(titleContainer.firstChild);
|
||||
titleContainer.appendChild(title);
|
||||
}
|
||||
}
|
||||
|
||||
// 处理内容为 HTMLElement
|
||||
if (content instanceof HTMLElement) {
|
||||
var contentContainer = container.querySelector(".win-contentdialog-content");
|
||||
if (contentContainer) {
|
||||
while (contentContainer.firstChild) contentContainer.removeChild(contentContainer.firstChild);
|
||||
contentContainer.appendChild(content);
|
||||
}
|
||||
}
|
||||
|
||||
// 背景色
|
||||
if (!IsBlackLabel(bgColor)) {
|
||||
dialog.backgroundColor = bgColor;
|
||||
}
|
||||
|
||||
// 添加命令
|
||||
for (var i = 0; i < commands.length; i++) {
|
||||
var cmd = commands[i];
|
||||
var dialogCmd = new WinJS.UI.ContentDialogCommand(cmd.label, function(evt) {
|
||||
// 阻止多次点击
|
||||
if (dialog._isClosing) return;
|
||||
dialog._isClosing = true;
|
||||
|
||||
// 调用回调传递返回值
|
||||
if (callback) callback(cmd.value);
|
||||
|
||||
// 关闭并移除对话框
|
||||
dialog.hide().then(function() {
|
||||
try { document.body.removeChild(container); } catch (e) {}
|
||||
dialog._isClosing = false;
|
||||
});
|
||||
|
||||
// 返回 false 会阻止关闭,但我们手动关闭,所以返回 undefined 即可
|
||||
}, cmd.value.toString());
|
||||
dialog.commands.push(dialogCmd);
|
||||
}
|
||||
|
||||
// 设置默认按钮
|
||||
if (defaultIndex >= 0 && defaultIndex < dialog.commands.length) {
|
||||
dialog.primaryCommandIndex = defaultIndex;
|
||||
}
|
||||
|
||||
return dialog;
|
||||
}
|
||||
|
||||
// ==================== 核心 API 实现 ====================
|
||||
|
||||
// 新版 MessageBoxForJS(完全基于 ContentDialog)
|
||||
function MessageBoxForJS(_lpText, _lpCaption, _uType, _objColor, _callback) {
|
||||
var dialogId = _generateMsgBoxId();
|
||||
var commandsInfo = _buildCommandsFromFlags(_uType);
|
||||
|
||||
var dialog = _createContentDialog(
|
||||
_lpCaption,
|
||||
_lpText,
|
||||
_objColor,
|
||||
commandsInfo.commands,
|
||||
commandsInfo.defaultIndex,
|
||||
function(returnValue) {
|
||||
if (_callback) _callback(returnValue);
|
||||
}
|
||||
);
|
||||
|
||||
// 存储 dialog 引用以便可能的后续操作(如 GetMessageBoxResult 不需要,但保留)
|
||||
if (!window._activeDialogs) window._activeDialogs = {};
|
||||
window._activeDialogs[dialogId] = dialog;
|
||||
dialog.element.id = dialogId;
|
||||
// 显示对话框
|
||||
dialog.show().then(null, function(err) { console.error("ContentDialog show error:", err); });
|
||||
|
||||
return dialogId;
|
||||
}
|
||||
|
||||
// MessageBox:返回 ID,结果通过 GetMessageBoxResult 获取
|
||||
function MessageBox(_lpText, _lpCaption, _uType, _objColor) {
|
||||
var msgboxId = _generateMsgBoxId();
|
||||
MessageBoxForJS(_lpText, _lpCaption, _uType, _objColor, function(valueReturn) {
|
||||
msgboxResult[msgboxId] = valueReturn;
|
||||
if (window._activeDialogs) delete window._activeDialogs[msgboxId];
|
||||
});
|
||||
return msgboxId;
|
||||
}
|
||||
|
||||
function GetMessageBoxResult(msgboxId) {
|
||||
@@ -71,201 +254,84 @@ function GetMessageBoxResult(msgboxId) {
|
||||
return result;
|
||||
}
|
||||
|
||||
function ClearAllMessageBoxResults() {
|
||||
msgboxResult = null;
|
||||
msgboxResult = {};
|
||||
}
|
||||
|
||||
// 注意:callback 函数无返回值,传入参数:整数型 按下的按钮值。
|
||||
/*
|
||||
使用示例:
|
||||
MessageBoxForJS("请选择一个按钮", "", MBFLAGS.MB_OKCANCEL, "#0078d7", function(value) {
|
||||
console.log("MessageBoxForJS callback value: " + value);
|
||||
})
|
||||
*/
|
||||
function MessageBoxForJS(_lpText, _lpCaption, _uType, _objColor, _callback) {
|
||||
var msgbox = document.createElement("div");
|
||||
msgbox.classList.add("notice-back");
|
||||
msgbox.classList.add("win-ui-dark");
|
||||
var uniqueId = "msgbox_" + new Date().getTime();
|
||||
msgbox.id = uniqueId;
|
||||
var msgbody = document.createElement("div");
|
||||
msgbody.classList.add("notice-body");
|
||||
if (!IsBlackLabel(_objColor)) {
|
||||
msgbody.style.backgroundColor = _objColor;
|
||||
// 异步版本(返回 Promise)
|
||||
function messageBoxAsync(swText, swTitle, uType, swColor, pfCallback) {
|
||||
if (typeof Promise === "undefined") {
|
||||
console.error("Promise is not supported in this environment.");
|
||||
MessageBoxForJS(swText, swTitle, uType, swColor, pfCallback);
|
||||
return null;
|
||||
}
|
||||
msgbox.appendChild(msgbody);
|
||||
var msgcontainter = document.createElement("div");
|
||||
msgcontainter.style.height = "100%";
|
||||
msgcontainter.style.width = "100%";
|
||||
msgcontainter.style.maxHeight = "100%";
|
||||
msgcontainter.style.minHeight = "0px";
|
||||
msgcontainter.style.boxSizing = "border-box";
|
||||
msgbody.appendChild(msgcontainter);
|
||||
var msgcaption = document.createElement("div");
|
||||
msgcontainter.appendChild(msgcaption);
|
||||
msgcontainter.style.display = "flex";
|
||||
msgcontainter.style.flexDirection = "column";
|
||||
var msgcontent = document.createElement("div");
|
||||
msgcontent.style.flex = "1 1 auto";
|
||||
msgcontent.style.marginRight = "3px";
|
||||
msgcontent.style.overflowX = "hidden";
|
||||
msgcontent.style.overflowY = "auto";
|
||||
msgcontent.style.minHeight = "0px";
|
||||
msgcontainter.appendChild(msgcontent);
|
||||
if (_lpCaption instanceof HTMLElement) {
|
||||
msgcaption.appendChild(_lpCaption);
|
||||
msgcaption.classList.add("notice-title");
|
||||
} else {
|
||||
if (!IsBlackLabel(_lpCaption)) {
|
||||
var msgtitle = document.createElement("h2");
|
||||
msgtitle.textContent = _lpCaption;
|
||||
msgtitle.classList.add("notice-title");
|
||||
msgcaption.appendChild(msgtitle);
|
||||
} else {
|
||||
var msgtitle = document.createElement("h2");
|
||||
msgtitle.textContent = "";
|
||||
msgtitle.classList.add("notice-title");
|
||||
msgcaption.appendChild(msgtitle);
|
||||
}
|
||||
}
|
||||
if (_lpText instanceof HTMLElement || _lpText instanceof HTMLDivElement || typeof _lpText !== "string") {
|
||||
return new Promise(function(resolve, reject) {
|
||||
try {
|
||||
_lpText.classList.add("notice-text");
|
||||
msgcontent.appendChild(_lpText);
|
||||
} catch (e) {
|
||||
if (!IsBlackLabel(_lpText)) {
|
||||
var msgtext = document.createElement("p");
|
||||
msgtext.textContent = _lpText;
|
||||
msgtext.classList.add("notice-text");
|
||||
if (IsBlackLabel(_lpCaption)) {
|
||||
msgtext.style.marginTop = "0";
|
||||
}
|
||||
msgcontent.appendChild(msgtext);
|
||||
} else {
|
||||
var msgtext = document.createElement("p");
|
||||
msgtext.innerText = "";
|
||||
msgtext.classList.add("notice-text");
|
||||
if (IsBlackLabel(_lpCaption)) {
|
||||
msgtext.style.marginTop = "0";
|
||||
}
|
||||
msgcontent.appendChild(msgtext);
|
||||
}
|
||||
MessageBoxForJS(swText, swTitle, uType, swColor, function(valueReturn) {
|
||||
if (pfCallback) pfCallback(valueReturn);
|
||||
resolve(valueReturn);
|
||||
});
|
||||
} catch (ex) {
|
||||
reject(ex);
|
||||
}
|
||||
} else {
|
||||
if (!IsBlackLabel(_lpText)) {
|
||||
var msgtext = document.createElement("p");
|
||||
msgtext.textContent = _lpText;
|
||||
msgtext.classList.add("notice-text");
|
||||
if (IsBlackLabel(_lpCaption)) {
|
||||
msgtext.style.marginTop = "0";
|
||||
}
|
||||
msgcontent.appendChild(msgtext);
|
||||
} else {
|
||||
var msgtext = document.createElement("p");
|
||||
msgtext.innerText = "";
|
||||
msgtext.classList.add("notice-text");
|
||||
if (IsBlackLabel(_lpCaption)) {
|
||||
msgtext.style.marginTop = "0";
|
||||
}
|
||||
msgcontent.appendChild(msgtext);
|
||||
}
|
||||
}
|
||||
var msgctrls = document.createElement("div");
|
||||
msgctrls.classList.add("notice-controls");
|
||||
msgcontainter.appendChild(msgctrls);
|
||||
var cnt = 0;
|
||||
var cbFuncPress = function(valueReturn) {
|
||||
getRes = valueReturn;
|
||||
msgbox.style.opacity = 0;
|
||||
setTimeout(function() {
|
||||
document.body.removeChild(msgbox);
|
||||
}, 500);
|
||||
if (_callback) {
|
||||
_callback(valueReturn);
|
||||
}
|
||||
};
|
||||
var pfCreateButton = function(displayNameResId, valueReturn) {
|
||||
var btn = document.createElement("button");
|
||||
btn.innerHTML = GetLocaleStringFromResId(displayNameResId);
|
||||
btn.classList.add("notice-btn");
|
||||
btn.addEventListener("click", function() {
|
||||
cbFuncPress(valueReturn);
|
||||
});
|
||||
msgctrls.appendChild(btn);
|
||||
};
|
||||
if ((_uType & MBFLAGS.MB_HELP) === MBFLAGS.MB_HELP) {
|
||||
pfCreateButton(808, MBRET.IDHELP);
|
||||
}
|
||||
for (cnt = 0; cnt <= MBFLAGS.MB_RETRYCANCEL; cnt++) {
|
||||
if ((_uType & 0xF) === cnt) {
|
||||
switch (cnt) {
|
||||
case MBFLAGS.MB_OK:
|
||||
{
|
||||
pfCreateButton(800, MBRET.IDOK);
|
||||
}
|
||||
break;
|
||||
case MBFLAGS.MB_OKCANCEL:
|
||||
{
|
||||
pfCreateButton(800, MBRET.IDOK);
|
||||
pfCreateButton(801, MBRET.IDCANCEL);
|
||||
}
|
||||
break;
|
||||
case MBFLAGS.MB_ABORTRETRYIGNORE:
|
||||
{
|
||||
pfCreateButton(802, MBRET.IDABORT);
|
||||
pfCreateButton(803, MBRET.IDRETRY);
|
||||
pfCreateButton(804, MBRET.IDIGNORE);
|
||||
}
|
||||
break;
|
||||
case MBFLAGS.MB_YESNOCANCEL:
|
||||
{
|
||||
pfCreateButton(805, MBRET.IDYES);
|
||||
pfCreateButton(806, MBRET.IDNO);
|
||||
pfCreateButton(801, MBRET.IDCANCEL);
|
||||
}
|
||||
break;
|
||||
case MBFLAGS.MB_YESNO:
|
||||
{
|
||||
pfCreateButton(805, MBRET.IDYES);
|
||||
pfCreateButton(806, MBRET.IDNO);
|
||||
}
|
||||
break;
|
||||
case MBFLAGS.MB_RETRYCANCEL:
|
||||
{
|
||||
pfCreateButton(803, MBRET.IDRETRY);
|
||||
pfCreateButton(801, MBRET.IDCANCEL);
|
||||
}
|
||||
break;
|
||||
case MBFLAGS.MB_CANCELTRYCONTINUE:
|
||||
{
|
||||
pfCreateButton(801, MBRET.IDCANCEL);
|
||||
pfCreateButton(803, MBRET.IDRETRY);
|
||||
pfCreateButton(810, MBRET.IDCONTINUE);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
var btns = msgctrls.querySelectorAll("button");
|
||||
var defaultBtnCnt = 0;
|
||||
if ((_uType & MBFLAGS.MB_DEFBUTTON1) === MBFLAGS.MB_DEFBUTTON1) defaultBtnCnt = 0;
|
||||
if ((_uType & MBFLAGS.MB_DEFBUTTON2) === MBFLAGS.MB_DEFBUTTON2) defaultBtnCnt = 1;
|
||||
if ((_uType & MBFLAGS.MB_DEFBUTTON3) === MBFLAGS.MB_DEFBUTTON3) defaultBtnCnt = 2;
|
||||
if ((_uType & MBFLAGS.MB_DEFBUTTON4) === MBFLAGS.MB_DEFBUTTON4) defaultBtnCnt = 3;
|
||||
for (cnt = 0; cnt < btns.length; cnt++) {
|
||||
if (cnt === defaultBtnCnt) {
|
||||
btns[cnt].focus();
|
||||
break;
|
||||
}
|
||||
}
|
||||
document.body.appendChild(msgbox);
|
||||
setTimeout(function() {
|
||||
msgbox.style.opacity = 1;
|
||||
}, 1);
|
||||
return msgbox.id;
|
||||
});
|
||||
}
|
||||
|
||||
// MessageBoxButton 类(保持不变)
|
||||
function MessageBoxButton(swDisplayName, nValueReturn) {
|
||||
this.displayName = swDisplayName;
|
||||
this.value = nValueReturn;
|
||||
}
|
||||
|
||||
// 高级自定义按钮对话框
|
||||
function messageBoxAdvance(swText, swCaption, aCommands, swColor, pfCallback) {
|
||||
var dialogId = _generateMsgBoxId();
|
||||
|
||||
// 转换 aCommands 为内部格式
|
||||
var commands = [];
|
||||
for (var i = 0; i < aCommands.length; i++) {
|
||||
var cmd = aCommands[i];
|
||||
commands.push({
|
||||
label: cmd.displayName,
|
||||
value: cmd.value
|
||||
});
|
||||
}
|
||||
if (commands.length === 0) {
|
||||
commands.push({ label: GetLocaleStringFromResId(800) || "OK", value: MBRET.IDOK });
|
||||
}
|
||||
|
||||
var dialog = _createContentDialog(
|
||||
swCaption,
|
||||
swText,
|
||||
swColor,
|
||||
commands,
|
||||
0, // 默认第一个按钮为默认
|
||||
function(returnValue) {
|
||||
if (pfCallback) pfCallback(returnValue);
|
||||
}
|
||||
);
|
||||
dialog.element.id = dialogId;
|
||||
if (!window._activeDialogs) window._activeDialogs = {};
|
||||
window._activeDialogs[dialogId] = dialog;
|
||||
|
||||
dialog.show();
|
||||
return dialogId;
|
||||
}
|
||||
|
||||
function messageBoxAdvanceAsync(swText, swCaption, aCommands, swColor) {
|
||||
if (typeof Promise === "undefined") {
|
||||
console.error("Promise is not supported in this environment.");
|
||||
messageBoxAdvance(swText, swCaption, aCommands, swColor);
|
||||
return null;
|
||||
}
|
||||
return new Promise(function(resolve, reject) {
|
||||
try {
|
||||
messageBoxAdvance(swText, swCaption, aCommands, swColor, function(valueReturn) {
|
||||
resolve(valueReturn);
|
||||
});
|
||||
} catch (ex) {
|
||||
reject(ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// ==================== MsgBoxObj 类(保持原接口,内部已适配) ====================
|
||||
function MsgBoxObj() {
|
||||
this.elementId = "";
|
||||
this.callback = null;
|
||||
@@ -274,28 +340,31 @@ function MsgBoxObj() {
|
||||
this._text = "";
|
||||
this._title = "";
|
||||
this._color = "#0078d7";
|
||||
|
||||
this.show = function() {
|
||||
var self = this;
|
||||
this.elementId = MessageBoxForJS(
|
||||
this._text,
|
||||
this._title,
|
||||
this.type,
|
||||
this._color,
|
||||
this._boundCallback
|
||||
function(valueReturn) {
|
||||
self._boundCallback(valueReturn);
|
||||
}
|
||||
);
|
||||
setTimeout(function() {
|
||||
var element = document.getElementById(this.elementId);
|
||||
var element = document.getElementById(self.elementId);
|
||||
if (element) {
|
||||
var bodyElement = element.querySelector(".notice-body");
|
||||
if (bodyElement) {
|
||||
bodyElement.style.transition = "all 0.5s linear";
|
||||
}
|
||||
}
|
||||
}.bind(this), 100);
|
||||
}
|
||||
}, 100);
|
||||
};
|
||||
|
||||
Object.defineProperty(this, "text", {
|
||||
get: function() {
|
||||
return this._text;
|
||||
},
|
||||
get: function() { return this._text; },
|
||||
set: function(value) {
|
||||
this._text = value;
|
||||
if (this.elementId) {
|
||||
@@ -314,10 +383,9 @@ function MsgBoxObj() {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Object.defineProperty(this, "title", {
|
||||
get: function() {
|
||||
return this._title;
|
||||
},
|
||||
get: function() { return this._title; },
|
||||
set: function(value) {
|
||||
this._title = value;
|
||||
if (this.elementId) {
|
||||
@@ -331,10 +399,9 @@ function MsgBoxObj() {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Object.defineProperty(this, "color", {
|
||||
get: function() {
|
||||
return this._color;
|
||||
},
|
||||
get: function() { return this._color; },
|
||||
set: function(value) {
|
||||
this._color = value;
|
||||
if (this.elementId) {
|
||||
@@ -348,6 +415,7 @@ function MsgBoxObj() {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
this.getElement = function() {
|
||||
return document.getElementById(this.elementId);
|
||||
};
|
||||
@@ -357,176 +425,4 @@ MsgBoxObj.prototype._internalCallback = function(returnValue) {
|
||||
if (typeof this.callback === "function") {
|
||||
this.callback(returnValue);
|
||||
}
|
||||
};
|
||||
/**
|
||||
* 异步显示消息框,返回一个 Promise 对象。
|
||||
* @param {string | HTMLElement} swText 内容
|
||||
* @param {string} swTitle 标题
|
||||
* @param {MBFLAGS} uType 标志,使用 MBFLAGS 常量
|
||||
* @param {string} swColor 背景颜色文本。
|
||||
* @returns {Promise}
|
||||
*/
|
||||
function messageBoxAsync(swText, swTitle, uType, swColor, pfCallback) {
|
||||
if (typeof Promise === "undefined") {
|
||||
console.error("Promise is not supported in this environment.");
|
||||
MessageBoxForJS(swText, swTitle, uType, swColor, pfCallback);
|
||||
}
|
||||
return new Promise(function(resolve, reject) {
|
||||
try {
|
||||
MessageBoxForJS(swText, swTitle, uType, swColor, function(valueReturn) {
|
||||
if (resolve) resolve(valueReturn);
|
||||
});
|
||||
} catch (ex) {
|
||||
if (reject) reject(ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function MessageBoxButton(swDisplayName, nValueReturn) {
|
||||
this.displayName = swDisplayName;
|
||||
this.value = nValueReturn;
|
||||
}
|
||||
|
||||
function messageBoxAdvance(swText, swCaption, aCommands, swColor, pfCallback) {
|
||||
var _lpText = swText;
|
||||
var _lpCaption = swCaption;
|
||||
var msgbox = document.createElement("div");
|
||||
msgbox.classList.add("notice-back");
|
||||
msgbox.classList.add("win-ui-dark");
|
||||
var uniqueId = "msgbox_" + new Date().getTime();
|
||||
msgbox.id = uniqueId;
|
||||
var msgbody = document.createElement("div");
|
||||
msgbody.classList.add("notice-body");
|
||||
if (!IsBlackLabel(swColor)) {
|
||||
msgbody.style.backgroundColor = swColor;
|
||||
}
|
||||
msgbox.appendChild(msgbody);
|
||||
var msgcontainter = document.createElement("div");
|
||||
msgcontainter.style.height = "100%";
|
||||
msgcontainter.style.width = "100%";
|
||||
msgcontainter.style.maxHeight = "100%";
|
||||
msgcontainter.style.minHeight = "0px";
|
||||
msgcontainter.style.boxSizing = "border-box";
|
||||
msgbody.appendChild(msgcontainter);
|
||||
var msgcaption = document.createElement("div");
|
||||
msgcontainter.appendChild(msgcaption);
|
||||
msgcontainter.style.display = "flex";
|
||||
msgcontainter.style.flexDirection = "column";
|
||||
var msgcontent = document.createElement("div");
|
||||
msgcontent.style.flex = "1 1 auto";
|
||||
msgcontent.style.marginRight = "3px";
|
||||
msgcontent.style.overflowX = "hidden";
|
||||
msgcontent.style.overflowY = "auto";
|
||||
msgcontent.style.minHeight = "0px";
|
||||
msgcontainter.appendChild(msgcontent);
|
||||
if (_lpCaption instanceof HTMLElement) {
|
||||
msgcaption.appendChild(_lpCaption);
|
||||
msgcaption.classList.add("notice-title");
|
||||
} else {
|
||||
if (!IsBlackLabel(_lpCaption)) {
|
||||
var msgtitle = document.createElement("h2");
|
||||
msgtitle.textContent = _lpCaption;
|
||||
msgtitle.classList.add("notice-title");
|
||||
msgcaption.appendChild(msgtitle);
|
||||
} else {
|
||||
var msgtitle = document.createElement("h2");
|
||||
msgtitle.textContent = "";
|
||||
msgtitle.classList.add("notice-title");
|
||||
msgcaption.appendChild(msgtitle);
|
||||
}
|
||||
}
|
||||
if (_lpText instanceof HTMLElement || _lpText instanceof HTMLDivElement || typeof _lpText !== "string") {
|
||||
try {
|
||||
_lpText.classList.add("notice-text");
|
||||
msgcontent.appendChild(_lpText);
|
||||
} catch (e) {
|
||||
if (!IsBlackLabel(_lpText)) {
|
||||
var msgtext = document.createElement("p");
|
||||
msgtext.textContent = _lpText;
|
||||
msgtext.classList.add("notice-text");
|
||||
if (IsBlackLabel(_lpCaption)) {
|
||||
msgtext.style.marginTop = "0";
|
||||
}
|
||||
msgcontent.appendChild(msgtext);
|
||||
} else {
|
||||
var msgtext = document.createElement("p");
|
||||
msgtext.innerText = "";
|
||||
msgtext.classList.add("notice-text");
|
||||
if (IsBlackLabel(_lpCaption)) {
|
||||
msgtext.style.marginTop = "0";
|
||||
}
|
||||
msgcontent.appendChild(msgtext);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!IsBlackLabel(_lpText)) {
|
||||
var msgtext = document.createElement("p");
|
||||
msgtext.textContent = _lpText;
|
||||
msgtext.classList.add("notice-text");
|
||||
if (IsBlackLabel(_lpCaption)) {
|
||||
msgtext.style.marginTop = "0";
|
||||
}
|
||||
msgcontent.appendChild(msgtext);
|
||||
} else {
|
||||
var msgtext = document.createElement("p");
|
||||
msgtext.innerText = "";
|
||||
msgtext.classList.add("notice-text");
|
||||
if (IsBlackLabel(_lpCaption)) {
|
||||
msgtext.style.marginTop = "0";
|
||||
}
|
||||
msgcontent.appendChild(msgtext);
|
||||
}
|
||||
}
|
||||
var msgctrls = document.createElement("div");
|
||||
msgctrls.classList.add("notice-controls");
|
||||
msgcontainter.appendChild(msgctrls);
|
||||
if (aCommands.length <= 0) {
|
||||
aCommands.push(new MessageBoxButton(GetLocaleStringFromResId(800) || "OK", MBRET.IDOK));
|
||||
}
|
||||
for (var i = 0; i < aCommands.length; i++) {
|
||||
var cmd = aCommands[i];
|
||||
var btn = document.createElement("button");
|
||||
btn.textContent = cmd.displayName;
|
||||
btn.setAttribute("data-msgbox-value", cmd.value);
|
||||
Windows.UI.Event.Util.addEvent(btn, "click", function(event) {
|
||||
var btns = this.parentNode.querySelectorAll("button");
|
||||
var lastbtnstatus = [];
|
||||
for (var j = 0; j < btns.length; j++) {
|
||||
lastbtnstatus.push(btns[j].disabled);
|
||||
btns[j].disabled = true;
|
||||
}
|
||||
try {
|
||||
pfCallback(this.getAttribute("data-msgbox-value"));
|
||||
} catch (e) {}
|
||||
msgbox.style.opacity = 0;
|
||||
setTimeout(function(nodes, laststatus) {
|
||||
for (var k = 0; k < nodes.length; k++) {
|
||||
nodes[k].disabled = laststatus[k];
|
||||
}
|
||||
document.body.removeChild(msgbox);
|
||||
}, 500, btns, lastbtnstatus);
|
||||
});
|
||||
msgctrls.appendChild(btn);
|
||||
}
|
||||
document.body.appendChild(msgbox);
|
||||
setTimeout(function() {
|
||||
msgbox.style.opacity = 1;
|
||||
}, 1);
|
||||
return msgbox.id;
|
||||
}
|
||||
|
||||
function messageBoxAdvanceAsync(swText, swCaption, aCommands, swColor) {
|
||||
if (typeof Promise === "undefined") {
|
||||
console.error("Promise is not supported in this environment.");
|
||||
messageBoxAdvance(swText, swCaption, aCommands, swColor);
|
||||
}
|
||||
return new Promise(function(resolve, reject) {
|
||||
try {
|
||||
messageBoxAdvance(swText, swCaption, aCommands, swColor, function(valueReturn) {
|
||||
if (resolve) resolve(valueReturn);
|
||||
});
|
||||
} catch (ex) {
|
||||
if (reject) reject(ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user