1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
|
<!doctype html>
<html lang="en">
<head>
<title>jQuery UI Droppable - Simple photo manager</title>
<link type="text/css" href="jqueryui/css/ui.all.css" rel="stylesheet" />
<script type="text/javascript" src="js/jquery-1.3.2.js"></script>
<script type="text/javascript" src="jqueryui/ui/ui.core.js"></script>
<script type="text/javascript" src="jqueryui/ui/ui.draggable.js"></script>
<script type="text/javascript" src="jqueryui/ui/ui.droppable.js"></script>
<script type="text/javascript" src="jqueryui/ui/ui.resizable.js"></script>
<script type="text/javascript" src="jqueryui/ui/ui.dialog.js"></script>
<link type="text/css" href="jqueryui/css/demos.css" rel="stylesheet" />
<link type="text/css" href="jqueryui/css/ui.theme.css" rel="stylesheet" />
<style type="text/css">
#gallery { float: left; width: 65%; min-height: 12em; } * html #gallery { height: 12em; } /* IE6 */
.gallery.custom-state-active { background: #eee; }
.gallery li { float: left; width: 96px; padding: 0.4em; margin: 0 0.4em 0.4em 0; text-align: center; }
.gallery li h5 { margin: 0 0 0.4em; cursor: move; }
.gallery li a { float: right; }
.gallery li a.ui-icon-zoomin { float: left; }
.gallery li img { width: 100%; cursor: move; }
#trash { float: right; width: 32%; min-height: 18em; padding: 1%;} * html #trash { height: 18em; } /* IE6 */
#trash h4 { line-height: 16px; margin: 0 0 0.4em; }
#trash h4 .ui-icon { float: left; }
#trash .gallery h5 { display: none; }
</style>
<script language="javascript" type="text/javascript">
function getXmlHttpRequestObject() {
if (window.XMLHttpRequest) {
return new XMLHttpRequest();
} else if(window.ActiveXObject) {
return new ActiveXObject("Microsoft.XMLHTTP");
} else {
throw new Error("Your browser don't support ajax");
}
}
var xhr = getXmlHttpRequestObject();
function getImages() {
if (xhr.readyState == 4 || xhr.readyState == 0) {
xhr.open("GET", 'images.php' , true);
xhr.onreadystatechange = handleimages;
xhr.send(null);
}
}
function handleimages() {
if (xhr.readyState == 4) {
var image_div = document.getElementById('container');
var xmldoc = xhr.responseXML;
var images = xmldoc.getElementsByTagName("image");
var n_images = images.length
var ul = document.createElement("ul");
ul.setAttribute("class", "gallery ui-helper-reset ui-helper-clearfix");
ul.setAttribute("id", "gallery");
for (i = 0; i < n_images; i++) {
var li = document.createElement("li");
li.setAttribute("class", "ui-widget-content ui-corner-tr");
var h5 = document.createElement("h5");
h5.setAttribute("class", "ui-widget-header");
var h5Text = document.createTextNode(images[i].firstChild.nodeValue);
h5.appendChild(h5Text);
var img = document.createElement("img");
img.setAttribute("src", "testimages/" + images[i].firstChild.nodeValue);
img.setAttribute("width", "75");
img.setAttribute("height", "75");
var a1 = document.createElement("a");
a1.setAttribute("class", "ui-icon ui-icon-zoomin");
a1.setAttribute("href", "testimages/" + images[i].firstChild.nodeValue);
var a1Text = document.createTextNode("View Larger");
a1.appendChild(a1Text);
var a2 = document.createElement("a");
a2.setAttribute("class", "ui-icon ui-icon-trash");
a2.setAttribute("href", "");
var a2Text = document.createTextNode("Delete Image");
a2.appendChild(a2Text);
li.appendChild(h5);
li.appendChild(img);
li.appendChild(a1);
li.appendChild(a2);
ul.appendChild(li);
}
image_div.appendChild(ul);
var trash_div = document.createElement('div');
trash_div.setAttribute("id", "trash");
trash_div.setAttribute("class", "ui-widget-content ui-state-default");
var h4 = document.createElement("h4");
h4.setAttribute("class", "ui-widget-header");
var h4Text = document.createTextNode("Trash");
h4.appendChild(h4Text);
var span = document.createElement("span");
span.setAttribute("class", "ui-icon ui-icon-trash");
var spanText = document.createTextNode("Trash");
span.appendChild(spanText);
h4.appendChild(span);
trash_div.appendChild(h4);
image_div.appendChild(trash_div);
alert(image_div.innerHTML);
}
}
$(function() {
// there's the gallery and the trash
var $gallery = $('#gallery'), $trash = $('#trash');
// let the gallery items be draggable
$('li',$gallery).draggable({
cancel: 'a.ui-icon',// clicking an icon won't initiate dragging
revert: 'invalid', // when not dropped, the item will revert back to its initial position
containment: $('#demo-frame').length ? '#demo-frame' : 'document', // stick to demo-frame if present
helper: 'clone',
cursor: 'move'
});
// let the trash be droppable, accepting the gallery items
$trash.droppable({
accept: '#gallery > li',
activeClass: 'ui-state-highlight',
drop: function(ev, ui) {
deleteImage(ui.draggable);
}
});
// let the gallery be droppable as well, accepting items from the trash
$gallery.droppable({
accept: '#trash li',
activeClass: 'custom-state-active',
drop: function(ev, ui) {
recycleImage(ui.draggable);
}
});
// image deletion function
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>';
function deleteImage($item) {
$item.fadeOut(function() {
var $list = $('ul',$trash).length ? $('ul',$trash) : $('<ul class="gallery ui-helper-reset"/>').appendTo($trash);
$item.find('a.ui-icon-trash').remove();
$item.append(recycle_icon).appendTo($list).fadeIn(function() {
$item.animate({ width: '48px' }).find('img').animate({ height: '36px' });
});
});
}
// image recycle function
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>';
function recycleImage($item) {
$item.fadeOut(function() {
$item.find('a.ui-icon-refresh').remove();
$item.css('width','96px').append(trash_icon).find('img').css('height','72px').end().appendTo($gallery).fadeIn();
});
}
// image preview function, demonstrating the ui.dialog used as a modal window
function viewLargerImage($link) {
var src = $link.attr('href');
var title = $link.siblings('img').attr('alt');
var $modal = $('img[src$="'+src+'"]');
if ($modal.length) {
$modal.dialog('open')
} else {
var img = $('<img alt="'+title+'" width="384" height="288" style="display:none;padding: 8px;" />')
.attr('src',src).appendTo('body');
setTimeout(function() {
img.dialog({
title: title,
width: 400,
modal: true
});
}, 1);
}
}
// resolve the icons behavior with event delegation
$('ul.gallery > li').click(function(ev) {
var $item = $(this);
var $target = $(ev.target);
if ($target.is('a.ui-icon-trash')) {
deleteImage($item);
} else if ($target.is('a.ui-icon-zoomin')) {
viewLargerImage($target);
} else if ($target.is('a.ui-icon-refresh')) {
recycleImage($item);
}
return false;
});
});
window.onload = function(){
getImages();
}
</script>
</head>
<body>
<div id="container" class="demo ui-widget ui-helper-clearfix">
</div>
</body>
</html> |