27.10.2015 Views

AJAX and PHP

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

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

<strong>AJAX</strong> Drag <strong>and</strong> Drop<br />

A few websites have already put this into practice. One such example is Panic Goods—selling<br />

t-shirts! The URL for this is: http://www.panic.com/goods.<br />

Notice the light blue bar on the bottom of the screen? That's the actual shopping cart. Just drag<br />

some t-shirts from the catalog, <strong>and</strong> drop them into the shopping cart, to see how the cart performs.<br />

Products are lined up in the cart <strong>and</strong> it's easy to see what you have chosen <strong>and</strong> for what amount.<br />

Drag items outside the light blue bar to remove them from the cart. Pretty impressive, isn't it?<br />

Sortable Lists<br />

There's a type of list we probably use daily, namely, a to-do list. We usually use yellow Post-its<br />

<strong>and</strong> some of us even use specialized software.<br />

But with so many new web applications available out there, surely there must be a dozen to-do list<br />

applications! I'll just mention Ta-da Lists (http://www.tadalist.com), created by 37signals.<br />

This company has actually reinvented the entire concept of web applications <strong>and</strong> has taken it to the<br />

next level. Ta-da Lists, one of its first products, is a tool that allows you to create several to-do<br />

lists, each with its own items (things to do, that is). It's a really helpful tool <strong>and</strong> a lot of people use<br />

it, although most of them have upgraded to other 37signals products like Basecamp<br />

(http://www.basecamphq.com) <strong>and</strong> Backpack (http://www.backpackit.com).<br />

Despite its intuitive user interface <strong>and</strong> easy-to-use actions, Ta-da Lists lacks a very basic feature<br />

that would greatly increase its usability: dragging <strong>and</strong> dropping list items, thus reordering the list.<br />

To reorder a list in Ta-da Lists, you have to click on a link that will refresh the page <strong>and</strong> display<br />

four arrow buttons (bring to front, move up, move down, <strong>and</strong> send to back).<br />

Although this implementation works well, a drag-<strong>and</strong>-drop system would make it faster <strong>and</strong> easier<br />

to use. 37signals have improved this functionality in Basecamp, though, <strong>and</strong> the to-do lists in there<br />

have draggable items—an upgrade that proves the usability of the drag-<strong>and</strong>-drop concept.<br />

Building the <strong>AJAX</strong> Drag-<strong>and</strong>-Drop Sortable List<br />

Application<br />

One thing that sets this application apart from other applications we've built in this book is that in<br />

this case, we are going to use two external JavaScript frameworks: Prototype <strong>and</strong> script.aculo.us.<br />

"Prototype is a JavaScript framework that aims to ease development of dynamic web<br />

applications." It was created by Sam Stephenson <strong>and</strong> is quickly becoming the JavaScript<br />

framework, because of its great functionality.<br />

Prototype is distributed under an MIT-style license <strong>and</strong> it can be downloaded from<br />

http://prototype.conio.net.<br />

If you want to learn more about Prototype, check out the tutorial on<br />

http://www.particletree.com/features/quick-guide-to-prototype.<br />

238<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!