Path: blob/master/webroot/rsrc/js/application/uiexample/gesture-example.js
12242 views
/**1* @requires javelin-stratcom2* javelin-behavior3* javelin-vector4* javelin-dom5* @provides javelin-behavior-phabricator-gesture-example6*/78JX.behavior('phabricator-gesture-example', function(config) {910var strokes = [];11var current = [];1213var root = JX.$(config.rootID);1415var canvas = JX.$N('canvas');16var d = JX.Vector.getDim(root);17canvas.width = d.x;18canvas.height = d.y;19root.appendChild(canvas);2021var cxt = canvas.getContext('2d');22JX.Stratcom.listen(23'gesture.swipe.end',24null,25function(e) {26var stroke = get_stroke(e);27strokes.push(stroke);28current = [];29redraw();30});3132JX.Stratcom.listen(33'gesture.swipe.move',34null,35function(e) {36var stroke = get_stroke(e);37current = [stroke];38redraw();39});4041JX.Stratcom.listen(42'gesture.swipe.cancel',43null,44function() {45current = [];46redraw();47});4849function get_stroke(e) {50var data = e.getData();51var p = JX.$V(root);52return [53data.p0.x - p.x,54data.p0.y - p.y,55data.p1.x - p.x,56data.p1.y - p.y57];58}5960function redraw() {61cxt.fillStyle = '#dfdfdf';62cxt.fillRect(0, 0, d.x, d.y);6364var s;65var ii;66for (ii = 0; ii < strokes.length; ii++) {67s = strokes[ii];68cxt.strokeStyle = 'rgba(0, 0, 0, 0.50)';69cxt.beginPath();70cxt.moveTo(s[0], s[1]);71cxt.lineTo(s[2], s[3]);72cxt.stroke();73}7475for (ii = 0; ii < current.length; ii++) {76s = current[ii];77cxt.strokeStyle = 'rgba(255, 0, 0, 1)';78cxt.beginPath();79cxt.moveTo(s[0], s[1]);80cxt.lineTo(s[2], s[3]);81cxt.stroke();82}83}8485redraw();86});878889