Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

Commit

Permalink
Merge pull request #2603 from njam/navigate-event
Browse files Browse the repository at this point in the history
Trigger "navigate:*" events on any location change
  • Loading branch information
njam authored Mar 17, 2017
2 parents 9107fa2 + 187633a commit 2576098
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
21 changes: 19 additions & 2 deletions library/CM/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -1297,7 +1297,7 @@ var CM_App = CM_Class_Abstract.extend({
return;
}
router.hrefInitialIgnore = null;
router._handleLocationChange(location.href);
router._navigateToUrl(location.href);
});

var urlSite = cm.getUrl();
Expand Down Expand Up @@ -1342,7 +1342,7 @@ var CM_App = CM_Class_Abstract.extend({
this.pushState(fragment);
}
}
return this._handleLocationChange(url);
return this._navigateToUrl(url);
},

/**
Expand Down Expand Up @@ -1396,6 +1396,23 @@ var CM_App = CM_Class_Abstract.extend({
return this._getFragmentByLocation(this._getLocationByUrl(url));
},

/**
* @param {String} url
* @returns {Promise}
*/
_navigateToUrl: function(url) {
Promise
.try(function() {
cm.event.trigger('navigate:start', {url: url});
})
.then(function() {
return this._handleLocationChange(url)
}.bind(this))
.then(function() {
cm.event.trigger('navigate:end', {url: url});
});
},

/**
* @param {String} url
* @returns {Promise}
Expand Down
3 changes: 0 additions & 3 deletions library/CM/View/Document.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ var CM_View_Document = CM_View_Abstract.extend({
layout.removePagePlaceholder(view.$el);
view._ready();

cm.event.trigger('navigate:end', {page: view, path: path});
return view;
})
.catch(function(error) {
Expand All @@ -68,8 +67,6 @@ var CM_View_Document = CM_View_Abstract.extend({
* @returns {Promise}
*/
loadPage: function(path) {
cm.event.trigger('navigate', path); // deprecated
cm.event.trigger('navigate:start', {path: path});
return this._loadPageThrottled(path);
},

Expand Down

0 comments on commit 2576098

Please sign in to comment.