From 95a243753614b21a165966c589780706a31ed53f Mon Sep 17 00:00:00 2001 From: Matthew Noorenberghe Date: Sun, 23 Feb 2014 00:52:37 -0800 Subject: Switch from browser detection using document.all to feature detection --- find.php | 21 +++--------- lifespan.php | 6 ++-- .../_MEDIA/media_0_inverselink.php | 37 ++++++++++++---------- 3 files changed, 29 insertions(+), 35 deletions(-) diff --git a/find.php b/find.php index 287f66476c..f931f2c320 100644 --- a/find.php +++ b/find.php @@ -334,23 +334,12 @@ if ($type == "facts") { DefaultTag.prototype= { _newCounter:0 ,view:function() { - var row=document.createElement("tr"),cell,o; + var row=document.createElement("tr"),cell; row.appendChild(cell=document.createElement("td")); - o=null; - if (document.all) { - //Old IEs handle the creation of a checkbox already checked, as far as I know, only in this way - try { - o=document.createElement(""); - } catch(e) { - o=null; - } - } - if (!o) { - o=document.createElement("input"); - o.setAttribute("id","tag"+this._counter); - o.setAttribute("type","checkbox"); - if (this.selected) o.setAttribute("checked", "checked"); - } + var o = document.createElement("input"); + o.id = "tag"+this._counter; + o.type = "checkbox"; + o.checked = this.selected; o.DefaultTag=this; o.ParentRow=row; o.onclick=function() { diff --git a/lifespan.php b/lifespan.php index cd775c4d7d..1524ac47a4 100644 --- a/lifespan.php +++ b/lifespan.php @@ -98,10 +98,11 @@ $controller } // Main function to retrieve mouse x-y pos.s function getMouseXY(e) { - if (IE) { // grab the x-y pos.s if browser is IE + var event = e || window.event; + if (typeof event.pageX === "undefined" || typeof event.pageY === "undefined") { msX = event.clientX + document.documentElement.scrollLeft; msY = event.clientY + document.documentElement.scrollTop; - } else { // grab the x-y pos.s if browser is NS + } else { msX = e.pageX; msY = e.pageY; } @@ -124,7 +125,6 @@ $controller } } - var IE = document.all?true:false; document.onmousemove = getMouseXY; document.onmouseup = releaseimage; '); diff --git a/modules_v3/GEDFact_assistant/_MEDIA/media_0_inverselink.php b/modules_v3/GEDFact_assistant/_MEDIA/media_0_inverselink.php index ec04709d2d..a6bf55a1b1 100644 --- a/modules_v3/GEDFact_assistant/_MEDIA/media_0_inverselink.php +++ b/modules_v3/GEDFact_assistant/_MEDIA/media_0_inverselink.php @@ -270,10 +270,10 @@ function insertRowToTable(pid, nam, head) var numrows = links.rows.length; var strRow = ''; for (var i=1; i Date: Sun, 23 Feb 2014 00:58:00 -0800 Subject: Declare JS variables in timeline.php to avoid automatic globals --- timeline.php | 257 +++++++++++++++++++++++++++++------------------------------ 1 file changed, 127 insertions(+), 130 deletions(-) diff --git a/timeline.php b/timeline.php index c7c658d4bf..259566bb88 100644 --- a/timeline.php +++ b/timeline.php @@ -43,6 +43,7 @@ var ob=null; var Y=0; var X=0; var oldx=0; +var oldlinew; var personnum=0; var type=0; var state=0; @@ -53,12 +54,9 @@ function ageMD(divbox, num) { ob=divbox; personnum=num; type=0; - if (N) { - X=ob.offsetLeft; - Y=ob.offsetTop; - } else { - X=ob.offsetLeft; - Y=ob.offsetTop; + X=ob.offsetLeft; + Y=ob.offsetTop; + if (!N) { oldx = event.clientX + document.documentElement.scrollLeft; } } @@ -69,143 +67,142 @@ function factMD(divbox, num, mean) { personnum=num; boxmean = mean; type=1; + oldx=ob.offsetLeft; if (N) { - oldx=ob.offsetLeft; oldlinew=0; - } - else { - oldx = ob.offsetLeft; + } else { oldlinew = event.clientX + document.documentElement.scrollLeft; } } function MM(e) { - if (ob) { - tldiv = document.getElementById("timeline_chart"); - if (type==0) { - // age boxes - newy = 0; - newx = 0; - if (N) { - newy = e.pageY - tldiv.offsetTop; - newx = e.pageX - tldiv.offsetLeft; - if (oldx==0) oldx=newx; - } - else { - newy = event.clientY + document.documentElement.scrollTop - tldiv.offsetTop; - newx = event.clientX + document.documentElement.scrollLeft - tldiv.offsetLeft; - } - if ((newy >= topy-bheight/2)&&(newy<=bottomy)) newy = newy; - else if (newy < topy-bheight/2) newy = topy-bheight/2; - else newy = (bottomy-1); - ob.style.top = newy+"px"; - tyear = ((newy+bheight-4 - topy) + scale)/scale + baseyear - year = Math.floor(tyear); - month = Math.floor((tyear*12)-(year*12)); - day = Math.floor((tyear*365)-(year*365 + month*30)); - mstamp = (year*365)+(month*30)+day; - bdstamp = (birthyears[personnum]*365)+(birthmonths[personnum]*30)+birthdays[personnum]; - daydiff = mstamp - bdstamp; - ba = 1; - if (daydiff < 0 ) { - ba = -1; - daydiff = (bdstamp - mstamp); - } - yage = Math.floor(daydiff / 365); - mage = Math.floor((daydiff-(yage*365))/30); - dage = Math.floor(daydiff-(yage*365)-(mage*30)); - if (dage<0) mage = mage -1; - if (dage<-30) { - dage = 30+dage; - } - if (mage<0) yage = yage-1; - if (mage<-11) { - mage = 12+mage; - } - yearform = document.getElementById('yearform'+personnum); - ageform = document.getElementById('ageform'+personnum); - yearform.innerHTML = year+" "+month+" "+day+" "; - if (ba*yage>1 || ba*yage<-1 || ba*yage==0) - ageform.innerHTML = (ba*yage)+" "+(ba*mage)+" "+(ba*dage)+" "; - else ageform.innerHTML = (ba*yage)+" "+(ba*mage)+" "+(ba*dage)+" "; - var line = document.getElementById('ageline'+personnum); - temp = newx-oldx; - if (textDirection=='rtl') temp = temp * -1; - line.style.width=(line.width+temp)+"px"; - oldx=newx; - return false; + if (!ob) { + return true; + } + var tldiv = document.getElementById("timeline_chart"); + var newx = 0, newy = 0; + if (type==0) { + // age boxes + if (N) { + newy = e.pageY - tldiv.offsetTop; + newx = e.pageX - tldiv.offsetLeft; + if (oldx==0) oldx=newx; + } + else { + newy = event.clientY + document.documentElement.scrollTop - tldiv.offsetTop; + newx = event.clientX + document.documentElement.scrollLeft - tldiv.offsetLeft; + } + if ((newy >= topy-bheight/2)&&(newy<=bottomy)) newy = newy; + else if (newy < topy-bheight/2) newy = topy-bheight/2; + else newy = (bottomy-1); + ob.style.top = newy+"px"; + var tyear = ((newy+bheight-4 - topy) + scale)/scale + baseyear; + var year = Math.floor(tyear); + var month = Math.floor((tyear*12)-(year*12)); + var day = Math.floor((tyear*365)-(year*365 + month*30)); + var mstamp = (year*365)+(month*30)+day; + var bdstamp = (birthyears[personnum]*365)+(birthmonths[personnum]*30)+birthdays[personnum]; + var daydiff = mstamp - bdstamp; + var ba = 1; + if (daydiff < 0 ) { + ba = -1; + daydiff = (bdstamp - mstamp); + } + var yage = Math.floor(daydiff / 365); + var mage = Math.floor((daydiff-(yage*365))/30); + var dage = Math.floor(daydiff-(yage*365)-(mage*30)); + if (dage<0) mage = mage -1; + if (dage<-30) { + dage = 30+dage; + } + if (mage<0) yage = yage-1; + if (mage<-11) { + mage = 12+mage; + } + var yearform = document.getElementById('yearform'+personnum); + var ageform = document.getElementById('ageform'+personnum); + yearform.innerHTML = year+" "+month+" "+day+" "; + if (ba*yage>1 || ba*yage<-1 || ba*yage==0) + ageform.innerHTML = (ba*yage)+" "+(ba*mage)+" "+(ba*dage)+" "; + else ageform.innerHTML = (ba*yage)+" "+(ba*mage)+" "+(ba*dage)+" "; + var line = document.getElementById('ageline'+personnum); + var temp = newx-oldx; + if (textDirection=='rtl') temp = temp * -1; + line.style.width=(line.width+temp)+"px"; + oldx=newx; + return false; + } else { + // fact boxes + var linewidth; + if (N) { + newy = e.pageY - tldiv.offsetTop; + newx = e.pageX - tldiv.offsetLeft; + if (oldx==0) oldx=newx; + linewidth = e.pageX; } else { - newy = 0; - newx = 0; - if (N) { - newy = e.pageY - tldiv.offsetTop; - newx = e.pageX - tldiv.offsetLeft; - if (oldx==0) oldx=newx; - linewidth = e.pageX; + newy = event.clientY + document.documentElement.scrollTop - tldiv.offsetTop; + newx = event.clientX + document.documentElement.scrollLeft - tldiv.offsetLeft; + linewidth = event.clientX + document.documentElement.scrollLeft; + } + // get diagnal line box + dbox = document.getElementById('dbox'+personnum); + var etopy, ebottomy; + // set up limits + if (boxmean-175 < topy) etopy = topy; + else etopy = boxmean-175; + if (boxmean+175 > bottomy) ebottomy = bottomy; + else ebottomy = boxmean+175; + // check if in the bounds of the limits + if ((newy >= etopy)&&(newy<=ebottomy)) newy = newy; + else if (newy < etopy) newy = etopy; + else if (newy >ebottomy) newy = ebottomy; + // calculate the change in Y position + var dy = newy-ob.offsetTop; + // check if we are above the starting point and switch the background image + if (newy < boxmean) { + if (textDirection=='ltr') { + dbox.style.backgroundImage = "url('')"; + dbox.style.backgroundPosition = "0% 100%"; } else { - newy = event.clientY + document.documentElement.scrollTop - tldiv.offsetTop; - newx = event.clientX + document.documentElement.scrollLeft - tldiv.offsetLeft; - linewidth = event.clientX + document.documentElement.scrollLeft; + dbox.style.backgroundImage = "url('')"; + dbox.style.backgroundPosition = "0% 0%"; } - // get diagnal line box - dbox = document.getElementById('dbox'+personnum); - // set up limits - if (boxmean-175 < topy) etopy = topy; - else etopy = boxmean-175; - if (boxmean+175 > bottomy) ebottomy = bottomy; - else ebottomy = boxmean+175; - // check if in the bounds of the limits - if ((newy >= etopy)&&(newy<=ebottomy)) newy = newy; - else if (newy < etopy) newy = etopy; - else if (newy >ebottomy) newy = ebottomy; - // calculate the change in Y position - dy = newy-ob.offsetTop; - // check if we are above the starting point and switch the background image - if (newy < boxmean) { - if (textDirection=='ltr') { - dbox.style.backgroundImage = "url('')"; - dbox.style.backgroundPosition = "0% 100%"; - } else { - dbox.style.backgroundImage = "url('')"; - dbox.style.backgroundPosition = "0% 0%"; - } - dy = (-1)*dy; - state=1; - dbox.style.top = (newy+bheight/3)+"px"; + dy = (-1)*dy; + state=1; + dbox.style.top = (newy+bheight/3)+"px"; + } else { + if (textDirection=='ltr') { + dbox.style.backgroundImage = "url('')"; + dbox.style.backgroundPosition = "0% 0%"; } else { - if (textDirection=='ltr') { - dbox.style.backgroundImage = "url('')"; - dbox.style.backgroundPosition = "0% 0%"; - } else { - dbox.style.backgroundImage = "url('')"; - dbox.style.backgroundPosition = "0% 100%"; - } - - dbox.style.top = (boxmean+(bheight/3))+"px"; - state=0; + dbox.style.backgroundImage = "url('')"; + dbox.style.backgroundPosition = "0% 100%"; } - // the new X posistion moves the same as the y position - if (textDirection=='ltr') newx = dbox.offsetLeft+Math.abs(newy-boxmean); - else newx = dbox.offsetRight+Math.abs(newy-boxmean); - // set the X position of the box - if (textDirection=='ltr') ob.style.left=newx+"px"; - else ob.style.right=newx+"px"; - // set new top positions - ob.style.top = newy+"px"; - // get the width for the diagnal box - newwidth = (ob.offsetLeft-dbox.offsetLeft); - // set the width - dbox.style.width=newwidth+"px"; - if (textDirection=='rtl') dbox.style.right = (dbox.offsetRight - newwidth) + 'px'; - dbox.style.height=newwidth+"px"; - // change the line width to the change in the mouse X position - line = document.getElementById('boxline'+personnum); - if (oldlinew!=0) line.width=line.width+(linewidth-oldlinew); - oldlinew = linewidth; - oldx=newx; - oldstate=state; - return false; + + dbox.style.top = (boxmean+(bheight/3))+"px"; + state=0; } + // the new X posistion moves the same as the y position + if (textDirection=='ltr') newx = dbox.offsetLeft+Math.abs(newy-boxmean); + else newx = dbox.offsetRight+Math.abs(newy-boxmean); + // set the X position of the box + if (textDirection=='ltr') ob.style.left=newx+"px"; + else ob.style.right=newx+"px"; + // set new top positions + ob.style.top = newy+"px"; + // get the width for the diagnal box + var newwidth = (ob.offsetLeft-dbox.offsetLeft); + // set the width + dbox.style.width=newwidth+"px"; + if (textDirection=='rtl') dbox.style.right = (dbox.offsetRight - newwidth) + 'px'; + dbox.style.height=newwidth+"px"; + // change the line width to the change in the mouse X position + line = document.getElementById('boxline'+personnum); + if (oldlinew!=0) line.width=line.width+(linewidth-oldlinew); + oldlinew = linewidth; + oldx=newx; + oldstate=state; + return false; } } -- cgit v1.3