Commit e0e855b5 authored by Clement Ho's avatar Clement Ho

Fix code review suggestions

parent c0287e69
...@@ -3,6 +3,10 @@ ...@@ -3,6 +3,10 @@
/* global droplab */ /* global droplab */
require('../window')(function(w){ require('../window')(function(w){
function droplabAjaxException(message) {
this.message = message;
}
w.droplabAjax = { w.droplabAjax = {
_loadUrlData: function _loadUrlData(url) { _loadUrlData: function _loadUrlData(url) {
return new Promise(function(resolve, reject) { return new Promise(function(resolve, reject) {
...@@ -56,11 +60,7 @@ require('../window')(function(w){ ...@@ -56,11 +60,7 @@ require('../window')(function(w){
} }
hook.list[config.method].call(hook.list, d); hook.list[config.method].call(hook.list, d);
}).catch(function(e) { }).catch(function(e) {
if(e.message) { throw new droplabAjaxException(e.message || e);
console.error(e.message, e.stack); // eslint-disable-line no-console
} else {
console.error(e); // eslint-disable-line no-console
}
}); });
}, },
......
...@@ -169,6 +169,8 @@ ...@@ -169,6 +169,8 @@
w.gl.utils.getParameterByName = (name) => { w.gl.utils.getParameterByName = (name) => {
const url = window.location.href; const url = window.location.href;
name = name.replace(/[[\]]/g, '\\$&'); name = name.replace(/[[\]]/g, '\\$&');
// Finds the value associated to the name
// Example, state=open where state is the name and open is the value
const regex = new RegExp(`[?&]${name}(=([^&#]*)|&|#|$)`); const regex = new RegExp(`[?&]${name}(=([^&#]*)|&|#|$)`);
const results = regex.exec(url); const results = regex.exec(url);
if (!results) return null; if (!results) return null;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment