# HG changeset patch # User Romain # Date 1329856136 -3600 # Node ID 5e1d7f77f3551ba422a171148a8b8db7d9797ac0 # Parent 83cf3d8be3961ba951df4616caee69cb3a51db9a code cleaning diff -r 83cf3d8be396 -r 5e1d7f77f355 client/js/tweetvote-anim.js --- a/client/js/tweetvote-anim.js Tue Feb 21 19:20:44 2012 +0100 +++ b/client/js/tweetvote-anim.js Tue Feb 21 21:28:56 2012 +0100 @@ -6,12 +6,10 @@ var stage = [195, 250, 1150, 835] // bottom var b2bod = []; -var BALL_SIZE = 40; - var worldAABB, world, iterations = 1, timeStep = 1 / 20; var walls = []; -var wall_thickness = 10; +var wall_thickness = 20; var wallsSetted = false; var bodies, elements, text; @@ -38,11 +36,7 @@ init(); play(); -/* -listLastTweets(); -getInitialTweets(); -TweetAnim.shiftQueue(); -*/ + function init() { worldAABB = new b2AABB(); @@ -80,70 +74,6 @@ elements = []; } -function onDocumentMouseDown() { - isMouseDragging = false; - isMouseDown = true; - return false; -} - -function onDocumentMouseUp() { - isMouseDown = false; - return false; -} - -function onDocumentMouseMove( event ) { - - if(isMouseDown) - isMouseDragging = true; - mouse.x = event.clientX; - mouse.y = event.clientY; - -} - -function onDocumentTouchStart( event ) { - - - - if( event.touches.length == 1 ) { - - event.preventDefault(); - - // Faking double click for touch devices - - var now = new Date().getTime(); - - if ( now - timeOfLastTouch < 250 ) { - - reset(); - return; - } - - timeOfLastTouch = now; - - mouse.x = event.touches[ 0 ].pageX; - mouse.y = event.touches[ 0 ].pageY; - isMouseDown = true; - } -} - -function onDocumentTouchMove( event ) { - - if (event.touches.length == 1) { - - event.preventDefault(); - mouse.x = event.touches[ 0 ].pageX; - mouse.y = event.touches[ 0 ].pageY; - } -} - -function onDocumentTouchEnd( event ) { - - if (event.touches.length == 0) { - event.preventDefault(); - isMouseDown = false; - } -} - function loop() { delta[0] += (0 - delta[0]) * .5; @@ -151,7 +81,6 @@ world.m_gravity.x = gravity.x * 350 + delta[0]; world.m_gravity.y = gravity.y * 350 + delta[1]; - mouseDrag(); world.Step(timeStep, iterations); for (i = 0; i < bodies.length; i++) { @@ -159,23 +88,15 @@ var element = elements[i]; element.style.left = (body.m_position0.x - (element.width >> 1)) + 'px'; element.style.top = (body.m_position0.y - (element.height >> 1)) + 'px'; - - if (element.tagName == 'DIV') { - var rotationStyle = 'rotate(' + (body.m_rotation0 * 57.2957795) + 'deg)'; - text.style.WebkitTransform = rotationStyle; - text.style.MozTransform = rotationStyle; - text.style.OTransform = rotationStyle; - text.style.msTransform = rotationStyle; - } } } function createBox(world, x, y, width, height, fixed) { -var c=document.createElement('canvas'); -var ctx=c.getContext("2d"); -ctx.fillStyle="#FF0000"; -ctx.fillRect(0,0,1500,750); + var c=document.createElement('canvas'); + var ctx=c.getContext("2d"); + ctx.fillStyle="#FF0000"; + ctx.fillRect(0,0,1500,750); if (typeof(fixed) == 'undefined') { fixed = true; @@ -192,49 +113,10 @@ boxBd.AddShape(boxSd); boxBd.position.Set(x,y); - return world.CreateBody(boxBd); } -function mouseDrag() -{ - // mouse press - if (createMode) { - } else if (isMouseDown && !mouseJoint) { - - var body = getBodyAtMouse(); - - if (body) { - var md = new b2MouseJointDef(); - md.body1 = world.m_groundBody; - md.body2 = body; - md.target.Set(mouse.x, mouse.y); - md.maxForce = 30000 * body.m_mass; - md.timeStep = timeStep; - mouseJoint = world.CreateJoint(md); - body.WakeUp(); - } else { - createMode = true; - } - } - - if (!isMouseDown) { // mouse release - - createMode = false; - destroyMode = false; - - if (mouseJoint) { - world.DestroyJoint(mouseJoint); - mouseJoint = null; - } - } - - if (mouseJoint) { // mouse move - var p2 = new b2Vec2(mouse.x, mouse.y); - mouseJoint.SetTarget(p2); - } -} function getBodyAtMouse() { @@ -275,8 +157,6 @@ walls[2] = null; walls[3] = null; } else { - - wall_thickness = 20; walls[0] = createBox(world, 1910, 900, wall_thickness, 900); // rightmost wall walls[1] = createBox(world, 1540, 600, wall_thickness, 300); // wall 4 / 3 @@ -297,15 +177,14 @@ $('#podium div').each( function(idx, panel) { - var idxWall = 5+idx; - var yWall = 920-$(this).height(); - world.DestroyBody(walls[idxWall]); - walls[idxWall] = createBox(world, 580+370*idx, yWall, 170, 10); + var idxWall = 5+idx; + var yWall = 920-$(this).height(); + world.DestroyBody(walls[idxWall]); + walls[idxWall] = createBox(world, 580+370*idx, yWall, 170, 10); }); } }, 1000); - } } @@ -366,17 +245,6 @@ element.appendChild(circle); - text = document.createElement( 'div' ); - text.onSelectStart = null; - text.style.color = "#95AB63"; - text.style.position = 'absolute'; - text.style.left = '0px'; - text.style.top = '0px'; - text.style.fontFamily = 'Georgia'; - text.style.textAlign = 'center'; - text.id = t.id_str; - element.appendChild(text); - var circle = new b2CircleDef(); circle.radius = BALL_SIZE/4+2 ; circle.density = 1; @@ -428,9 +296,6 @@ b2bod[t.id_str] = world.CreateBody(b2body); console.log("created " + t.id_str) bodies.push(b2bod[t.id_str]); - -// toDel[t.cat].push(t); - $("#"+t.id_str).mouseover(function() { var _of = $(this).offset(); diff -r 83cf3d8be396 -r 5e1d7f77f355 client/main.html --- a/client/main.html Tue Feb 21 19:20:44 2012 +0100 +++ b/client/main.html Tue Feb 21 21:28:56 2012 +0100 @@ -37,8 +37,7 @@ -
- +