From ce996962d6bec0d29664ac3dbe62dcd18630230e Mon Sep 17 00:00:00 2001 From: Regis Date: Fri, 6 Jan 2017 15:27:56 -0700 Subject: add param_helper to utils - fix switch statement in pagination --- app/assets/javascripts/lib/utils/param_helper.js.es6 | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 app/assets/javascripts/lib/utils/param_helper.js.es6 (limited to 'app/assets/javascripts/lib/utils') diff --git a/app/assets/javascripts/lib/utils/param_helper.js.es6 b/app/assets/javascripts/lib/utils/param_helper.js.es6 new file mode 100644 index 00000000000..2b150c415c8 --- /dev/null +++ b/app/assets/javascripts/lib/utils/param_helper.js.es6 @@ -0,0 +1,18 @@ +/* eslint-disable no-param-reassign */ + +((w) => { + /** + 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.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 = {})); -- cgit v1.2.1