function ViewModel(){
var self = this;
self.mode = ko.observable();
self.articles = ko.observableArray();
self.pages = ko.observableArray();
self.showArticles = function(data){
self.mode('articles');
var articles = getArticles().filter(function name(article) {
return !data.category ? true : article.category === data.category;
});
self.pages.removeAll();
for(var i = 0; i < Math.ceil(articles.length / 3); i++){
self.pages.push({ page: i + 1 });
}
var start = (data.page - 1) * 3;
articles = articles.slice(start, start + 3);
self.articles(articles);
};
self.article = ko.observable();
self.showArticle = function(data){
self.mode('article');
var article = getArticles().filter(function name(article) {
return article.slug === data.slug;
})[0];
self.article(article);
}
self.showBooks = function(){
self.mode('books');
};
var articleDialog = Navigation.StateInfoConfig.dialogs.article;
var articleListState = articleDialog.states.list;
var articleDetailsState = articleDialog.states.details;
articleListState.navigated = self.showArticles;
articleDetailsState.navigated = self.showArticle;
var bookDialog = Navigation.StateInfoConfig.dialogs.book;
var bookListState = bookDialog.states.list;
bookListState.navigated = self.showBooks;
}
var articleDialog = {
key: 'article', initial: 'list', states: [
{ key: 'list', route: '{category?}', defaults: { page: 1 }, transitions: [
{ key: 'select', to: 'details' }
], trackCrumbTrail: false},
{ key: 'details', route: 'article/{slug}' }
]
};
var bookDialog = {
key: 'book', initial: 'list', states: [
{ key: 'list', route: 'books', trackCrumbTrail: false }
]
};
Navigation.StateInfoConfig.build([ articleDialog, bookDialog ]);
ko.applyBindings(new ViewModel());
Navigation.start();
function getArticles(){
return [
{
title: 'Designers And Developers: No Longer A House Divided',
slug: 'designers-and-developers-no-longer-a-house-divided',
text: 'As the web continues to evolve at a breakneck, Moore\'s-law pace, the divisions between traditional design and development are increasingly shifting. The "learn to code" movement is also gaining momentum among designers, but you\'d be hard pressed to find a similarly strong movement for other disciplines within a team. Perhaps there should be.',
author: 'Ivana McConnell',
category: 'coding'
},
{
title: 'A Better Way To Design For Retina In Photoshop',
slug: 'retina-design-in-photoshop',
text: 'Recently, I had a project in which I needed to produce high-fidelity screens for a tablet. I was to present these screens on the device and also produce a clickable prototype. They needed to be pixel-perfect. The timeline was tight (as always), so I went with my go-to tool, Photoshop. I’ve been using it for over ten years, and it gives me the fastest high-quality output.',
author: 'Murdoch Carpenter',
category: 'design'
},
{
title: 'Extending In Sass Without Creating A Mess',
slug: 'extending-in-sass-without-mess',
text: 'The @extend directive in Sass is a powerful directive that facilitates the sharing of rules and relationships between selectors. However, it can produce undesirable side effects if it is not carefully implemented. Thankfully, there are many strategies for using @extend effectively that can prevent these side effects and produce clean, organized CSS.',
author: 'David Khourshid',
category: 'coding'
},
{
title: 'Creating A Complete Web App In Foundation For Apps',
slug: 'creating-web-app-in-foundation-for-apps',
text: 'Foundation for Apps is a new single-page app framework from Zurb that is closely related to Foundation 5 (also known as Foundation for Sites, a widely used front-end framework). It\'s built around AngularJS and a flexbox grid framework. It\'s intended to make creating a web app very quick and simple, enabling us to quickly start writing the code that’s unique to our application, rather than boilerplate.',
author: 'Stephen Saucier',
category: 'coding'
},
{
title: 'Design Principles: Compositional Flow And Rhythm',
slug: 'design-principles-compositional-flow-and-rhythm',
text: 'When someone lands on a page of your site what do you want that person to do? Where do you want them to look? What information do you want your visitors to notice and in what order?',
author: 'Steven Bradley',
category: 'design'
},
{
title: 'An In-Depth Overview Of Living Style Guide Tools',
slug: 'an-in-depth-overview-of-living-style-guide-tools',
text: 'Following the market\'s demand for minimalistic and consistent UIs, and the growth in modular web development, we tend to pay more and more attention to documentation and the efficiency of designer-engineer workflow with each project we undertake. Also, since the documentation process is often the weakest spot for modern web teams, we\'re constantly looking for the right tools to help us.',
author: 'Robert Haritonov',
category: 'design'
},
{
title: 'React To The Future With Isomorphic Apps',
slug: 'react-to-the-future-with-isomorphic-apps',
text: 'Things often come full circle in software engineering. The web in particular started with servers delivering content down to the client. Recently, with the creation of modern web frameworks such as AngularJS and Ember, we\'ve seen a push to render on the client and only use a server for an API. We\'re now seeing a possible return or, rather, more of a combination of both architectures happening.',
author: 'Jonathan Creamer',
category: 'coding'
},
{
title: 'Web Scraping With Node.js',
slug: 'web-scraping-with-nodejs',
text: 'Web scraping is the process of programmatically retrieving information from the Internet. As the volume of data on the web has increased, this practice has become increasingly widespread, and a number of powerful services have emerged to simplify it. Unfortunately, the majority of them are costly, limited or have other disadvantages. Instead of turning to one of these third-party resources, you can use Node.js to create a powerful web scraper that is both extremely versatile and completely free.',
author: 'Elliot Bonneville',
category: 'coding'
},
{
title: 'On China\'s Bleeding Edge: Web Design Trends 2015',
slug: 'china-web-design-trends-2015',
text: 'There are many parallels between the volatility of the web industry and China\'s breakneck rate of change: For one thing, it\'s hard to keep a finger on the pulse of either. But add the two together and you get China\'s tech scene, a virtual landscape in such constant flux that our only hope of keeping pace is to look as far into the future as we\'re able, try to discern what\'s coming, and brace for impact.',
author: 'Kendra Schaefer',
category: 'design'
}
];
}