MediaWiki:Gadget-Ding.js:修订间差异

MediaWiki系统消息页面
(导入1个版本:​[页面文字原许可:CC BY-SA 4.0])
(Git更新:代码仓库同步更新)
第1行: 第1行:
"use strict";

/* <nowiki> */
/**
/**
* SPDX-License-Identifier: CC-BY-SA-4.0
* SPDX-License-Identifier: CC-BY-SA-4.0
* _addText: '{{Gadget Header|license=CC-BY-SA-4.0}}'
* _addText: '{{Gadget Header|license=CC-BY-SA-4.0}}'
*
*
* @source <zh.wikipedia.org/wiki/Special:Permalink/59753812>
* @base <https://zh.wikipedia.org/wiki/Special:Permalink/59753812>
* @source <https://git.qiuwen.wiki/InterfaceAdmin/Gadgets/src/branch/master/src/Gadgets/Ding>
*/
*/
/**
/* ding ("message here should be safe html, beacuse you can write <button>Buttons</button>", "info" | "warning" | "success" | "default", "long" | 10000 <-- expiry time in ms ) */
* +--------------------------------------------------------+
window.DingExposedInterface = function () {
* | === WARNING: GLOBAL GADGET FILE === |
/**
* +--------------------------------------------------------+
*
* @param {string} message message here should be safe html, beacuse you can write <button>Buttons</button> in this
* | All changes should be made in the repository, |
* | otherwise they will be lost. |
* @param {string} type "info": dark blue/black, "warning": red/white, "success": green/white, "default": light blue/black (background/text)
* +--------------------------------------------------------+
* @param {number|"long"} ttl number of microseconds before ding element disappears, "long" if the ding should not disappear after a timeout
* | Changes to this page affect many users. |
* @param {boolean} history does nothing currently
* | Please discuss changes at Talk page before editing. |
* @param {boolean} persist If the element should go away when user clicks anywhere on it. If persist= true && ttl= long, make sure to include a button to allow the user to remove the banner
* +--------------------------------------------------------+
*/
*/
var ding = function ding(message, type, ttl, history, persist) {
/* <nowiki> */
if (type === undefined) {
'use strict';
type = "info";

window.DingExposedInterface = function ding() {
var dingMain = function dingMain(message) {
var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'info';
var ttl = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 3600;
var persist = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
if (!document.querySelector('#ding')) {
document.body.insertAdjacentHTML('afterbegin', '<div id="ding"></div>');
}
}
var dingElement = document.querySelector('#ding');
if (ttl === undefined) {
var previousMessage = dingElement.lastChild;
ttl = 3500;
}
if (history === undefined) {
history = true;
}
if (persist === undefined) {
persist = false;
}
if (!document.querySelector("#ding")) {
document.body.insertAdjacentHTML("afterbegin", "<style>#ding button{box-sizing:border-box;margin:0 .2em;padding:0 .7em;border:.2em solid #fff;border-radius:9em;background:0 0;color:inherit;font-weight:inherit}#ding button:active{background:hsla(0deg 0% 100%/60%)}</style>");
document.body.insertAdjacentHTML("afterbegin", '<div id="ding"></div>');
}
if (!document.querySelector("#ding_history")) {
document.body.insertAdjacentHTML("afterbegin", '<div id="ding_history"></div>');
}
var dingEle = document.querySelector("#ding");
var previousMessage = dingEle.lastChild;
if (previousMessage) {
if (previousMessage) {
var previousMessageStyle = previousMessage.style;
previousMessage.style.transform = "translateY(-130%)";
previousMessageStyle.transform = 'translateY(-130%)';
setTimeout(function () {
setTimeout(function () {
previousMessage.remove();
previousMessage.remove();
}, 500);
}, 500);
}
}
dingElement.insertAdjacentHTML('beforeend', "<div class=\"ding_inner ding_".concat(type, "\">").concat(message, "</div>"));
var color_sets = {
var noticeElement = dingElement.lastChild;
warning: {
var noticeElementStyle = noticeElement.style;
text: "rgb(255, 255, 255)",
if (persist) {
background: "rgb(221, 51, 51)"
noticeElement === null || noticeElement === void 0 ? void 0 : noticeElement.addEventListener('click', function () {
},
noticeElementStyle.transform = 'translateY(-130%)';
info: {
text: "rgb(255, 255, 255)",
setTimeout(function () {
noticeElement.remove();
background: "rgb(51, 102, 204)"
},
}, 500);
success: {
});
}
text: "rgb(255, 255, 255)",
background: "rgb(0, 175, 137)"
},
confusion: {
text: "rgb(0, 0, 0)",
background: "rgb(234, 236, 240)"
},
"default": {
text: "rgb(0, 0, 0)",
background: "rgb(234, 236, 240)"
}
};
var retractant = persist ? "" : "onclick='this.style.transform=\"translateY(-130%)\";setTimeout(function(){this.remove()}.bind(this),500);' ";
dingEle.insertAdjacentHTML("beforeend", "<div ".concat(retractant, "style=\"position:fixed;right:0;bottom:0;left:0;z-index:9999;margin:0 0 auto;padding:.6em 2em;height:auto;box-shadow:0 2px 5px rgb(0,0,0,.2);text-align:center;font-weight:700;font-size:86%;line-height:1.4em;opacity:1;transition:all .2s;transform:translateY(-130%);background:").concat(color_sets[type].background, ";color:").concat(color_sets[type].text, ";\">").concat(message, "</div>"));
var noticeEle = dingEle.lastChild;
setTimeout(function () {
setTimeout(function () {
noticeEle.style.transform = "translateY(0%)";
noticeElementStyle.transform = 'translateY(0%)';
}, 10);
}, 10);
if (ttl !== "long") {
if (ttl !== 'long') {
setTimeout(function () {
setTimeout(function () {
noticeEle.style.transform = "translateY(-130%)";
noticeElementStyle.transform = 'translateY(-130%)';
}, ttl + 10);
}, ttl + 10);
setTimeout(function () {
setTimeout(function () {
noticeElement === null || noticeElement === void 0 ? void 0 : noticeElement.remove();
noticeEle.remove();
}, ttl + 510);
}, ttl + 510);
}
}
};
};
return ding;
return dingMain;
}();
}();

/* </nowiki> */
/* </nowiki> */

2023年5月24日 (三) 23:39的版本

/**
 * SPDX-License-Identifier: CC-BY-SA-4.0
 * _addText: '{{Gadget Header|license=CC-BY-SA-4.0}}'
 *
 * @base <https://zh.wikipedia.org/wiki/Special:Permalink/59753812>
 * @source <https://git.qiuwen.wiki/InterfaceAdmin/Gadgets/src/branch/master/src/Gadgets/Ding>
 */
/**
 * +--------------------------------------------------------+
 * |         === WARNING: GLOBAL GADGET FILE ===            |
 * +--------------------------------------------------------+
 * |      All changes should be made in the repository,     |
 * |              otherwise they will be lost.              |
 * +--------------------------------------------------------+
 * |        Changes to this page affect many users.         |
 * |  Please discuss changes at Talk page before editing.   |
 * +--------------------------------------------------------+
 */
/* <nowiki> */
'use strict';

window.DingExposedInterface = function ding() {
  var dingMain = function dingMain(message) {
    var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'info';
    var ttl = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 3600;
    var persist = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
    if (!document.querySelector('#ding')) {
      document.body.insertAdjacentHTML('afterbegin', '<div id="ding"></div>');
    }
    var dingElement = document.querySelector('#ding');
    var previousMessage = dingElement.lastChild;
    if (previousMessage) {
      var previousMessageStyle = previousMessage.style;
      previousMessageStyle.transform = 'translateY(-130%)';
      setTimeout(function () {
        previousMessage.remove();
      }, 500);
    }
    dingElement.insertAdjacentHTML('beforeend', "<div class=\"ding_inner ding_".concat(type, "\">").concat(message, "</div>"));
    var noticeElement = dingElement.lastChild;
    var noticeElementStyle = noticeElement.style;
    if (persist) {
      noticeElement === null || noticeElement === void 0 ? void 0 : noticeElement.addEventListener('click', function () {
        noticeElementStyle.transform = 'translateY(-130%)';
        setTimeout(function () {
          noticeElement.remove();
        }, 500);
      });
    }
    setTimeout(function () {
      noticeElementStyle.transform = 'translateY(0%)';
    }, 10);
    if (ttl !== 'long') {
      setTimeout(function () {
        noticeElementStyle.transform = 'translateY(-130%)';
      }, ttl + 10);
      setTimeout(function () {
        noticeElement === null || noticeElement === void 0 ? void 0 : noticeElement.remove();
      }, ttl + 510);
    }
  };
  return dingMain;
}();
/* </nowiki> */