zimjs 20.0.7 → 20.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/zim.js +315 -284
package/package.json
CHANGED
package/src/zim.js
CHANGED
|
@@ -58287,6 +58287,9 @@ Automatically manages user sensor permission via ZIM PermissionAsk if permission
|
|
|
58287
58287
|
NOTE: If permission has already been granted, tilt activates immediately.
|
|
58288
58288
|
If multiple objects call tilt(), turn(), or shake() before permission is granted, they are queued and activated together once the user accepts.
|
|
58289
58289
|
|
|
58290
|
+
NOTE: To change the text of the Dialog set: F.sensorText = "OKAY?"; // BEFORE calling the tilt()
|
|
58291
|
+
To change buttons of the Dialog set: F.sensorAsk.yes.text = "OUI"; F.sensorAsk.no.text = "NON"; // AFTER calling the tilt()
|
|
58292
|
+
|
|
58290
58293
|
ALSO: see noTilt() to remove tilt behaviors.
|
|
58291
58294
|
|
|
58292
58295
|
ALSO: see tiltBoundary() to dynamically change or clear the boundary rectangle.
|
|
@@ -58323,135 +58326,135 @@ ready - (default null) callback function called when permission resolves, receiv
|
|
|
58323
58326
|
|
|
58324
58327
|
RETURNS obj for chaining
|
|
58325
58328
|
--*///+34.9
|
|
58326
|
-
zim.tilt = function(obj, boundary, damp, factor, mode, type, ready) {
|
|
58327
|
-
|
|
58328
|
-
|
|
58329
|
-
|
|
58330
|
-
|
|
58329
|
+
zim.tilt = function(obj, boundary, damp, factor, mode, type, ready) {
|
|
58330
|
+
var sig = "obj, boundary, damp, factor, mode, type, ready";
|
|
58331
|
+
var duo; if (duo = zob(zim.tilt, arguments, sig)) return duo;
|
|
58332
|
+
if ((obj.type=="AC"||(obj.type=="Emoji"&&obj.svg&&obj.svg.type=="AC"))&&WW.zdf) {WW.zdf.ac("tilt", arguments); return obj;}
|
|
58333
|
+
z_d("34.9");
|
|
58331
58334
|
|
|
58332
|
-
|
|
58333
|
-
|
|
58334
|
-
|
|
58335
|
+
// MONITOR
|
|
58336
|
+
var mID = "z~tilt";
|
|
58337
|
+
if (obj && obj.mID && ((obj.mID[2] && obj.mID[2]=="-") || obj.mID[0]=="-")) mID = "z~-";
|
|
58335
58338
|
|
|
58336
|
-
|
|
58339
|
+
if (zot(obj)) return;
|
|
58337
58340
|
|
|
58338
|
-
|
|
58339
|
-
|
|
58340
|
-
|
|
58341
|
-
var f = obj.frame || (typeof zdf != "undefined" ? zdf : WW.zdf);
|
|
58342
|
-
var s = obj.stage || (f ? f.stage : null);
|
|
58343
|
-
|
|
58344
|
-
// Set initial boundary
|
|
58345
|
-
zim.tiltBoundary(obj, boundary);
|
|
58346
|
-
|
|
58347
|
-
if (zot(damp)) damp = 0.05;
|
|
58348
|
-
if (zot(factor)) factor = 0.5;
|
|
58349
|
-
var factorX = typeof factor === "object" ? factor.x : factor;
|
|
58350
|
-
var factorY = typeof factor === "object" ? factor.y : factor;
|
|
58351
|
-
if (zot(mode)) mode = "move";
|
|
58352
|
-
if (zot(type)) type = "deviceorientation";
|
|
58353
|
-
|
|
58354
|
-
var dampX = damp ? new zim.Damp(mode == "position" ? obj.x : 0, damp) : null;
|
|
58355
|
-
var dampY = damp ? new zim.Damp(mode == "position" ? obj.y : 0, damp) : null;
|
|
58356
|
-
var currentRot = {x: 0, y: 0, z: 0};
|
|
58357
|
-
|
|
58358
|
-
function updateTilt() {
|
|
58359
|
-
var orient = 0;
|
|
58360
|
-
if (typeof WW != "undefined") {
|
|
58361
|
-
if (WW.screen && WW.screen.orientation && WW.screen.orientation.angle != null) {
|
|
58362
|
-
orient = WW.screen.orientation.angle;
|
|
58363
|
-
} else if (typeof WW.orientation != "undefined") {
|
|
58364
|
-
orient = WW.orientation;
|
|
58365
|
-
}
|
|
58366
|
-
}
|
|
58367
|
-
|
|
58368
|
-
var beta = currentRot.x;
|
|
58369
|
-
var gamma = currentRot.y;
|
|
58370
|
-
var tiltX, tiltY;
|
|
58371
|
-
|
|
58372
|
-
if (orient == 90) {
|
|
58373
|
-
tiltX = beta;
|
|
58374
|
-
tiltY = -gamma;
|
|
58375
|
-
} else if (orient == -90 || orient == 270) {
|
|
58376
|
-
tiltX = -beta;
|
|
58377
|
-
tiltY = gamma;
|
|
58378
|
-
} else if (orient == 180) {
|
|
58379
|
-
tiltX = -gamma;
|
|
58380
|
-
tiltY = -beta;
|
|
58381
|
-
} else {
|
|
58382
|
-
tiltX = gamma;
|
|
58383
|
-
tiltY = beta;
|
|
58384
|
-
}
|
|
58341
|
+
// Clean up any existing tilt on this object first
|
|
58342
|
+
if (obj._tiltTicker) zim.noTilt(obj);
|
|
58385
58343
|
|
|
58386
|
-
|
|
58387
|
-
|
|
58388
|
-
var rotY = dampY ? dampY.convert(tiltY) : tiltY;
|
|
58389
|
-
obj.x += rotX * factorX;
|
|
58390
|
-
obj.y += rotY * factorY;
|
|
58391
|
-
} else if (mode == "position") {
|
|
58392
|
-
var targetX = (obj._tiltStartX != null ? obj._tiltStartX : obj.x) + tiltX * factorX * 10;
|
|
58393
|
-
var targetY = (obj._tiltStartY != null ? obj._tiltStartY : obj.y) + tiltY * factorY * 10;
|
|
58394
|
-
obj.x = dampX ? dampX.convert(targetX) : targetX;
|
|
58395
|
-
obj.y = dampY ? dampY.convert(targetY) : targetY;
|
|
58396
|
-
}
|
|
58344
|
+
var f = obj.frame || (typeof zdf != "undefined" ? zdf : WW.zdf);
|
|
58345
|
+
var s = obj.stage || (f ? f.stage : null);
|
|
58397
58346
|
|
|
58398
|
-
|
|
58399
|
-
|
|
58400
|
-
obj.y = zim.constrain(obj.y, obj._tiltBoundary.y, obj._tiltBoundary.y + obj._tiltBoundary.height);
|
|
58401
|
-
}
|
|
58347
|
+
// Set initial boundary
|
|
58348
|
+
zim.tiltBoundary(obj, boundary);
|
|
58402
58349
|
|
|
58403
|
-
if (
|
|
58404
|
-
|
|
58350
|
+
if (zot(damp)) damp = 0.05;
|
|
58351
|
+
if (zot(factor)) factor = 0.5;
|
|
58352
|
+
var factorX = typeof factor === "object" ? factor.x : factor;
|
|
58353
|
+
var factorY = typeof factor === "object" ? factor.y : factor;
|
|
58354
|
+
if (zot(mode)) mode = "move";
|
|
58355
|
+
if (zot(type)) type = "deviceorientation";
|
|
58405
58356
|
|
|
58406
|
-
|
|
58407
|
-
|
|
58408
|
-
|
|
58409
|
-
|
|
58410
|
-
|
|
58411
|
-
|
|
58412
|
-
|
|
58413
|
-
|
|
58414
|
-
|
|
58415
|
-
|
|
58416
|
-
|
|
58417
|
-
|
|
58418
|
-
|
|
58419
|
-
|
|
58357
|
+
var dampX = damp ? new zim.Damp(mode == "position" ? obj.x : 0, damp) : null;
|
|
58358
|
+
var dampY = damp ? new zim.Damp(mode == "position" ? obj.y : 0, damp) : null;
|
|
58359
|
+
var currentRot = {x: 0, y: 0, z: 0};
|
|
58360
|
+
|
|
58361
|
+
function updateTilt() {
|
|
58362
|
+
var orient = 0;
|
|
58363
|
+
if (typeof WW != "undefined") {
|
|
58364
|
+
if (WW.screen && WW.screen.orientation && WW.screen.orientation.angle != null) {
|
|
58365
|
+
orient = WW.screen.orientation.angle;
|
|
58366
|
+
} else if (typeof WW.orientation != "undefined") {
|
|
58367
|
+
orient = WW.orientation;
|
|
58368
|
+
}
|
|
58369
|
+
}
|
|
58370
|
+
|
|
58371
|
+
var beta = currentRot.x;
|
|
58372
|
+
var gamma = currentRot.y;
|
|
58373
|
+
var tiltX, tiltY;
|
|
58374
|
+
|
|
58375
|
+
if (orient == 90) {
|
|
58376
|
+
tiltX = beta;
|
|
58377
|
+
tiltY = -gamma;
|
|
58378
|
+
} else if (orient == -90 || orient == 270) {
|
|
58379
|
+
tiltX = -beta;
|
|
58380
|
+
tiltY = gamma;
|
|
58381
|
+
} else if (orient == 180) {
|
|
58382
|
+
tiltX = -gamma;
|
|
58383
|
+
tiltY = -beta;
|
|
58420
58384
|
} else {
|
|
58421
|
-
|
|
58422
|
-
|
|
58423
|
-
currentRot.z = e.alpha || 0;
|
|
58385
|
+
tiltX = gamma;
|
|
58386
|
+
tiltY = beta;
|
|
58424
58387
|
}
|
|
58425
|
-
};
|
|
58426
|
-
f.on(type, obj._tiltListener);
|
|
58427
58388
|
|
|
58428
|
-
|
|
58429
|
-
|
|
58430
|
-
|
|
58389
|
+
if (mode == "move") {
|
|
58390
|
+
var rotX = dampX ? dampX.convert(tiltX) : tiltX;
|
|
58391
|
+
var rotY = dampY ? dampY.convert(tiltY) : tiltY;
|
|
58392
|
+
obj.x += rotX * factorX;
|
|
58393
|
+
obj.y += rotY * factorY;
|
|
58394
|
+
} else if (mode == "position") {
|
|
58395
|
+
var targetX = (obj._tiltStartX != null ? obj._tiltStartX : obj.x) + tiltX * factorX * 10;
|
|
58396
|
+
var targetY = (obj._tiltStartY != null ? obj._tiltStartY : obj.y) + tiltY * factorY * 10;
|
|
58397
|
+
obj.x = dampX ? dampX.convert(targetX) : targetX;
|
|
58398
|
+
obj.y = dampY ? dampY.convert(targetY) : targetY;
|
|
58399
|
+
}
|
|
58431
58400
|
|
|
58432
|
-
|
|
58433
|
-
|
|
58434
|
-
|
|
58435
|
-
|
|
58436
|
-
f._permissionQueue.push(activate);
|
|
58437
|
-
} else {
|
|
58438
|
-
f._permissionPending = true;
|
|
58439
|
-
f._permissionQueue = [activate];
|
|
58401
|
+
if (obj._tiltBoundary) {
|
|
58402
|
+
obj.x = zim.constrain(obj.x, obj._tiltBoundary.x, obj._tiltBoundary.x + obj._tiltBoundary.width);
|
|
58403
|
+
obj.y = zim.constrain(obj.y, obj._tiltBoundary.y, obj._tiltBoundary.y + obj._tiltBoundary.height);
|
|
58404
|
+
}
|
|
58440
58405
|
|
|
58441
|
-
|
|
58442
|
-
|
|
58443
|
-
|
|
58444
|
-
|
|
58445
|
-
|
|
58406
|
+
if (s) s.update();
|
|
58407
|
+
}
|
|
58408
|
+
|
|
58409
|
+
function activate() {
|
|
58410
|
+
obj._tiltStartX = obj.x;
|
|
58411
|
+
obj._tiltStartY = obj.y;
|
|
58412
|
+
if (mode == "position" && dampX && dampY) {
|
|
58413
|
+
dampX.immediate(obj.x);
|
|
58414
|
+
dampY.immediate(obj.y);
|
|
58415
|
+
}
|
|
58416
|
+
|
|
58417
|
+
obj._tiltType = type;
|
|
58418
|
+
obj._tiltListener = function(e) {
|
|
58419
|
+
if (e.rotation) {
|
|
58420
|
+
currentRot.x = e.rotation.x || 0;
|
|
58421
|
+
currentRot.y = e.rotation.y || 0;
|
|
58422
|
+
currentRot.z = e.rotation.z || 0;
|
|
58423
|
+
} else {
|
|
58424
|
+
currentRot.x = e.beta || 0;
|
|
58425
|
+
currentRot.y = e.gamma || 0;
|
|
58426
|
+
currentRot.z = e.alpha || 0;
|
|
58427
|
+
}
|
|
58428
|
+
};
|
|
58429
|
+
f.on(type, obj._tiltListener);
|
|
58430
|
+
|
|
58431
|
+
obj._tiltTicker = zim.Ticker.add(updateTilt);
|
|
58432
|
+
if (ready) ready(true, obj);
|
|
58433
|
+
}
|
|
58434
|
+
|
|
58435
|
+
// Shared Permission check & queueing
|
|
58436
|
+
if (f._permissionGranted) {
|
|
58437
|
+
activate();
|
|
58438
|
+
} else if (f._permissionPending) {
|
|
58439
|
+
f._permissionQueue.push({ activate: activate, reject: function() { if (ready) ready(false, obj); } });
|
|
58440
|
+
} else {
|
|
58441
|
+
f._permissionPending = true;
|
|
58442
|
+
f._permissionQueue = [{ activate: activate, reject: function() { if (ready) ready(false, obj); } }];
|
|
58443
|
+
|
|
58444
|
+
new zim.PermissionAsk(function(yes) {
|
|
58445
|
+
f._permissionPending = false;
|
|
58446
|
+
if (yes) {
|
|
58447
|
+
f._permissionGranted = true;
|
|
58448
|
+
zim.loop(f._permissionQueue, function(item) { item.activate(); });
|
|
58449
|
+
} else {
|
|
58450
|
+
zim.loop(f._permissionQueue, function(item) { item.reject(); });
|
|
58451
|
+
}
|
|
58446
58452
|
f._permissionQueue = [];
|
|
58447
|
-
}
|
|
58448
|
-
|
|
58449
|
-
}
|
|
58450
|
-
}, type);
|
|
58451
|
-
}
|
|
58453
|
+
}, type);
|
|
58454
|
+
}
|
|
58452
58455
|
|
|
58453
|
-
|
|
58454
|
-
};//-34.9
|
|
58456
|
+
return obj;
|
|
58457
|
+
};//-34.9
|
|
58455
58458
|
|
|
58456
58459
|
|
|
58457
58460
|
/*--
|
|
@@ -58472,33 +58475,31 @@ END EXAMPLE
|
|
|
58472
58475
|
|
|
58473
58476
|
RETURNS obj for chaining
|
|
58474
58477
|
--*///+34.91
|
|
58475
|
-
zim.noTilt = function(obj) {
|
|
58476
|
-
|
|
58477
|
-
|
|
58478
|
-
|
|
58479
|
-
|
|
58480
|
-
if (zot(obj) || !obj.on || !obj.zimTouch) return;
|
|
58478
|
+
zim.noTilt = function(obj) {
|
|
58479
|
+
var sig = "obj";
|
|
58480
|
+
var duo; if (duo = zob(zim.noTilt, arguments, sig)) return duo;
|
|
58481
|
+
z_d("34.91");
|
|
58481
58482
|
|
|
58482
|
-
|
|
58483
|
-
var mID = "z~noTilt";
|
|
58484
|
-
if (obj && obj.mID && ((obj.mID[2] && obj.mID[2]=="-") || obj.mID[0]=="-")) mID = "z~-";
|
|
58485
|
-
|
|
58486
|
-
if (zot(obj)) return;
|
|
58487
|
-
var f = obj.frame || (typeof zdf != "undefined" ? zdf : WW.zdf);
|
|
58483
|
+
if (zot(obj) || !obj.on || !obj.zimTouch) return;
|
|
58488
58484
|
|
|
58489
|
-
|
|
58490
|
-
|
|
58491
|
-
obj.
|
|
58492
|
-
|
|
58493
|
-
|
|
58494
|
-
zim.Ticker.remove(obj._tiltTicker);
|
|
58495
|
-
obj._tiltTicker = null;
|
|
58496
|
-
}
|
|
58497
|
-
obj._tiltBoundary = null;
|
|
58485
|
+
// MONITOR
|
|
58486
|
+
var mID = "z~noTilt";
|
|
58487
|
+
if (obj && obj.mID && ((obj.mID[2] && obj.mID[2]=="-") || obj.mID[0]=="-")) mID = "z~-";
|
|
58488
|
+
|
|
58489
|
+
var f = obj.frame || (typeof zdf != "undefined" ? zdf : WW.zdf);
|
|
58498
58490
|
|
|
58499
|
-
|
|
58491
|
+
if (obj._tiltListener && f) {
|
|
58492
|
+
f.off(obj._tiltType || "deviceorientation", obj._tiltListener);
|
|
58493
|
+
obj._tiltListener = null;
|
|
58494
|
+
}
|
|
58495
|
+
if (obj._tiltTicker) {
|
|
58496
|
+
zim.Ticker.remove(obj._tiltTicker);
|
|
58497
|
+
obj._tiltTicker = null;
|
|
58498
|
+
}
|
|
58499
|
+
obj._tiltBoundary = null;
|
|
58500
58500
|
|
|
58501
|
-
|
|
58501
|
+
return obj;
|
|
58502
|
+
};//-34.91
|
|
58502
58503
|
|
|
58503
58504
|
|
|
58504
58505
|
/*--
|
|
@@ -58610,6 +58611,9 @@ NOTE: If permission has already been granted, turn activates immediately.
|
|
|
58610
58611
|
If multiple objects call tilt(), turn(), or shake() before permission is granted, they are queued and activated together once the user accepts.
|
|
58611
58612
|
Rotation is applied relative to the object's initial rotation when turn() is called (for example, an arrow rotated -90 to point up will maintain that -90 offset).
|
|
58612
58613
|
|
|
58614
|
+
NOTE: To change the text of the Dialog set: F.sensorText = "OKAY?"; // BEFORE calling the turn()
|
|
58615
|
+
To change buttons of the Dialog set: F.sensorAsk.yes.text = "OUI"; F.sensorAsk.no.text = "NON"; // AFTER calling the turn()
|
|
58616
|
+
|
|
58613
58617
|
ALSO: see noTurn() to remove turning behaviors.
|
|
58614
58618
|
|
|
58615
58619
|
EXAMPLE
|
|
@@ -58755,7 +58759,6 @@ RETURNS obj for chaining
|
|
|
58755
58759
|
lastMode = curMode;
|
|
58756
58760
|
if (dampRot) dampRot.immediate(obj.rotation);
|
|
58757
58761
|
} else if (lastMode !== null && curMode !== lastMode) {
|
|
58758
|
-
// Seamless transition between upright and flat
|
|
58759
58762
|
var prevDiff = angleDiff(currentDeviceAngle, startDeviceAngle);
|
|
58760
58763
|
startDeviceAngle = ang - prevDiff;
|
|
58761
58764
|
lastMode = curMode;
|
|
@@ -58769,24 +58772,24 @@ RETURNS obj for chaining
|
|
|
58769
58772
|
if (ready) ready(true, obj);
|
|
58770
58773
|
}
|
|
58771
58774
|
|
|
58772
|
-
//
|
|
58775
|
+
// Shared Permission check & queueing
|
|
58773
58776
|
if (f._permissionGranted) {
|
|
58774
58777
|
activate();
|
|
58775
58778
|
} else if (f._permissionPending) {
|
|
58776
|
-
f._permissionQueue.push(activate);
|
|
58779
|
+
f._permissionQueue.push({ activate: activate, reject: function() { if (ready) ready(false, obj); } });
|
|
58777
58780
|
} else {
|
|
58778
58781
|
f._permissionPending = true;
|
|
58779
|
-
f._permissionQueue = [activate];
|
|
58782
|
+
f._permissionQueue = [{ activate: activate, reject: function() { if (ready) ready(false, obj); } }];
|
|
58780
58783
|
|
|
58781
58784
|
new zim.PermissionAsk(function(yes) {
|
|
58782
58785
|
f._permissionPending = false;
|
|
58783
58786
|
if (yes) {
|
|
58784
58787
|
f._permissionGranted = true;
|
|
58785
|
-
zim.loop(f._permissionQueue, function(
|
|
58786
|
-
f._permissionQueue = [];
|
|
58788
|
+
zim.loop(f._permissionQueue, function(item) { item.activate(); });
|
|
58787
58789
|
} else {
|
|
58788
|
-
|
|
58790
|
+
zim.loop(f._permissionQueue, function(item) { item.reject(); });
|
|
58789
58791
|
}
|
|
58792
|
+
f._permissionQueue = [];
|
|
58790
58793
|
}, type);
|
|
58791
58794
|
}
|
|
58792
58795
|
|
|
@@ -58851,6 +58854,9 @@ Automatically manages user sensor permission via ZIM PermissionAsk if permission
|
|
|
58851
58854
|
NOTE: If permission has already been granted, shake activates immediately.
|
|
58852
58855
|
If multiple objects call tilt(), turn(), or shake() before permission is granted, they are queued and activated together once the user accepts.
|
|
58853
58856
|
|
|
58857
|
+
NOTE: To change the text of the Dialog set: F.sensorText = "OKAY?"; // BEFORE calling the shake()
|
|
58858
|
+
To change buttons of the Dialog set: F.sensorAsk.yes.text = "OUI"; F.sensorAsk.no.text = "NON"; // AFTER calling the shake()
|
|
58859
|
+
|
|
58854
58860
|
ALSO: see noShake() to remove shake listeners.
|
|
58855
58861
|
|
|
58856
58862
|
EXAMPLE
|
|
@@ -58897,137 +58903,137 @@ Dispatches a "shakestop" event on obj when shaking stops.
|
|
|
58897
58903
|
|
|
58898
58904
|
RETURNS obj for chaining
|
|
58899
58905
|
--*///+34.95
|
|
58900
|
-
zim.shake = function(obj, call, stopCall, threshold, wait, factor, type, ready) {
|
|
58901
|
-
|
|
58902
|
-
|
|
58903
|
-
|
|
58904
|
-
|
|
58906
|
+
zim.shake = function(obj, call, stopCall, threshold, wait, factor, type, ready) {
|
|
58907
|
+
var sig = "obj, call, stopCall, threshold, wait, factor, type, ready";
|
|
58908
|
+
var duo; if (duo = zob(zim.shake, arguments, sig)) return duo;
|
|
58909
|
+
if ((obj.type=="AC"||(obj.type=="Emoji"&&obj.svg&&obj.svg.type=="AC"))&&WW.zdf) {WW.zdf.ac("shake", arguments); return obj;}
|
|
58910
|
+
z_d("34.95");
|
|
58905
58911
|
|
|
58906
|
-
|
|
58907
|
-
|
|
58908
|
-
|
|
58912
|
+
// MONITOR
|
|
58913
|
+
var mID = "z~shake";
|
|
58914
|
+
if (obj && obj.mID && ((obj.mID[2] && obj.mID[2]=="-") || obj.mID[0]=="-")) mID = "z~-";
|
|
58909
58915
|
|
|
58910
|
-
|
|
58916
|
+
if (zot(obj)) return;
|
|
58911
58917
|
|
|
58912
|
-
|
|
58913
|
-
|
|
58918
|
+
// Clean up any existing shake on this object first
|
|
58919
|
+
if (obj._shakeListener) zim.noShake(obj);
|
|
58914
58920
|
|
|
58915
|
-
|
|
58916
|
-
|
|
58921
|
+
var f = obj.frame || (typeof zdf != "undefined" ? zdf : WW.zdf);
|
|
58922
|
+
var s = obj.stage || (f ? f.stage : null);
|
|
58917
58923
|
|
|
58918
|
-
|
|
58919
|
-
|
|
58920
|
-
|
|
58921
|
-
|
|
58924
|
+
if (zot(threshold)) threshold = 10;
|
|
58925
|
+
if (zot(wait)) wait = 0.5;
|
|
58926
|
+
if (zot(factor)) factor = 1;
|
|
58927
|
+
if (zot(type)) type = "devicemotion";
|
|
58922
58928
|
|
|
58923
|
-
|
|
58924
|
-
|
|
58929
|
+
var lastX = 0, lastY = 0, lastZ = 0;
|
|
58930
|
+
var lastTime = 0;
|
|
58925
58931
|
|
|
58926
|
-
|
|
58927
|
-
|
|
58928
|
-
|
|
58932
|
+
function handleMotion(e) {
|
|
58933
|
+
var acc = e.acceleration && (e.acceleration.x != null || e.acceleration.y != null) ?
|
|
58934
|
+
e.acceleration : (e.accelerationIncludingGravity || e);
|
|
58929
58935
|
|
|
58930
|
-
|
|
58931
|
-
|
|
58932
|
-
|
|
58936
|
+
var ax = acc.x || 0;
|
|
58937
|
+
var ay = acc.y || 0;
|
|
58938
|
+
var az = acc.z || 0;
|
|
58933
58939
|
|
|
58934
|
-
|
|
58935
|
-
|
|
58936
|
-
|
|
58940
|
+
var deltaX = ax - lastX;
|
|
58941
|
+
var deltaY = ay - lastY;
|
|
58942
|
+
var deltaZ = az - lastZ;
|
|
58937
58943
|
|
|
58938
|
-
|
|
58939
|
-
|
|
58940
|
-
|
|
58944
|
+
lastX = ax;
|
|
58945
|
+
lastY = ay;
|
|
58946
|
+
lastZ = az;
|
|
58941
58947
|
|
|
58942
|
-
|
|
58948
|
+
var mag = Math.sqrt(deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ) * factor;
|
|
58943
58949
|
|
|
58944
|
-
|
|
58945
|
-
|
|
58950
|
+
if (mag >= threshold) {
|
|
58951
|
+
var now = Date.now();
|
|
58946
58952
|
|
|
58947
|
-
|
|
58948
|
-
if (obj._shakeStopTimeout) obj._shakeStopTimeout.clear();
|
|
58953
|
+
if (obj._shakeStopTimeout) obj._shakeStopTimeout.clear();
|
|
58949
58954
|
|
|
58950
|
-
|
|
58951
|
-
|
|
58952
|
-
|
|
58953
|
-
|
|
58954
|
-
|
|
58955
|
-
|
|
58955
|
+
obj._shakeStopTimeout = zim.timeout(wait, function() {
|
|
58956
|
+
obj._shakeStopTimeout = null;
|
|
58957
|
+
if (stopCall) stopCall(obj);
|
|
58958
|
+
obj.dispatchEvent({
|
|
58959
|
+
type: "shakestop",
|
|
58960
|
+
event: e
|
|
58961
|
+
});
|
|
58962
|
+
if (s) s.update();
|
|
58956
58963
|
});
|
|
58957
|
-
if (s) s.update();
|
|
58958
|
-
});
|
|
58959
58964
|
|
|
58960
|
-
|
|
58961
|
-
|
|
58965
|
+
if (now - lastTime >= wait * 1000) {
|
|
58966
|
+
lastTime = now;
|
|
58962
58967
|
|
|
58963
|
-
|
|
58964
|
-
|
|
58965
|
-
|
|
58966
|
-
|
|
58967
|
-
|
|
58968
|
-
|
|
58968
|
+
var orient = 0;
|
|
58969
|
+
if (typeof WW != "undefined") {
|
|
58970
|
+
if (WW.screen && WW.screen.orientation && WW.screen.orientation.angle != null) {
|
|
58971
|
+
orient = WW.screen.orientation.angle;
|
|
58972
|
+
} else if (typeof WW.orientation != "undefined") {
|
|
58973
|
+
orient = WW.orientation;
|
|
58974
|
+
}
|
|
58969
58975
|
}
|
|
58970
|
-
}
|
|
58971
58976
|
|
|
58972
|
-
|
|
58973
|
-
|
|
58974
|
-
|
|
58975
|
-
|
|
58976
|
-
|
|
58977
|
-
|
|
58978
|
-
|
|
58979
|
-
|
|
58980
|
-
|
|
58981
|
-
|
|
58982
|
-
|
|
58983
|
-
|
|
58984
|
-
|
|
58985
|
-
|
|
58986
|
-
|
|
58987
|
-
if (call) call(mag, shakeX, shakeY, shakeZ, obj, e);
|
|
58988
|
-
obj.dispatchEvent({
|
|
58989
|
-
type: "shake",
|
|
58990
|
-
total: mag,
|
|
58991
|
-
x: shakeX,
|
|
58992
|
-
y: shakeY,
|
|
58993
|
-
z: shakeZ,
|
|
58994
|
-
event: e
|
|
58995
|
-
});
|
|
58977
|
+
var shakeX, shakeY, shakeZ = deltaZ * factor;
|
|
58978
|
+
if (orient == 90) {
|
|
58979
|
+
shakeX = deltaY * factor;
|
|
58980
|
+
shakeY = -deltaX * factor;
|
|
58981
|
+
} else if (orient == -90 || orient == 270) {
|
|
58982
|
+
shakeX = -deltaY * factor;
|
|
58983
|
+
shakeY = deltaX * factor;
|
|
58984
|
+
} else if (orient == 180) {
|
|
58985
|
+
shakeX = -deltaX * factor;
|
|
58986
|
+
shakeY = -deltaY * factor;
|
|
58987
|
+
} else {
|
|
58988
|
+
shakeX = deltaX * factor;
|
|
58989
|
+
shakeY = deltaY * factor;
|
|
58990
|
+
}
|
|
58996
58991
|
|
|
58992
|
+
if (call) call(mag, shakeX, shakeY, shakeZ, obj, e);
|
|
58993
|
+
obj.dispatchEvent({
|
|
58994
|
+
type: "shake",
|
|
58995
|
+
total: mag,
|
|
58996
|
+
x: shakeX,
|
|
58997
|
+
y: shakeY,
|
|
58998
|
+
z: shakeZ,
|
|
58999
|
+
event: e
|
|
59000
|
+
});
|
|
59001
|
+
|
|
59002
|
+
if (s) s.update();
|
|
59003
|
+
}
|
|
58997
59004
|
}
|
|
58998
59005
|
}
|
|
58999
|
-
}
|
|
59000
59006
|
|
|
59001
|
-
|
|
59002
|
-
|
|
59003
|
-
|
|
59004
|
-
|
|
59005
|
-
|
|
59006
|
-
|
|
59007
|
+
function activate() {
|
|
59008
|
+
obj._shakeType = type;
|
|
59009
|
+
obj._shakeListener = handleMotion;
|
|
59010
|
+
f.on(type, obj._shakeListener);
|
|
59011
|
+
if (ready) ready(true, obj);
|
|
59012
|
+
}
|
|
59007
59013
|
|
|
59008
|
-
|
|
59009
|
-
|
|
59010
|
-
|
|
59011
|
-
|
|
59012
|
-
|
|
59013
|
-
|
|
59014
|
-
|
|
59015
|
-
|
|
59014
|
+
// Shared Permission check & queueing
|
|
59015
|
+
if (f._permissionGranted) {
|
|
59016
|
+
activate();
|
|
59017
|
+
} else if (f._permissionPending) {
|
|
59018
|
+
f._permissionQueue.push({ activate: activate, reject: function() { if (ready) ready(false, obj); } });
|
|
59019
|
+
} else {
|
|
59020
|
+
f._permissionPending = true;
|
|
59021
|
+
f._permissionQueue = [{ activate: activate, reject: function() { if (ready) ready(false, obj); } }];
|
|
59016
59022
|
|
|
59017
|
-
|
|
59018
|
-
|
|
59019
|
-
|
|
59020
|
-
|
|
59021
|
-
|
|
59023
|
+
new zim.PermissionAsk(function(yes) {
|
|
59024
|
+
f._permissionPending = false;
|
|
59025
|
+
if (yes) {
|
|
59026
|
+
f._permissionGranted = true;
|
|
59027
|
+
zim.loop(f._permissionQueue, function(item) { item.activate(); });
|
|
59028
|
+
} else {
|
|
59029
|
+
zim.loop(f._permissionQueue, function(item) { item.reject(); });
|
|
59030
|
+
}
|
|
59022
59031
|
f._permissionQueue = [];
|
|
59023
|
-
}
|
|
59024
|
-
|
|
59025
|
-
}
|
|
59026
|
-
}, type);
|
|
59027
|
-
}
|
|
59032
|
+
}, type);
|
|
59033
|
+
}
|
|
59028
59034
|
|
|
59029
|
-
|
|
59030
|
-
};//-34.95
|
|
59035
|
+
return obj;
|
|
59036
|
+
};//-34.95
|
|
59031
59037
|
|
|
59032
59038
|
|
|
59033
59039
|
/*--
|
|
@@ -59048,30 +59054,30 @@ END EXAMPLE
|
|
|
59048
59054
|
|
|
59049
59055
|
RETURNS obj for chaining
|
|
59050
59056
|
--*///+34.96
|
|
59051
|
-
zim.noShake = function(obj) {
|
|
59052
|
-
|
|
59053
|
-
|
|
59054
|
-
|
|
59057
|
+
zim.noShake = function(obj) {
|
|
59058
|
+
var sig = "obj";
|
|
59059
|
+
var duo; if (duo = zob(zim.noShake, arguments, sig)) return duo;
|
|
59060
|
+
z_d("34.96");
|
|
59055
59061
|
|
|
59056
|
-
|
|
59062
|
+
if (zot(obj) || !obj.on || !obj.zimTouch) return;
|
|
59057
59063
|
|
|
59058
|
-
|
|
59059
|
-
|
|
59060
|
-
|
|
59064
|
+
// MONITOR
|
|
59065
|
+
var mID = "z~noShake";
|
|
59066
|
+
if (obj && obj.mID && ((obj.mID[2] && obj.mID[2]=="-") || obj.mID[0]=="-")) mID = "z~-";
|
|
59061
59067
|
|
|
59062
|
-
|
|
59068
|
+
var f = obj.frame || (typeof zdf != "undefined" ? zdf : WW.zdf);
|
|
59063
59069
|
|
|
59064
|
-
|
|
59065
|
-
|
|
59066
|
-
|
|
59067
|
-
|
|
59068
|
-
|
|
59069
|
-
|
|
59070
|
-
|
|
59071
|
-
|
|
59070
|
+
if (obj._shakeListener && f) {
|
|
59071
|
+
f.off(obj._shakeType || "devicemotion", obj._shakeListener);
|
|
59072
|
+
obj._shakeListener = null;
|
|
59073
|
+
}
|
|
59074
|
+
if (obj._shakeStopTimeout) {
|
|
59075
|
+
obj._shakeStopTimeout.clear();
|
|
59076
|
+
obj._shakeStopTimeout = null;
|
|
59077
|
+
}
|
|
59072
59078
|
|
|
59073
|
-
|
|
59074
|
-
};//-34.96
|
|
59079
|
+
return obj;
|
|
59080
|
+
};//-34.96
|
|
59075
59081
|
|
|
59076
59082
|
// SUBSECTION HIT TESTS
|
|
59077
59083
|
|
|
@@ -98758,7 +98764,9 @@ Pre ZIM 018, this was done with a sensors parameter on the Frame.
|
|
|
98758
98764
|
The sensors parameter has now been removed and the events are handled with PermissionAsk.
|
|
98759
98765
|
|
|
98760
98766
|
NOTE: this started as SensorAsk but the class has been adjusted to handle other permissions and the name has been changed in ZIM 016
|
|
98767
|
+
|
|
98761
98768
|
NOTE: as of ZIM 5.5.0 the zim namespace is no longer required (unless zns is set to true before running zim)
|
|
98769
|
+
|
|
98762
98770
|
NOTE: sensor prompt text can be customized prior to calling with F.sensorText = "Custom message";
|
|
98763
98771
|
|
|
98764
98772
|
EXAMPLE
|
|
@@ -98930,27 +98938,49 @@ no - reference to the zim Button with NO
|
|
|
98930
98938
|
return;
|
|
98931
98939
|
}
|
|
98932
98940
|
|
|
98933
|
-
//
|
|
98941
|
+
// Sensors probe: iOS uses PermissionAsk popup; Android/Desktop probes hardware directly
|
|
98934
98942
|
if (typeof DeviceOrientationEvent != "undefined" && DeviceOrientationEvent && typeof DeviceOrientationEvent.requestPermission == "function") {
|
|
98935
98943
|
setPane();
|
|
98936
98944
|
} else {
|
|
98937
|
-
var
|
|
98938
|
-
|
|
98945
|
+
var tested = false;
|
|
98946
|
+
var timer = setTimeout(function() {
|
|
98947
|
+
if (tested) return;
|
|
98948
|
+
tested = true;
|
|
98949
|
+
WW.removeEventListener(permissionType, testMe);
|
|
98950
|
+
callback(false, 3); // 3 - timeout / no sensor hardware (e.g. desktop)
|
|
98951
|
+
}, 1000);
|
|
98952
|
+
|
|
98939
98953
|
function testMe(e) {
|
|
98940
|
-
if (okay) return;
|
|
98941
|
-
if (permissionType=="deviceorientation") {
|
|
98942
|
-
if (e.alpha
|
|
98943
|
-
|
|
98954
|
+
if (tested || okay) return;
|
|
98955
|
+
if (permissionType == "deviceorientation") {
|
|
98956
|
+
if (e.alpha != null || e.beta != null || e.gamma != null) {
|
|
98957
|
+
tested = true;
|
|
98958
|
+
clearTimeout(timer);
|
|
98959
|
+
WW.removeEventListener(permissionType, testMe);
|
|
98960
|
+
setEvents();
|
|
98961
|
+
} else {
|
|
98962
|
+
tested = true;
|
|
98963
|
+
clearTimeout(timer);
|
|
98964
|
+
WW.removeEventListener(permissionType, testMe);
|
|
98965
|
+
callback(false, 1);
|
|
98966
|
+
}
|
|
98944
98967
|
} else {
|
|
98945
|
-
|
|
98946
|
-
|
|
98947
|
-
|
|
98948
|
-
|
|
98949
|
-
|
|
98950
|
-
|
|
98951
|
-
|
|
98952
|
-
|
|
98953
|
-
|
|
98968
|
+
var hasAcc = e.acceleration && (e.acceleration.x != null || e.acceleration.y != null || e.acceleration.z != null);
|
|
98969
|
+
var hasGrav = e.accelerationIncludingGravity && (e.accelerationIncludingGravity.x != null || e.accelerationIncludingGravity.y != null || e.accelerationIncludingGravity.z != null);
|
|
98970
|
+
if (hasAcc || hasGrav) {
|
|
98971
|
+
tested = true;
|
|
98972
|
+
clearTimeout(timer);
|
|
98973
|
+
WW.removeEventListener(permissionType, testMe);
|
|
98974
|
+
setEvents();
|
|
98975
|
+
} else {
|
|
98976
|
+
tested = true;
|
|
98977
|
+
clearTimeout(timer);
|
|
98978
|
+
WW.removeEventListener(permissionType, testMe);
|
|
98979
|
+
callback(false, 2);
|
|
98980
|
+
}
|
|
98981
|
+
}
|
|
98982
|
+
}
|
|
98983
|
+
WW.addEventListener(permissionType, testMe);
|
|
98954
98984
|
}
|
|
98955
98985
|
|
|
98956
98986
|
var lastZ = 0;
|
|
@@ -98966,6 +98996,7 @@ no - reference to the zim Button with NO
|
|
|
98966
98996
|
frame.dispatchEvent(e);
|
|
98967
98997
|
}
|
|
98968
98998
|
function setEvents() {
|
|
98999
|
+
if (frame) frame._permissionGranted = true;
|
|
98969
99000
|
if (permissionType=="deviceorientation") {
|
|
98970
99001
|
frame.zimDeviceorientationEvent = deviceorientationEvent;
|
|
98971
99002
|
WW.addEventListener("deviceorientation", frame.zimDeviceorientationEvent);
|