Changeset 37568
- Timestamp:
- 2023-03-25T22:18:10+13:00 (13 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
gs3-extensions/tabletop-dl/trunk/tabletop-interact.js
r37561 r37568 1 1 2 function dragRestrictionRect(x,y,interactable_elem) 3 { 4 // This function effectively does the same as restrictEdges { outer: 'parent', ... } 5 // but .... 6 // Upgraded to cope with the more complicated case where the interactable has 7 // been rotated and scaled. Without the extra checks, the 'outer' div that is 8 // used for a rotated and scale interactable has is the one for the original element 9 // prior to any scale or rotation applied to it (which is applied to .scale-element, 10 // which is a child of the outer element) 11 12 13 let elem = interactable_elem.element; 14 let parent_elem = elem.parentElement; 15 //console.log("parent elem:"); 16 //console.log(parent_elem); 17 18 let parent_rect = parent_elem.getBoundingClientRect(); 19 let restrict_to_rect = { 20 left: parent_rect.left, 21 right: parent_rect.right, 22 top: parent_rect.top, 23 bottom: parent_rect.bottom 24 }; 25 26 27 let delta_xl = x - restrict_to_rect.left; 28 let delta_xr = restrict_to_rect.right - x; 29 let delta_yt = y - restrict_to_rect.top; 30 let delta_yb = restrict_to_rect.bottom - y; 31 32 let dragged_rect; 33 34 let $dragged_elem = $(elem).find('.scale-element'); 35 if ($dragged_elem.length>0) { 36 dragged_rect = $dragged_elem[0].getBoundingClientRect(); 37 } 38 else { 39 dragged_rect = elem.getBoundingClientRect(); 40 } 41 42 //console.log(dragged_rect); 43 //console.log("restrict to:"); 44 //console.log(restrict_to_rect); 45 46 // test bounds of dragged_rect, to restrict_to_rect 47 // factor in any overshoots in the encoded rect returned 48 49 if ((dragged_rect.left >= restrict_to_rect.left) || (dragged_rect.right <= restrict_to_rect.right)) { 50 // want to avoid situation where for dragged_rect both left and right are 51 // outside of the restrict_to_rect 52 53 if (dragged_rect.left < restrict_to_rect.left) { 54 // encode how much the overshoot it 55 restrict_to_rect.left += (restrict_to_rect.left - dragged_rect.left); 56 57 // Now factor in the offset that comes from the supplied (x,y); 58 restrict_to_rect.left += (x - parent_rect.left); 59 restrict_to_rect.right += (x - parent_rect.left); 60 61 } 62 if (dragged_rect.right > restrict_to_rect.right) { 63 // encode how much the overshoot it 64 restrict_to_rect.right -= (dragged_rect.right - restrict_to_rect.right); 65 66 // Now factor in the offset that comes from the supplied (x,y); 67 restrict_to_rect.left -= (parent_rect.right - x) + 1; 68 restrict_to_rect.right -= (parent_rect.right - x) + 1; 69 70 } 71 } 72 if ((dragged_rect.top >= restrict_to_rect.top) || (dragged_rect.bottom <= restrict_to_rect.bottom)) { 73 // want to avoid situation where for dragged_rect both left and right are 74 // outside of the restrict_to_rect 75 76 if (dragged_rect.top < restrict_to_rect.top) { 77 // encode how much the overshoot it 78 restrict_to_rect.top += (restrict_to_rect.top - dragged_rect.top); 79 80 // Now factor in the offset that comes from the supplied (x,y); 81 restrict_to_rect.top += (y - parent_rect.top); 82 restrict_to_rect.bottom += (y - parent_rect.top); 83 } 84 if (dragged_rect.bottom > restrict_to_rect.bottom) { 85 // encode how much the overshoot it 86 restrict_to_rect.bottom -= (dragged_rect.bottom - restrict_to_rect.bottom); 87 88 // Now factor in the offset that comes from the supplied (x,y); 89 restrict_to_rect.top -= (parent_rect.bottom - y) + 1; 90 restrict_to_rect.bottom -= (parent_rect.bottom - y) + 1; 91 } 92 } 93 94 return restrict_to_rect; 95 } 96 97 2 98 function dragMoveListener(event) 3 99 { … … 20 116 let core_draggable_options = { 21 117 22 listeners: { move: dragMoveListener },118 //listeners: { move: dragMoveListener }, 23 119 24 120 /* 25 modifiers: [ 26 interact.modifiers.restrictRect({ 27 restriction: 'parent', 28 endOnly: true 29 }) 30 ], 121 onstart: function(event) { 122 let target = event.target; 123 }, 124 31 125 */ 126 127 onmove: dragMoveListener, 128 129 /* 130 onend: function(event) { 131 let target = event.target; 132 }, 133 */ 134 32 135 33 136 modifiers: [ 34 137 interact.modifiers.restrict({ 35 restriction: function(x,y,interactable_elem) { 36 console.log(`Called draggable restriction function with: x=${x}, y=${y}`); 138 restriction: dragRestrictionRect, 139 140 /* 141 function(x,y,interactable_elem) { 142 //console.log(`!!! Called draggable restriction function with: x=${x}, y=${y}`); 37 143 38 144 let elem = interactable_elem.element; … … 70 176 //let delta_yt = y - dragged_rect.top; 71 177 //let delta_yb = dragged_rect.bottom - y; 72 73 console.log(dragged_rect);74 console.log("restrict to:");75 console.log(restrict_to_rect);178 179 //console.log(dragged_rect); 180 //console.log("restrict to:"); 181 //console.log(restrict_to_rect); 76 182 77 183 // test bounds of dragged_rect, to restrict_to_rect … … 130 236 //restrict_to_rect.height = restrict_to_rect.bottom - restrict_to_rect.top + 1; 131 237 132 console.log(`Returning for (${x},${y}) as delta [xl<->xr],[yt,<->yb] [(${delta_xl}<->${delta_xr}],[${delta_yt})<->${delta_yb}]`);133 console.log(restrict_to_rect);238 //console.log(`Returning for (${x},${y}) as delta [xl<->xr],[yt,<->yb] [(${delta_xl}<->${delta_xr}],[${delta_yt})<->${delta_yb}]`); 239 //console.log(restrict_to_rect); 134 240 135 241 return restrict_to_rect; 136 }, 137 242 },*/ 138 243 139 244 endOnly: true … … 233 338 { 234 339 let core_gesturable_options = { 235 236 340 listeners: { 237 341 start (event) { 238 angleScale.angle -= event.angle; 342 angleScale.angle -= event.angle; 239 343 }, 240 344 move (event) { 345 241 346 let currentAngle = angleScale.angle + event.angle; 242 347 let currentScale = angleScale.scale * event.scale; … … 336 441 337 442 338 339 340 443 let doc_url = "http://localhost:8383/greenstone3/library/collection/gs2mgdemo/document/HASHe3aae2159b0dda6553cee4"; 341 444 … … 350 453 351 454 352 const win2 = new WinBox({455 let win2 = new WinBox({ 353 456 id: "my-winbox2", 354 457 title: 'Winbox + Interact Example: Drag, Scale and Rotate', … … 358 461 height: '600px', 359 462 border: "0.3em", 360 //background: "#29e",361 //html: "<p>Some Sample Text</p>"362 463 html: html_result 363 464 }); … … 369 470 let $scale_element_div = $('<div>') 370 471 .attr("class","scale-element") 472 .css("pointer-events","all") 371 473 .css("position","relative") 372 474 .css("width","100%") … … 386 488 angle: 0, 387 489 scale: 1 388 } 490 }; 389 491 390 492 … … 392 494 let gesturable_options = getCoreGesturableOptions(this_elem,this_angle_scale); 393 495 394 interact('#my-winbox2')496 var my_winbox2 = interact('#my-winbox2') 395 497 .gesturable(gesturable_options) 396 498 .draggable(gdraggable_options); 499 500 $('#my-winbox2').css("pointer-events","none"); 397 501 398 502 }); 399 400 503 });
Note:
See TracChangeset
for help on using the changeset viewer.