-
Notifications
You must be signed in to change notification settings - Fork 107
/
Copy pathscripts.js
54 lines (54 loc) · 1.33 KB
/
scripts.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
(function() {
var App;
App = {};
/*
Init
*/
App.init = function() {
App.canvas = document.createElement('canvas');
App.canvas.height = 400;
App.canvas.width = 800;
document.getElementsByTagName('article')[0].appendChild(App.canvas);
App.ctx = App.canvas.getContext("2d");
App.ctx.fillStyle = "solid";
App.ctx.strokeStyle = "#ECD018";
App.ctx.lineWidth = 5;
App.ctx.lineCap = "round";
App.socket = io.connect('http://localhost:4000');
App.socket.on('draw', function(data) {
return App.draw(data.x, data.y, data.type);
});
App.draw = function(x, y, type) {
if (type === "dragstart") {
App.ctx.beginPath();
return App.ctx.moveTo(x, y);
} else if (type === "drag") {
App.ctx.lineTo(x, y);
return App.ctx.stroke();
} else {
return App.ctx.closePath();
}
};
};
/*
Draw Events
*/
$('canvas').live('drag dragstart dragend', function(e) {
var offset, type, x, y;
type = e.handleObj.type;
offset = $(this).offset();
e.offsetX = e.layerX - offset.left;
e.offsetY = e.layerY - offset.top;
x = e.offsetX;
y = e.offsetY;
App.draw(x, y, type);
App.socket.emit('drawClick', {
x: x,
y: y,
type: type
});
});
$(function() {
return App.init();
});
}).call(this);