forked from mirrors/easyappointments
Added the URL JS helper file
This commit is contained in:
parent
6376fea885
commit
f0f0a029ab
1 changed files with 69 additions and 0 deletions
69
assets/js/utils/url.js
Normal file
69
assets/js/utils/url.js
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
/* ----------------------------------------------------------------------------
|
||||||
|
* Easy!Appointments - Open Source Web Scheduler
|
||||||
|
*
|
||||||
|
* @package EasyAppointments
|
||||||
|
* @author A.Tselegidis <alextselegidis@gmail.com>
|
||||||
|
* @copyright Copyright (c) 2013 - 2020, Alex Tselegidis
|
||||||
|
* @license http://opensource.org/licenses/GPL-3.0 - GPLv3
|
||||||
|
* @link http://easyappointments.org
|
||||||
|
* @since v1.5.0
|
||||||
|
* ---------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
window.App.Utils.Url = (function () {
|
||||||
|
/**
|
||||||
|
* Get complete URL of the provided URI segment.
|
||||||
|
*
|
||||||
|
* @param {String} uri
|
||||||
|
*
|
||||||
|
* @return {String}
|
||||||
|
*/
|
||||||
|
function baseUrl(uri) {
|
||||||
|
return `${App.Config.base_url}/${uri}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the complete site URL (including the index.php) of the provided URI segment.
|
||||||
|
*
|
||||||
|
* @param {String} uri
|
||||||
|
*
|
||||||
|
* @returns {String}
|
||||||
|
*/
|
||||||
|
function siteUrl(uri) {
|
||||||
|
return `${App.Config.base_url}${App.Config.index_page ? '/' + App.Config.index_page : ''}/${uri}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve a query parameter from the current request.
|
||||||
|
*
|
||||||
|
* @link http://www.netlobo.com/url_query_string_javascript.html
|
||||||
|
*
|
||||||
|
* @param {String} name Parameter name.
|
||||||
|
|
||||||
|
* @return {String} Returns the parameter value.
|
||||||
|
*/
|
||||||
|
function queryParam(name) {
|
||||||
|
const url = location.href;
|
||||||
|
|
||||||
|
const parsedUrl = url.substr(url.indexOf('?')).slice(1).split('&');
|
||||||
|
|
||||||
|
for (let index in parsedUrl) {
|
||||||
|
const parsedValue = parsedUrl[index].split('=');
|
||||||
|
|
||||||
|
if (parsedValue.length === 1 && parsedValue[0] === name) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parsedValue.length === 2 && parsedValue[0] === name) {
|
||||||
|
return decodeURIComponent(parsedValue[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
baseUrl,
|
||||||
|
siteUrl,
|
||||||
|
queryParam
|
||||||
|
};
|
||||||
|
})();
|
Loading…
Reference in a new issue