Commit 76c68d1a authored by Regis's avatar Regis

namespace getParametersByName to gl.utils instead of just gl

parent 3fff93ca
/* eslint-disable no-param-reassign */ /* eslint-disable no-param-reassign */
((w) => { ((gl) => {
gl.utils = gl.utils || (gl.utils = {});
/** /**
this will take in the `name` of the param you want to parse in the url 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` if the name does not exist this function will return `null`
otherwise it will return the value of the param key provided otherwise it will return the value of the param key provided
*/ */
w.getParameterByName = (name) => {
gl.utils.getParameterByName = (name) => {
const url = window.location.href; const url = window.location.href;
name = name.replace(/[[\]]/g, '\\$&'); name = name.replace(/[[\]]/g, '\\$&');
const regex = new RegExp(`[?&]${name}(=([^&#]*)|&|#|$)`); const regex = new RegExp(`[?&]${name}(=([^&#]*)|&|#|$)`);
......
...@@ -58,7 +58,7 @@ ...@@ -58,7 +58,7 @@
}, },
methods: { methods: {
changePage(e) { changePage(e) {
let apiScope = gl.getParameterByName('scope'); let apiScope = gl.utils.getParameterByName('scope');
if (!apiScope) apiScope = 'all'; if (!apiScope) apiScope = 'all';
......
...@@ -28,8 +28,8 @@ ...@@ -28,8 +28,8 @@
}, },
props: ['scope', 'store', 'svgs'], props: ['scope', 'store', 'svgs'],
created() { created() {
const pagenum = gl.getParameterByName('p'); const pagenum = gl.utils.getParameterByName('p');
const scope = gl.getParameterByName('scope'); const scope = gl.utils.getParameterByName('scope');
if (pagenum) this.pagenum = pagenum; if (pagenum) this.pagenum = pagenum;
if (scope) this.apiScope = scope; if (scope) this.apiScope = scope;
this.store.fetchDataLoop.call(this, Vue, this.pagenum, this.scope, this.apiScope); this.store.fetchDataLoop.call(this, Vue, this.pagenum, this.scope, this.apiScope);
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
this.store.fetchDataLoop.call(this, Vue, pagenum, this.scope, apiScope); this.store.fetchDataLoop.call(this, Vue, pagenum, this.scope, apiScope);
}, },
author(pipeline) { author(pipeline) {
if (!pipeline.commit) return ({ avatar_url: '', web_url: '', username: '' }); if (!pipeline.commit) return { avatar_url: '', web_url: '', username: '' };
if (pipeline.commit.author) return pipeline.commit.author; if (pipeline.commit.author) return pipeline.commit.author;
return { return {
avatar_url: pipeline.commit.author_gravatar_url, avatar_url: pipeline.commit.author_gravatar_url,
......
...@@ -147,8 +147,8 @@ describe('paramHelper', () => { ...@@ -147,8 +147,8 @@ describe('paramHelper', () => {
it('can parse url parameters correctly', () => { it('can parse url parameters correctly', () => {
window.history.pushState({}, null, '?scope=all&p=2'); window.history.pushState({}, null, '?scope=all&p=2');
const scope = gl.getParameterByName('scope'); const scope = gl.utils.getParameterByName('scope');
const p = gl.getParameterByName('p'); const p = gl.utils.getParameterByName('p');
expect(scope).toEqual('all'); expect(scope).toEqual('all');
expect(p).toEqual('2'); expect(p).toEqual('2');
...@@ -157,8 +157,8 @@ describe('paramHelper', () => { ...@@ -157,8 +157,8 @@ describe('paramHelper', () => {
it('returns null if param not in url', () => { it('returns null if param not in url', () => {
window.history.pushState({}, null, '?p=2'); window.history.pushState({}, null, '?p=2');
const scope = gl.getParameterByName('scope'); const scope = gl.utils.getParameterByName('scope');
const p = gl.getParameterByName('p'); const p = gl.utils.getParameterByName('p');
expect(scope).toEqual(null); expect(scope).toEqual(null);
expect(p).toEqual('2'); expect(p).toEqual('2');
......
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