Add multiplicators to certain inputs, closes #154

Allows for users to enter `10g` into a memory field and have it
converted to 10GB equivalent in MB.
This commit is contained in:
Dane Everitt 2016-11-26 19:56:19 -05:00
parent 90cd2b677e
commit e47bb6ef0f
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
5 changed files with 29 additions and 9 deletions

View file

@ -46,4 +46,24 @@ $(document).ready(function () {
centerModal($(this));
});
$(window).on('resize', centerModal);
// Idea code for multiplicators submitted by @Taronyuu on Github
// https://github.com/Pterodactyl/Panel/issues/154#issuecomment-257116078
$('input[data-multiplicator="true"]').on('change', function () {
var value = $(this).val();
if (!/^\d+$/.test(value)) {
var multiplicator = value.replace(/[0-9]/g, '').toLowerCase();
value = value.replace(/\D/g, '');
if (multiplicator === 't') {
value = value * (1024 * 1024);
}
if (multiplicator === 'g') {
value = value * 1024;
}
}
$(this).val(value);
});
});