diff --git a/src/assets/js/frontend_book.js b/src/assets/js/frontend_book.js index a1298e06..e7b7a62f 100644 --- a/src/assets/js/frontend_book.js +++ b/src/assets/js/frontend_book.js @@ -97,20 +97,42 @@ window.FrontendBook = window.FrontendBook || {}; } }); - - // Bind the event handlers (might not be necessary every time - // we use this class). + // Bind the event handlers (might not be necessary every time we use this class). if (bindEventHandlers) { _bindEventHandlers(); } - // If the manage mode is true, the appointments data should be - // loaded by default. + // If the manage mode is true, the appointments data should be loaded by default. if (FrontendBook.manageMode) { _applyAppointmentData(GlobalVariables.appointmentData, GlobalVariables.providerData, GlobalVariables.customerData); } else { - $('#select-service').trigger('change'); // Load the available hours. + var $selectProvider = $('#select-provider'); + var $selectService = $('#select-service'); + + // Check if a specific service was selected. + var selectedServiceId = GeneralFunctions.getUrlParameter(location.href, 'service'); + + if (selectedServiceId && $selectService.find('option[value="' + selectedServiceId + '"]').length > 0) { + $selectService + .val(selectedServiceId) + .prop('disabled', true) + .css('opacity', '0.5'); + } + + $selectService.trigger('change'); // Load the available hours. + + // Check if a specific provider was selected. + var selectedProviderId = GeneralFunctions.getUrlParameter(location.href, 'provider'); + + if (selectedProviderId && $selectProvider.find('option[value="' + selectedProviderId + '"]').length > 0) { + $selectProvider + .val(selectedProviderId) + .prop('disabled', true) + .css('opacity', '0.5') + .trigger('change'); + } + } }; diff --git a/src/assets/js/general_functions.js b/src/assets/js/general_functions.js index e9c217be..44bb9327 100644 --- a/src/assets/js/general_functions.js +++ b/src/assets/js/general_functions.js @@ -114,11 +114,21 @@ window.GeneralFunctions = window.GeneralFunctions || {}; * @return {String} Returns the parameter value. */ exports.getUrlParameter = function(url, parameterName) { - parameterName = parameterName.replace(/[\[]/,'\\\[').replace(/[\]]/,'\\\]'); - var regexS = '[\\#&]' + parameterName + '=([^&#]*)'; - var regex = new RegExp(regexS); - var results = regex.exec(url); - return (results == null) ? '' : results[1]; + var parsedUrl = url.substr(url.indexOf('?')).slice(1).split('&'); + + for (var index in parsedUrl) { + var parsedValue = parsedUrl[index].split('='); + + if (parsedValue.length === 1 && parsedValue[0] === parameterName) { + return ''; + } + + if (parsedValue.length === 2 && parsedValue[0] === parameterName) { + return decodeURIComponent(parsedValue[1]); + } + } + + return ''; }; /**