Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: dd1741842e
Fetching contributors…

Cannot retrieve contributors at this time

104 lines (96 sloc) 4.484 kb
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>KnockbackNavigators.js Interactive Tests</title>
<link rel="stylesheet" href="vendor/normalize.css">
<link rel="stylesheet" href="vendor/bootstrap/css/bootstrap.css">
<link rel="stylesheet" href="../knockback-navigators.css">
</head>
<body>
<a class='btn' href='../index.html#page_navigator_panes' style='position: absolute; z-index: 200'>More Examples</a>
<div class='embed' data-bind="PageNavigatorPanes: {loaded: loaded}"></div>
<!-- VIEWS -->
<script type="text/x-jq" id='page'>
<div data-bind="attr: {id: id}">
<div class='hero-unit'>
<!-- ko if: $data.back -->
<a class='btn btn-small' data-bind="click: function(){kb.loadUrl(back().href(), back_transition()); }"><i class='icon-step-backward'></i><span> Back</span></a>
<!-- /ko -->
<!-- ko if: $data.next -->
<a class='btn btn-warning btn-small' data-bind="attr: {href: next().href()}, text: next().title"></a>
<!-- /ko -->
<h1 data-bind="text: title"></h1>
</div>
</div>
</script>
<script src="vendor/jquery-1.8.0.js"></script>
<script src="vendor/knockback-core-stack-0.16.5.js"></script>
<script src="../knockback-page-navigator-panes.js"></script>
<script src="../lib/knockback-sample-transitions.js"></script>
<script type='text/javascript'>
////////////////////////////////////
// Models
////////////////////////////////////
var pages = new Backbone.Collection([
new Backbone.Model({title: 'Main', id: 'main', href: '#'}),
new Backbone.Model({title: 'Page1', id: 'page1', href: '#page1'}),
new Backbone.Model({title: 'Page2', id: 'page2', href: '#page2'})
]);
// Initialize relationships between pages - NOTE: you can use BackboneRelational to automate this at model creation time (of course, this is just an example so you might not use models for your pages)
pages.get('main').set({next: pages.get('page1')});
pages.get('page1').set({back: pages.get('main'), back_transition: {name: 'NavigationSlide', inverse: true}, next: pages.get('page2')});
pages.get('page2').set({back: pages.get('page1'), back_transition: {name: 'CoverVertical', inverse: true}});
////////////////////////////////////
// ViewModels
////////////////////////////////////
var PageViewModel = kb.ViewModel.extend({
constructor: function(model, options) {
kb.ViewModel.prototype.constructor.call(this, model, {options: options, factories: {
'back': PageViewModel, // provide a custom view model for relationships
'next': PageViewModel
}});
return this;
}
});
////////////////////////////////////
// Page Routing and Navigating
// Use Knockout.js page embedding to create and bind
// Allow pages to be detached/destroyed since they are dynamically created
////////////////////////////////////
ko.applyBindings({
loaded: function(page_navigator) {
var router = new Backbone.Router()
router.route('', null, page_navigator.dispatcher(function(){
page_navigator.loadPage({
el: kb.renderTemplate('page', new PageViewModel(pages.get('main'))),
transition: 'FadeIn'
});
}));
router.route('page1', null, page_navigator.dispatcher(function(){
page_navigator.loadPage({
el: kb.renderTemplate('page', new PageViewModel(pages.get('page1'))),
transition: 'NavigationSlide'
});
}));
router.route('page2', null, page_navigator.dispatcher(function(){
page_navigator.loadPage({
el: kb.renderTemplate('page', new PageViewModel(pages.get('page2'))),
transition: 'CoverVertical'
});
}));
}
});
Backbone.history.start({hashChange: true});
</script>
<!-- ****************** -->
<!-- Source -->
<!-- ****************** -->
<script src="vendor/backbone/underscore-1.3.3.js"></script>
<script type='text/javascript'>
$('body').append($('<div style="position: absolute; top: 220px"><h1>Example Source</h1><pre>' +_.escape(document.body.innerHTML.substring(0, document.body.innerHTML.indexOf('<!-- ****************** -->')))+'</pre></div>')[0]);
</script>
</body>
</html>
Jump to Line
Something went wrong with that request. Please try again.