forked from mustache/mustache.github.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tom.coffee
32 lines (27 loc) · 824 Bytes
/
tom.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# Scrolls the window to element at the specified speed:
# $('element').scrollTo(speed)
$.fn.scrollTo = (speed) ->
target = this
container = 'html,body'
offset = $(target).offset().top - 30
$(container).animate({scrollTop: offset}, speed or 1000)
this
$ ->
$('#demo').click ->
$('#demo-box').toggle()
if $('#demo-box:visible').length > 0
$('#demo').scrollTo(1)
window.location.hash = '#demo'
else
window.location.hash = ''
false
$('#demo').click() if window.location.hash is "#demo"
$('.run').click ->
try
template = $('.template').val()
json = $.parseJSON $('.json').val()
html = Mustache.to_html(template, json).replace(/^\s*/mg, '')
catch e
html = e.toString()
$('.html').text(html).scrollTo(1)
Highlight.highlightDocument()