跳转到内容
主菜单
主菜单
移至侧栏
隐藏
导航
首页
最近更改
随机页面
MediaWiki帮助
中医百科
搜索
搜索
登录
个人工具
登录
深色模式
查看“MediaWiki:Gadget-Toastify.js”的源代码
系统消息
讨论
English
阅读
查看源代码
查看历史
工具
工具
移至侧栏
隐藏
操作
阅读
查看源代码
查看历史
清除缓存
常规
链入页面
相关更改
特殊页面
页面信息
页面值
←
MediaWiki:Gadget-Toastify.js
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于该用户组的用户执行:
用户
此页面为本wiki上的软件提供界面文本,并受到保护以防止滥用。 如欲修改所有wiki的翻译,请访问
translatewiki.net
上的MediaWiki本地化项目。
您无权编辑此JavaScript页面,因为编辑此页面可能会影响所有访问者。
您必须确认您的电子邮件地址才能编辑页面。请通过
参数设置
设置并确认您的电子邮件地址。
您可以查看和复制此页面的源代码。
/** * SPDX-License-Identifier: MIT * _addText: '{{Gadget Header|license=MIT|attribution=2018 apvarun}}' * * @base {@link https://github.com/apvarun/toastify-js} * @source {@link https://git.qiuwen.net.cn/InterfaceAdmin/QiuwenGadgets/src/branch/master/src/Toastify} * @license MIT {@link https://github.com/apvarun/toastify-js/blob/master/LICENSE} */ /** * Copyright (c) 2018 apvarun * * 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. */ /** * +------------------------------------------------------------+ * | === WARNING: GLOBAL GADGET FILE === | * +------------------------------------------------------------+ * | All changes should be made in the repository, | * | otherwise they will be lost. | * +------------------------------------------------------------+ * | Changes to this page may affect many users. | * | Please discuss changes by opening an issue before editing. | * +------------------------------------------------------------+ */ /* <nowiki> */ (() => { "use strict"; // dist/Toastify/Toastify.js function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var n = 0, F = function() { }; return { s: F, n: function() { return n >= r.length ? { done: true } : { done: false, value: r[n++] }; }, e: function(r2) { throw r2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = true, u = false; return { s: function() { t = t.call(r); }, n: function() { var r2 = t.next(); return a = r2.done, r2; }, e: function(r2) { u = true, o = r2; }, f: function() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; } function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } } function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; } var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __commonJS = (cb, mod) => function __require() { return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; }; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { var _iterator = _createForOfIteratorHelper(__getOwnPropNames(from)), _step; try { for (_iterator.s(); !(_step = _iterator.n()).done; ) { let key = _step.value; if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } } catch (err) { _iterator.e(err); } finally { _iterator.f(); } } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var require_toastify = __commonJS({ "node_modules/.pnpm/toastify-js@1.12.0/node_modules/toastify-js/src/toastify.js"(exports2, module2) { /*! * Toastify js 1.12.0 * https://github.com/apvarun/toastify-js * @license MIT licensed * * Copyright (C) 2018 Varun A P */ (function(root, factory) { if (typeof module2 === "object" && module2.exports) { module2.exports = factory(); } else { root.Toastify = factory(); } })(exports2, function(global) { var Toastify2 = function(options) { return new Toastify2.lib.init(options); }, version = "1.12.0"; Toastify2.defaults = { oldestFirst: true, text: "Toastify is awesome!", node: void 0, duration: 3e3, selector: void 0, callback: function() { }, destination: void 0, newWindow: false, close: false, gravity: "toastify-top", positionLeft: false, position: "", backgroundColor: "", avatar: "", className: "", stopOnFocus: true, onClick: function() { }, offset: { x: 0, y: 0 }, escapeMarkup: true, ariaLive: "polite", style: { background: "" } }; Toastify2.lib = Toastify2.prototype = { toastify: version, constructor: Toastify2, // Initializing the object with required parameters init: function(options) { if (!options) { options = {}; } this.options = {}; this.toastElement = null; this.options.text = options.text || Toastify2.defaults.text; this.options.node = options.node || Toastify2.defaults.node; this.options.duration = options.duration === 0 ? 0 : options.duration || Toastify2.defaults.duration; this.options.selector = options.selector || Toastify2.defaults.selector; this.options.callback = options.callback || Toastify2.defaults.callback; this.options.destination = options.destination || Toastify2.defaults.destination; this.options.newWindow = options.newWindow || Toastify2.defaults.newWindow; this.options.close = options.close || Toastify2.defaults.close; this.options.gravity = options.gravity === "bottom" ? "toastify-bottom" : Toastify2.defaults.gravity; this.options.positionLeft = options.positionLeft || Toastify2.defaults.positionLeft; this.options.position = options.position || Toastify2.defaults.position; this.options.backgroundColor = options.backgroundColor || Toastify2.defaults.backgroundColor; this.options.avatar = options.avatar || Toastify2.defaults.avatar; this.options.className = options.className || Toastify2.defaults.className; this.options.stopOnFocus = options.stopOnFocus === void 0 ? Toastify2.defaults.stopOnFocus : options.stopOnFocus; this.options.onClick = options.onClick || Toastify2.defaults.onClick; this.options.offset = options.offset || Toastify2.defaults.offset; this.options.escapeMarkup = options.escapeMarkup !== void 0 ? options.escapeMarkup : Toastify2.defaults.escapeMarkup; this.options.ariaLive = options.ariaLive || Toastify2.defaults.ariaLive; this.options.style = options.style || Toastify2.defaults.style; if (options.backgroundColor) { this.options.style.background = options.backgroundColor; } return this; }, // Building the DOM element buildToast: function() { if (!this.options) { throw "Toastify is not initialized"; } var divElement = document.createElement("div"); divElement.className = "toastify on " + this.options.className; if (!!this.options.position) { divElement.className += " toastify-" + this.options.position; } else { if (this.options.positionLeft === true) { divElement.className += " toastify-left"; console.warn("Property `positionLeft` will be depreciated in further versions. Please use `position` instead."); } else { divElement.className += " toastify-right"; } } divElement.className += " " + this.options.gravity; if (this.options.backgroundColor) { console.warn('DEPRECATION NOTICE: "backgroundColor" is being deprecated. Please use the "style.background" property.'); } for (var property in this.options.style) { divElement.style[property] = this.options.style[property]; } if (this.options.ariaLive) { divElement.setAttribute("aria-live", this.options.ariaLive); } if (this.options.node && this.options.node.nodeType === Node.ELEMENT_NODE) { divElement.appendChild(this.options.node); } else { if (this.options.escapeMarkup) { divElement.innerText = this.options.text; } else { divElement.innerHTML = this.options.text; } if (this.options.avatar !== "") { var avatarElement = document.createElement("img"); avatarElement.src = this.options.avatar; avatarElement.className = "toastify-avatar"; if (this.options.position == "left" || this.options.positionLeft === true) { divElement.appendChild(avatarElement); } else { divElement.insertAdjacentElement("afterbegin", avatarElement); } } } if (this.options.close === true) { var closeElement = document.createElement("button"); closeElement.type = "button"; closeElement.setAttribute("aria-label", "Close"); closeElement.className = "toast-close"; closeElement.innerHTML = "✖"; closeElement.addEventListener("click", function(event) { event.stopPropagation(); this.removeElement(this.toastElement); window.clearTimeout(this.toastElement.timeOutValue); }.bind(this)); var width = window.innerWidth > 0 ? window.innerWidth : screen.width; if ((this.options.position == "left" || this.options.positionLeft === true) && width > 360) { divElement.insertAdjacentElement("afterbegin", closeElement); } else { divElement.appendChild(closeElement); } } if (this.options.stopOnFocus && this.options.duration > 0) { var self = this; divElement.addEventListener("mouseover", function(event) { window.clearTimeout(divElement.timeOutValue); }); divElement.addEventListener("mouseleave", function() { divElement.timeOutValue = window.setTimeout(function() { self.removeElement(divElement); }, self.options.duration); }); } if (typeof this.options.destination !== "undefined") { divElement.addEventListener("click", function(event) { event.stopPropagation(); if (this.options.newWindow === true) { window.open(this.options.destination, "_blank"); } else { window.location = this.options.destination; } }.bind(this)); } if (typeof this.options.onClick === "function" && typeof this.options.destination === "undefined") { divElement.addEventListener("click", function(event) { event.stopPropagation(); this.options.onClick(); }.bind(this)); } if (typeof this.options.offset === "object") { var x = getAxisOffsetAValue("x", this.options); var y = getAxisOffsetAValue("y", this.options); var xOffset = this.options.position == "left" ? x : "-" + x; var yOffset = this.options.gravity == "toastify-top" ? y : "-" + y; divElement.style.transform = "translate(" + xOffset + "," + yOffset + ")"; } return divElement; }, // Displaying the toast showToast: function() { this.toastElement = this.buildToast(); var rootElement; if (typeof this.options.selector === "string") { rootElement = document.getElementById(this.options.selector); } else if (this.options.selector instanceof HTMLElement || typeof ShadowRoot !== "undefined" && this.options.selector instanceof ShadowRoot) { rootElement = this.options.selector; } else { rootElement = document.body; } if (!rootElement) { throw "Root element is not defined"; } var elementToInsert = Toastify2.defaults.oldestFirst ? rootElement.firstChild : rootElement.lastChild; rootElement.insertBefore(this.toastElement, elementToInsert); Toastify2.reposition(); if (this.options.duration > 0) { this.toastElement.timeOutValue = window.setTimeout(function() { this.removeElement(this.toastElement); }.bind(this), this.options.duration); } return this; }, hideToast: function() { if (this.toastElement.timeOutValue) { clearTimeout(this.toastElement.timeOutValue); } this.removeElement(this.toastElement); }, // Removing the element from the DOM removeElement: function(toastElement) { toastElement.className = toastElement.className.replace(" on", ""); window.setTimeout(function() { if (this.options.node && this.options.node.parentNode) { this.options.node.parentNode.removeChild(this.options.node); } if (toastElement.parentNode) { toastElement.parentNode.removeChild(toastElement); } this.options.callback.call(toastElement); Toastify2.reposition(); }.bind(this), 400); } }; Toastify2.reposition = function() { var topLeftOffsetSize = { top: 15, bottom: 15 }; var topRightOffsetSize = { top: 15, bottom: 15 }; var offsetSize = { top: 15, bottom: 15 }; var allToasts = document.getElementsByClassName("toastify"); var classUsed; for (var i = 0; i < allToasts.length; i++) { if (containsClass(allToasts[i], "toastify-top") === true) { classUsed = "toastify-top"; } else { classUsed = "toastify-bottom"; } var height = allToasts[i].offsetHeight; classUsed = classUsed.substr(9, classUsed.length - 1); var offset = 15; var width = window.innerWidth > 0 ? window.innerWidth : screen.width; if (width <= 360) { allToasts[i].style[classUsed] = offsetSize[classUsed] + "px"; offsetSize[classUsed] += height + offset; } else { if (containsClass(allToasts[i], "toastify-left") === true) { allToasts[i].style[classUsed] = topLeftOffsetSize[classUsed] + "px"; topLeftOffsetSize[classUsed] += height + offset; } else { allToasts[i].style[classUsed] = topRightOffsetSize[classUsed] + "px"; topRightOffsetSize[classUsed] += height + offset; } } } return this; }; function getAxisOffsetAValue(axis, options) { if (options.offset[axis]) { if (isNaN(options.offset[axis])) { return options.offset[axis]; } else { return options.offset[axis] + "px"; } } return "0px"; } function containsClass(elem, yourClass) { if (!elem || typeof yourClass !== "string") { return false; } else if (elem.className && elem.className.trim().split(/\s+/gi).indexOf(yourClass) > -1) { return true; } else { return false; } } Toastify2.lib.init.prototype = Toastify2.lib; return Toastify2; }); } }); //! src/Toastify/Toastify.ts var Toastify_exports = {}; __export(Toastify_exports, { toastify: () => toastify }); module.exports = __toCommonJS(Toastify_exports); var import_toastify_js = __toESM(require_toastify()); var toastify = (options, type) => { var _options, _options2, _options3; (_options = options) !== null && _options !== void 0 ? _options : options = {}; let className = "gadget-toastify"; if (type) { switch (type) { case "error": className += " ".concat(className, "--error"); break; case "success": className += " ".concat(className, "--success"); break; case "warning": className += " ".concat(className, "--warning"); break; default: className += " ".concat(className, "--info"); } } options.className = className; (_options2 = options).gravity || (_options2.gravity = "bottom"); (_options3 = options).position || (_options3.position = "center"); const instance = (0, import_toastify_js.default)(options); instance.showToast(); return { hideToast: instance.hideToast.bind(instance) }; }; })();
该页面使用的模板:
Template:Gadget Header
(
查看源代码
)
返回
MediaWiki:Gadget-Toastify.js
。
开关有限宽度模式