InPageEdit.edit(options)
options: {object}
page: 必须;编辑的页面名revision: 修订版本号,如果与当前页面版本号不同则取代section: 编辑的段落编号最基础的调用
InPageEdit.edit({
page: mw.config.get('wgPageName')
});
InPageEdit.redirect(type)
type: "string"(to/from)
最基础的调用
InPageEdit.redirect('from');
InPageEdit.redirect('to');
InPageEdit.deletepage(page)
page "string"
InPageEdit.renamepage()
InPageEdit.preference()
InPageEdit.quickDiff(options)
options: {object}
fromtitle: First title to compare.fromid: First page ID to compare. Type: integerfromrev: First revision to compare. Type: integerfromtext: Use this text instead of the content specified by fromtitle, fromid or fromrev.frompst: Do a pre-save transform on fromtext. Type: booleantotitle: Second title to compare.toid: Second page ID to compare. Type: integertorev: Second revision to compare. Type: integertorelative: Compare to a relative revision of fromtitle, fromid or fromrev. All the other "to" options will be ignored. Possible values: prev, next, curtotext: Use this text instead of the content specified by totitle, toid, torev, or torelative.topst: Do a pre-save transform on totext. Type: boolean最简单的示例,比较本页面最后一次修改
InPageEdit.quickDiff({
fromtitle: mw.config.get('wgPageName'),
torelative: 'prev'
});
该模块在页面加载时将运行一次[1]
InPageEdit.articleLink(element)
element: <element>
$('#mw-content-text a:not(.new)')无示例
不建议使用[2]
InPageEdit.progress(title)
title: "string",√boolean×
function testProgress() {
InPageEdit.progress('正在测试加载框……');
setTimeout(function(){
InPageEdit.progress(true);
setTimeout(function(){
InPageEdit.progress(false);
},3000);
},5000);
}
Wjghj Project 的服务器不是高带宽高并发服务器,请不要过于频繁调用此模块[3]
InPageEdit.versionInfo()
请勿改写此变量;这是一个变量,不是一个函数
InPageEdit.version
可以自定义需要的按钮,按以下提示在个人js页面写入全局变量window.InPageEdit.buttons即可,类型为Array。
window.InPageEdit = window.InPageEdit || {}; // 务必在之前添加这一行否则会报错
InPageEdit.buttons =[{
open: '<-- ', // 添加到光标前的内容
middle: '注释文字', // 选区内容占位符,选填
close: ' -->', // 添加到光标后的内容
text: '<span class="material-icons">description</span>' // 按钮文字,被解析为html
}, { // 再举个栗子
open: '<s>',
middle: '删除线',
close: '</s>',
text: '<span class="material-icons">strikethrough_s</span>'
}];
通过IPE的扩展接口,您可以制作很多自定义插件,这里提供一些简单、实用的代码实例
这里是IPE原版右下角工具盒的源代码,只要您明白了其中的原理,便完全可以自由自定义一个工具盒
| 原版代码 |
|---|
/**
* InPageEdit Toolbox
* Example extension for InPageEdit-v2,
* Default loaded for everyone.
**/
mw.hook('InPageEdit').add(function () {
// Not article
if (mw.config.get('wgIsArticle') === false) {
return;
}
/**
* ${msg} function - this is the function for load i18n-js strings
** You can use normally strings insteed.
**/
function msg(i){
dfgh.i18n.loadMessages('InPageEdit-v2').then(function(i18n){
return i18n.msg(i).parse();
});
}
$('<div>', { id: 'ipe-edit-toolbox' }).append(
$('<ul>', { class: 'btn-group group1' }).append(
$('<li>', { class: 'btn-tip-group' }).append(
$('<div>', { class: 'btn-tip', text: msg('quick-edit') }),
$('<button>', { id: 'edit-btn', class: 'ipe-toolbox-btn material-icons', text: 'edit' })
),
$('<li>', { class: 'btn-tip-group' }).append(
$('<div>', { class: 'btn-tip', text: msg('redirect-from') }),
$('<button>', { id: 'redirectfrom-btn', class: 'ipe-toolbox-btn material-icons', text: 'flight_land' })
),
$('<li>', { class: 'btn-tip-group' }).append(
$('<div>', { class: 'btn-tip', text: msg('redirect-to') }),
$('<button>', { id: 'redirectto-btn', class: 'ipe-toolbox-btn material-icons', text: 'flight_takeoff' })
)
),
$('<ul>', { class: 'btn-group group2' }).append(
$('<div>', { style: 'display: flex;' }).append(
$('<li>', { class: 'btn-tip-group' }).append(
$('<div>', { class: 'btn-tip', text: msg('quick-delete') }),
$('<button>', { id: 'deletepage-btn', class: 'ipe-toolbox-btn material-icons', text: 'delete_forever' })
),
$('<li>', { class: 'btn-tip-group' }).append(
$('<div>', { class: 'btn-tip', text: msg('quick-rename') }),
$('<button>', { id: 'renamepage-btn', class: 'ipe-toolbox-btn material-icons', text: 'format_italic' })
),
$('<li>', { class: 'btn-tip-group' }).append(
$('<div>', { class: 'btn-tip', text: msg('ipe-preference') }),
$('<button>', { id: 'preference-btn', class: 'ipe-toolbox-btn material-icons', text: 'settings' })
)
)
),
$('<button>', { class: 'ipe-toolbox-btn material-icons', id: 'toolbox-toggle', text: 'add' })
).appendTo('body');
$('#ipe-edit-toolbox #toolbox-toggle').click(function () {
$('#ipe-edit-toolbox #toolbox-toggle, #ipe-edit-toolbox .btn-group').toggleClass('opened');
});
$('body > *:not(#ipe-edit-toolbox)').click(function () {
$('#ipe-edit-toolbox #toolbox-toggle, #ipe-edit-toolbox .btn-group').removeClass('opened');
});
$('#ipe-edit-toolbox .btn-group .ipe-toolbox-btn').click(function () {
InPageEdit.analysis({ type: 'functionCount', function: '工具盒' });
switch ($(this).attr('id')) {
case 'edit-btn':
InPageEdit.quickEdit({
page: mw.config.get('wgPageName'),
revision: mw.config.get('wgRevisionId')
});
break;
case 'redirectfrom-btn':
InPageEdit.quickRedirect('from');
break;
case 'redirectto-btn':
InPageEdit.quickRedirect('to');
break;
case 'preference-btn':
InPageEdit.preference();
break;
case 'deletepage-btn':
InPageEdit.quickDelete();
break;
case 'renamepage-btn':
InPageEdit.quickRename();
break;
}
});
mw.hook('InPageEdit.toolbox').fire();
});
|
此示例代码已在Vector、Timeless以及Hydra皮肤上测试可用
| 源代码 |
|---|
mw.hook('InPageEdit').add(function(){
$('#ca-view').after(
$('<li>',{
id:'ca-quick-edit',
class:'collapsible'
}).append(
$('<span>').append(
$('<a>',{
href: 'javascript:void(0)'
})
.text('快速编辑')
.click(function(){
InPageEdit.edit({
page: mw.config.get('wgPageName'),
revision: mw.config.get('wgRevisionId')
});
})
)
)
);
});
|
InPageEdit.articleLink($('#mw-content-text a:not(.new)'))
<div class="ipe-progress" style="width:可规定一个长度"><div class="ipe-progress-bar"></div></div>