-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathjquery.wormhole.0.5.js
125 lines (114 loc) · 4.73 KB
/
jquery.wormhole.0.5.js
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
// Generated by CoffeeScript 1.4.0
(function() {
var $;
$ = jQuery;
$.fn.isWorm = function() {
return $(this).data('isWorm') === true || $(this).data('isClone') === true;
};
$.fn.explicitlyPosition = function() {
if ($(this).css('position') === "static") {
return $(this).css('position', 'relative');
}
};
$.fn.explicitlyPositionAbsolute = function() {
if ($(this).css('position') !== 'absolute') {
return $(this).css('position', 'absolute');
}
};
$.fn.containmentCoordinates = function() {
var offset;
offset = $(this).offset();
return [offset.left, offset.top - $(this).height(), offset.left + $(this).width() - $(this).width(), offset.top + ($(this).height() * 2)];
};
$.fn.cloneAsWorm = function(deep) {
var $cloneWorm;
return $cloneWorm = $(this).clone(deep).data('isClone', true);
};
$.fn.wormHole = function(options) {
var defaults;
defaults = {
group: 'default',
selector: '*',
stop: function() {}
};
options = $.extend(defaults, options);
return this.each(function() {
var $thisObject;
$thisObject = $(this);
$thisObject.css("overflow", 'hidden');
$thisObject.explicitlyPosition();
$thisObject.find(options.selector).each(function() {
return $(this).explicitlyPositionAbsolute();
});
$thisObject.data('wormGroup', options.group);
$thisObject.addClass('wormgroup-' + options.group);
return $thisObject.delegate(options.selector, 'mouseover', function() {
if (!$(this).isWorm()) {
$(this).draggable("option", "containment", $(this).containmentCoordinates());
$(this).draggable("option", "stack", options.selector);
return $(this).worm(options.group, $thisObject, options.stop);
}
});
});
};
$.fn.worm = function(group, parent, stopCallback) {
var $cloneWorm, $nextWormHole, $prevWormHole;
if (stopCallback == null) {
stopCallback = function() {};
}
if (!this.isWorm()) {
$nextWormHole = parent.next('.wormgroup-' + group);
$prevWormHole = parent.prev('.wormgroup-' + group);
$(this).data('isWorm', true);
$cloneWorm = $(this).cloneAsWorm(true);
this.bind('drag', function(event, ui) {
var newHeight;
if ($(this).position().top + $(this).height() > parent.height() && $nextWormHole.length > 0) {
newHeight = $(this).position().top - parent.height();
$cloneWorm.css('left', $(this).css('left')).css('opacity', $(this).css('opacity')).css('top', newHeight + "px");
if (!$(this).data('hasClone')) {
$nextWormHole.append($cloneWorm);
return $(this).data('hasClone', true);
} else if ($(this).position().top < 0 && $prevWormHole.length > 0) {
newHeight = $(this).position().top + parent.height();
$cloneWorm.css('left', $(this).css('left')).css('opacity', $(this).css('opacity')).css('top', newHeight + "px");
if (!$(this).data('hasClone')) {
$prevWormHole.append($cloneWorm);
return $(this).data('hasClone', true);
}
}
}
});
this.bind("dragstop", function(event, ui) {
var draggableOptions, newHeight;
if ($(this).position().top > parent.height()) {
draggableOptions = $(this).data("uiDraggable").options;
$(this).css('top', $cloneWorm.position().top + 'px');
$cloneWorm.replaceWith($(this));
stopCallback;
$(this).unbind('drag').unbind('dragstop');
$(this).draggable(draggableOptions);
return $(this).data('isWorm', false).data('hasClone', false);
} else if ($(this).position().top + $(this).height() > parent.height()) {
newHeight = $(this).position().top - parent.height();
return $cloneWorm.css('left', $(this).css('left')).css('opacity', $(this).css('opacity')).css('top', newHeight + "px");
} else if ($(this).position().top <= (0 - $(this).height())) {
draggableOptions = $(this).data("draggable").options;
$(this).css('top', $cloneWorm.position().top + 'px');
$cloneWorm.replaceWith($(this));
stopCallback;
$(this).unbind('drag').unbind('dragstop');
$(this).draggable(draggableOptions);
return $(this).data('isWorm', false).data('hasClone', false);
} else if ($(this).position().top < 0) {
newHeight = $(this).position().top + parent.height();
return $cloneWorm.css('left', $(this).css('left')).css('opacity', $(this).css('opacity')).css('top', newHeight + "px");
} else {
$cloneWorm.detach();
return $(this).data('hasClone', false);
}
});
}
return this;
};
}).call(this);