04.11.2015 Views

javascript

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 21: Upcoming API s<br />

❑<br />

❑<br />

❑<br />

❑<br />

“ copyLink ” — dropEffect “ copy ” and “ link ” are allowed.<br />

“ copyMove ” — dropEffect “ copy ” and “ move ” are allowed.<br />

“ linkMove ” — dropEffect “ link ” and “ move ” are allowed.<br />

“ all ” — All dropEffect values are allowed.<br />

This property must be set inside the ondragstart event handler.<br />

Suppose that you want to allow a user to move text from a text box into a < div > . To accomplish this, you<br />

must set both dropEffect and effectAllowed to “ move ” . The text won ’ t automatically move itself<br />

because the default behavior for the drop event on a < div > is to do nothing. If you override the default<br />

behavior, the text is automatically removed from the text box. It is then up to you to insert it into the<br />

< div > to finish the action. If you were to change dropEffect and effectAllowed to “ copy ” , the text<br />

in the text box would not automatically be removed.<br />

Additional Members<br />

The HTML 5 specification indicates the following additional methods on the dataTransfer object:<br />

❑<br />

❑<br />

❑<br />

❑<br />

addElement( element ) — Adds an element to the drag operation. This is purely for data<br />

purposes and doesn ’ t affect the appearance of the drag operation.<br />

clearData( format ) — Clears the data being stored with the particular format. This has been<br />

implemented in IE, Firefox, Chrome, and Safari.<br />

setDragImage( element , x , y ) — Allows you to specify an image to be displayed under the<br />

cursor as the drag takes place. This method accepts three arguments: an HTML element to<br />

display, and the x - and y - coordinates on the image where the cursor should be positioned. The<br />

HTML element may be an image, in which case the image is displayed, or any other element, in<br />

which case a rendering of the element is displayed. Safari is the only browser that has this<br />

method; however, it doesn ’ t appear to work.<br />

types — A list of data types currently being stored. This is not yet implemented in any browsers.<br />

The WebSocket Type<br />

Another interesting addition to HTML 5 is the WebSocket type, a facility for enabling bidirectional<br />

communication between the browser and server. The WebSocket constructor takes a single argument<br />

that indicates the URL with which to make the connection. This URL must specify the ws or wss protocol<br />

and an absolute URL. A connection to the URL is initiated as soon as the constructor is called. Here’s an<br />

example:<br />

var socket = new WebSocket(“ws://www.yourdomain.com/connect/”);<br />

The current state of the WebSocket object can be determined by using the readyState property, whose<br />

value will be one of the following: 0 to indicate that it ’ s connecting, 1 to indicate that the connection is<br />

700

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!