Created
April 17, 2013 20:50
-
-
Save adamalex/5407664 to your computer and use it in GitHub Desktop.
automated test example
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> | |
<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