跳转到内容
主菜单
主菜单
移至侧栏
隐藏
导航
首页
分类索引
最近更改
随便看看
灵兰秘典
捐助本站
帮助
帮助
联系我们
关于本站
MediaWiki帮助
USER-SIDEBAR
GROUP-SIDEBAR
CATEGORY-SIDEBAR
中医百科
搜索
搜索
外观
登录
个人工具
登录
查看“︁MediaWiki:Gadget-PrintOptions.js”︁的源代码
系统消息
讨论
English
阅读
查看源代码
查看历史
工具
工具
移至侧栏
隐藏
操作
阅读
查看源代码
查看历史
常规
链入页面
相关更改
特殊页面
页面信息
外观
移至侧栏
隐藏
←
MediaWiki:Gadget-PrintOptions.js
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于该用户组的用户执行:
用户
此页面为本wiki上的软件提供界面文本,并受到保护以防止滥用。 如欲修改所有wiki的翻译,请访问
translatewiki.net
上的MediaWiki本地化项目。
您无权编辑此JavaScript页面,因为编辑此页面可能会影响所有访问者。
您可以查看和复制此页面的源代码。
(function () { 'use strict'; var windowManager; var printDialog; // Modernized configuration object var printOptions = { install: function () { var $printLink = $('#t-print a'); if ($printLink.length === 0) { return; } $printLink .text('可打印版本') .off('click') .on('click', function (e) { mw.loader.using([ 'oojs-ui-core', 'oojs-ui-widgets', 'oojs-ui-windows', 'mediawiki.api' ]).then(printOptions.createWindow); e.preventDefault(); e.stopPropagation(); }); // Preload resources mw.loader.load(['oojs-ui-core', 'oojs-ui-widgets', 'oojs-ui-windows']); }, createWindow: function () { // Modern OOUI dialog implementation var PrintDialog = function (config) { PrintDialog.super.call(this, config); }; OO.inheritClass(PrintDialog, OO.ui.ProcessDialog); PrintDialog.static.name = 'printdialog'; PrintDialog.static.title = mw.message('printdialog-title').plain(); PrintDialog.static.actions = [ { action: 'print', label: mw.message('printdialog-action-print').plain(), flags: ['primary', 'progressive'] }, { action: 'cancel', label: mw.message('cancel').plain(), flags: 'safe' } ]; PrintDialog.prototype.initialize = function () { PrintDialog.super.prototype.initialize.apply(this, arguments); this.contentPanel = new OO.ui.PanelLayout({ padded: true, expanded: false }); this.fieldset = new OO.ui.FieldsetLayout({ label: mw.message('printdialog-options').plain() }); // Dynamically create checkboxes from configuration printOptions.questions.forEach(function (question) { if (question.type === 'checkbox') { var checkbox = new OO.ui.CheckboxInputWidget({ selected: question.checked }); question.widget = checkbox; this.fieldset.addItems([ new OO.ui.FieldLayout(checkbox, { label: mw.message(question.msgKey || question.label).plain(), align: 'inline' }) ]); } }.bind(this)); this.contentPanel.$element.append(this.fieldset.$element); this.$body.append(this.contentPanel.$element); }; PrintDialog.prototype.getActionProcess = function (action) { var dialog = this; if (action === 'print') { return new OO.ui.Process(function () { // Gather all selected options printOptions.questions.forEach(function (question) { if (question.type === 'checkbox' && question.widget) { printOptions[question.returnvalue] = question.widget.isSelected(); } }); return dialog.close({ action: action }).then(function () { printOptions.prepareForPrinting(); window.print(); setTimeout(function () { window.location.reload(); }, 500); }); }); } return PrintDialog.super.prototype.getActionProcess.call(this, action); }; // Initialize window manager if needed if (!windowManager) { windowManager = new OO.ui.WindowManager(); windowManager.$element.css('z-index', '2000'); $(document.body).append(windowManager.$element); } // Create dialog if needed if (!printDialog) { printDialog = new PrintDialog({ size: 'medium', classes: ['print-dialog'] }); windowManager.addWindows([printDialog]); } windowManager.openWindow(printDialog); }, prepareForPrinting: function () { this.updatePrintStyles(); this.applyCustomPrintStyles(); this.enhancePrintFooter(); }, updatePrintStyles: function () { if (this.enhanced === false) return; Array.from(document.styleSheets).forEach(function (stylesheet) { try { if (!stylesheet.media) return; // Handle media rules for stylesheets var mediaText = stylesheet.media.mediaText || ''; if (mediaText.includes('print')) { if (!mediaText.includes('screen')) { stylesheet.disabled = true; } } else if (mediaText.includes('screen')) { try { stylesheet.media.appendMedium('print'); } catch (e) { stylesheet.media.mediaText += ',print'; } } // Handle media rules within stylesheets var rules = stylesheet.cssRules || stylesheet.rules; if (!rules) return; for (var i = 0; i < rules.length; i++) { var rule = rules[i]; if (rule.type !== CSSRule.MEDIA_RULE || !rule.media) continue; var media = Array.from(rule.media); if (media.includes('print') && !media.includes('screen')) { stylesheet.deleteRule ? stylesheet.deleteRule(i) : stylesheet.removeRule(i); i--; } else if (media.includes('screen') && !media.includes('print')) { try { rule.media.appendMedium('print'); } catch (e) { rule.media.mediaText += ',print'; } } } } catch (e) { mw.log.warn('Could not process stylesheet:', e.message); } }); }, applyCustomPrintStyles: function () { var styles = []; if (this.noimages) { styles.push('img, .thumb, figure { display: none !important; }'); } if (this.norefs) { styles.push('.references, .reference, .mw-references-wrap { display: none !important; }'); } if (this.notoc) { styles.push('#toc, .toc { display: none !important; }'); } if (this.nobackground) { styles.push('* { background: none !important; }'); styles.push('body { background-color: white !important; }'); } if (this.blacktext) { styles.push('* { color: black !important; }'); styles.push('a { color: #0645ad !important; }'); } if (styles.length) { var styleEl = document.createElement('style'); styleEl.setAttribute('media', 'print'); styleEl.textContent = styles.join('\n'); document.head.appendChild(styleEl); } }, enhancePrintFooter: function () { var printFooter = document.querySelector('.printfooter'); if (printFooter) { var link = printFooter.querySelector('a'); if (link) { try { link.textContent = decodeURIComponent(link.textContent); } catch (e) { mw.log.warn('Could not decode print footer URL:', e.message); } } } }, // Updated configuration with i18n message keys questions: [ { msgKey: 'printdialog-option-enhance', type: 'checkbox', checked: true, returnvalue: 'enhanced' }, { msgKey: 'printdialog-option-noimages', type: 'checkbox', checked: false, returnvalue: 'noimages' }, { msgKey: 'printdialog-option-norefs', type: 'checkbox', checked: false, returnvalue: 'norefs' }, { msgKey: 'printdialog-option-notoc', type: 'checkbox', checked: false, returnvalue: 'notoc' }, { msgKey: 'printdialog-option-nobackground', type: 'checkbox', checked: false, returnvalue: 'nobackground' }, { msgKey: 'printdialog-option-blacktext', type: 'checkbox', checked: true, returnvalue: 'blacktext' } ] }; // Localization messages mw.messages.set({ 'printdialog-title': '打印此页面', 'printdialog-options': '打印选项', 'printdialog-action-print': '打印', 'printdialog-option-enhance': '隐藏界面元素', 'printdialog-option-noimages': '隐藏图像', 'printdialog-option-norefs': '隐藏引用', 'printdialog-option-notoc': '隐藏目录', 'printdialog-option-nobackground': '删除背景(您的浏览器可能会或可能不会覆盖此背景)', 'printdialog-option-blacktext': '强制所有文本为黑色' }); // Run installation after page load mw.hook('wikipage.content').add(function () { if (mw.config.get('wgNamespaceNumber') >= 0) { printOptions.install(); } }); }());
返回
MediaWiki:Gadget-PrintOptions.js
。