2021-12-14 09:20:58 +03:00
|
|
|
/* ----------------------------------------------------------------------------
|
2022-01-18 15:05:42 +03:00
|
|
|
* Easy!Appointments - Online Appointment Scheduler
|
2021-12-14 09:20:58 +03:00
|
|
|
*
|
|
|
|
* @package EasyAppointments
|
|
|
|
* @author A.Tselegidis <alextselegidis@gmail.com>
|
2021-12-18 19:43:45 +03:00
|
|
|
* @copyright Copyright (c) Alex Tselegidis
|
|
|
|
* @license https://opensource.org/licenses/GPL-3.0 - GPLv3
|
|
|
|
* @link https://easyappointments.org
|
2021-12-14 09:20:58 +03:00
|
|
|
* @since v1.5.0
|
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
2022-01-14 11:26:44 +03:00
|
|
|
/**
|
|
|
|
* URLs utility.
|
|
|
|
*
|
|
|
|
* This module implements the functionality of URLs.
|
|
|
|
*/
|
2021-12-14 09:20:58 +03:00
|
|
|
window.App.Utils.Url = (function () {
|
|
|
|
/**
|
|
|
|
* Get complete URL of the provided URI segment.
|
|
|
|
*
|
|
|
|
* @param {String} uri
|
|
|
|
*
|
|
|
|
* @return {String}
|
|
|
|
*/
|
|
|
|
function baseUrl(uri) {
|
2022-01-18 10:18:22 +03:00
|
|
|
return `${vars('base_url')}/${uri}`;
|
2021-12-14 09:20:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the complete site URL (including the index.php) of the provided URI segment.
|
|
|
|
*
|
|
|
|
* @param {String} uri
|
|
|
|
*
|
|
|
|
* @returns {String}
|
|
|
|
*/
|
|
|
|
function siteUrl(uri) {
|
2022-01-18 10:18:22 +03:00
|
|
|
return `${vars('base_url')}${vars('index_page') ? '/' + vars('index_page') : ''}/${uri}`;
|
2021-12-14 09:20:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
};
|
|
|
|
})();
|