Menu:

Recent Entries

Categories

Archives

Links

Blogs
- Dflying's Night
- David's Untitled Life
- Dflying's Blog in Chinese

This blog is hosted by DreamHost!

Syndicate

RSS 0.90
RSS 1.0
RSS 2.0
Atom 0.3

Atlas Drag & Drop Overview

Dflying | 13 March, 2006 04:53

The Atlas framework provides amazing cross-browser support for drag & drop operations. Basically, to create a UI with drag & drop is really simple and we just need:


So, the steps we needed to create a drag & drop UI could be

In summary, a drag & drop operation is tipically started by an IDragSource object with the call to the startDragDrop() method of the DragDropManager. Then, the operation is handled by the DragDropManager, through calls to the IDragSource methods of the item being dragged, and IDropTarget methods of the registered drop target(s).

Built-in Classes for Drag & Drop

Before getting into the drag & drop engine details (later posts, maybe), it's better to look at some built-in controls and behaviors provided by the Atlas framework to perform drag & drop operations. Obviously, all these classes implement the IDragSource, IDropTarget interface, or both. Note these controls are all in client side.

DEMO

In the example, we'll build a simple page with draggable content (Take a look to Start or Windows Live page for more complex examples of this kind of layout and functionality. If you are familiar with ASP.NET Web Parts, that is almost the same.) by using the DragDropList and DraggableListItem behaviors. Another example using the DragDropList and other drag & drop examples can be found in Wilco's website. You can found the full code for this example at the end of this post. First of all, let's create the page with static layout (think of it as a "screenshot" of the final dynamic layout). Then, we'll add dynamic behaviors to controls with some Atlas markup. I've created two zones that are supposed to act as drop zones for draggable content. The draggable content is represented by panels with ASP.NET controls inside them.

<!-- Left Area -->
<div id="leftArea" class="list1">
    <div id="content1" class="item">
        <div id="content1Title" class="itemTitle">Content 1</div>
        <div class="itemContent">
            <asp:login id="myLogin" runat="server"></asp:login>
        </div>
    </div>
    <div id="content2" class="item">
        <div id="content2Title" class="itemTitle">Content 2</div>
        <div class="itemContent">
            Dflying's Item
        </div>
    </div>
</div>
<!-- Right Area -->
<div id="rightArea" class="list2">
    <div id="content3" class="item">
        <div id="content3Title" class="itemTitle">
            Content 3</div>
        <div class="itemContent">
            <asp:calendar id="myCalendar" runat="server" cssclass="centered"></asp:calendar>
        </div>
    </div>
</div>

I've created two drop zones and three content panels inside them, obtaining the static layout for the page. Now, we need some HTML to represent the "highlighted" content area when a panel is dragged over (the dropCueTemplate), and some HTML to display when all the panels have been moved away from a drop zone (the emptyTemplate).

<!-- Hide template elements -->
<div class="templates">
    <!-- DropCue Template -->
    <div id="dropCueTemplate" class="dropCue">
    </div>
    <!-- Empty Template -->
    <div id="emptyTemplate" class="emptyList">
        Drop content here.</div>
</div>

Ok, we are ready to make this a dynamic page by adding Atlas markup. The two drop zones will become two Atlas controls with DragDropList behavior. The code for the left drop area is

<!-- Left Area -->
<control id="leftArea">
    <behaviors>
        <dragDropList dataType="HTML" acceptedDataTypes="'HTML'"
                      dragMode="Move" direction="Vertical">
            <dropCueTemplate>
                <template layoutElement="dropCueTemplate" />
            </dropCueTemplate>
            <emptyTemplate>
                <template layoutElement="emptyTemplate" />
            </emptyTemplate>
        </dragDropList>
    </behaviors>
</control>
<!-- Right Area -->
<control id="rightArea">
    <behaviors>
        <dragDropList dataType="HTML" acceptedDataTypes="'HTML'"
                      dragMode="Move" direction="Vertical">
            <dropCueTemplate>
                <template layoutElement="dropCueTemplate" />
            </dropCueTemplate>
            <emptyTemplate>
                <template layoutElement="emptyTemplate" />
            </emptyTemplate>
        </dragDropList>
    </behaviors>
</control>

while the code for the right area is similar. In the above code, we have wrapped the "leftArea" <div> element in an Atlas control, and added a DragDropList behavior to it. This DragDropList holds data of type "HTML", accepts data of type "HTML", has a Vertical orientation (the directon can be Horizontal or Vertical) and the drag operation is done by moving the whole item (the other option is dragMode="Copy", that drags a copy of the item). Inside the <dragDropList> element we have specified, by providing their IDs, which DOM elements to use as the dropCueTemplate and the emptyTemplate. Let's see the markup for one of the content panels (the code for the other panels is similar):

<!-- Draggable items -->
<control id="content1">
    <behaviors>
        <draggableListItem handle="content1Title" dataType="HTML" />
    </behaviors>
</control>

Again, the DOM element "content1" becomes an Atlas control with a draggableListItem behavior. This behavior allows the content panel to be dragged. The handle attribute contains the ID of an element that acts as the "grip" for the drag operation. I've set the handle to be the header of each content panel. Finally, our draggableListItem holds data of type "HTML". This means that we can drop this item on drop targets that accept data of type "HTML". A similar declaration is repeated for each content panel defined as static HTML in the page.

Here's the full source code: Atlas Drag and Drop Demo

Posted in Atlas. Comment: (1). Trackbacks:(195). Permalink
«Next post | Previous post»

Referers

Comments

  1. 1. Malini  |  11/22,2007 at 00:19

    Hi Dflying ,
    I red your drag and drop exaples(Shopping cart) . But Drag and drop is limited to webpage . How to implement drag file from desktop and drop in to fileupload control, where text area get the dragged file path .Is there any solution?

    Malini

Leave a Reply

Auth Image