2014-02-01 18:18:29 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
$(document).ready(function() {
|
|
|
|
window.c = $('canvas')[0].getContext('2d');
|
|
|
|
|
|
|
|
window.settings = {
|
|
|
|
lineWidth : 5,
|
|
|
|
strokeStyle : 'black',
|
|
|
|
type: 'sketch',
|
|
|
|
lineCap: 'round',
|
|
|
|
lineJoin: 'round'
|
|
|
|
};
|
|
|
|
window.points = [];
|
|
|
|
window.$c = $('canvas');
|
|
|
|
|
|
|
|
sizeAndPos();
|
|
|
|
$(window).resize(sizeAndPos);
|
|
|
|
|
2014-02-02 09:58:27 +00:00
|
|
|
$c.bind('mousedown', function(e) {
|
|
|
|
e.preventDefault();
|
2014-02-01 18:18:29 +00:00
|
|
|
var xy = relative(e.pageX, e.pageY);
|
|
|
|
startPoint(xy.x, xy.y);
|
|
|
|
window.active = true;
|
2014-02-02 09:58:27 +00:00
|
|
|
}).bind('mousemove', function(e) {
|
|
|
|
e.preventDefault();
|
2014-02-01 18:18:29 +00:00
|
|
|
if (!window.active || settings.type == 'line') return;
|
|
|
|
var xy = relative(e.pageX, e.pageY);
|
|
|
|
drawPoint(xy.x, xy.y);
|
2014-02-02 09:58:27 +00:00
|
|
|
}).bind('mouseup touchend', function(e) {
|
|
|
|
e.preventDefault();
|
2014-02-01 18:18:29 +00:00
|
|
|
window.active = false;
|
2014-02-02 09:58:27 +00:00
|
|
|
}).bind('touchstart', function(e) {
|
|
|
|
e.preventDefault();
|
2014-02-02 10:04:02 +00:00
|
|
|
var touch = e.changedTouches[0];
|
|
|
|
var xy = relative(touch.pageX, touch.pageY);
|
|
|
|
startPoint(xy.x, xy.y);
|
2014-02-02 09:58:27 +00:00
|
|
|
window.active = true;
|
|
|
|
}).bind('touchmove', function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
if(!window.active || settings.type =='line') return;
|
2014-02-02 10:04:02 +00:00
|
|
|
var touch = e.changedTouches[0];
|
|
|
|
var xy = relative(touch.pageX, touch.pageY);
|
|
|
|
drawPoint(xy.x, xy.y);
|
2014-02-02 09:58:27 +00:00
|
|
|
window.active = true;
|
2014-02-01 18:18:29 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
})
|