User:MarkS/extraeditbuttons.js: Difference between revisions

Content deleted Content added
MarkS (talk | contribs)
Copy of dev code - Bug fix for Mozilla browser
m Maintenance: Replacing importScriptURI with mw.loader.load (phab:T95964)
 
(13 intermediate revisions by 7 users not shown)
Line 1:
//<pre>
//Version: 3.1
//============================================================
// en: ADD SOME EXTRA BUTTONS TO THE EDITPANEL
Line 13 ⟶ 14:
//XEBOrder - The order in which the buttons are displayed
 
mw.loader.load( '//en.wikipedia.org/w/index.php?title=User:MarkS/XEB/live.css&action=raw&ctype=text/css', 'text/css' );
document.write('<link rel="stylesheet" type="text/css" href="' +
'http://en.wikipedia.org/w/index.php?title=User:MarkS/XEB/live.css' +
'&action=raw&ctype=text/css&dontcountme=s">');
 
if(typeof XEBPopups== 'undefined')XEBPopups=true;
Line 33 ⟶ 32:
if (typeof usersignature == 'undefined') var usersignature = '-- \~\~\~\~';
 
var Isrc='http://upload.wikimedia.org/wikipedia/commons/';
 
// English Wikipedia creates 11 extra buttons which are stored in mwCustomEditButtons
// rather than mwEditButtons. However, there is no guarantee it will always be 11
// so we count them here.
var enExtraButtons=typeof mwCustomEditButtons !== 'undefined' && mwCustomEditButtons.length;
 
 
Line 90 ⟶ 89:
 
var XEBOrder2=[];
if (typeof XEBOrder!='string') // can be modified
XEBOrder2="A,D,C,D1,F,U,J1,E,G,Q,W,X,K,L,H,O,R,T".split(",");
else if (XEBOrder.toLowerCase()=='all')
for (b in BDict) XEBOrder2.push(b);
else XEBOrder2=XEBOrder.toUpperCase().split(",");
 
 
 
addOnloadHook(initButtons);
if(!wgIsArticle)// only if edit
{
 
if(typeof mwCustomEditButtons !== 'undefined') {
if(XEBPopups)hookEvent("load", extendButtons);
$(initButtons);
if(!mw.config.get('wgIsArticle'))// only if edit
{
 
if(XEBPopups)hookEvent("load", extendButtons);
}
}
 
Line 108 ⟶ 105:
 
var bc,d;
 
if (typeof XEBOrder!='string') // can be modified
XEBOrder2="A,D,C,D1,F,U,J1,E,G,Q,W,X,K,L,H,O,R,T".split(",");
else if (XEBOrder.toLowerCase()=='all')
for (b in BDict) XEBOrder2.push(b);
else XEBOrder2=XEBOrder.toUpperCase().split(",");
 
for (b in BDict) BDict[b][0] = Isrc+BDict[b][0]; // // Add the start of the URL (Isrc) to the XEB buttons
// If the user has defined any buttons then add them into the available button lists
Line 116 ⟶ 120:
 
for (b in mwEditButtons) { // add standard buttons for full XEB order changing
//bug(mwEditButtons[1].imageFile);
 
// BDict[b]=[];
Line 134 ⟶ 137:
if(typeof bc=='object')
{
 
//bug(bc[0]);
//Call addCustomButton in wikibits
addCustomButton(bc[0],bc[1],bc[2],bc[3],bc[4]);
Line 153 ⟶ 156:
//Remove the buttons the user doesn't want
 
if (typeof rmEditButtons!='object') return;
 
if (typeof rmEditButtons[0] == 'string' && rmEditButtons[0].toLowerCase() == 'all')
Line 201 ⟶ 204:
 
 
//Function:
 
//Purpose:
// Adds extended onclick-function to some buttons
// Adds extended onclick-function to some buttons
function extendButtons(){
 
Line 208 ⟶ 212:
if(typeof editform != 'undefined')
if(!(window.editform = document.forms['editform'])) return false;
 
XEBOrder2.getIndex = function (item){
if(is_gecko) return this.indexOf(item);
else //is IE (Opera < 9)
for (var i=0;i < this.length;i++) if (this[i]==item) return Number(i);
return -1
}
var searchbox = allEditButtons.getElementsByTagName('span')[0];
if (searchbox) allEditButtons.appendChild(searchbox) // pay Zocky/Search Box
allEditButtons = allEditButtons.getElementsByTagName('img');
var bu_len = mwEditButtons.length;
var c=0;
if(!allEditButtons.length) return false;
// own signature
if (bu_len>0){
if(typeof rmEditButtons=='object' && rmEditButtons.pop()==10) c=1;
mwEditButtons[bu_len-2+c].tagOpen=usersignature;
if(usersignature != '-- \~\~\~\~')
allEditButtons[bu_len-2+c].src=Isrc+'d/d1/Button_mysignature.png';
}
// table
extendAButton(Isrc+"0/04/Button_array.png",XEBPopupTable)
c=XEBOrder2.getIndex('E');
extendAButton(Isrc+"7/79/Button_reflink.png",XEBPopupRef)
if(c != -1) allEditButtons[bu_len+enExtraButtons+c].onclick=XEBPopupTable;
extendAButton(Isrc+"b/b8/Button_Globe.png",XEBPopupGeoLink)
// ref
extendAButton(Isrc+"4/49/Button_talk.png",XEBPopupTalk)
c=XEBOrder2.getIndex('R');
extendAButton(Isrc+"1/1c/Button_advanced_image.png",XEBPopupImage)
if(c != -1) allEditButtons[bu_len+enExtraButtons+c].onclick=XEBPopupRef;
//extendAButton(Isrc+"6/6a/Button_sup_letter.png",XEBPopupFormattedText)
// Geo
c=XEBOrder2.getIndex('GEO');
if(c != -1) allEditButtons[bu_len+enExtraButtons+c].onclick=XEBPopupGeoLink;
c=XEBOrder2.getIndex('TALK');
if(c != -1) allEditButtons[bu_len+enExtraButtons+c].onclick=XEBPopupTalk;
c=XEBOrder2.getIndex('AI');
if(c != -1) allEditButtons[bu_len+enExtraButtons+c].onclick=XEBPopupImage;
// c=XEBOrder2.getIndex('I1');
// if(c != -1) allEditButtons[bu_len+enExtraButtons+c].onclick=XEBPopupFormattedText;
 
// redirect -##IE doesn't like this line. Object doesn't support this property or method
//c=XEBOrder2.getIndex('V');
 
// if(c != -1)
// redirect
// allEditButtons[bu_len+c].onclick=function(){
c=XEBOrder2.getIndex('V');
// var a='#REDIRECT \[\['+prompt("Which page do you want to redirect to\?")+'\]\]';
if(c != -1)
// document.editform.elements['wpTextbox1'].value=a;
allEditButtons[bu_len+c].onclick=function(){
// document.editform.elements['wpSummary'].value=a;
var a='#REDIRECT \[\['+prompt("Which page do you want to redirect to\?")+'\]\]';
// document.editform.elements['wpTextbox1wpWatchthis'].valuechecked=a;false
// };
document.editform.elements['wpSummary'].value=a;
document.editform.elements['wpWatchthis'].checked=false
};
};
 
function extendAButton(url,newfunc)
{
if(!(allEditButtons = document.getElementById('toolbar'))) return false;
if(typeof editform != 'undefined')
if(!(window.editform = document.forms['editform'])) return false;
allEditButtons = allEditButtons.getElementsByTagName('img');
for(i=0;i<allEditButtons.length;i++)
{
if(allEditButtons[i].src==url)
{
allEditButtons[i].onclick=newfunc;
}
}
}
 
//==========================================================================================================
Line 282 ⟶ 274:
return me;
}
 
//Function:
// CheckHideXEBPopup
Line 294 ⟶ 286:
if(is_gecko)
{
// var x=e.clientX + window.scrollX;
// var y=e.clientY + window.scrollY;;
// var x=e.clientX-10+ document.documentElement.scrollLeft + document.body.scrollLeft;
// var y=e.clientY-10+ document.documentElement.scrollTop + document.body.scrollTop;
 
ph=m.offsetHeight;
 
 
var x=e.clientX + window.scrollX;
var y=e.clientY + window.scrollY;;
Line 307 ⟶ 292:
ph=s.height;
ph=Number(ph.substring(0,ph.length-2));
 
}
else
Line 313 ⟶ 297:
var x=event.clientX+ document.documentElement.scrollLeft + document.body.scrollLeft;
var y=event.clientY+ document.documentElement.scrollTop + document.body.scrollTop;
 
ph=m.offsetHeight;
}
Line 323 ⟶ 306:
if(x>(pl+2)&&x<(pl+pw-5)&&y>(pt+2)&&y<(pt+ph-5))return;
curPopup.hideTimeout=setTimeout('hideXEBPopup()',XEBHideDelay*1000);
//hideXEBPopup();
}
 
function cancelHidePopup()
{
Line 339 ⟶ 322:
{
m=new GetPos(e||event);
 
curPopup.startDrag.mouse=m;
curPopup.startDrag.floatpopup.y=parseInt(curPopup.div.style.top);
curPopup.startDrag.floatpopup.x=parseInt(curPopup.div.style.left);
curPopup.dragging=true;
 
}
 
function XEBstopDrag(e)
{
Line 351 ⟶ 333:
curPopup.dragging=false;
}
 
function XEBDrag(e)
{
 
if(curPopup.dragging==false)return;
 
Line 360 ⟶ 342:
y=parseInt(curPopup.startDrag.floatpopup.y+(m.y-curPopup.startDrag.mouse.y));
 
curPopup.div.style.top=y+"px";
curPopup.div.style.left=x+"px";
 
curPopup.x=x;
curPopup.y=y;
 
 
}
 
Line 376 ⟶ 356:
{
// Make sure the popup can appear on the screen
 
this.IESelectedRange=XEBgetIESelectedRange();
 
winW=(is_gecko)?window.innerWidth:document.body.offsetWidth;
Line 391 ⟶ 373:
this.startDrag=new Object;
this.startDrag.floatpopup=new Object;
 
}
 
function setInnerHTML(text)
{
Line 412 ⟶ 394:
}
//Add rollover features to menu items. Doing it here means we don't have to do it for each menu
x=getElementsByClassNameXEBgetElementsByClassName(this.div,'XEBMnuItm','span');
for (var i = 0; i < x.length; i++) {
var theItm = x[i];
Line 493 ⟶ 475:
return false;
}
 
// Get the text currently selected by user in the textAra
// This code is based on part of the insertTags function in wikibits.js
 
function XEBGetSelectedText()
{
var txtarea;
if (document.editform) {
txtarea = document.editform.wpTextbox1;
} else {
// some alternate form? take the first one we can find
var areas = document.getElementsByTagName('textarea');
 
txtarea = areas[0];
}
// IE & Opera
if (document.selection && !is_gecko)
{
var theSelection = document.selection.createRange().text;
if (!theSelection) theSelection='';
}
// Mozilla
else if(txtarea.selectionStart || txtarea.selectionStart == '0') {
var replaced = false;
var startPos = txtarea.selectionStart;
var endPos = txtarea.selectionEnd;
var theSelection = (txtarea.value).substring(startPos, endPos);
if (!theSelection) theSelection='';
}
return theSelection;
}
 
//Notes:
// IE loses the cursor position in the textarea when the popup is used.
// So we save the cursor position here
function XEBgetIESelectedRange(){
var IESel=new Object;
var txtarea;
if (document.editform) {
txtarea = document.editform.wpTextbox1;
} else {
// some alternate form? take the first one we can find
var areas = document.getElementsByTagName('textarea');
 
txtarea = areas[0];
}
// IE & Opera
 
if (document.selection && !is_gecko)
{
txtarea.focus();
IESel.Rng=document.selection.createRange();
return IESel;
}
}
 
function XEBinsertText(beforeText,selText,afterText,IESelectedRange) {
var newText=beforeText + selText + afterText;
var txtarea;
if (document.editform) {
txtarea = document.editform.wpTextbox1;
} else {
// some alternate form? take the first one we can find
var areas = document.getElementsByTagName('textarea');
txtarea = areas[0];
}
 
// IE
if (document.selection && !is_gecko) {
 
tr=IESelectedRange.Rng;
tr.text=newText;
txtarea.focus();
//txtarea.caretpos=tr.duplicate();
tr.select();
 
return;
 
// Mozilla
} else if(txtarea.selectionStart || txtarea.selectionStart == '0') {
var replaced = false;
var startPos = txtarea.selectionStart;
var endPos = txtarea.selectionEnd;
 
if (endPos-startPos) {
replaced = true;
}
var scrollTop = txtarea.scrollTop;
// var myText = (txtarea.value).substring(startPos, endPos);
// if (!myText) {
// myText=sampleText;
// }
// if (myText.charAt(myText.length - 1) == " ") { // exclude ending space char, if any
// subst = tagOpen + myText.substring(0, (myText.length - 1)) + tagClose + " ";
// } else {
// subst = tagOpen + myText + tagClose;
// }
txtarea.value = txtarea.value.substring(0, startPos) + newText +
txtarea.value.substring(endPos, txtarea.value.length);
txtarea.focus();
//set new selection
if (!replaced) {
var cPos = startPos+(newText.length);
txtarea.selectionStart = cPos;
txtarea.selectionEnd = cPos;
} else {
txtarea.selectionStart = startPos+beforeText.length;
txtarea.selectionEnd = startPos+beforeText.length+selText.length;
}
txtarea.scrollTop = scrollTop;
 
// All other browsers get no toolbar.
// There was previously support for a crippled "help"
// bar, but that caused more problems than it solved.
}
// reposition cursor if possible
if (txtarea.createTextRange) {
 
txtarea.caretPos = document.selection.createRange().duplicate();
//txtarea.caretPos =IESelectedRange.Rng;
}
txtarea.focus();
}
 
 
//============================================================
Line 506 ⟶ 612:
 
function XEBPopupRef(e){
 
m=new GetPos(e||event);
 
Line 513 ⟶ 620:
+'<form name="XEBPopupRefForm">'
+'Name:<input type="text" name="refName" value="" size="10"><p\/>'
+'Material:<input type="text" name="refMaterial" value="' + XEBGetSelectedText() + '" size="20">'
+'<\/form>'
+'<p><button onClick="javascript:insertRef()">Insert</button>'
Line 519 ⟶ 626:
 
curPopup.setInnerHTML(mt);
// document.XEBPopupRefForm.refName.focus();
return true;
}
Line 529 ⟶ 636:
hideXEBPopup();
var codecode1='<ref';
codecode1+=(refName!='')?' name="'+refName+'">':'>';
code+code2=refMaterial+'<\/ref>';
code3='<\/ref>'
XEBinsertText(code1,code2,code3,curPopup.IESelectedRange);
 
insertTags('','', code);
extendSummary('ref');
 
return false;
}
Line 552 ⟶ 659:
+'<table style="background: transparent;">'
+'<tr><td>Latitude:<\/td><td><input type="text" autocomplete="off" name="geoLatDeg" value="" size="4"><\/td>'
+'<td><input type="text" name="geoLatMin" value="" size="4"><\/td>'
+'<td><input type="text" name="geoLatSec" value="" size="4"><\/td>'
+'<td><select name="geoLatNS"><option value="N">N<option value="S">S</select><\/td><\/tr>'
+'<tr><td>Longitude:<\/td><td><input type="text" name="geoLonDeg" value="" size="4"><\/td>'
Line 656 ⟶ 763:
mt='<p>Enter the image parameters below: <\/p>'
+'<form name="XEBPopupImageForm">'
+'File:<input type="text" name="imgFile" value="' + XEBGetSelectedText() + '" size="30"><br>'
+'Enter the image parameters below:<p\/>'
+'File:<input type="text" name="imgFile" value="" size="30"><br>'
+'Type:<SELECT NAME="imgType">'
+'<OPTION VALUE="thumb">Thumbnail'
Line 669 ⟶ 775:
+'<OPTION VALUE="none">None'
+'</SELECT><br>'
+'Size:<input type="text" name="imgSize" value="100" size="3">px<br>'
+'Caption:<input type="text" name="imgCaption" value="" size="30">px<\/p>'
+'<\/form>'
+'<p><button onClick="javascript:XEBInsertImage()">Insert</button>'
Line 684 ⟶ 790:
hideXEBPopup();
var code='[[Image:';
code+=f.imgFile.value;
code+='|'+f.imgType.value;
code+='|'+f.imgLocation.value;
code+='|'+f.imgSize.value;
code+='|'+f.imgCaption.value;
code+=']]';
insertTags('','', code);
extendSummary('image');
 
return false;
 
 
}
 
Line 740 ⟶ 844:
return true;
}
 
function XEBUpdateSampleText()
{
Line 755 ⟶ 860:
 
targ.style.color='black';
}
 
function XEBMenuMouseOver(e)
{ var targ;
Line 770 ⟶ 875:
//=======================================================================
 
function getElementsByClassNameXEBgetElementsByClassName(parent,clsName,htmltag){
var arr = new Array();
var elems = parent.getElementsByTagName(htmltag);
Line 780 ⟶ 885:
return arr;
}
 
function extendSummary(newText)
{
Line 790 ⟶ 896:
function bug(msg)
{
if(mw.config.get('wgUserName')=='MarkS')alert(msg);
}