cartodb-4.42/lib/assets/javascripts/deep-insights/api/url-helper.js
2024-04-06 05:25:13 +00:00

32 lines
844 B
JavaScript

var URI = require('urijs');
var _ = require('underscore');
module.exports = {
getURLFromState: function (state) {
var thisURL = new URI(this.getLocalURL());
thisURL.removeQuery('state');
if (!_.isEmpty(state)) {
var statesString = JSON.stringify(state);
thisURL.setQuery('state', statesString);
}
return thisURL.toString();
},
getStateFromCurrentURL: function () {
var currentURL = this.getLocalURL();
return this.getStateFromURL(currentURL);
},
getStateFromURL: function (url) {
var uri = new URI(url);
var state;
var result = {};
if (uri.hasQuery('state')) {
state = uri.query(true)['state'];
if (!_.isEmpty(state)) {
result = JSON.parse(decodeURIComponent(state));
}
}
return result;
},
getLocalURL: _.constant(window.location.href)
};