User:Emojiwiki/module/PopupBox.js
< User:Emojiwiki | module
注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google Chrome、Firefox、Microsoft Edge及Safari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
/* Original License
Copyright by Code Boxx
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
(function() {
var pop = {
// (A) ATTACH POPUP HTML
pWrap : null, // HTML POPUP WRAPPER
pTitle : null, // HTML POPUP TITLE
ptxt : null, // HTML POPUP TEXT
init : function () {
// (A1) POPUP WRAPPER
pop.pWrap = document.createElement("div");
pop.pWrap.id = "popwrap";
document.body.appendChild(pop.pWrap);
// (A2) POPUP BOX
let pBox = document.createElement("div");
pBox.id = "popbox";
pop.pWrap.appendChild(pBox);
// (A3) TITLE
pop.pTitle = document.createElement("h1");
pop.pTitle.id = "poptitle";
pBox.appendChild(pop.pTitle);
// (A4) TEXT
pop.pText = document.createElement("p");
pop.pText.id = "poptext";
pBox.appendChild(pop.pText);
// (A5) CLOSE BUTTON
let pClose = document.createElement("div");
pClose.id = "popclose";
pClose.innerHTML = "☒";
pClose.onclick = pop.close;
pBox.appendChild(pClose);
},
// (B) OPEN POPUP
open : function (title, text) {
pop.pTitle.innerHTML = title;
pop.pText.innerHTML = text;
pop.pWrap.classList.add("open");
},
// (C) CLOSE POPUP
close : function () {
pop.pWrap.classList.remove("open");
}
};
window.addEventListener("DOMContentLoaded", pop.init);
return pop;
});