Skip to content

Instantly share code, notes, and snippets.

@everaldomatias
Last active July 5, 2024 21:59
Show Gist options
  • Save everaldomatias/ed0bb5de309e9fbfa1553de5b00a30d3 to your computer and use it in GitHub Desktop.
Save everaldomatias/ed0bb5de309e9fbfa1553de5b00a30d3 to your computer and use it in GitHub Desktop.
/*!
* Understrap v1.1.0 (https://understrap.com)
* Copyright 2013-2022 The UnderStrap Authors (https://github.com/understrap/understrap/graphs/contributors)
* Licensed under GPL (http://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html)
*/
(function (factory) {
typeof define === 'function' && define.amd ? define(factory) :
factory();
})((function () { 'use strict';
/**
* File skip-link-focus-fix.js.
*
* Helps with accessibility for keyboard only users.
*
* Learn more: https://git.io/vWdr2
*/
(function () {
var isWebkit = navigator.userAgent.toLowerCase().indexOf('webkit') > -1,
isOpera = navigator.userAgent.toLowerCase().indexOf('opera') > -1,
isIe = navigator.userAgent.toLowerCase().indexOf('msie') > -1;
if ((isWebkit || isOpera || isIe) && document.getElementById && window.addEventListener) {
window.addEventListener('hashchange', function () {
var id = location.hash.substring(1),
element;
if (!/^[A-z0-9_-]+$/.test(id)) {
return;
}
element = document.getElementById(id);
if (element) {
if (!/^(?:a|select|input|button|textarea)$/i.test(element.tagName)) {
element.tabIndex = -1;
}
element.focus();
}
}, false);
}
})();
// Add your custom JS here.
function animateValue(id, start, end, duration) {
if (start === end) return;
var range = end - start;
var current = start;
var increment = end > start ? 1 : -1;
var stepTime = Math.abs(Math.floor(duration / range));
var obj = document.getElementById(id);
if (typeof obj != 'undefined' && obj != null) {
var timer = setInterval(function () {
current += increment;
obj.innerHTML = current;
if (current == end) {
clearInterval(timer);
}
}, stepTime);
}
}
document.addEventListener('DOMContentLoaded', function () {
animateValue('count-years', 0, 27, 5000);
animateValue('count-tax', 0, 30, 5000);
animateValue('count-donation', 0, 192, 5000);
animateValue('count-international-donation', 0, 116, 5000);
flatpickr.localize(flatpickr.l10ns.pt); // Flatpickr to Birthday
flatpickr('.birthday-date', {
dateFormat: "d/m/Y",
disableMobile: "true",
locale: "pt"
}); // Flatpickr to Scheduling
flatpickr('.scheduling-date', {
dateFormat: "d/m/Y",
disableMobile: "true",
minDate: "today",
maxDate: "01/01/2025",
disable: [function (date) {
let holidays = ['01/01/2024', '09/07/2024', '07/09/2024', '12/10/2024', '02/11/2024', '15/11/2024', '20/11/2024', '25/12/2024', '01/01/2025']; // return true to disable
return date.getDay() === 0 || date.getDay() === 6 || holidays.includes(("0" + date.getDate()).slice(-2) + "/" + ("0" + (date.getMonth() + 1)).slice(-2) + "/" + date.getFullYear());
}],
locale: {
firstDayOfWeek: 1 // start week on Monday
}
});
});
jQuery(function () {
jQuery('.date').mask('00/00/0000');
jQuery('.time').mask('00:00:00');
jQuery('.date_time').mask('00/00/0000 00:00:00');
jQuery('.cep').mask('00000-000');
jQuery('.phone').mask('0000-0000');
jQuery('.phone_with_ddd').mask('(00) 00000-0000');
jQuery('.mixed').mask('AAA 000-S0S');
jQuery('.ip_address').mask('099.099.099.099');
jQuery('.percent').mask('##0,00%', {
reverse: true
});
jQuery('.clear-if-not-match').mask("00/00/0000", {
clearIfNotMatch: true
});
jQuery('.placeholder').mask("00/00/0000", {
placeholder: "__/__/____"
});
jQuery('.fallback').mask("00r00r0000", {
translation: {
'r': {
pattern: /[\/]/,
fallback: '/'
},
placeholder: "__/__/____"
}
});
});
var selectUf = document.getElementById('select-uf');
if (typeof selectUf !== "undefined" && selectUf !== null) {
document.querySelectorAll('#select-uf option[data-to-filter-uf]');
var selectCity = document.querySelectorAll('#select-city option[data-filtered-uf]');
var itemsMap = document.querySelectorAll('#svg-map .estado');
var listClinics = document.querySelectorAll('.result-map-search .each');
var filteredBy = 'uf'; // uf or city
document.getElementById('messages');
var separator = document.getElementById('separator');
var em = document.getElementById('em');
var nothingFound = document.getElementById('nothing-found'); // load
document.addEventListener('DOMContentLoaded', function () {
filteredBy = 'uf';
setUf('sp');
filterCity('sp');
filterClinics('sp');
updateResultSearch();
}); // select uf
selectUf.addEventListener('input', function (event) {
if (event.target.id !== 'select-uf') return;
filteredBy = 'uf';
filterCity(event.target.value);
filterClinics(event.target.value);
updateResultSearch();
}); // select city
document.querySelector('#select-city').addEventListener('input', function (event) {
if (event.target.id !== 'select-city') return;
filteredBy = 'city';
filterClinics(event.target.value);
updateResultSearch();
}); // map
itemsMap.forEach(function (item) {
item.addEventListener('click', function (event) {
event.preventDefault();
filteredBy = 'uf';
filterClinics(item.dataset.uf);
filterCity(item.dataset.uf);
setUf(item.dataset.uf);
updateResultSearch(item.dataset.uf);
});
});
}
function filterCity(value) {
clearCity();
selectCity.forEach(function (item) {
if (item.dataset.filteredUf === value) {
item.classList.add('show');
}
});
}
function filterClinics(value) {
clearClinics();
listClinics.forEach(function (item) {
if (filteredBy == 'uf') {
if (item.dataset.toFilterUf === value) {
item.classList.add('show');
}
} else {
if (item.dataset.toFilterCity === value) {
item.classList.add('show');
}
}
});
}
function setUf(value) {
var select = document.querySelector('#select-uf');
Array.from(document.querySelector('#select-uf')).forEach(function (option, index) {
if (value === option.dataset.toFilterUf) {
select.selectedIndex = index;
} else if (value === 'all') {
select.selectedIndex = 0;
}
});
}
function clearCity() {
selectCity.forEach(function (item) {
item.classList.remove('show');
item.classList.add('hidden');
});
var select = document.querySelector('#select-city');
Array.from(document.querySelector('#select-city')).forEach(function (option, index) {
select.selectedIndex = 0;
});
}
function clearClinics() {
listClinics.forEach(function (item) {
item.classList.remove('show');
item.classList.add('hidden');
});
}
function hasClinics() {
nothingFound.classList.add('show');
for (const item of listClinics) {
if (item.classList.contains('show')) {
nothingFound.classList.remove('show');
break;
}
}
}
function updateResultSearch(ufFromMap = false) {
var uf = document.querySelector('#select-uf');
var resultSearchUf = document.getElementById('result-search-uf');
var city = document.querySelector('#select-city');
var resultSearchCity = document.getElementById('result-search-city');
em.classList.remove('d-inline-block');
separator.classList.remove('d-inline-block');
resultSearchUf.textContent = '';
resultSearchCity.textContent = '';
if (ufFromMap) {
resultSearchUf.textContent = ufFromMap.toUpperCase();
em.classList.add('d-inline-block');
} else if (uf.value && uf.value != 'all') {
resultSearchUf.textContent = uf.options[uf.selectedIndex].text;
em.classList.add('d-inline-block');
}
if (city.value && city.value != 'all') {
resultSearchCity.textContent = city.options[city.selectedIndex].text;
separator.classList.add('d-inline-block');
}
hasClinics();
}
/**
* FAQs
*/
var body = document.querySelector('body');
if (body.classList.contains('tax-categoria-faqs')) {
var buttons = document.querySelectorAll('header h6[data-click]');
buttons.forEach(function (button) {
button.addEventListener('click', function (event) {
event.preventDefault;
var content = document.querySelector('.entry-content[data-content=' + event.target.dataset.click + ']');
var article = document.getElementById(event.target.dataset.click);
removeCssClass('.entry-content[data-content]', 'show');
removeCssClass('.each-faq', 'bg');
content.classList.add('show');
article.classList.add('bg');
});
});
}
function removeCssClass(element, cssClass) {
document.querySelectorAll(element).forEach(function (el) {
el.classList.remove(cssClass);
});
}
}));
//# sourceMappingURL=theme.js.map
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment