User:MarkS/extraeditbuttons.js: Difference between revisions

Content deleted Content added
MarkS (talk | contribs)
Copy of dev code - Bug fix for advanced image button
MarkS (talk | contribs)
Copy of Development code 3.1
Line 1:
//<pre>
//Version: 3.1
//============================================================
// en: ADD SOME EXTRA BUTTONS TO THE EDITPANEL
Line 90 ⟶ 91:
 
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(",");
 
 
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 200 ⟶ 204:
 
 
//Function:
 
//Purpose:
// Adds extended onclick-function to some buttons
// Adds extended onclick-function to some buttons
function extendButtons(){
 
Line 209 ⟶ 214:
 
// table
extendAButton(Isrc+"0/04/Button_array.png",XEBPopupTable)
extendAButton(Isrc+"7/79/Button_reflink.png",XEBPopupRef)
extendAButton(Isrc+"b/b8/Button_Globe.png",XEBPopupGeoLink)
extendAButton(Isrc+"4/49/Button_talk.png",XEBPopupTalk)
extendAButton(Isrc+"1/1c/Button_advanced_image.png",XEBPopupImage)
//extendAButton(Isrc+"6/6a/Button_sup_letter.png",XEBPopupFormattedText)
 
// redirect -##IE doesn't like this line. Object doesn't support this property or method
// redirect
//c=XEBOrder2.getIndex('V');
 
if(c != -1)
// if(c != -1)
allEditButtons[bu_len+c].onclick=function(){
// allEditButtons[bu_len+c].onclick=function(){
var a='#REDIRECT \[\['+prompt("Which page do you want to redirect to\?")+'\]\]';
// var a='#REDIRECT \[\['+prompt("Which page do you want to redirect to\?")+'\]\]';
document.editform.elements['wpTextbox1'].value=a;
// document.editform.elements['wpSummarywpTextbox1'].value=a;
// document.editform.elements['wpWatchthiswpSummary'].checkedvalue=falsea;
// document.editform.elements['wpWatchthis'].checked=false
};
// };
};
 
Line 240 ⟶ 246:
}
}
 
}
 
 
//==========================================================================================================
Line 270 ⟶ 274:
return me;
}
 
//Function:
// CheckHideXEBPopup
Line 282 ⟶ 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 295 ⟶ 292:
ph=s.height;
ph=Number(ph.substring(0,ph.length-2));
 
}
else
Line 301 ⟶ 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 311 ⟶ 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 327 ⟶ 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 339 ⟶ 333:
curPopup.dragging=false;
}
 
function XEBDrag(e)
{
 
if(curPopup.dragging==false)return;
 
Line 348 ⟶ 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 364 ⟶ 356:
{
// Make sure the popup can appear on the screen
 
this.IESelectedRange=XEBgetIESelectedRange();
 
winW=(is_gecko)?window.innerWidth:document.body.offsetWidth;
Line 379 ⟶ 373:
this.startDrag=new Object;
this.startDrag.floatpopup=new Object;
 
}
 
function setInnerHTML(text)
{
Line 400 ⟶ 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 481 ⟶ 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 494 ⟶ 612:
 
function XEBPopupRef(e){
 
m=new GetPos(e||event);
 
Line 501 ⟶ 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 507 ⟶ 626:
 
curPopup.setInnerHTML(mt);
// document.XEBPopupRefForm.refName.focus();
return true;
}
Line 517 ⟶ 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 540 ⟶ 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 644 ⟶ 763:
mt='<p>Enter the image parameters below: <\/p>'
+'<form name="XEBPopupImageForm">'
+'File:<input type="text" name="imgFile" value="' + XEBGetSelectedText() + '" size="30"><br>'
+'Type:<SELECT NAME="imgType">'
+'<OPTION VALUE="thumb">Thumbnail'
Line 681 ⟶ 800:
 
return false;
 
 
}
 
Line 727 ⟶ 844:
return true;
}
 
function XEBUpdateSampleText()
{
Line 742 ⟶ 860:
 
targ.style.color='black';
}
 
function XEBMenuMouseOver(e)
{ var targ;
Line 757 ⟶ 875:
//=======================================================================
 
function getElementsByClassNameXEBgetElementsByClassName(parent,clsName,htmltag){
var arr = new Array();
var elems = parent.getElementsByTagName(htmltag);
Line 767 ⟶ 885:
return arr;
}
 
function extendSummary(newText)
{