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