Commit d60394338f9737374c08c964a1d3c9a7e02ed517

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.
  • Diff rendering mode:
  • inline
  • side by side

js/mouchak.js

300 _.each(children, function(child) {300 _.each(children, function(child) {
301 child = M.sanitize(child);301 child = M.sanitize(child);
302 var model = M.pages.get(child);302 var model = M.pages.get(child);
303 if(!_.isObject(model)) {
304 console.log('Error: Cannot find page '+ child +' which is defined as children of ' + page);
305 return false;
306 }
303 var children = model.get('children');307 var children = model.get('children');
304 if(_.isEmpty(children)) {308 if(_.isEmpty(children)) {
305 li = '<li><a href="#/' + child + '">' + M.humanReadable(child) + '</a></li>';309 li = '<li><a href="#/' + child + '">' + M.humanReadable(child) + '</a></li>';
354 var new_page = new Page(page);354 var new_page = new Page(page);
355 var contents = [];355 var contents = [];
356 _.each(page.content, function(content) {356 _.each(page.content, function(content) {
357 if(_.isEmpty(content)) {
358 console.log('Empty content for ' + page.name);
359 return;
360 }
357 var Item = type_map.model[content.type];361 var Item = type_map.model[content.type];
358 if(!Item) {362 if(!Item) {
359 console.log('Error initing item: ', content);
363 console.log('Error: Invalid type '+ content.type +' for ', content);
360 return;364 return;
361 }365 }
362 var item = new Item(content);366 var item = new Item(content);
379 Backbone.history.start();379 Backbone.history.start();
380 // start with index page380 // start with index page
381 var location = window.location;381 var location = window.location;
382 location.href = location.origin + location.pathname + '#/index';
382 location.href = location.protocol + '//' + location.hostname +
383 location.pathname + '#/index';
383 M.simHeir();384 M.simHeir();
384};385};
385386