Skip to content

Instantly share code, notes, and snippets.

@adamalex
Created April 17, 2013 20:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamalex/5407664 to your computer and use it in GitHub Desktop.
Save adamalex/5407664 to your computer and use it in GitHub Desktop.
automated test example
<!DOCTYPE html>
<html>
<head>
<title>automated test example</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.4/underscore-min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.0.0/backbone-min.js"></script>
</head>
<body>
<p>Status: <span id="status"></span></p>
<p><button id="action"></button>
<script>
var $action = $('#action');
var $status = $('#status');
$action.on('click', function () {
switch ($action.text()) {
case 'create':
router.navigate('new', { trigger: true });
break;
case 'save':
router.navigate('save', { trigger: true });
break;
case 'done':
router.navigate('', { trigger: true });
break;
}
});
var Router = Backbone.Router.extend({
routes: {
"new": "new",
"save": "save",
"": "clear"
},
new: function () {
$status.text('creating');
$action.text('save');
},
save: function () {
$status.text('created');
$action.text('done');
},
clear: function () {
$status.text('idle');
$action.text('create');
}
});
var router = new Router();
Backbone.history.start();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment