Forum Moderators: open

Message Too Old, No Replies

need this translated to cross-browser

anyone willing to look at it?

         

txbakers

2:24 am on Apr 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This works fine in IE. I'd like it to also work in gecko (firefox, mozilla, NN7) and Safari.

I don't need it to work in any old Netscape.

var dragapproved=false
var z,x,y
function move(){
if (event.button==1&&dragapproved){
z.style.pixelLeft=temp1+event.clientX-x
z.style.pixelTop=temp2+event.clientY-y
return false
}
}
function drags(){
if (!document.all) return
if (event.srcElement.className=="drag"){
dragapproved=true
z=event.srcElement
temp1=z.style.pixelLeft
temp2=z.style.pixelTop
x=event.clientX
y=event.clientY
document.onmousemove=move
}
}
document.onmousedown=drags
document.onmouseup=new Function("dragapproved=false")

Bernard Marx

3:13 am on Apr 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I got this far:
(NB: Replace all ¦¦ with unbroken pipe chars!)

getEventSrc = window.Event
? function(e){var targ=e.target;return targ.nodeType==1?targ:targ.parentNode}
: function() {return event.srcElement}

var dragapproved=false
var z,x,y
var leftButton = Event? 0:1;

function move(eMoz) // <- may need more info here
{
var e = eMoz¦¦event;
if (!(e.button==1 && dragapproved)) return;
z.style.left = temp1 + event.clientX-x + 'px';
z.style.top = temp2 + event.clientY-y + 'px';
return false;
}

function drags(eMoz)
{
var src = getEventSrc(eMoz);
if (src.className!="drag") return;
dragapproved = true;
z = src;
temp1 = parseInt(z.style.left);
temp2 = parseInt(z.style.top)
x = (eMoz¦¦event).clientX;
y = (eMoz¦¦event).clientY;
/* This isn't removed onmouseup
Perhaps it should be. */
document.onmousemove = move;
}

document.onmousedown = drags;
document.onmouseup = function(){ dragapproved = false };

..then I remembered that there's a very good and simple drag'n'drop script (+ very decent explanation) at BrainJar [brainjar.com]

If that's no use, I'll try and complete the task after I've woken up.

Bernard Marx

8:39 am on Apr 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It now works in IE && FF:
(again, change ¦ to a 'real' ¦)

getEventSrc = window.Event
? function(e){var targ=e.target;return targ.nodeType==1?targ:targ.parentNode}
: function() {return event.srcElement}

var dragapproved=false
var z,x,y
var leftButton = window.Event? 0:1;

function move(eMoz)
{
var e = eMoz¦¦event;
if (!(dragapproved && e.button==leftButton)) return;
z.style.left = temp1 + e.clientX-x + 'px';
z.style.top = temp2 + e.clientY-y + 'px';
return false;
}

function drags(eMoz)
{
var src = getEventSrc(eMoz);
if (src.className!="drag") return;
dragapproved = true;
z = src;
temp1 = parseInt(z.style.left);
temp2 = parseInt(z.style.top);
x = (eMoz¦¦event).clientX;
y = (eMoz¦¦event).clientY;
document.onmousemove = move;
}

document.onmousedown = drags;
document.onmouseup = function(){
dragapproved = false ;
// added this - remove if any problem
document.onmousemove = null;

};

txbakers

11:58 am on Apr 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks! I'll give it a try.