跳转到内容
主菜单
主菜单
移至侧栏
隐藏
导航
首页
最近更改
随机页面
MediaWiki帮助
中医百科
搜索
搜索
登录
个人工具
登录
深色模式
查看“MediaWiki:Gadget-PreviewWithVariant.js”的源代码
系统消息
讨论
English
阅读
查看源代码
查看历史
工具
工具
移至侧栏
隐藏
操作
阅读
查看源代码
查看历史
清除缓存
常规
链入页面
相关更改
特殊页面
页面信息
页面值
←
MediaWiki:Gadget-PreviewWithVariant.js
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于该用户组的用户执行:
用户
此页面为本wiki上的软件提供界面文本,并受到保护以防止滥用。 如欲修改所有wiki的翻译,请访问
translatewiki.net
上的MediaWiki本地化项目。
您无权编辑此JavaScript页面,因为编辑此页面可能会影响所有访问者。
您必须确认您的电子邮件地址才能编辑页面。请通过
参数设置
设置并确认您的电子邮件地址。
您可以查看和复制此页面的源代码。
/** * SPDX-License-Identifier: MIT + CC-BY-SA-4.0 * _addText: '{{Gadget Header|license=CC-BY-SA-4.0}}' * _addText: '{{Gadget Header|license=MIT|attribution=Diskdance, Lt2818}}' * * @base {@link https://zh.wikipedia.org/wiki/MediaWiki:Gadget-PreviewWithVariant.js} * @source {@link https://git.qiuwen.net.cn/InterfaceAdmin/QiuwenGadgets/src/branch/master/src/PreviewWithVariant} * @license MIT {@link https://zh.wikipedia.org/wiki/MediaWiki:Gadget-PreviewWithVariant.js} * @license CC-BY-SA-4.0 {@link https://www.qiuwenbaike.cn/wiki/H:CC-BY-SA-4.0} */ /** * Copyright Diskdance, Lt2818 * * 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/PreviewWithVariant/PreviewWithVariant.js //! src/PreviewWithVariant/options.json var configKey = "gadget-PreviewWithVariant__Initialized"; //! src/PreviewWithVariant/modules/constant.ts var VARIANTS = [{ data: "zh", label: window.wgULS("不转换", "不轉換") }, { data: "zh-hans", label: "简体" }, { data: "zh-hant", label: "繁體" }, { data: "zh-cn", label: "中国大陆简体" }, { data: "zh-hk", label: "中國香港繁體" }, { data: "zh-mo", label: "中國澳門繁體" }, { data: "zh-my", label: "马来西亚简体" }, { data: "zh-sg", label: "新加坡简体" }, { data: "zh-tw", label: "中國臺灣繁體" }]; //! src/PreviewWithVariant/modules/processWikiEditor.ts var processWikiEditor = ($editForm) => { if (mw.config.get(configKey)) { return; } const { wgPageContentModel, wgUserVariant } = mw.config.get(); const $templateSandboxPreview = $editForm.find('input[name="wpTemplateSandboxPreview"]'); if (wgPageContentModel !== "wikitext" && !$templateSandboxPreview.length) { return; } const $layout = $editForm.find(".editCheckboxes .oo-ui-horizontalLayout"); if (!$layout.length) { return; } mw.config.set(configKey, true); const uriVariant = mw.util.getParamValue("variant"); const checkbox = new OO.ui.CheckboxInputWidget({ selected: Boolean(uriVariant) }); const dropdown = new OO.ui.DropdownWidget({ $overlay: true, disabled: !checkbox.isSelected(), menu: { items: VARIANTS.map(({ data, label }) => { return new OO.ui.MenuOptionWidget({ data, label }); }) } }); dropdown.getMenu().selectItemByData(wgUserVariant || uriVariant || mw.user.options.get("variant")); checkbox.on("change", (selected) => { dropdown.setDisabled(!selected); }); const getSelectedVariant = () => { if (!checkbox.isSelected()) { return; } const selectedItem = dropdown.getMenu().findSelectedItem(); return selectedItem ? selectedItem.getData() : void 0; }; const manipulateActionUrl = () => { const selectedVariant = getSelectedVariant(); const originalAction = $editForm.attr("action"); if (selectedVariant && originalAction) { $editForm.attr("action", new mw.Uri(originalAction).extend({ variant: selectedVariant }).getRelativePath()); } }; const manipulateVariantConfig = () => { mw.config.set("wgUserVariant", getSelectedVariant() || mw.user.options.get("variant")); }; $editForm.find("input[name=wpPreview]").on("click", mw.user.options.get("uselivepreview") ? manipulateVariantConfig : manipulateActionUrl); $templateSandboxPreview.on("click", manipulateActionUrl); dropdown.getMenu().on("select", manipulateVariantConfig); const checkboxField = new OO.ui.FieldLayout(checkbox, { align: "inline", label: window.wgULS("预览字词转换", "預覽字詞轉換") }); const dropdownField = new OO.ui.FieldLayout(dropdown, { align: "top", label: window.wgULS("使用该语言变体显示预览:", "使用該語言變體顯示預覽:"), invisibleLabel: true }); $layout.append($("<div>").attr("id", "pwv-area").append(checkboxField.$element, dropdownField.$element)); }; //! src/PreviewWithVariant/PreviewWithVariant.ts (function previewWithVariants() { mw.hook("wikipage.editform").add(($editForm) => { processWikiEditor($editForm); }); })(); })();
该页面使用的模板:
Template:Gadget Header
(
查看源代码
)
返回
MediaWiki:Gadget-PreviewWithVariant.js
。
开关有限宽度模式