move param helper to common utils

This commit is contained in:
Regis 2017-01-09 10:26:43 -07:00
parent 5498448535
commit 55df55367f
4 changed files with 16 additions and 23 deletions

View file

@ -139,6 +139,21 @@
}, 200);
};
/**
this will take in the `name` of the param you want to parse in the url
if the name does not exist this function will return `null`
otherwise it will return the value of the param key provided
*/
w.gl.utils.getParameterByName = (name) => {
const url = window.location.href;
name = name.replace(/[[\]]/g, '\\$&');
const regex = new RegExp(`[?&]${name}(=([^&#]*)|&|#|$)`);
const results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, ' '));
};
})(window);
}).call(this);

View file

@ -1,21 +0,0 @@
/* eslint-disable no-param-reassign */
((gl) => {
gl.utils = gl.utils || (gl.utils = {});
/**
this will take in the `name` of the param you want to parse in the url
if the name does not exist this function will return `null`
otherwise it will return the value of the param key provided
*/
gl.utils.getParameterByName = (name) => {
const url = window.location.href;
name = name.replace(/[[\]]/g, '\\$&');
const regex = new RegExp(`[?&]${name}(=([^&#]*)|&|#|$)`);
const results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, ' '));
};
})(window.gl || (window.gl = {}));

View file

@ -1,8 +1,6 @@
/* global Vue, gl */
/* eslint-disable no-param-reassign, no-plusplus */
/*= require lib/utils/param_helper.js.es6 */
((gl) => {
const PAGINATION_UI_BUTTON_LIMIT = 4;
const UI_LIMIT = 6;

View file

@ -1,4 +1,5 @@
//= require vue
//= require lib/utils/common_utils
//= require vue_pagination/index
describe('Pagination component', () => {