Oh, I thought the auto-adding of scrollbars was desired.  That's how
that original one you sent me works.  That's what I've been racking my
brain to fix in IE.  Anyway, I doubt we can get around it in
Mozilla-based browsers, but I can keep trying.  I suppose if we can
crack it, we should make it optional; maybe sometimes it is desirable
and other times not.  I'll try to work on making it less jumpy.  What I
sent yesterday was obviously pretty rough draft at this point.

Thanks for the feedback.

Greg

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of James
Peters
Sent: Wednesday, November 09, 2005 5:22 PM
To: [email protected]
Subject: RE: [Rails-spinoffs] Drag & Scroll

Yeah it lets me drag both horizontally & vertically, but only if there
is room to scroll (as it should).  So if there is no horizontal
scrollbar, it won't scroll horizontally - unlike your solution at the
moment.

Here is the javascript - I hope it's all self-contained:
http://demo.plainblack.com/extras/draggable.js

It looks like your solution is a great start, but it's pretty jumpy and
seems to keep scrolling even when there's no more room to scroll, but
that might be a problem with scriptaculous/prototype since (in Firefox
not IE) when I drag my DIV either to the right (off the page) or down
(off the page), it turns on the scrollbars and increases the scrollable
area automatically.

Not sure how easy that is to fix.

James


----- Original Message ----- 
Does it let you drag it horizontally, automatically scrolling with you, 
if there is no horizontal scrollbar? If so, then email me the url to 
the js file they use and I'll check it out. 

I tweaked my code a bit more, but it still has issues. It works great 
in Firefox. It also works in IE and Opera, so long as you don't try to 
drag past the end of the scrollbar (i.e. it scrolls along as long as 
there is a scrollbar to move). It doesn't work in Safari at all. 
Anyone is free to try it out and pitch in ideas. 

Copy and paste this code into a .js file and include it after you 
include scriptaculous (since it overloads functions from dragdrop.js), 
and you should have what I have so far: 

Object.extend(Draggable.prototype, { 
oldUpdate: Draggable.prototype.update, 
oldDraw: Draggable.prototype.draw, 
draw: function(event) { 
this.oldDraw(event); 
this.scrollIntoView(); 
}, 
scrollIntoView: function() { 
var offsets = Position.cumulativeOffset(this.element); 
var x = offsets[0]; 
var y = offsets[1]; 
var scrollX = 0; 
var scrollY = 0; 
if ( (x < document.body.scrollLeft + 5 && x > 0) 
|| (y < document.body.scrollTop + 5 && y > 0) 
) { 
scrollX = -5; 
scrollY = -5; 
} 
else { 
var elDimensions = Element.getDimensions(this.element); 
var winDimensions = Element.getDimensions(document.body); 

if (x + elDimensions.width > winDimensions.width - 5) { 
this.element.style.left = 
(parseInt(this.element.style.left.replace(/px/,'')) + 5) + 'px'; 
scrollX = 5; 
} 
if (y + elDimensions.height > winDimensions.height - 5) { 
this.element.style.top = 
(parseInt(this.element.style.top.replace(/px/,'')) + 5) + 'px'; 
scrollY = 5; 
} 
} 
if (scrollX != 0 || scrollY != 0) { 
window.scrollTo(document.body.scrollLeft + scrollX, 
document.body.scrollTop + scrollY); 
this.movedSinceScrolled = false; 
} 

// if we still have an active drag but the mouse hasn't moved since 
we started 
// scrolling, keep scrolling until they move it again 
if (this.active && ! this.movedSinceScrolled) { 
setTimeout(this.scrollIntoView.bind(this), 200); 
} 
}, 
update: function(event) { 
if (this.active) { 
this.movedSinceScrolled = true; 
} 
this.oldUpdate(event); 
} 
});

-- 
___________________________________________________
Play 100s of games for FREE! http://games.mail.com/

_______________________________________________
Rails-spinoffs mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
_______________________________________________
Rails-spinoffs mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs

Reply via email to