From d60394338f9737374c08c964a1d3c9a7e02ed517 Mon Sep 17 00:00:00 2001 From: Anon Ray Date: Wed, 30 Jan 2013 01:28:04 +0530 Subject: [PATCH] Fix URL routing and error handling - Fix URL routing to start with index page. Changed location.origin which is only available in Chrome to standart location.protocol and location.hostname. - Add error handling and reporting in the console; in Page views. --- js/mouchak.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/js/mouchak.js b/js/mouchak.js index de338c7..bf52663 100644 --- a/js/mouchak.js +++ b/js/mouchak.js @@ -300,6 +300,10 @@ var AppView = Backbone.View.extend({ _.each(children, function(child) { child = M.sanitize(child); var model = M.pages.get(child); + if(!_.isObject(model)) { + console.log('Error: Cannot find page '+ child +' which is defined as children of ' + page); + return false; + } var children = model.get('children'); if(_.isEmpty(children)) { li = '
  • ' + M.humanReadable(child) + '
  • '; @@ -350,9 +354,13 @@ M.init = function() { var new_page = new Page(page); var contents = []; _.each(page.content, function(content) { + if(_.isEmpty(content)) { + console.log('Empty content for ' + page.name); + return; + } var Item = type_map.model[content.type]; if(!Item) { - console.log('Error initing item: ', content); + console.log('Error: Invalid type '+ content.type +' for ', content); return; } var item = new Item(content); @@ -371,7 +379,8 @@ M.init = function() { Backbone.history.start(); // start with index page var location = window.location; - location.href = location.origin + location.pathname + '#/index'; + location.href = location.protocol + '//' + location.hostname + + location.pathname + '#/index'; M.simHeir(); }; -- 1.7.10.4