2
* The very first increment of Droppables&Draggables demo. The code is going to
3
* be more concise (remove unnecessary code repetitions etc.). And imho the
4
* photo management is a good candidate for demonstration of more jQuery UI
5
* components (sortables, selectables...). More to come...
9
$(window).bind('load', function() {
10
// make images in the gallery draggable
11
$('ul.gallery img').addClass('img_content').draggable({
15
// make the trash box droppable, accepting images from the content section only
16
$('#trash div').droppable({
17
accept: '.img_content',
18
activeClass: 'active',
19
drop: function(ev, ui) {
21
ui.draggable.parent().fadeOut('slow', function() {
30
.removeClass('img_content')
31
.addClass('img_trash');
37
// make the shredder box droppable, accepting images from both content and trash sections
38
$('#shred div').droppable({
39
accept: '.img_content, .img_trash',
40
activeClass: 'active',
41
drop: function(ev, ui) {
43
// images from the content
44
if (ui.draggable.hasClass('img_content')) {
45
ui.draggable.parent().fadeOut('slow', function() {
51
}, 'slow', function(){
57
// images from the trash
58
else if (ui.draggable.hasClass('img_trash')) {
64
}, 'slow', function(){
71
// make the gallery droppable as well, accepting images from the trash only
72
$('ul.gallery').droppable({
74
activeClass: 'active',
75
drop: function(ev, ui) {
77
ui.draggable.fadeOut('slow', function() {
78
var $item = createGalleryItem(this).appendTo($that);
80
.removeClass('img_trash')
81
.addClass('img_content')
82
.css({ width: '144px', height: '108px' })
89
// handle the trash icon behavior
90
$('a.tb_trash').livequery('click', function() {
92
var $img = $this.parent().siblings('img');
93
var $item = $this.parents('li');
95
$item.fadeOut('slow', function() {
98
.appendTo('#trash div')
104
.removeClass('img_content')
105
.addClass('img_trash');
112
// handle the magnify button
113
$('a.tb_supersize').livequery('click', function() {
114
$('<img width="576" height="432">')
115
.attr('src', $(this).attr('href'))
116
.appendTo('#body_wrap')
122
var sliderChange = function(e, ui){
123
$('.img_content').each(function(index, item){
124
var _new = 1.44 * $('#sliderSize').slider("value");
126
$(this).css("width", _new+'px')
127
.parent().css("width", (_new+16)+'px');
131
$('#sliderSize').slider({
136
slide : sliderChange,
137
change : sliderChange
142
function createGalleryItem(img) {
143
var title = img.getAttribute('alt');
144
var href = img.getAttribute('src').replace(/thumbs\//, '');
146
var $item = $('<li><p>'+title+'</p><div><a href="#" title="Trash me" class="tb_trash">Trash me</a><a href="'+href+'" title="See me supersized" class="tb_supersize">See me supersized</a></div></li>').hide();
147
$item.prepend($(img));