1 |
|
---|
2 | function dragMoveListener(event)
|
---|
3 | {
|
---|
4 | var target = event.target
|
---|
5 | // keep the dragged position in the data-x/data-y attributes
|
---|
6 | var x = (parseFloat(target.getAttribute('data-x')) || 0) + event.dx
|
---|
7 | var y = (parseFloat(target.getAttribute('data-y')) || 0) + event.dy
|
---|
8 |
|
---|
9 | // translate the element
|
---|
10 | target.style.transform = 'translate(' + x + 'px, ' + y + 'px)'
|
---|
11 |
|
---|
12 | // update the posiion attributes
|
---|
13 | target.setAttribute('data-x', x)
|
---|
14 | target.setAttribute('data-y', y)
|
---|
15 | }
|
---|
16 |
|
---|
17 | function getCoreDraggableOptions()
|
---|
18 | {
|
---|
19 | let core_draggable_options = {
|
---|
20 |
|
---|
21 | listeners: { move: dragMoveListener },
|
---|
22 |
|
---|
23 | modifiers: [
|
---|
24 | interact.modifiers.restrictRect({
|
---|
25 | restriction: 'parent',
|
---|
26 | endOnly: true
|
---|
27 | })
|
---|
28 | ],
|
---|
29 |
|
---|
30 | inertia: {
|
---|
31 | resistance: 6,
|
---|
32 | //minSpeed: 20,
|
---|
33 | //endSpeed: 10,
|
---|
34 | smoothEndDuration: 500,
|
---|
35 | allowResume: true
|
---|
36 | }
|
---|
37 | };
|
---|
38 |
|
---|
39 | return core_draggable_options;
|
---|
40 | }
|
---|
41 |
|
---|
42 | // http://localhost:8383/greenstone3/library
|
---|
43 |
|
---|
44 | function getCoreResizableOptions()
|
---|
45 | {
|
---|
46 | let core_resizable_options = {
|
---|
47 |
|
---|
48 | edges: { left: true, right: true, bottom: true, top: true },
|
---|
49 |
|
---|
50 | listeners: {
|
---|
51 |
|
---|
52 | moveNEWER: function (event) {
|
---|
53 | let { x, y } = event.target.dataset
|
---|
54 |
|
---|
55 | x = (parseFloat(x) || 0) + event.deltaRect.left
|
---|
56 | y = (parseFloat(y) || 0) + event.deltaRect.top
|
---|
57 |
|
---|
58 | Object.assign(event.target.style, {
|
---|
59 | width: `${event.rect.width}px`,
|
---|
60 | height: `${event.rect.height}px`,
|
---|
61 | transform: `translate(${x}px, ${y}px)`
|
---|
62 | })
|
---|
63 |
|
---|
64 | Object.assign(event.target.dataset, { x, y })
|
---|
65 | },
|
---|
66 |
|
---|
67 | move (event) {
|
---|
68 | var target = event.target
|
---|
69 | var x = (parseFloat(target.getAttribute('data-x')) || 0)
|
---|
70 | var y = (parseFloat(target.getAttribute('data-y')) || 0)
|
---|
71 | //var x = (parseFloat(target.getAttribute('data-x')) || target.style.clientLeft)
|
---|
72 | //var y = (parseFloat(target.getAttribute('data-y')) || target.style.clientTop)
|
---|
73 |
|
---|
74 | // update the element's style
|
---|
75 | target.style.width = event.rect.width + 'px'
|
---|
76 | target.style.height = event.rect.height + 'px'
|
---|
77 |
|
---|
78 | // translate when resizing from top or left edges
|
---|
79 | x += event.deltaRect.left
|
---|
80 | y += event.deltaRect.top
|
---|
81 |
|
---|
82 | target.style.transform = 'translate(' + x + 'px,' + y + 'px)'
|
---|
83 |
|
---|
84 | //var target_new_x_org = target.clientLeft + event.deltaRect.left;
|
---|
85 | //var target_new_y_org = target.clientTop + event.deltaRect.top;
|
---|
86 |
|
---|
87 | //target.style.left = target_new_x_org + 'px';
|
---|
88 | //target.style.top = target_new_y_org + 'px';
|
---|
89 |
|
---|
90 | //target.style.left = x + 'px';
|
---|
91 | //target.style.top = y + 'px';
|
---|
92 |
|
---|
93 | target.setAttribute('data-x', x)
|
---|
94 | target.setAttribute('data-y', y)
|
---|
95 |
|
---|
96 | // var textEl = $(event.target).find('.interact-info-bar')[0];
|
---|
97 | // textEl.textContent = "Resized to: " + Math.round(event.rect.width) + '\u00D7' + Math.round(event.rect.height) + " pixels"
|
---|
98 | }
|
---|
99 | },
|
---|
100 |
|
---|
101 | modifiers: [
|
---|
102 | // keep the edges inside the parent
|
---|
103 | interact.modifiers.restrictEdges({
|
---|
104 | outer: 'parent'
|
---|
105 | }),
|
---|
106 |
|
---|
107 | // minimum size
|
---|
108 | interact.modifiers.restrictSize({
|
---|
109 | min: { width: 100, height: 50 }
|
---|
110 | })
|
---|
111 | ],
|
---|
112 |
|
---|
113 | inertia: false
|
---|
114 |
|
---|
115 | /*inertia: {
|
---|
116 | resistance: 6,
|
---|
117 | //minSpeed: 20,
|
---|
118 | //endSpeed: 10,
|
---|
119 | smoothEndDuration: 500,
|
---|
120 | allowResume: true
|
---|
121 | }*/
|
---|
122 | };
|
---|
123 |
|
---|
124 | return core_resizable_options;
|
---|
125 |
|
---|
126 | }
|
---|
127 |
|
---|
128 |
|
---|
129 | function getCoreGesturableOptions(elem,angleScale)
|
---|
130 | {
|
---|
131 | let core_gesturable_options = {
|
---|
132 |
|
---|
133 | listeners: {
|
---|
134 | start (event) {
|
---|
135 | angleScale.angle -= event.angle;
|
---|
136 | },
|
---|
137 | move (event) {
|
---|
138 | let currentAngle = event.angle + angleScale.angle;
|
---|
139 | let currentScale = event.scale * angleScale.scale;
|
---|
140 |
|
---|
141 | //let scale_elem = $(elem).find('.scale-element')[0];
|
---|
142 |
|
---|
143 | //scale_elem.style.transform =
|
---|
144 | // 'rotate(' + currentAngle + 'deg)' + 'scale(' + currentScale + ')';
|
---|
145 |
|
---|
146 | let $scale_elem = $(elem).find('.scale-element');
|
---|
147 |
|
---|
148 | $scale_elem.css(
|
---|
149 | 'transform',
|
---|
150 | 'rotate(' + currentAngle + 'deg)' + 'scale(' + currentScale + ')'
|
---|
151 | );
|
---|
152 |
|
---|
153 |
|
---|
154 | dragMoveListener(event);
|
---|
155 | },
|
---|
156 | end (event) {
|
---|
157 | angleScale.angle = angleScale.angle + event.angle;
|
---|
158 | angleScale.scale = angleScale.scale * event.scale;
|
---|
159 | }
|
---|
160 | }
|
---|
161 | };
|
---|
162 |
|
---|
163 | return core_gesturable_options;
|
---|
164 | }
|
---|
165 |
|
---|
166 |
|
---|
167 |
|
---|
168 | $(document).ready(function() {
|
---|
169 |
|
---|
170 | let draggable_options = getCoreDraggableOptions();
|
---|
171 | let resizable_options = getCoreResizableOptions();
|
---|
172 |
|
---|
173 | draggable_options.autoScroll =true;
|
---|
174 |
|
---|
175 | interact('.resize-drag')
|
---|
176 | .draggable(draggable_options)
|
---|
177 | .resizable(resizable_options)
|
---|
178 |
|
---|
179 | // still needed??
|
---|
180 | //window.dragMoveListener = dragMoveListener
|
---|
181 |
|
---|
182 |
|
---|
183 | var $drag_and_zoom_elems = $('.drag-and-zoom');
|
---|
184 |
|
---|
185 | $drag_and_zoom_elems.each(function(index) {
|
---|
186 |
|
---|
187 | let this_elem = this;
|
---|
188 |
|
---|
189 | /*
|
---|
190 | let draggable_options = getCoreDraggableOptions();
|
---|
191 | let angleScale = {
|
---|
192 | angle: 0,
|
---|
193 | scale: 1
|
---|
194 | }
|
---|
195 |
|
---|
196 | */
|
---|
197 |
|
---|
198 | let this_angle_scale = {
|
---|
199 | angle: 0,
|
---|
200 | scale: 1
|
---|
201 | }
|
---|
202 |
|
---|
203 |
|
---|
204 | let gdraggable_options = getCoreDraggableOptions();
|
---|
205 | let gesturable_options = getCoreGesturableOptions(this_elem,this_angle_scale);
|
---|
206 |
|
---|
207 | interact(this_elem)
|
---|
208 | .gesturable(gesturable_options)
|
---|
209 | .draggable(gdraggable_options);
|
---|
210 |
|
---|
211 | /*
|
---|
212 | interact(this_elem)
|
---|
213 | .gesturable({
|
---|
214 | listeners: {
|
---|
215 | start (event) {
|
---|
216 | angleScale.angle -= event.angle
|
---|
217 | },
|
---|
218 | move (event) {
|
---|
219 | let currentAngle = event.angle + angleScale.angle
|
---|
220 | let currentScale = event.scale * angleScale.scale
|
---|
221 |
|
---|
222 | let this_scale_elem = $(this_elem).find('.scale-element')[0];
|
---|
223 |
|
---|
224 | this_scale_elem.style.transform =
|
---|
225 | 'rotate(' + currentAngle + 'deg)' + 'scale(' + currentScale + ')'
|
---|
226 |
|
---|
227 | dragMoveListener(event)
|
---|
228 | },
|
---|
229 | end (event) {
|
---|
230 | angleScale.angle = angleScale.angle + event.angle
|
---|
231 | angleScale.scale = angleScale.scale * event.scale
|
---|
232 | }
|
---|
233 | }
|
---|
234 | })
|
---|
235 | .draggable(draggable_options)
|
---|
236 |
|
---|
237 | */
|
---|
238 |
|
---|
239 | });
|
---|
240 | });
|
---|
241 |
|
---|
242 |
|
---|
243 | $(document).ready(function() {
|
---|
244 |
|
---|
245 | $.ajax({
|
---|
246 | url: "http://localhost:8383/greenstone3/library?excerptid=collectionAndGroupLinks"
|
---|
247 | })
|
---|
248 | .done(function(data) {
|
---|
249 | const winbox1 = new WinBox({
|
---|
250 | id: "my-winbox1",
|
---|
251 | title: 'Winbox + Interact Example 1',
|
---|
252 | x: 200,
|
---|
253 | y: 200,
|
---|
254 | width: '900px',
|
---|
255 | height: '400px',
|
---|
256 | border: "0.3em",
|
---|
257 | background: "#29e",
|
---|
258 | html: data
|
---|
259 |
|
---|
260 | });
|
---|
261 |
|
---|
262 | $('#my-winbox1 .wb-header').css("user-select", "none");
|
---|
263 | $('#my-winbox1 .wb-header').css("touch-action","none");
|
---|
264 |
|
---|
265 | let draggable_options = getCoreDraggableOptions();
|
---|
266 | let resizable_options = getCoreResizableOptions();
|
---|
267 |
|
---|
268 | draggable_options.autoScroll = true;
|
---|
269 |
|
---|
270 | interact('#my-winbox1')
|
---|
271 | .draggable(draggable_options)
|
---|
272 | .resizable(resizable_options);
|
---|
273 | });
|
---|
274 |
|
---|
275 |
|
---|
276 |
|
---|
277 | const win2 = new WinBox({
|
---|
278 | id: "my-winbox2",
|
---|
279 | title: 'Winbox + Interact Example 2',
|
---|
280 | x: 800,
|
---|
281 | y: 200,
|
---|
282 | width: '500px',
|
---|
283 | height: '300px',
|
---|
284 | border: "0.3em",
|
---|
285 | background: "#29e",
|
---|
286 | html: "<p classXXX=\"scale-element\" style=\"padding: 8px; color: #000;\">This window can be dragged around, rotated and zoomed in and out</p>"
|
---|
287 | });
|
---|
288 |
|
---|
289 | // user-select: none;
|
---|
290 | // touch-action: none;
|
---|
291 |
|
---|
292 | let $win2 = $('#my-winbox2');
|
---|
293 | let $scale_element_div = $('<div>').attr("class","scale-element");
|
---|
294 | $scale_element_div.append($win2.children()).clone();
|
---|
295 |
|
---|
296 | $win2.empty().append($scale_element_div);
|
---|
297 |
|
---|
298 |
|
---|
299 |
|
---|
300 | /*
|
---|
301 | interact('#my-winbox2')
|
---|
302 | .draggable(draggable_options)
|
---|
303 | .resizable(resizable_options);
|
---|
304 | */
|
---|
305 |
|
---|
306 | let this_elem = document.getElementById('my-winbox2');
|
---|
307 |
|
---|
308 | let this_angle_scale = {
|
---|
309 | angle: 0,
|
---|
310 | scale: 1
|
---|
311 | }
|
---|
312 |
|
---|
313 |
|
---|
314 | let gdraggable_options = getCoreDraggableOptions();
|
---|
315 | let gesturable_options = getCoreGesturableOptions(this_elem,this_angle_scale);
|
---|
316 |
|
---|
317 | interact('#my-winbox2')
|
---|
318 | .gesturable(gesturable_options)
|
---|
319 | .draggable(gdraggable_options);
|
---|
320 |
|
---|
321 |
|
---|
322 | /*
|
---|
323 | interact('#my-winbox')
|
---|
324 | .draggable({
|
---|
325 | // enable inertial throwing
|
---|
326 | inertia: true,
|
---|
327 | // keep the element within the area of it's parent
|
---|
328 | modifiers: [
|
---|
329 | interact.modifiers.restrictRect({
|
---|
330 | restriction: 'parent',
|
---|
331 | endOnly: true
|
---|
332 | })
|
---|
333 | ],
|
---|
334 | // enable autoScroll
|
---|
335 | autoScroll: true,
|
---|
336 |
|
---|
337 | listeners: {
|
---|
338 | // call this function on every dragmove event
|
---|
339 | move: dragMoveListener,
|
---|
340 |
|
---|
341 | // call this function on every dragend event
|
---|
342 | end (event) {
|
---|
343 | var textEl = event.target.querySelector('p')
|
---|
344 |
|
---|
345 | textEl && (textEl.textContent =
|
---|
346 | 'moved a distance of ' +
|
---|
347 | (Math.sqrt(Math.pow(event.pageX - event.x0, 2) +
|
---|
348 | Math.pow(event.pageY - event.y0, 2) | 0))
|
---|
349 | .toFixed(2) + 'px')
|
---|
350 | }
|
---|
351 | }
|
---|
352 | });
|
---|
353 | */
|
---|
354 |
|
---|
355 | });
|
---|