source: main/trunk/greenstone3/web/interfaces/oran/js/jquery-ui-1.8rc1/demos/droppable/photo-manager.html@ 24245

Last change on this file since 24245 was 24245, checked in by sjb48, 13 years ago

Oran code for supporting format changes to document.

  • Property svn:executable set to *
File size: 7.3 KB
Line 
1<!doctype html>
2<html lang="en">
3 <head>
4 <title>jQuery UI Droppable - Simple photo manager</title>
5 <link type="text/css" href="../../themes/base/ui.all.css" rel="stylesheet" />
6 <script type="text/javascript" src="../../jquery-1.4.1.js"></script>
7 <script type="text/javascript" src="../../ui/jquery.ui.core.js"></script>
8 <script type="text/javascript" src="../../ui/jquery.ui.widget.js"></script>
9 <script type="text/javascript" src="../../ui/jquery.ui.mouse.js"></script>
10 <script type="text/javascript" src="../../ui/jquery.ui.draggable.js"></script>
11 <script type="text/javascript" src="../../ui/jquery.ui.droppable.js"></script>
12 <script type="text/javascript" src="../../ui/jquery.ui.resizable.js"></script>
13 <script type="text/javascript" src="../../ui/jquery.ui.dialog.js"></script>
14 <link type="text/css" href="../demos.css" rel="stylesheet" />
15 <style type="text/css">
16 #gallery { float: left; width: 65%; min-height: 12em; } * html #gallery { height: 12em; } /* IE6 */
17 .gallery.custom-state-active { background: #eee; }
18 .gallery li { float: left; width: 96px; padding: 0.4em; margin: 0 0.4em 0.4em 0; text-align: center; }
19 .gallery li h5 { margin: 0 0 0.4em; cursor: move; }
20 .gallery li a { float: right; }
21 .gallery li a.ui-icon-zoomin { float: left; }
22 .gallery li img { width: 100%; cursor: move; }
23
24 #trash { float: right; width: 32%; min-height: 18em; padding: 1%;} * html #trash { height: 18em; } /* IE6 */
25 #trash h4 { line-height: 16px; margin: 0 0 0.4em; }
26 #trash h4 .ui-icon { float: left; }
27 #trash .gallery h5 { display: none; }
28 </style>
29 <script type="text/javascript">
30 $(function() {
31 // there's the gallery and the trash
32 var $gallery = $('#gallery'), $trash = $('#trash');
33
34 // let the gallery items be draggable
35 $('li',$gallery).draggable({
36 cancel: 'a.ui-icon',// clicking an icon won't initiate dragging
37 revert: 'invalid', // when not dropped, the item will revert back to its initial position
38 containment: $('#demo-frame').length ? '#demo-frame' : 'document', // stick to demo-frame if present
39 helper: 'clone',
40 cursor: 'move'
41 });
42
43 // let the trash be droppable, accepting the gallery items
44 $trash.droppable({
45 accept: '#gallery > li',
46 activeClass: 'ui-state-highlight',
47 drop: function(ev, ui) {
48 deleteImage(ui.draggable);
49 }
50 });
51
52 // let the gallery be droppable as well, accepting items from the trash
53 $gallery.droppable({
54 accept: '#trash li',
55 activeClass: 'custom-state-active',
56 drop: function(ev, ui) {
57 recycleImage(ui.draggable);
58 }
59 });
60
61 // image deletion function
62 var recycle_icon = '<a href="link/to/recycle/script/when/we/have/js/off" title="Recycle this image" class="ui-icon ui-icon-refresh">Recycle image</a>';
63 function deleteImage($item) {
64 $item.fadeOut(function() {
65 var $list = $('ul',$trash).length ? $('ul',$trash) : $('<ul class="gallery ui-helper-reset"/>').appendTo($trash);
66
67 $item.find('a.ui-icon-trash').remove();
68 $item.append(recycle_icon).appendTo($list).fadeIn(function() {
69 $item.animate({ width: '48px' }).find('img').animate({ height: '36px' });
70 });
71 });
72 }
73
74 // image recycle function
75 var trash_icon = '<a href="link/to/trash/script/when/we/have/js/off" title="Delete this image" class="ui-icon ui-icon-trash">Delete image</a>';
76 function recycleImage($item) {
77 $item.fadeOut(function() {
78 $item.find('a.ui-icon-refresh').remove();
79 $item.css('width','96px').append(trash_icon).find('img').css('height','72px').end().appendTo($gallery).fadeIn();
80 });
81 }
82
83 // image preview function, demonstrating the ui.dialog used as a modal window
84 function viewLargerImage($link) {
85 var src = $link.attr('href');
86 var title = $link.siblings('img').attr('alt');
87 var $modal = $('img[src$="'+src+'"]');
88
89 if ($modal.length) {
90 $modal.dialog('open')
91 } else {
92 var img = $('<img alt="'+title+'" width="384" height="288" style="display:none;padding: 8px;" />')
93 .attr('src',src).appendTo('body');
94 setTimeout(function() {
95 img.dialog({
96 title: title,
97 width: 400,
98 modal: true
99 });
100 }, 1);
101 }
102 }
103
104 // resolve the icons behavior with event delegation
105 $('ul.gallery > li').click(function(ev) {
106 var $item = $(this);
107 var $target = $(ev.target);
108
109 if ($target.is('a.ui-icon-trash')) {
110 deleteImage($item);
111 } else if ($target.is('a.ui-icon-zoomin')) {
112 viewLargerImage($target);
113 } else if ($target.is('a.ui-icon-refresh')) {
114 recycleImage($item);
115 }
116
117 return false;
118 });
119 });
120 </script>
121 </head>
122 <body>
123 <div class="demo ui-widget ui-helper-clearfix">
124
125 <ul id="gallery" class="gallery ui-helper-reset ui-helper-clearfix">
126 <li class="ui-widget-content ui-corner-tr">
127 <h5 class="ui-widget-header">High Tatras</h5>
128 <img src="images/high_tatras_min.jpg" alt="The peaks of High Tatras" width="96" height="72" />
129 <a href="images/high_tatras.jpg" title="View larger image" class="ui-icon ui-icon-zoomin">View larger</a>
130 <a href="link/to/trash/script/when/we/have/js/off" title="Delete this image" class="ui-icon ui-icon-trash">Delete image</a>
131 </li>
132 <li class="ui-widget-content ui-corner-tr">
133 <h5 class="ui-widget-header">High Tatras 2</h5>
134 <img src="images/high_tatras2_min.jpg" alt="The chalet at the Green mountain lake" width="96" height="72" />
135 <a href="images/high_tatras2.jpg" title="View larger image" class="ui-icon ui-icon-zoomin">View larger</a>
136 <a href="link/to/trash/script/when/we/have/js/off" title="Delete this image" class="ui-icon ui-icon-trash">Delete image</a>
137 </li>
138 <li class="ui-widget-content ui-corner-tr">
139 <h5 class="ui-widget-header">High Tatras 3</h5>
140 <img src="images/high_tatras3_min.jpg" alt="Planning the ascent" width="96" height="72" />
141 <a href="images/high_tatras3.jpg" title="View larger image" class="ui-icon ui-icon-zoomin">View larger</a>
142 <a href="link/to/trash/script/when/we/have/js/off" title="Delete this image" class="ui-icon ui-icon-trash">Delete image</a>
143 </li>
144 <li class="ui-widget-content ui-corner-tr">
145 <h5 class="ui-widget-header">High Tatras 4</h5>
146 <img src="images/high_tatras4_min.jpg" alt="On top of Kozi kopka" width="96" height="72" />
147 <a href="images/high_tatras4.jpg" title="View larger image" class="ui-icon ui-icon-zoomin">View larger</a>
148 <a href="link/to/trash/script/when/we/have/js/off" title="Delete this image" class="ui-icon ui-icon-trash">Delete image</a>
149 </li>
150 </ul>
151
152 <div id="trash" class="ui-widget-content ui-state-default">
153 <h4 class="ui-widget-header"><span class="ui-icon ui-icon-trash">Trash</span> Trash</h4>
154 </div>
155
156 </div><!-- End demo -->
157
158 <div class="demo-description">
159
160 <p>You can delete an image either by dragging it to the Trash or by clicking the trash icon.</p>
161 <p>You can "recycle" an image by dragging it back to the gallery or by clicking the recycle icon.</p>
162 <p>You can view larger image by clicking the zoom icon. jQuery UI dialog widget is used for the modal window.</p>
163
164 </div><!-- End demo-description -->
165 </body>
166</html>
Note: See TracBrowser for help on using the repository browser.