Skip to content
This repository has been archived by the owner on May 3, 2021. It is now read-only.

Commit

Permalink
- added config file with config object
Browse files Browse the repository at this point in the history
  • Loading branch information
MilanTuryna committed Feb 5, 2020
1 parent 72b7d55 commit ee95d5f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 23 deletions.
1 change: 1 addition & 0 deletions css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ main {
-webkit-animation-timing-function: linear;
-moz-animation-timing-function: linear;
}

.loader div {
width: 8px;
height: 8px;
Expand Down
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ <h4 class="alert-heading">{{nadpis}}</h4>
</div>
</script>
</div>
<script src="js/config.js"></script>
<script src="js/api.js"></script>
<script src="js/main.js"></script>
</body>
Expand Down
16 changes: 5 additions & 11 deletions js/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,15 @@ Array.prototype.where = function (matcher) {
}
return result;
};
/**
* @type {{settings: {url: string, date_url: string, zaloha_url: string}, getResponse: API.getResponse}}
*/

var API = {
settings: {
url: 'https://yacdn.org/serve/https://www.cnb.cz/cs/financni_trhy/devizovy_trh/kurzy_devizoveho_trhu/denni_kurz.xml?maxAge=3600',
zaloha_url: 'https://api.codetabs.com/v1/proxy?quest=https://www.cnb.cz/cs/financni_trhy/devizovy_trh/kurzy_devizoveho_trhu/denni_kurz.xml',
date_url: 'https://yacdn.org/proxy/https://www.cnb.cz/cs/financni_trhy/devizovy_trh/kurzy_devizoveho_trhu/denni_kurz.xml'
}, getResponse: (callback, date) => {
let url = API.settings.url,
zaloha_url = API.settings.zaloha_url,
getResponse: (callback, date) => {
let url = config.REQUEST.classic,
zaloha_url = config.REQUEST.backup,
xhttp = new XMLHttpRequest();

if (date) {
url = API.settings.date_url + '?date=' + date;
url = config.REQUEST.with_date + date;
zaloha_url += '?date=' + date;
}

Expand Down
26 changes: 14 additions & 12 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ APIParser.lastTime((time) => {
$('#input-datum').val(date_array[0] + '-' + date_array[1] + '-' + date_array[2]);
});

APIParser.currency((options, count = null) => {
APIParser.currency((options, count) => {
let i, array_options = options.split('</option>').sort();

options = '<option value="disabled" id="option-to-delete" disabled selected>Vyber měnu</option>';
Expand All @@ -32,7 +32,7 @@ function createComponent(element, template, variables, blind) {
element = "#" + element;
blind = (typeof blind === 'undefined');
$(element).html(document.getElementById(template).innerHTML.strReplace(variables));
(blind) ? $(element).show("blind") : $(element).fadeIn('slow');
(blind) ? $(element).show(config.UI.show) : $(element).fadeIn(config.UI.fade);

$('html, body').animate({
scrollTop: $(element).offset().top
Expand All @@ -44,7 +44,7 @@ function createComponent(element, template, variables, blind) {
*/
function deleteComponent(element) {
element = "#" + element;
$(element).hide( "blind" );
$(element).hide(config.UI.show);
}
/**
* @param i
Expand All @@ -59,12 +59,7 @@ function addZero(i) {

$('a').attr('target', '_blank');
$(()=>{$('[data-toggle="tooltip"]').tooltip();});
$('[data-tooltip-slow]').tooltip({
delay: {
show: 1000,
hide: 0
}
});
$('[data-tooltip-slow]').tooltip(config.UI.tooltip_slow);
$('.overlay-loader').fadeOut(800);
setTimeout(()=>{
$('.body').fadeIn(600);
Expand All @@ -86,15 +81,16 @@ $(document).ready(function() {
});
});

$('.meny::-webkit-scrollbar-track').css('backgroundColor', '#e4f5e4');
$('#prevod-button').on('click', ()=>{
let first = document.getElementById('first'),
second = document.getElementById('second'),
castka = document.getElementById('input-castka'),
zaokr = document.getElementById('input-zaokr'),
d = new Date(), time, datum = document.getElementById('input-datum');

if(first.value !== 'disabled' && first.value && second.value !== 'disabled' && second.value) {
if(first.value !== 'disabled' && first.value && second.value !== 'disabled' && second.value
&& parseInt(datum.value.split("-")[0]) > parseInt(datum.getAttribute('min').split("-")[0]))
{
APIParser.getMoney(first.value, second.value,(countfirst, countsecond, ok) => {
if(ok) {
let zaokrvalue = zaokr.value;
Expand Down Expand Up @@ -134,13 +130,19 @@ $('#prevod-button').on('click', ()=>{
}

}, datum.value.split('-').reverse().join('.'));
} else if(parseInt(datum.value.split('-')[0]) < parseInt(datum.getAttribute('min').split("-")[0])) {
createComponent('alert-vysledek', 'alert', {
'{{type}}': 'danger',
'{{nadpis}}': 'Chyba datum',
'{{obsah}}': 'Nastavil jste datum, kdy nebyl kurzovní lístek od ČNB k dispozici, prosím zadejte datum od 1.1.1991',
'{{footer}}': addZero(d.getHours()) + ':' + addZero(d.getMinutes())
});
} else {
$('#prevod-button').val('Nemůžeš převádět když sis nevybral měnu.');
$('#prevod-button').attr('disabled', 'disabled');
setTimeout(()=>{
$('#prevod-button').val('Zkus to znovu.. převést měnu pro datum ' + $('#input-datum').val().split('-').reverse().join('.'));
$('#prevod-button').removeAttr('disabled');
}, 1000)

}
});

0 comments on commit ee95d5f

Please sign in to comment.