My goal is to write some reusable code to render basic navbars, since it would be a very repetitive task. The following features are my first goal:
Here is how you can built it. This is only example.
The structure of app is like this which you can customize.
app/
/index.js
/index.html/
/lib/
/pager.js
/require.js
/knockout-3.0.0beta.js
/views/
/test.html
/test1.html
And here is how you can do it.
First index.html
I am span
you are currently viewing the content of first page.
first child
second child
you are currently viewing the content of first page inside First Page.
Second Child
you are currently viewing the content of second page inside Second Page.
First Child
Go to Structure
you are currently viewing the content of second page.
Go to Start
Next index.js
requirejs.config({
shim:{
bootstrap:['jquery'],
hashchange:['jquery']
},
paths:{
jquery:'lib/jquery-1.10.2',
knockout:'lib/knockout-3.0.0beta',
pager:'lib/pager'
}
});
requirejs(['jquery','knockout','pager'], function ($, ko,pager) {
function PagerViewModel(){
var self = this;
}
$(function () {
pager.Href.hash = '#!/';
pager.extendWithPage(PagerViewModel.prototype);
ko.applyBindings(new PagerViewModel());
pager.start();
});
});
And the views to load
test.html
Second Page
This is a test view loaded by pager.js
The view loads with ajax request when the main page loads
All the pages that need to be loaded are loaded only once with ajax
while navigating the pages are not loaded again
First Child
test1.html
First Page
This is yet another page loaded by pager.js
Second Child
You can see how i created navigation bar the titles are first child
and second child
.
You can download the demo here