aboutsummaryrefslogtreecommitdiffstats
path: root/web/src/js/utils.js
diff options
context:
space:
mode:
Diffstat (limited to 'web/src/js/utils.js')
-rw-r--r--web/src/js/utils.js44
1 files changed, 44 insertions, 0 deletions
diff --git a/web/src/js/utils.js b/web/src/js/utils.js
index 8ae7aa54..b475980a 100644
--- a/web/src/js/utils.js
+++ b/web/src/js/utils.js
@@ -23,6 +23,50 @@ var StickyHeadMixin = {
};
+var Navigation = _.extend({}, ReactRouter.Navigation, {
+ setQuery: function (k, v) {
+ var q = this.context.getCurrentQuery();
+ q[k] = v;
+ this.replaceWith(this.context.getCurrentPath(), this.context.getCurrentParams(), q);
+ },
+ replaceWith: function(routeNameOrPath, params, query) {
+ if(routeNameOrPath === undefined){
+ routeNameOrPath = this.context.getCurrentPath();
+ }
+ if(params === undefined){
+ params = this.context.getCurrentParams();
+ }
+ if(query === undefined){
+ query = this.context.getCurrentQuery();
+ }
+ ReactRouter.Navigation.replaceWith.call(this, routeNameOrPath, params, query);
+ }
+});
+
+var State = _.extend({}, ReactRouter.State, {
+ getInitialState: function () {
+ this._query = this.context.getCurrentQuery();
+ this._queryWatches = [];
+ return null;
+ },
+ onQueryChange: function (key, callback) {
+ this._queryWatches.push({
+ key: key,
+ callback: callback
+ });
+ },
+ componentWillReceiveProps: function (nextProps, nextState) {
+ var q = this.context.getCurrentQuery();
+ for (var i = 0; i < this._queryWatches.length; i++) {
+ var watch = this._queryWatches[i];
+ if (this._query[watch.key] !== q[watch.key]) {
+ watch.callback(this._query[watch.key], q[watch.key], watch.key);
+ }
+ }
+ this._query = q;
+ }
+});
+
var Key = {
UP: 38,
DOWN: 40,