|
1 function toggle_dir (header_a_tag) { |
|
2 var div = Element.next(header_a_tag); |
|
3 |
|
4 if (div._have_contents) { |
|
5 if (div.visible()) |
|
6 Effect.BlindUp(div, {duration: 0.5}); |
|
7 else |
|
8 Effect.BlindDown(div, {duration: 0.5}); |
|
9 } else { |
|
10 |
|
11 new Ajax.Updater(div, "taggr2.py", { |
|
12 parameters: { |
|
13 act: "dirlist", |
|
14 path: div.id, |
|
15 }, |
|
16 method: 'get', |
|
17 onSuccess: function () { |
|
18 Effect.BlindDown(div, {duration: 0.5}); |
|
19 div._have_contents = true; |
|
20 } |
|
21 }); |
|
22 } |
|
23 } |
|
24 |
|
25 function new_tag (tag_name) { |
|
26 var tag_images = Builder.node("td", {className:"tag_images"}); |
|
27 |
|
28 $("tag_table").appendChild( |
|
29 Builder.node("tr", [ |
|
30 Builder.node("td", {className:"tag"}, [ |
|
31 tag_name |
|
32 ]), |
|
33 tag_images |
|
34 ]) |
|
35 ); |
|
36 } |
|
37 |
|
38 function image_dropped (img, tag, e) { |
|
39 } |
|
40 |
|
41 function image_loaded (img) { |
|
42 } |
|
43 |
|
44 function image_click (img, ev) { |
|
45 |
|
46 } |
|
47 |
|
48 function init () { |
|
49 } |
|
50 |
|
51 var g_drag, g_hover, g_start, g_offset, g_targets; |
|
52 function check_mouse_down (ev) { |
|
53 var e = ev.element(); |
|
54 |
|
55 if (e.hasClassName("image")) { |
|
56 g_drag = e; |
|
57 g_start = false; |
|
58 |
|
59 var offset = e.cumulativeOffset(); |
|
60 |
|
61 g_offset = { |
|
62 'left': ev.pointerX() - offset.left, |
|
63 'top': ev.pointerY() - offset.top |
|
64 }; |
|
65 |
|
66 g_hover = null; |
|
67 |
|
68 g_targets = $$(".tag_images"); |
|
69 |
|
70 } else if (e.hasClassName("directory_link")) { |
|
71 toggle_dir(e); |
|
72 |
|
73 } else { |
|
74 return true; |
|
75 } |
|
76 |
|
77 ev.stop(); |
|
78 return false; |
|
79 } |
|
80 |
|
81 function check_mouse_up (ev) { |
|
82 if (g_drag) { |
|
83 if (g_start) { |
|
84 if (g_hover) { |
|
85 drag_unhover(g_drag, g_hover, ev); |
|
86 drag_end_drop(g_drag, g_hover, ev); |
|
87 } else |
|
88 drag_end_fail(g_drag, ev); |
|
89 |
|
90 drag_cleanup(g_drag); |
|
91 } else |
|
92 image_click(g_drag, ev); |
|
93 |
|
94 g_start = null; |
|
95 g_drag = null; |
|
96 g_hover = null; |
|
97 |
|
98 ev.stop(); |
|
99 return false; |
|
100 } |
|
101 } |
|
102 |
|
103 function check_mouse_move (ev) { |
|
104 if (g_drag) { |
|
105 if (!g_start) { |
|
106 drag_start(g_drag); |
|
107 g_start = true; |
|
108 } |
|
109 |
|
110 drag_move(g_drag, ev); |
|
111 |
|
112 Position.prepare(); |
|
113 |
|
114 var px = ev.pointerX(); |
|
115 var py = ev.pointerY(); |
|
116 |
|
117 if (g_hover) { |
|
118 if (!Position.withinIncludingScrolloffsets(g_hover, px, py)) { |
|
119 drag_unhover(g_drag, g_hover, ev); |
|
120 g_hover = null; |
|
121 } |
|
122 } else { |
|
123 for (var i=0;i<g_targets.length;i++) |
|
124 if (Position.withinIncludingScrolloffsets(g_targets[i], px, py)) { |
|
125 drag_hover(g_drag, g_targets[i], ev); |
|
126 g_hover = g_targets[i]; |
|
127 } |
|
128 } |
|
129 |
|
130 ev.stop(); |
|
131 return false; |
|
132 } |
|
133 } |
|
134 |
|
135 function check_drag_hover (ev) { |
|
136 var e = ev.element(); |
|
137 if (g_start) { |
|
138 |
|
139 if (e.hasClassName("tag_images")) { |
|
140 drag_hover(g_drag, e, ev); |
|
141 g_hover = e; |
|
142 } |
|
143 } |
|
144 } |
|
145 |
|
146 function check_drag_nohover (ev) { |
|
147 var e = ev.element(); |
|
148 if (g_start) { |
|
149 |
|
150 if (g_hover && e == g_hover) { |
|
151 drag_unhover(g_drag, g_hover, ev); |
|
152 g_hover = null; |
|
153 } |
|
154 } |
|
155 } |
|
156 |
|
157 var g_ghost; |
|
158 function drag_start (e) { |
|
159 g_ghost = Builder.node("img", { |
|
160 src: e.src |
|
161 }); |
|
162 |
|
163 g_ghost._key = e.id; |
|
164 |
|
165 $('taggr').appendChild(g_ghost); |
|
166 |
|
167 g_ghost.style.position = "absolute"; |
|
168 } |
|
169 |
|
170 function drag_move (e, ev) { |
|
171 g_ghost.style.left = ev.pointerX() - g_offset.left + "px"; |
|
172 g_ghost.style.top = ev.pointerY() - g_offset.top + "px"; |
|
173 } |
|
174 |
|
175 function drag_end_drop (e, s, ev) { |
|
176 if (!s.images) |
|
177 s.images = new Array(); |
|
178 |
|
179 if (s.images.indexOf(g_ghost._key) != -1) |
|
180 return drag_end_fail(); |
|
181 |
|
182 g_ghost.id = s.id + "_" + g_ghost._key |
|
183 |
|
184 s.images.push(g_ghost._key) |
|
185 |
|
186 $('taggr').removeChild(g_ghost); |
|
187 s.appendChild(g_ghost); |
|
188 |
|
189 g_ghost.style.position = "static"; |
|
190 } |
|
191 |
|
192 function drag_end_fail (e, ev) { |
|
193 $('taggr').removeChild(g_ghost); |
|
194 } |
|
195 |
|
196 function drag_cleanup (e, ev) { |
|
197 g_ghost = null; |
|
198 } |
|
199 |
|
200 function drag_hover (e, s, ev) { |
|
201 s.addClassName("hover"); |
|
202 } |
|
203 |
|
204 function drag_unhover (e, s, ev) { |
|
205 s.removeClassName("hover"); |
|
206 } |
|
207 |
|
208 Event.observe(window, "load", init); |
|
209 Event.observe(document, "mousedown", check_mouse_down); |
|
210 Event.observe(document, "mouseup", check_mouse_up); |
|
211 Event.observe(document, "mousemove", check_mouse_move); |
|
212 Event.observe(document, "mouseover", check_drag_hover); |
|
213 Event.observe(document, "mouseout", check_drag_nohover); |
|
214 Event.observe(document, "dragenter", check_drag_hover); |
|
215 Event.observe(document, "dragexit", check_drag_nohover); |
|
216 |
|
217 |