Created
May 5, 2014 19:26
-
-
Save ColinTheRobot/11545330 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
h1 { | |
color: red | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src="http://code.jquery.com/jquery-git.js"></script> | |
<script src="http://jashkenas.github.io/underscore/underscore-min.js"></script> | |
<script src="http://jashkenas.github.io/backbone/backbone-min.js"></script> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<div id="main"> | |
</div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Class View < Backbone::View | |
var View = Backbone.View.extend({ | |
el: "#main", | |
// gets called on instantiation | |
initialize: function(){ | |
this.render(); | |
}, | |
render: function(){ | |
// $(this.el).html("<h1>Hi</h1>"); | |
this.$el.html('<h1>Hi</h1><input type="text">'); | |
}, | |
events: { | |
// model "event selector" : "callback" | |
"click h1" : "colorMeBad", | |
"dblclick h1" : "colorMeGreen", | |
// this blur when you move out of sckope of input send alert | |
"blur input" : function(){alert('blur');} | |
}, | |
colorMeBad: function(){ | |
this.$('h1').css({background: "blue"}); | |
// $(this.el).find("h1").css({background: "blue"}); | |
}, | |
colorMeGreen: function(){ | |
$(this.el).find("h1").css({background: "green"}); | |
} | |
}); | |
// Instantiate | |
$(document).ready(function(){ | |
view = new View(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment