Improved tab behavior of scatter

This commit is contained in:
Uwe Oestermeier 2019-07-05 14:40:15 +02:00
commit 14f2c2fbe6
3 changed files with 21 additions and 16 deletions

5
dist/iwmlib.js vendored
View File

@ -4985,10 +4985,11 @@
* @param {String} [touchAction=none] - CSS to set touch action style, needed to prevent * @param {String} [touchAction=none] - CSS to set touch action style, needed to prevent
* pointer cancel events. Use null if the * pointer cancel events. Use null if the
* the touch action should not be set. * the touch action should not be set.
* @param {DOM node} debugCanvas - Shows debug infos about touches if not null
*/ */
constructor( constructor(
element, element,
{ stopEvents = 'auto', claimEvents = true, useCapture = true, touchAction = 'none' } = {} { stopEvents = 'auto', claimEvents = true, useCapture = true, touchAction = 'none', debugCanvas = null } = {}
) { ) {
this.onCapture = null; this.onCapture = null;
this.element = element; this.element = element;
@ -5020,7 +5021,7 @@
mouseWheelElement: window mouseWheelElement: window
}); });
if (typeof debugCanvas !== 'undefined') { if (debugCanvas !== null) {
requestAnimationFrame(dt => { requestAnimationFrame(dt => {
this.showTouches(dt, debugCanvas); this.showTouches(dt, debugCanvas);
}); });

View File

@ -13,9 +13,8 @@
debugCanvas.width = main.getBoundingClientRect().width debugCanvas.width = main.getBoundingClientRect().width
let context = debugCanvas.getContext('2d') let context = debugCanvas.getContext('2d')
context.clearRect(0, 0, debugCanvas.width, debugCanvas.height) context.clearRect(0, 0, debugCanvas.width, debugCanvas.height)
let stage = scatterContainer.polygon let stage = scatterContainer.polygon
stage.draw(context, { stroke: '#0000FF'}) stage.draw(context, { stroke: "#0000FF"})
for(let scatter of scatterContainer.scatter.values()) { for(let scatter of scatterContainer.scatter.values()) {
let polygon = scatter.polygon let polygon = scatter.polygon
polygon.draw(context, { stroke: '#0000FF'}) polygon.draw(context, { stroke: '#0000FF'})
@ -26,6 +25,7 @@
requestAnimationFrame((dt) => { requestAnimationFrame((dt) => {
drawPolygons() drawPolygons()
animatePolygons() animatePolygons()
}) })
} }
</script> </script>
@ -81,6 +81,8 @@ app.run()
animatePolygons() animatePolygons()
</script> </script>
<h1> <h1>
Interactive Content Interactive Content
</h1> </h1>
@ -89,32 +91,33 @@ Scatter objects may contain interactive HTML structures. There is one major flag
to simulate click events by using taps. If the scatter detects a tap it looks for clickable to simulate click events by using taps. If the scatter detects a tap it looks for clickable
elements under or nearby the event position and calls the click handler. Thus gestures elements under or nearby the event position and calls the click handler. Thus gestures
can be disambiguated as moves, zooms. or taps. can be disambiguated as moves, zooms. or taps.
Note that on touch devices you can tap beside the object if you use clickOnTap. The allowed distance
can be configured by allowClickDistance. The default value is 44px.
</p> </p>
<div id="main2" class="grayBorder interactive" style="position: relative; width: 100%; height: 280px;"> <div id="contentExample" class="grayBorder interactive" style="position: relative; width: 100%; height: 280px;">
<!-- Note that we need to set draggable to false to avoid conflicts. The DOM elements
must also be positioned absolutely. -->
<div id="interactiveContent"> <div id="interactiveContent">
<img draggable="false" style="position: absolute;" src="examples/women.jpeg" /> <img draggable="false" style="position: absolute;" src="examples/women.jpeg" />
<a style="position:absolute; top: 10px; right: 10px; color:white;" href="https://www.iwm-tuebingen.de" target="_blank">A Link</a> <a style="position:absolute; top: 10px; right: 10px; color:white;" href="javascript:alert('test link')">A Link</a>
<div onclick="alert('clicked')" style="position:absolute; top: 30px; right: 10px; color:white;">A Div with click handler</div> <div onclick="alert('div clicked')" style="position:absolute; top: 30px; right: 10px; color:white;">A Div with click handler</div>
</div> </div>
</div> </div>
<script class="doctest"> <script class="doctest">
let app2 = new App() let contentContainer = new DOMScatterContainer(contentExample)
let scatterContainer2 = new DOMScatterContainer(main2, { stopEvents: true}) new DOMScatter(interactiveContent, contentContainer, {
let scatter2 = new DOMScatter(interactiveContent, scatterContainer2, {
x: 44, x: 44,
y: 44, y: 44,
width: 274, width: 274,
height: 184, height: 184,
clickOnTap: true,
throwVisibility: 88, throwVisibility: 88,
minScale: 0.5, minScale: 0.5,
maxScale: 1.5}) maxScale: 1.5})
app2.run()
</script> </script>
</body> </body>

View File

@ -865,10 +865,11 @@ export class DOMScatterContainer {
* @param {String} [touchAction=none] - CSS to set touch action style, needed to prevent * @param {String} [touchAction=none] - CSS to set touch action style, needed to prevent
* pointer cancel events. Use null if the * pointer cancel events. Use null if the
* the touch action should not be set. * the touch action should not be set.
* @param {DOM node} debugCanvas - Shows debug infos about touches if not null
*/ */
constructor( constructor(
element, element,
{ stopEvents = 'auto', claimEvents = true, useCapture = true, touchAction = 'none' } = {} { stopEvents = 'auto', claimEvents = true, useCapture = true, touchAction = 'none', debugCanvas = null } = {}
) { ) {
this.onCapture = null this.onCapture = null
this.element = element this.element = element
@ -900,7 +901,7 @@ export class DOMScatterContainer {
mouseWheelElement: window mouseWheelElement: window
}) })
if (typeof debugCanvas !== 'undefined') { if (debugCanvas !== null) {
requestAnimationFrame(dt => { requestAnimationFrame(dt => {
this.showTouches(dt, debugCanvas) this.showTouches(dt, debugCanvas)
}) })