小 (导入1个版本:[页面文字原许可:CC BY-SA 4.0]) |
Github-bot(留言 | 贡献) (Git更新:([https://github.com/TopRealm/InterfaceCodes/commit/382f0d5f77104964acdf3a9acbfe08e57b1685dc 382f0d5]) chore: change urls) |
||
(未显示同一用户的2个中间版本) | |||
第1行: | 第1行: | ||
"use strict"; |
|||
⚫ | |||
/** |
/** |
||
* 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}}' |
||
* |
* |
||
* @ |
* @base <https://zh.wikipedia.org/wiki/Special:Permalink/59753812> |
||
* @base <https://zh.wikipedia.org/wiki/MediaWiki:Gadget-ding.css> |
|||
* @source <https://git.qiuwen.net.cn/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 ) */ |
|||
* +--------------------------------------------------------+ |
|||
⚫ | |||
* | === WARNING: GLOBAL GADGET FILE === | |
|||
⚫ | |||
* +--------------------------------------------------------+ |
|||
⚫ | |||
* | 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 may 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) { |
|||
⚫ | |||
if (type === undefined) { |
|||
⚫ | |||
type = "info"; |
|||
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; |
|||
⚫ | |||
⚫ | |||
dingDiv.id = 'ding'; |
|||
dingDiv.className = 'noprint'; |
|||
⚫ | |||
} |
} |
||
⚫ | |||
if (ttl === undefined) { |
|||
⚫ | |||
ttl = 3500; |
|||
} |
|||
if (history === undefined) { |
|||
history = true; |
|||
} |
|||
⚫ | |||
persist = false; |
|||
} |
|||
⚫ | |||
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_history"></div>'); |
|||
} |
|||
⚫ | |||
⚫ | |||
if (previousMessage) { |
if (previousMessage) { |
||
var previousMessageStyle = previousMessage.style; |
|||
previousMessageStyle.transform = 'translateY(125%)'; |
|||
setTimeout(function () { |
setTimeout(function () { |
||
previousMessage.remove(); |
previousMessage.remove(); |
||
}, 500); |
}, 500); |
||
} |
} |
||
var dingInnerElement = document.createElement('div'); |
|||
var color_sets = { |
|||
// The following classes are used here: |
|||
warning: { |
|||
// * ding_inner |
|||
text: "rgb(255, 255, 255)", |
|||
// * ding_info |
|||
background: "rgb(221, 51, 51)" |
|||
// * ding_success |
|||
// * ding_warning |
|||
dingInnerElement.className = "ding_inner ding_".concat(type); |
|||
text: "rgb(255, 255, 255)", |
|||
dingInnerElement.innerHTML = message; |
|||
background: "rgb(51, 102, 204)" |
|||
dingElement.insertAdjacentElement('beforeend', dingInnerElement); |
|||
}, |
|||
⚫ | |||
success: { |
|||
var noticeElementStyle = noticeElement.style; |
|||
text: "rgb(255, 255, 255)", |
|||
⚫ | |||
background: "rgb(0, 175, 137)" |
|||
noticeElement === null || noticeElement === void 0 || noticeElement.addEventListener('click', function () { |
|||
}, |
|||
noticeElementStyle.transform = 'translateY(125%)'; |
|||
confusion: { |
|||
setTimeout(function () { |
|||
noticeElement.remove(); |
|||
background: "rgb(234, 236, 240)" |
|||
}, |
}, 500); |
||
}); |
|||
⚫ | |||
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>")); |
|||
⚫ | |||
setTimeout(function () { |
setTimeout(function () { |
||
noticeElementStyle.transform = 'translateY(0%)'; |
|||
}, 10); |
}, 10); |
||
if (ttl !== |
if (ttl !== 'long') { |
||
setTimeout(function () { |
setTimeout(function () { |
||
noticeElementStyle.transform = 'translateY(125%)'; |
|||
}, ttl + 10); |
}, ttl + 10); |
||
setTimeout(function () { |
setTimeout(function () { |
||
noticeElement === null || noticeElement === void 0 || noticeElement.remove(); |
|||
}, ttl + 510); |
}, ttl + 510); |
||
} |
} |
||
}; |
}; |
||
return |
return dingMain; |
||
}(); |
}(); |
||
/* </nowiki> */ |
/* </nowiki> */ |
2023年10月15日 (日) 18:46的最新版本
/**
* 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>
* @base <https://zh.wikipedia.org/wiki/MediaWiki:Gadget-ding.css>
* @source <https://git.qiuwen.net.cn/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 may affect many users. |
* | Please discuss changes at talk page before editing. |
* +--------------------------------------------------------+
*/
/* <nowiki> */
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')) {
var dingDiv = document.createElement('div');
dingDiv.id = 'ding';
dingDiv.className = 'noprint';
document.body.insertAdjacentElement('afterbegin', dingDiv);
}
var dingElement = document.querySelector('#ding');
var previousMessage = dingElement.lastChild;
if (previousMessage) {
var previousMessageStyle = previousMessage.style;
previousMessageStyle.transform = 'translateY(125%)';
setTimeout(function () {
previousMessage.remove();
}, 500);
}
var dingInnerElement = document.createElement('div');
// The following classes are used here:
// * ding_inner
// * ding_info
// * ding_success
// * ding_warning
dingInnerElement.className = "ding_inner ding_".concat(type);
dingInnerElement.innerHTML = message;
dingElement.insertAdjacentElement('beforeend', dingInnerElement);
var noticeElement = dingElement.lastChild;
var noticeElementStyle = noticeElement.style;
if (persist) {
noticeElement === null || noticeElement === void 0 || noticeElement.addEventListener('click', function () {
noticeElementStyle.transform = 'translateY(125%)';
setTimeout(function () {
noticeElement.remove();
}, 500);
});
}
setTimeout(function () {
noticeElementStyle.transform = 'translateY(0%)';
}, 10);
if (ttl !== 'long') {
setTimeout(function () {
noticeElementStyle.transform = 'translateY(125%)';
}, ttl + 10);
setTimeout(function () {
noticeElement === null || noticeElement === void 0 || noticeElement.remove();
}, ttl + 510);
}
};
return dingMain;
}();
/* </nowiki> */