"मिडियाविकी:Gadget-Easy LST.js" च्या विविध आवृत्यांमधील फरक
Content deleted Content added
नवीन गॅजेट |
(काही फरक नाही)
|
१०:५५, १४ जून २०२० ची नविनतम आवृत्ती
/**
* Easy Labeled Section Transclusion
*/
function restore_lst(){
var editbox = document.getElementById('wpTextbox1');
var search = /##[\s]*(.*?)[\s]*##[\s]*\n/;
var a = editbox.value.split(search);
var s = a[0];
var m = parseInt(a.length/2);
for( var i = 0 ; i < m ; i++ ) {
var title = a[i*2+1];
// Ensure we'll don't get twice quote.
title = title.replace(/^"(.*)"$/, "$1");
title = title.replace(/^'(.*)'$/, "$1");
var content = a[i*2+2];
if(title && content.substring(0,2)=='{|' ) content = '\n' + content;
if(title) s = s + '<section begin="' + title + '" />' + content + '<section end="' + title + '" />\n';
else s = s + content;
/* if( i < m-1 ) s = s + "----\n"; */
}
editbox.value = s;
}
/**
* easy lst : hide section markers
*/
function easy_lst() {
var editbox = document.getElementById('wpTextbox1');
if(editbox) {
var search = /<section\sbegin=[\s]*(.*?)[\s]*\/>/;
var a = editbox.value.split(search);
var s = a[0];
var ok = true;
for( var i = 0 ; i < parseInt(a.length/2) ; i++ ) {
var title = a[i*2+1];
var content = a[i*2+2];
var r2 = /^([\s\S]*?)<section\send=(.*?)\/>(\n|)[\s]*([\s\S]*?)$/;
var m2 = content.match(r2);
if( m2 ) {
title = title.replace(/^"(.*)"$/, "$1");
title = title.replace(/^'(.*)'$/, "$1");
if(s && s.charAt(s.length-1)!='\n' && s.charAt(s.length-1)!='|' ) s = s+'\n';
s = s + "## " + title + " ##\n"+ m2[1] ;
if( m2[4] ) {
if( m2[4]!='----\n' ) {
if(s && s.charAt(s.length-1)!='\n' ) s = s+'\n';
s = s + "####\n" + m2[4] ;
}
}
} else {
ok = false; /* alert("error"+title); */
}
}
if(ok) {
editbox.value = s;
}
var saveButton = document.getElementById("wpSave");
var previewButton = document.getElementById("wpPreview");
var diffButton = document.getElementById("wpDiff");
if(saveButton){
saveButton.onclick = restore_lst;
previewButton.onclick = restore_lst;
diffButton.onclick = restore_lst;
}
}
}
function easy_lst_setup() {
if (self.proofreadpage_raw_lst || mw.config.get( 'wgCanonicalNamespace' ) !== 'Page')
return;
if ($.inArray(mw.config.get('wgAction'), ['edit', 'submit']) !== -1) {
mw.loader.using('ext.proofreadpage.page', function () {
// mimic code in the extension, there is a conditionnal deps on ext.wikiEditor.
if (mw.user.options.get('usebetatoolbar') && $.inArray('ext.wikiEditor', mw.loader.getModuleNames()) > -1) {
if ( mw.user.options.get( 'codemirror-syntax-highlight' ) == 1 ) {
$loadingDependencies = [ 'ext.wikiEditor', 'ext.CodeMirror.lib' ];
} else {
$loadingDependencies = [ 'ext.wikiEditor' ];
}
mw.loader.using( $loadingDependencies, function() {
easy_lst();
});
} else {
easy_lst();
}
});
}
}
$( easy_lst_setup );