From bf4355f55a2cefa5955127539756027d3d127e47 Mon Sep 17 00:00:00 2001 From: Uku Taht Date: Thu, 5 Sep 2019 17:10:32 +0100 Subject: [PATCH] Remove unused JS --- assets/js/app.js | 1 - assets/js/timeframe-selector.js | 71 --------------------------------- 2 files changed, 72 deletions(-) delete mode 100644 assets/js/timeframe-selector.js diff --git a/assets/js/app.js b/assets/js/app.js index 3a17c5aa0..4d53e4903 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -1,7 +1,6 @@ import css from "../css/app.css" import "./polyfills/closest" import "./stats" -import "./timeframe-selector" import "phoenix_html" const triggers = document.querySelectorAll('[data-dropdown-trigger]') diff --git a/assets/js/timeframe-selector.js b/assets/js/timeframe-selector.js deleted file mode 100644 index b9421ae98..000000000 --- a/assets/js/timeframe-selector.js +++ /dev/null @@ -1,71 +0,0 @@ -const selector = document.querySelector('[data-timeframe-select]') - -if (selector) { - selector.addEventListener('change', function(e) { - if (e.target.value === 'Day') { - document.location = '?period=day' - } else if (e.target.value === 'Week') { - document.location = '?period=week' - } else if (e.target.value === 'Month') { - document.location = '?period=month' - } else if (e.target.value === 'Last 3 Months') { - document.location = '?period=3mo' - } else if (e.target.value === 'Last 6 Months') { - document.location = '?period=6mo' - } else if (e.target.value === 'Custom') { - const parent = e.target.closest('div') - parent.classList.add('hidden') - parent.nextElementSibling.classList.remove('hidden') - } - }) -} - -function getQueryVariable(variable) { - var query = window.location.search.substring(1); - var vars = query.split('&'); - for (var i = 0; i < vars.length; i++) { - var pair = vars[i].split('='); - if (decodeURIComponent(pair[0]) == variable) { - return decodeURIComponent(pair[1]); - } - } -} - -function defaultDate() { - const from = getQueryVariable("from") - const to = getQueryVariable("to") - return [Date.parse(from), Date.parse(to)] -} - -function dateToISOString(date) { - const year = date.getFullYear(); - let month = date.getMonth()+1; - let dt = date.getDate(); - - if (dt < 10) { - dt = '0' + dt; - } - if (month < 10) { - month = '0' + month; - } - - return year + '-' + month + '-'+ dt; -} - -const dateRangeTrigger = document.querySelector('#custom-daterange-trigger') - -if (dateRangeTrigger) { - const picker = flatpickr('#custom-daterange-trigger', { - mode: "range", - dateFormat: "M j", - maxDate: 'today', - onChange: function(selectedDates, dateStr) { - if (selectedDates.length === 2) { - dateRangeTrigger.innerHTML = dateStr - const from = dateToISOString(selectedDates[0]) - const to = dateToISOString(selectedDates[1]) - document.location = '?period=custom&from=' + from + '&to=' + to - } - }, - }) -}