2017-06-14 18:40:12 +00:00
|
|
|
// Generated by CoffeeScript 1.12.4
|
|
|
|
(function() {
|
2017-06-14 21:15:15 +00:00
|
|
|
var clipboard, createAlert, createOTPItem, currentTimeout, delay, fetchCodes, filterChange, initializeApplication, refreshTimerProgress, tick, timeLeft, updateCodes;
|
2017-06-14 18:40:12 +00:00
|
|
|
|
|
|
|
currentTimeout = 0;
|
|
|
|
|
|
|
|
clipboard = void 0;
|
|
|
|
|
|
|
|
$(function() {
|
|
|
|
if ($('body').hasClass('state-signedin')) {
|
|
|
|
return initializeApplication();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
createOTPItem = function(item) {
|
|
|
|
var otpItem, tpl;
|
2017-06-14 21:15:15 +00:00
|
|
|
tpl = $('#tpl-otp-item').html();
|
2017-06-14 18:40:12 +00:00
|
|
|
otpItem = $(tpl);
|
|
|
|
otpItem.find('.badge').text(item.code.replace(/^(.{3})(.{3})$/, '$1 $2'));
|
|
|
|
otpItem.find('.title').text(item.name);
|
2017-06-14 20:21:31 +00:00
|
|
|
otpItem.find('i.fa').addClass("fa-" + item.icon);
|
2017-06-14 18:40:12 +00:00
|
|
|
return otpItem.appendTo($('#keylist'));
|
|
|
|
};
|
|
|
|
|
2017-06-14 21:15:15 +00:00
|
|
|
createAlert = function(type, keyword, message, timeout) {
|
|
|
|
var alrt, tpl;
|
|
|
|
tpl = $('#tpl-message').html();
|
|
|
|
alrt = $(tpl);
|
|
|
|
alrt.addClass("alert-" + type);
|
|
|
|
alrt.find('.keyword').text(keyword);
|
|
|
|
alrt.find('.message').text(message);
|
|
|
|
alrt.appendTo($('#messagecontainer'));
|
|
|
|
if (timeout > 0) {
|
|
|
|
return delay(timeout, function() {
|
|
|
|
return alrt.remove();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-06-14 18:40:12 +00:00
|
|
|
delay = function(delayMSecs, fkt) {
|
|
|
|
return window.setTimeout(fkt, delayMSecs);
|
|
|
|
};
|
|
|
|
|
|
|
|
fetchCodes = function() {
|
|
|
|
return $.ajax({
|
|
|
|
url: 'codes.json',
|
|
|
|
success: updateCodes,
|
2017-06-14 21:15:15 +00:00
|
|
|
dataType: 'json',
|
|
|
|
error: function() {
|
|
|
|
createAlert('danger', 'Oops.', 'Server could not be contacted. Maybe you (or the server) are offline? I will retry in a few seconds.', 5000);
|
|
|
|
return delay(5000, fetchCodes);
|
|
|
|
},
|
|
|
|
statusCode: {
|
|
|
|
401: function() {
|
|
|
|
return window.location.reload();
|
|
|
|
},
|
|
|
|
500: function() {
|
|
|
|
createAlert('danger', 'Oops.', 'The server responded with an internal error. I will retry in a few seconds.', 2000);
|
|
|
|
return delay(2000, fetchCodes);
|
|
|
|
}
|
|
|
|
}
|
2017-06-14 18:40:12 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
filterChange = function() {
|
|
|
|
var filter;
|
|
|
|
filter = $('#filter').val().toLowerCase();
|
|
|
|
return $('.otp-item').each(function(idx, el) {
|
|
|
|
if ($(el).find('.title').text().toLowerCase().match(filter) === null) {
|
|
|
|
return $(el).hide();
|
|
|
|
} else {
|
|
|
|
return $(el).show();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
initializeApplication = function() {
|
|
|
|
$('#keylist').empty();
|
|
|
|
$('#filter').bind('keyup', filterChange);
|
|
|
|
tick(500, refreshTimerProgress);
|
|
|
|
return fetchCodes();
|
|
|
|
};
|
|
|
|
|
|
|
|
refreshTimerProgress = function() {
|
|
|
|
var secondsLeft;
|
|
|
|
secondsLeft = timeLeft();
|
|
|
|
return $('#timer').css('width', (secondsLeft / 30 * 100) + "%");
|
|
|
|
};
|
|
|
|
|
|
|
|
tick = function(delay, fkt) {
|
|
|
|
return window.setInterval(fkt, delay);
|
|
|
|
};
|
|
|
|
|
|
|
|
timeLeft = function() {
|
|
|
|
var now;
|
|
|
|
now = new Date().getTime();
|
|
|
|
return (currentTimeout - now) / 1000;
|
|
|
|
};
|
|
|
|
|
|
|
|
updateCodes = function(data) {
|
|
|
|
var i, len, ref, token;
|
|
|
|
currentTimeout = new Date(data.next_wrap).getTime();
|
|
|
|
if (clipboard) {
|
|
|
|
clipboard.destroy();
|
|
|
|
}
|
|
|
|
$('#keylist').empty();
|
|
|
|
ref = data.tokens;
|
|
|
|
for (i = 0, len = ref.length; i < len; i++) {
|
|
|
|
token = ref[i];
|
|
|
|
createOTPItem(token);
|
|
|
|
}
|
|
|
|
clipboard = new Clipboard('.otp-item', {
|
|
|
|
text: function(trigger) {
|
|
|
|
return $(trigger).find('.badge').text().replace(' ', '');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
filterChange();
|
|
|
|
return delay(timeLeft() * 1000, fetchCodes);
|
|
|
|
};
|
|
|
|
|
|
|
|
}).call(this);
|