Permalink
Browse files

simpler example

  • Loading branch information...
1 parent 39ee220 commit 63479bc37260731b17cb3ac39987f7517c1d8a97 @defunkt defunkt committed Mar 6, 2010
Showing with 30 additions and 50 deletions.
  1. +12 −16 index.html
  2. +4 −6 json.mustache
  3. +8 −10 template.mustache
  4. +3 −8 tom.coffee
  5. +3 −10 tom.js
View
@@ -78,16 +78,14 @@
<label>Mustache</label>
<textarea class="template">
<h1>{{header}}</h1>
-{{#list}}
- {{#item}}
- {{#current}}
- <li><strong>{{name}}</strong></li>
- {{/current}}
- {{#link}}
- <li><a href="{{url}}">{{name}}</a></li>
- {{/link}}
- {{/item}}
-{{/list}}
+{{#items}}
+ {{#first}}
+ <li><strong>{{name}}</strong></li>
+ {{/first}}
+ {{#link}}
+ <li><a href="{{url}}">{{name}}</a></li>
+ {{/link}}
+{{/items}}
{{#empty}}
<p>The list is empty.</p>
@@ -97,13 +95,11 @@
<label>JSON</label>
<textarea class="json">{
"header": "Colors",
- "item": [
- {"name": "red", "current": true, "url": "#Red"},
- {"name": "green", "current": false, "url": "#Green"},
- {"name": "blue", "current": false, "url": "#Blue"}
+ "items": [
+ {"name": "red", "first": true, "url": "#Red"},
+ {"name": "green", "link": true, "url": "#Green"},
+ {"name": "blue", "link": true, "url": "#Blue"}
],
- "link": true,
- "list": true,
"empty": false
}</textarea>
View
@@ -1,11 +1,9 @@
{
"header": "Colors",
- "item": [
- {"name": "red", "current": true, "url": "#Red"},
- {"name": "green", "current": false, "url": "#Green"},
- {"name": "blue", "current": false, "url": "#Blue"}
+ "items": [
+ {"name": "red", "first": true, "url": "#Red"},
+ {"name": "green", "link": true, "url": "#Green"},
+ {"name": "blue", "link": true, "url": "#Blue"}
],
- "link": true,
- "list": true,
"empty": false
}
View
@@ -3,16 +3,14 @@
{{#bug}}
{{/bug}}
-{{#list}}
- {{#item}}
- {{#current}}
- <li><strong>{{name}}</strong></li>
- {{/current}}
- {{#link}}
- <li><a href="{{url}}">{{name}}</a></li>
- {{/link}}
- {{/item}}
-{{/list}}
+{{#items}}
+ {{#first}}
+ <li><strong>{{name}}</strong></li>
+ {{/first}}
+ {{#link}}
+ <li><a href="{{url}}">{{name}}</a></li>
+ {{/link}}
+{{/items}}
{{#empty}}
<p>The list is empty.</p>
View
@@ -6,14 +6,9 @@
# Scrolls element1 to element2:
# $('element1').scrollTo($('element2'))
# $('element1').scrollTo($('element2'), speed)
-$.fn.scrollTo: (el, speed) ->
- if typeof el is 'number' or not el
- speed: el
- target: this
- container:'html,body'
- else
- target: el
- container: this
+$.fn.scrollTo: (speed) ->
+ target: this
+ container:'html,body'
offset: $(target).offset().top - 30
$(container).animate({scrollTop: offset}, speed or 1000)
View
@@ -6,16 +6,10 @@
// Scrolls element1 to element2:
// $('element1').scrollTo($('element2'))
// $('element1').scrollTo($('element2'), speed)
-$.fn.scrollTo = function scrollTo(el, speed) {
+$.fn.scrollTo = function scrollTo(speed) {
var container, offset, target;
- if (typeof el === 'number' || !el) {
- speed = el;
- target = this;
- container = 'html,body';
- } else {
- target = el;
- container = this;
- }
+ target = this;
+ container = 'html,body';
offset = $(target).offset().top - 30;
$(container).animate({
scrollTop: offset
@@ -33,7 +27,6 @@ $(function() {
}
return $('.run').click(function() {
var html, json, template;
- console.log('clicked run');
template = $('.template').val();
json = $.parseJSON($('.json').val());
html = Mustache.to_html(template, json).replace(/^\s*/mg, '');

0 comments on commit 63479bc

Please sign in to comment.