5 <title>jQuery UI Droppable - Shopping Cart Demo</title>
6 <link rel="stylesheet" href="../../themes/base/jquery.ui.all.css">
7 <script src="../../jquery-1.9.1.js"></script>
8 <script src="../../ui/jquery.ui.core.js"></script>
9 <script src="../../ui/jquery.ui.widget.js"></script>
10 <script src="../../ui/jquery.ui.mouse.js"></script>
11 <script src="../../ui/jquery.ui.draggable.js"></script>
12 <script src="../../ui/jquery.ui.droppable.js"></script>
13 <script src="../../ui/jquery.ui.sortable.js"></script>
14 <script src="../../ui/jquery.ui.accordion.js"></script>
15 <link rel="stylesheet" href="../demos.css">
17 h1 { padding: .2em; margin: 0; }
18 #products { float:left; width: 500px; margin-right: 2em; }
19 #cart { width: 200px; float: left; margin-top: 1em; }
20 /* style the list to maximize the droppable hitarea */
21 #cart ol { margin: 0; padding: 1em 0 1em 3em; }
25 $( "#catalog" ).accordion();
26 $( "#catalog li" ).draggable({
30 $( "#cart ol" ).droppable({
31 activeClass: "ui-state-default",
32 hoverClass: "ui-state-hover",
33 accept: ":not(.ui-sortable-helper)",
34 drop: function( event, ui ) {
35 $( this ).find( ".placeholder" ).remove();
36 $( "<li></li>" ).text( ui.draggable.text() ).appendTo( this );
39 items: "li:not(.placeholder)",
41 // gets added unintentionally by droppable interacting with sortable
42 // using connectWithSortable fixes this, but doesn't allow you to customize active/hoverClass options
43 $( this ).removeClass( "ui-state-default" );
52 <h1 class="ui-widget-header">Products</h1>
54 <h2><a href="#">T-Shirts</a></h2>
58 <li>Cheezeburger Shirt</li>
62 <h2><a href="#">Bags</a></h2>
65 <li>Zebra Striped</li>
66 <li>Black Leather</li>
67 <li>Alligator Leather</li>
70 <h2><a href="#">Gadgets</a></h2>
82 <h1 class="ui-widget-header">Shopping Cart</h1>
83 <div class="ui-widget-content">
85 <li class="placeholder">Add your items here</li>
90 <div class="demo-description">
91 <p>Demonstrate how to use an accordion to structure products into a catalog and make use of drag and drop for adding them to a shopping cart, where they are sortable.</p>