Hi,
Just wondering if anyone had any success implementing drag and drop?
Using script.aculo.us/shop as an example I took the advice of using the concepts from Textfield#dragContentsTo and added the following method to Image. I stripped out the select(), because it didn't seem to work for images, and all the value copying stuff, so it came out to this:
def drag_to(destination)
@o.focus
@o.fireEvent("ondragstart")
@o.fireEvent("ondrag")
destination.fireEvent("onDragEnter")
destination.fireEvent("onDragOver")
destination.fireEvent("ondrop")
@o.fireEvent("ondragend")
end
The result was lots of yellow flashing in the 'cart' div, but an empty cart (see also, IRB output below for testcase). Am I missing something?
Interestingly, this msdn article[1] suggests that some additional magic is required for div's:
"In the case of a div, the default action is not to drop. This can be contrasted with the case of an input type=text element, where the default action is to drop. In order to allow a drag-and-drop action on a div, you must cancel the default action by specifying window.event.returnValue=false in both the ondragenter and ondragover event handlers. Only then will ondrop fire."
Any idea if (a) I'm barking up the right tree with this and (b) how I go about implementing those event handlers from watir/win32ole?
Paul
[1] http://msdn.microsoft.com/workshop/author/dhtml/reference/events/ondrop.asp
----------------------------------------------------------------
irb(main):001:0> require_gem 'watir'
=> true
irb(main):002:0> include Watir
=> Object
irb(main):003:0> ie = IE.new
=> #<Watir::IE:0x2d612d8 @defaultSleepTime=0.1, @activeObjectHighLightColor="yellow", @enable_spinner=false, @url_list=[
], @logger=#<Watir::DefaultLogger:0x2d61218 @level=2, @datetime_format="%d-%b-%Y %H:%M:%S", @progname=nil, @logdev=#<Log
ger::LogDevice:0x2d611b8 @shift_age=nil, @filename=nil, @dev=#<IO:0x27de7d0>, @shift_size=nil>>, @typingspeed=0.08, @for
m=nil, @ie=#<WIN32OLE:0x2d61278>, @error_checkers=[#<Proc:[EMAIL PROTECTED]:/dev/ruby/lib/ruby/gems/1.8/gems/watir-1.4.1/./wa
tir.rb:1135>]>
irb(main):004:0> ie.goto('http://demo.script.aculo.us/shop')
=> 1.609
irb(main):005:0> class Image
irb(main):006:1> def drag_to(destination)
irb(main):007:2> @o.focus
irb(main):008:2> @o.fireEvent("ondragstart")
irb(main):009:2> @o.fireEvent("ondrag")
irb(main):010:2> destination.fireEvent("onDragEnter")
irb(main):011:2> destination.fireEvent("onDragOver")
irb(main):012:2> destination.fireEvent("ondrop")
irb(main):013:2> @o.fireEvent("ondragend")
irb(main):014:2> end
irb(main):015:1> end
=> nil
irb(main):016:0> cart = ie.div(:id, 'cart')
=> #<Watir::Div:0x2d41d60 @activeObjectHighLightColor="yellow", @how=:id, @ieController=#<Watir::IE:0x2d612d8 @pageHasRe
loaded=true, @defaultSleepTime=0.1, @activeObjectHighLightColor="yellow", @enable_spinner=false, @url_list=["http://demo
.script.aculo.us/shop"], @logger=#<Watir::DefaultLogger:0x2d61218 @level=2, @datetime_format="%d-%b-%Y %H:%M:%S", @progn
ame=nil, @logdev=#<Logger::LogDevice:0x2d611b8 @shift_age=nil, @filename=nil, @dev=#<IO:0x27de7d0>, @shift_size=nil>>, @
typingspeed=0.08, @form=nil, @ie=#<WIN32OLE:0x2d61278>, @down_load_time=1.609, @error_checkers=[#<Proc:[EMAIL PROTECTED]:/dev
/ruby/lib/ruby/gems/1.8/gems/watir-1.4.1/./watir.rb:1135>]>, @originalColor=nil, @typingspeed=0.08, @o=#<WIN32OLE:0x2d41
a30>, @what="cart">
irb(main):017:0> ie.image(:id, 'product_1').drag_to(cart)
=> true
irb(main):018:0>
This message and any attachments (the "message") is intended solely for the addressees and is confidential. If you receive this message in error, please delete it and immediately notify the sender. Any use not in accord with its purpose, any dissemination or disclosure, either whole or partial, is prohibited except formal approval. The internet can not guarantee the integrity of this message. BNP PARIBAS (and its subsidiaries) shall (will) not therefore be liable for the message if modified.
********************************************************************************************** BNP Paribas Private Bank London Branch is authorised by CECEI & AMF and is regulated by the Financial Services Authority for the conduct of its investment business in the United Kingdom. BNP Paribas Securities Services London Branch is authorised by CECEI & AMF and is regulated by the Financial Services Authority for the conduct of its investment business in the United Kingdom. BNP Paribas Fund Services UK Limited is authorised and regulated by the Financial Services Authority
_______________________________________________ Wtr-general mailing list [email protected] http://rubyforge.org/mailman/listinfo/wtr-general
