Site Notice
hello, world
Difference between revisions of "MediaWiki:Js-InPageEdit-v2.js"
From Project-EPB Commons
Line 14: | Line 14: | ||
editSection, | editSection, | ||
editReversion, | editReversion, | ||
+ | editText, | ||
editSummary, | editSummary, | ||
jsonPreview, | jsonPreview, | ||
jsonPost; | jsonPost; | ||
− | if (option | + | if (option === undefined) { |
− | + | editPage = wgPageName | |
+ | } else { | ||
+ | if (option.page !== '') editPage = option.page; | ||
+ | } | ||
+ | |||
// Show modal | // Show modal | ||
ssi_modal.show({ | ssi_modal.show({ | ||
className: 'ipe', | className: 'ipe', | ||
− | title: '<span style="font-style:normal;">123', | + | title: '<span id="editPage" style="font-style:normal;">123</span>', |
− | content: '<textarea id="editArea" style="max-width:100%;min-width:100%;min-height:350px"></textarea><label>摘要:<input id="editSummary"/></label><br/><label><input id="editMinor" type="checkbox" style="margin-left:0;margin-right:4px"/>小编辑</label>', | + | content: '<textarea id="editArea" style="max-width:100%;min-width:100%;min-height:350px">正在加载……</textarea><label>摘要:<input id="editSummary"/></label><br/><label><input id="editMinor" type="checkbox" style="margin-left:0;margin-right:4px"/>小编辑</label>', |
keepContent: false, | keepContent: false, | ||
beforeClose: function(modal) { | beforeClose: function(modal) { | ||
Line 53: | Line 58: | ||
buttons: [{ | buttons: [{ | ||
label: '预览', | label: '预览', | ||
− | method: requestPreview | + | method: function (){ |
+ | var text = $('#editArea').val(); | ||
+ | requestPreview(text) | ||
+ | } | ||
}, | }, | ||
{ | { | ||
Line 69: | Line 77: | ||
function(result) { | function(result) { | ||
if (result) { | if (result) { | ||
− | postArticle(); | + | var text = $('#editArea').val(); |
+ | postArticle(text); | ||
} | } | ||
}) | }) | ||
} | } | ||
}] | }] | ||
+ | }); | ||
+ | new mw.Api().get({ | ||
+ | action: 'parse', | ||
+ | page: wgPageName, | ||
+ | prop: 'wikitext', | ||
+ | format: 'json' | ||
+ | }).then(function(data){ | ||
+ | editText = data.parse.wikitext['*']; | ||
+ | |||
}); | }); | ||
− | function requestPreview(){ | + | function requestPreview(text){ |
− | ssi_modal.show({content:' | + | new mw.Api().post({ |
+ | action: "parse", | ||
+ | text: text, | ||
+ | prop: "text", | ||
+ | preview: true, | ||
+ | format: "json" | ||
+ | }).then(function(data){ | ||
+ | var content = data.parse.text['*']; | ||
+ | ssi_modal.show({content:content}); | ||
+ | }); | ||
+ | } | ||
+ | |||
+ | function postArticle(text){ | ||
+ | new mw.Api().post({ | ||
+ | action: "parse", | ||
+ | text: text, | ||
+ | prop: "text", | ||
+ | preview: true, | ||
+ | format: "json" | ||
+ | }).then(function(data){ | ||
+ | var content = data.parse.text['*']; | ||
+ | ssi_modal.show({content:content}); | ||
+ | }); | ||
} | } | ||
+ | |||
} | } |
Revision as of 21:23, 16 October 2019
/**
*『Wjghj Project Static』
* This _JavaScript_ code is from https://common.wjghj.cn
* CC BY-NC-SA
**/
// Modal plugin
mw.loader.load('https://common.wjghj.cn/js/SsiModal');
// Main
function InPageEdit(option) {
// Variables
var editPage,
editSection,
editReversion,
editText,
editSummary,
jsonPreview,
jsonPost;
if (option === undefined) {
editPage = wgPageName
} else {
if (option.page !== '') editPage = option.page;
}
// Show modal
ssi_modal.show({
className: 'ipe',
title: '<span id="editPage" style="font-style:normal;">123</span>',
content: '<textarea id="editArea" style="max-width:100%;min-width:100%;min-height:350px">正在加载……</textarea><label>摘要:<input id="editSummary"/></label><br/><label><input id="editMinor" type="checkbox" style="margin-left:0;margin-right:4px"/>小编辑</label>',
keepContent: false,
beforeClose: function(modal) {
ssi_modal.confirm({
position: 'top center',
content: '确定要关闭窗口吗',
okBtn: {
className: 'btn btn-primary',
label: '确定'
},
cancelBtn: {
className: 'btn btn-danger',
label: '取消'
}
},
function(result) {
if (result === true) {
modal.options.keepContent = false;
modal.options.beforeClose = '';
modal.close();
ssi_modal.notify('error', {
position: 'right top',
content: "编辑被取消。"
})
}
});
return false;
},
buttons: [{
label: '预览',
method: function (){
var text = $('#editArea').val();
requestPreview(text)
}
},
{
label: '发布',
method: function(modal) {
ssi_modal.confirm({
content: '是否发布',
okButton: {
label: '确定'
},
cancelButton: {
label: '取消'
},
},
function(result) {
if (result) {
var text = $('#editArea').val();
postArticle(text);
}
})
}
}]
});
new mw.Api().get({
action: 'parse',
page: wgPageName,
prop: 'wikitext',
format: 'json'
}).then(function(data){
editText = data.parse.wikitext['*'];
});
function requestPreview(text){
new mw.Api().post({
action: "parse",
text: text,
prop: "text",
preview: true,
format: "json"
}).then(function(data){
var content = data.parse.text['*'];
ssi_modal.show({content:content});
});
}
function postArticle(text){
new mw.Api().post({
action: "parse",
text: text,
prop: "text",
preview: true,
format: "json"
}).then(function(data){
var content = data.parse.text['*'];
ssi_modal.show({content:content});
});
}
}