From 55df55367f68ca0d1df2ad13363c98ec62fc3930 Mon Sep 17 00:00:00 2001 From: Regis Date: Mon, 9 Jan 2017 10:26:43 -0700 Subject: [PATCH] move param helper to common utils --- .../{common_utils.js => common_utils.js.es6} | 15 +++++++++++++ .../javascripts/lib/utils/param_helper.js.es6 | 21 ------------------- .../javascripts/vue_pagination/index.js.es6 | 2 -- .../vue_pagination/pagination_spec.js.es6 | 1 + 4 files changed, 16 insertions(+), 23 deletions(-) rename app/assets/javascripts/lib/utils/{common_utils.js => common_utils.js.es6} (88%) delete mode 100644 app/assets/javascripts/lib/utils/param_helper.js.es6 diff --git a/app/assets/javascripts/lib/utils/common_utils.js b/app/assets/javascripts/lib/utils/common_utils.js.es6 similarity index 88% rename from app/assets/javascripts/lib/utils/common_utils.js rename to app/assets/javascripts/lib/utils/common_utils.js.es6 index 31a71379af3..b8d637a9827 100644 --- a/app/assets/javascripts/lib/utils/common_utils.js +++ b/app/assets/javascripts/lib/utils/common_utils.js.es6 @@ -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); diff --git a/app/assets/javascripts/lib/utils/param_helper.js.es6 b/app/assets/javascripts/lib/utils/param_helper.js.es6 deleted file mode 100644 index 01b3a2ee07f..00000000000 --- a/app/assets/javascripts/lib/utils/param_helper.js.es6 +++ /dev/null @@ -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 = {})); diff --git a/app/assets/javascripts/vue_pagination/index.js.es6 b/app/assets/javascripts/vue_pagination/index.js.es6 index 78a26f65dfd..605824fa939 100644 --- a/app/assets/javascripts/vue_pagination/index.js.es6 +++ b/app/assets/javascripts/vue_pagination/index.js.es6 @@ -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; diff --git a/spec/javascripts/vue_pagination/pagination_spec.js.es6 b/spec/javascripts/vue_pagination/pagination_spec.js.es6 index c5f70ba5bfb..ca13d66282a 100644 --- a/spec/javascripts/vue_pagination/pagination_spec.js.es6 +++ b/spec/javascripts/vue_pagination/pagination_spec.js.es6 @@ -1,4 +1,5 @@ //= require vue +//= require lib/utils/common_utils //= require vue_pagination/index describe('Pagination component', () => {