ميدياويكي:Gadget-iRef.js

من أرابيكا، الموسوعة الحرة
اذهب إلى التنقل اذهب إلى البحث

ملاحظة: بعد الحفظ، قد يلزمك إفراغ الكاش لرؤية التغييرات.

//[[fr:MediaWiki:Gadget-iRef.js]]
if((mw.config.get("wgAction")==="edit"||mw.config.get("wgAction")==="submit")&&typeof iRef==="undefined"){window.iRef=function($){var textBox=document.getElementById("wpTextbox1");function cleanMark(){var position=textBox.scrollTop;textBox.value=textBox.value.replace(/\r\n/g,"\n").replace(/\n<!--\[iRef\]-->[\s\S]*<!--\[\/iRef\]-->\n/,"");textBox.scrollTop=position}function getGroups(source){var refs=source.match(/<ref [^>]+>/g);if(!refs){return[]}var groups=[];var i,l,attrib;for(i=0,l=refs.length;i<l;i++){attrib=/group *= *"([^"]+)"/.exec(refs[i]);if(attrib&&$.inArray(attrib[1],groups)===-1){groups.push(attrib[1]);continue}attrib=/group *= *([^" >]+)/.exec(refs[i]);if(attrib&&$.inArray(attrib[1],groups)===-1){groups.push(attrib[1])}}return groups}function buildMark(groups){var mark="\n<!--[iRef]--><div style=color:slategrey;margin-top:2em><references /></div>";var i,l;for(i=0,l=groups.length;i<l;i++){mark+='\n<!--[iRef]--><div style=color:slategrey;margin-top:2em><references group="'+groups[i]+'" /></div>'}mark+="<!--[/iRef]-->\n";return mark}function iRefPreview(){var source=textBox.value;if(source.indexOf("<ref")===-1){return}var position=textBox.scrollTop;source=source.replace(/\r\n/g,"\n").replace(/\n+$/,"")+"\n";textBox.value=source+buildMark(getGroups(source));textBox.scrollTop=position}cleanMark();$("#wpPreview").click(function(){if(typeof doLivePreview==="undefined"){iRefPreview()}});$(mw).on({LivePreviewPrepare:iRefPreview,LivePreviewDone:cleanMark});var jEditButtonsZone=$("#editform").find("div.editButtons");function iRefQPreview(){iRefPreview();qPreview();cleanMark()}function QPreviewOverride(){$("#btnQPreview").removeAttr("onclick").click(iRefQPreview);jEditButtonsZone.off("focus","#btnQPreview",QPreviewOverride)}jEditButtonsZone.on("focus","#btnQPreview",QPreviewOverride);$("#wpSave").click(function(){if(typeof doLivePreview==="undefined"){cleanMark()}})};$(document).ready(iRef)};