Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Feb 9th, 2012  |  syntax: None  |  size: 1.41 KB  |  views: 57  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. (function() {
  2.   var App;
  3.  
  4.   App = {};
  5.  
  6.   /*
  7.         Init
  8.   */
  9.  
  10.   App.init = function() {
  11.     App.canvas = document.createElement('canvas');
  12.     App.canvas.height = 600;
  13.     App.canvas.width = 1200;
  14.     document.getElementsByTagName('article')[0].appendChild(App.canvas);
  15.     App.ctx = App.canvas.getContext("2d");
  16.     App.ctx.fillStyle = "solid";
  17.     App.ctx.strokeStyle = "#ECD018";
  18.     App.ctx.lineWidth = 5;
  19.     App.ctx.lineCap = "round";
  20.     App.socket = io.connect('http://107.20.163.241');
  21.     App.socket.on('draw', function(data) {
  22.       return App.draw(data.x, data.y, data.type);
  23.     });
  24.     App.draw = function(x, y, type) {
  25.       if (type === "dragstart") {
  26.         App.ctx.beginPath();
  27.         return App.ctx.moveTo(x, y);
  28.       } else if (type === "drag") {
  29.         App.ctx.lineTo(x, y);
  30.         return App.ctx.stroke();
  31.       } else {
  32.         return App.ctx.closePath();
  33.       }
  34.     };
  35.   };
  36.  
  37.   /*
  38.         Draw Events
  39.   */
  40.  
  41.   $('canvas').live('drag dragstart dragend', function(e) {
  42.     var offset, type, x, y;
  43.     type = e.handleObj.type;
  44.     offset = $(this).offset();
  45.     e.offsetX = e.layerX - offset.left;
  46.     e.offsetY = e.layerY - offset.top;
  47.     x = e.offsetX;
  48.     y = e.offsetY;
  49.     App.draw(x, y, type);
  50.     App.socket.emit('drawClick', {
  51.       x: x,
  52.       y: y,
  53.       type: type
  54.     });
  55.   });
  56.  
  57.   $(function() {
  58.     return App.init();
  59.   });
  60.  
  61. }).call(this);