Created
November 16, 2017 06:57
-
-
Save yesnik/dcd5636382cf0e3e2544cc5ec603379e to your computer and use it in GitHub Desktop.
Jquery modules
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// We need to understand how to organise this piece of code better | |
var Delivery = (function () { | |
var selectedCityName, | |
$textDelivery, | |
$textNoDelivery; | |
function init() { | |
initElements(); | |
initVars(); | |
initListeners(); | |
initInterface(); | |
} | |
function initElements() { | |
$textDelivery = $('.js-text-delivery'); | |
$textNoDelivery = $('.js-text-no-delivery'); | |
} | |
function initVars() { | |
var cityName; | |
if (Ubrr.page == 'index') { | |
cityName = Ubrr.geoipCityName; | |
} else { | |
cityName = localStorage.getItem('selectedCityName'); | |
} | |
setSelectedCityName(cityName); | |
} | |
function initInterface() { | |
updateDeviveryTextVisibility(); | |
} | |
function setSelectedCityName(cityName) { | |
selectedCityName = cityName; | |
setLocalStorage('selectedCityName', cityName); | |
} | |
function onCitySelect(_event, data) { | |
setSelectedCityName(data.cityName); | |
} | |
function onOfficeSelect(_event, data) { | |
updateDeviveryTextVisibility(); | |
} | |
function updateDeviveryTextVisibility() { | |
if (needShowDeliveryText(selectedCityName)) { | |
showDeliveryText(); | |
} else { | |
hideDeliveryText(); | |
} | |
} | |
function setLocalStorage(key, value) { | |
localStorage.setItem(key, value); | |
} | |
function getLocalStorage(key) { | |
localStorage.getItem(key); | |
} | |
function needShowDeliveryText(selectedCityName) { | |
return $.inArray(selectedCityName, Ubrr.deliveryCityNames) !== -1; | |
} | |
function showDeliveryText() { | |
$textDelivery.show(); | |
$textNoDelivery.hide(); | |
} | |
function hideDeliveryText() { | |
$textDelivery.hide(); | |
$textNoDelivery.show(); | |
} | |
function initListeners() { | |
$('body').on({ | |
'modalCityOfficeChoice.city.selected': onCitySelect, | |
'modalCityOfficeChoice.office.selected': onOfficeSelect | |
}); | |
} | |
return { | |
init: init | |
} | |
}()); | |
$(function () { | |
FixedFooter.init(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment