1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-20 17:28:51 +02:00
phorge-phorge/webroot/rsrc/js/application/uiexample/gesture-example.js
epriestley 0569218201 Use JsShrink if jsxmin is not available
Summary: If `jsxmin` is not available, use a pure PHP implementation instead (JsShrink).

Test Plan:
  - Ran `arc lint --lintall` on all JS and fixed every relevant warning.
  - Forced minification on and browsed around the site using JS behaviors. Didn't hit anything problematic.

Reviewers: vrana, btrahan

Reviewed By: vrana

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D5670
2013-05-18 17:04:22 -07:00

87 lines
1.7 KiB
JavaScript

/**
* @requires javelin-stratcom
* javelin-behavior
* javelin-vector
* javelin-dom
* @provides javelin-behavior-phabricator-gesture-example
*/
JX.behavior('phabricator-gesture-example', function(config) {
var strokes = [];
var current = [];
var root = JX.$(config.rootID);
var canvas = JX.$N('canvas');
var d = JX.Vector.getDim(root);
canvas.width = d.x;
canvas.height = d.y;
root.appendChild(canvas);
var cxt = canvas.getContext('2d');
JX.Stratcom.listen(
'gesture.swipe.end',
null,
function(e) {
var stroke = get_stroke(e);
strokes.push(stroke);
current = [];
redraw();
});
JX.Stratcom.listen(
'gesture.swipe.move',
null,
function(e) {
var stroke = get_stroke(e);
current = [stroke];
redraw();
});
JX.Stratcom.listen(
'gesture.swipe.cancel',
null,
function(e) {
current = [];
redraw();
});
function get_stroke(e) {
var data = e.getData();
var p = JX.$V(root);
return [
data.p0.x - p.x,
data.p0.y - p.y,
data.p1.x - p.x,
data.p1.y - p.y
];
}
function redraw() {
cxt.fillStyle = '#dfdfdf';
cxt.fillRect(0, 0, d.x, d.y);
var s;
var ii;
for (ii = 0; ii < strokes.length; ii++) {
s = strokes[ii];
cxt.strokeStyle = 'rgba(0, 0, 0, 0.50)';
cxt.beginPath();
cxt.moveTo(s[0], s[1]);
cxt.lineTo(s[2], s[3]);
cxt.stroke();
}
for (ii = 0; ii < current.length; ii++) {
s = current[ii];
cxt.strokeStyle = 'rgba(255, 0, 0, 1)';
cxt.beginPath();
cxt.moveTo(s[0], s[1]);
cxt.lineTo(s[2], s[3]);
cxt.stroke();
}
}
redraw();
});