| OLD | NEW |
| (Empty) | |
| 1 var touches = $('touches'); |
| 2 |
| 3 var fadeDelay = 2; |
| 4 if (document.location.hash) { |
| 5 fadeDelay = document.location.hash.substr(1); |
| 6 } |
| 7 |
| 8 function createPoint(x, y, size, colour, stroke) { |
| 9 var div = document.createElement('div'); |
| 10 div.style.position = 'absolute'; |
| 11 div.style.webkitTransition = 'opacity ' + fadeDelay + 's linear'; |
| 12 div.style.left = x - size + 'px'; |
| 13 div.style.top = y - size + 'px'; |
| 14 div.style.width = (2 * size) + 'px'; |
| 15 div.style.height = (2 * size) + 'px'; |
| 16 div.style.background = colour; |
| 17 div.style.borderRadius = size + 'px'; |
| 18 if (stroke) { |
| 19 div.style.border = '2px solid ' + stroke; |
| 20 } |
| 21 return div; |
| 22 } |
| 23 |
| 24 function addFadingPoint(x, y, size, colour, stroke) { |
| 25 var point = createPoint(x, y, size, colour, stroke); |
| 26 touches.appendChild(point); |
| 27 window.setTimeout( |
| 28 function() { |
| 29 point.style.opacity = 0; |
| 30 window.setTimeout( |
| 31 function() { |
| 32 touches.removeChild(point); |
| 33 }, fadeDelay * 1000); |
| 34 }, |
| 35 0); |
| 36 } |
| 37 |
| 38 // -- modified rbyers' paint.js -- // |
| 39 var nextCount = 0; |
| 40 var touchMap = {}; |
| 41 |
| 42 function drawTouches(touchList, eventType) { |
| 43 for (var i = 0; i < touchList.length; ++i) { |
| 44 var touch = touchList[i]; |
| 45 |
| 46 // Map the identifier to a small count (no-op on Chrome, but |
| 47 // important for mobile Safari). |
| 48 if (!(touch.identifier in touchMap)) { |
| 49 touchMap[touch.identifier] = nextCount; |
| 50 nextCount++; |
| 51 } |
| 52 |
| 53 var radius = touch.webkitRadiusX > 1 ? touch.webkitRadiusX : 15; |
| 54 if (radius > 100) { |
| 55 console.error('Got large webkitRadiusX: ' + touch.webkitRadiusX); |
| 56 radius = 100; |
| 57 } |
| 58 |
| 59 // Try to avoid start/end circles overlapping exactly |
| 60 if (eventType == 'touchend') { |
| 61 radius++; |
| 62 } |
| 63 |
| 64 var x = touch.pageX; |
| 65 var y = touch.pageY; |
| 66 var size = radius; |
| 67 |
| 68 var hue = (touchMap[touch.identifier] * 30) % 256; |
| 69 var lum = 50; |
| 70 if (touch.webkitForce) { |
| 71 lum = Math.round(touch.webkitForce / 0.4 * 50 + 20); |
| 72 } |
| 73 var colour = 'hsla(' + hue + ',100%,' + lum + '%,1)'; |
| 74 |
| 75 var stroke = ''; |
| 76 // XXX(bryeung): since touchstart isn't working, just ignore stroke |
| 77 /* |
| 78 if (eventType != 'touchmove') { |
| 79 stroke = eventType == 'touchstart' ? 'black' : 'grey'; |
| 80 } |
| 81 */ |
| 82 |
| 83 // XXX(bryeung): HACK touch starts are showing up in the wrong spot |
| 84 if (eventType != 'touchstart') { |
| 85 addFadingPoint(x, y, size, colour, stroke); |
| 86 } |
| 87 } |
| 88 } |
| 89 |
| 90 function TouchHandler(event) { |
| 91 drawTouches(event.changedTouches, event.type); |
| 92 event.preventDefault(); |
| 93 } |
| 94 |
| 95 var trackMouseMoves = false; |
| 96 function MouseHandler(event) { |
| 97 if (event.type == 'mousedown') { |
| 98 trackMouseMoves = true; |
| 99 } |
| 100 if (event.type == 'mouseup') { |
| 101 trackMouseMoves = false; |
| 102 } |
| 103 if (trackMouseMoves) { |
| 104 addFadingPoint(event.clientX, event.clientY, 15, 'black', ''); |
| 105 } |
| 106 } |
| 107 |
| 108 /** |
| 109 * Disable default window onscroll handler. |
| 110 */ |
| 111 window.onscroll = null; |
| 112 // -- end modified rbyers' paint.js -- // |
| 113 |
| 114 touches.addEventListener('touchstart', TouchHandler); |
| 115 touches.addEventListener('touchmove', TouchHandler); |
| 116 touches.addEventListener('touchend', TouchHandler); |
| 117 |
| 118 touches.addEventListener('mousedown', MouseHandler); |
| 119 touches.addEventListener('mouseup', MouseHandler); |
| 120 touches.addEventListener('mousemove', MouseHandler); |
| OLD | NEW |