Permalink
Browse files

requestAnimationFrame shim, misc fixes

  • Loading branch information...
1 parent 73a2943 commit 5c8d18d115902b049a2556bb2c96eb0981fcf7f2 @tnovelli committed Apr 16, 2012
Showing with 37 additions and 10 deletions.
  1. +2 −0 bizcard/index.jade
  2. +1 −1 cogo/index.jade
  3. +25 −3 gravity/gravity.coffee
  4. +9 −6 rte/rte.coffee
View
@@ -44,3 +44,5 @@ html
p
a(href='https://github.com/tnovelli/hax5/tree/master/bizcard') source code
canvas
+
+ p Yep, something's broken. Bit-rot set in fast... probably a change in Jade, Stylus, or CoffeeScript. I'll sort it out sometime, like when I port these demos to vanilla JavaScript...
View
@@ -66,7 +66,7 @@ html
button Deed 2
span (These don't work yet)
.cell
- textarea#input
+ textarea#input.
N14E 117R
N24.30E 39R 10L
W26N 44R
@@ -287,6 +287,24 @@ class Game
@ctx.fill()
@ctx.restore()
+
+`
+// shim layer with setTimeout fallback
+// Thanks to Paul Irish --
+// http://paulirish.com/2011/requestanimationframe-for-smart-animating/)
+window.requestAnimFrame = (function(){
+ return window.requestAnimationFrame ||
+ window.webkitRequestAnimationFrame ||
+ window.mozRequestAnimationFrame ||
+ window.oRequestAnimationFrame ||
+ window.msRequestAnimationFrame ||
+ function( callback ){
+ window.setTimeout(callback, 1000 / 60);
+ };
+})();
+`
+
+
oldAnim = 0 # 0: use requestAnimationFrame(), 1: use setInterval()
running = null
t0 = 0
@@ -303,16 +321,20 @@ window.mainloop = (dt) ->
update = (timestamp) ->
dt = timestamp - t0
window.mainloop dt
- if running then mozRequestAnimationFrame update
+ if running then requestAnimFrame update
start = ->
$('#start').text('Stop')
if oldAnim
t0 = $.now()
running = setInterval('mainloop()', 1000/framerate)
else
running = true
- t0 = mozAnimationStartTime
- mozRequestAnimationFrame update
+ t0 = (window.animationStartTime ||
+ window.webkitAnimationStartTime ||
+ window.mozAnimationStartTime ||
+ window.oAnimationStartTime ||
+ window.msAnimationStartTime)
+ requestAnimFrame update
stop = ->
if oldAnim
window.clearInterval(running)
View
@@ -77,8 +77,15 @@ $ ->
.keyup(keyup)
#.keypress(keypress) # not needed
- # Create a container - useful for removing the RTE or having several RTEs
+ # This "improves" Firefox's HTML output
+ # NOTE: This must come *after* setting 'contentEditable' and *before*
+ # creating the wrapper.
+ command 'styleWithCSS', false
+ command 'insertBrOnReturn', true
+
+ # Create a wrapper (useful for removing the RTE or having several RTEs)
rte.wrap('<div class="editor">')
+ wrapper = rte.parent()
# Top row buttons
top = $('<div>').insertBefore(rte)
@@ -92,11 +99,7 @@ $ ->
makeButton bot, null, 'Save', 'S', save
makeButton bot, null, 'Preview', null, preview
- $('<h3>HTML preview:</h3><div class="preview">').insertAfter(rte)
-
- # This "improves" Firefox's HTML output
- command 'styleWithCSS', false
- command 'insertBrOnReturn', true
+ $('<h3>HTML preview:</h3><div class="preview">').appendTo(wrapper)
preview()

0 comments on commit 5c8d18d

Please sign in to comment.