From 70ea2bd8639a5a63e26a30630649f0599cc0ef65 Mon Sep 17 00:00:00 2001 From: Rufus Pollock Date: Fri, 23 Mar 2012 02:41:53 +0000 Subject: [PATCH] [#34,bugfix,view][s]: fix issues with interaction of hash changes with view updating. * Problem was in e.g. default demo that with new hash we were not matching on grid view and hence only displaying that (so we displayed both grid and graph which was nasty ...) * Fix this by better match on route. Also improve by using router.navigate on query update --- src/view.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/view.js b/src/view.js index db7c1e5a..72b1c0d3 100644 --- a/src/view.js +++ b/src/view.js @@ -114,7 +114,8 @@ my.DataExplorer = Backbone.View.extend({ // update navigation var qs = my.parseHashQueryString(); qs['reclineQuery'] = JSON.stringify(self.model.queryState.toJSON()); - my.setHashQueryString(qs); + var out = my.getNewHashForQueryString(qs); + self.router.navigate(out); }); this.model.bind('query:fail', function(error) { my.clearNotifications(); @@ -172,8 +173,8 @@ my.DataExplorer = Backbone.View.extend({ setupRouting: function() { var self = this; // Default route - this.router.route('', this.pageViews[0].id, function() { - self.updateNav(self.pageViews[0].id); + this.router.route(/^(\?.*)?$/, this.pageViews[0].id, function(queryString) { + self.updateNav(self.pageViews[0].id, queryString); }); $.each(this.pageViews, function(idx, view) { self.router.route(/^([^?]+)(\?.*)?/, 'view', function(viewId, queryString) { @@ -331,8 +332,18 @@ my.composeQueryString = function(queryParams) { return queryString; } +my.getNewHashForQueryString = function(queryParams) { + var queryPart = my.composeQueryString(queryParams); + if (window.location.hash) { + // slice(1) to remove # at start + return window.location.hash.split('?')[0].slice(1) + queryPart; + } else { + return queryPart; + } +} + my.setHashQueryString = function(queryParams) { - window.location.hash = window.location.hash.split('?')[0] + my.composeQueryString(queryParams); + window.location.hash = my.getNewHashForQueryString(queryParams); } // ## notify