mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-17 21:35:44 +03:00
turning on strict mode for various js files
This commit is contained in:
parent
01769559cc
commit
d9c315338d
12 changed files with 140 additions and 98 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
function configuration_backup() {
|
function configuration_backup() {
|
||||||
// request configuration data (one by one)
|
// request configuration data (one by one)
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
var firmware_version_accepted = 2.3;
|
var firmware_version_accepted = 2.3;
|
||||||
|
|
||||||
var CONFIG = {
|
var CONFIG = {
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
var tabs = {}; // filled by individual tab js file
|
var tabs = {}; // filled by individual tab js file
|
||||||
|
|
||||||
var GUI_control = function() {
|
var GUI_control = function() {
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
function localize() {
|
function localize() {
|
||||||
var localized = 0;
|
var localized = 0;
|
||||||
|
|
||||||
|
|
17
js/msp.js
17
js/msp.js
|
@ -1,3 +1,5 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
// MSP_codes needs to be re-integrated inside MSP object
|
// MSP_codes needs to be re-integrated inside MSP object
|
||||||
var MSP_codes = {
|
var MSP_codes = {
|
||||||
MSP_IDENT: 100,
|
MSP_IDENT: 100,
|
||||||
|
@ -55,7 +57,7 @@ var MSP_codes = {
|
||||||
|
|
||||||
var MSP = {
|
var MSP = {
|
||||||
state: 0,
|
state: 0,
|
||||||
message_status: 1,
|
message_direction: 1,
|
||||||
code: 0,
|
code: 0,
|
||||||
message_length_expected: 0,
|
message_length_expected: 0,
|
||||||
message_length_received: 0,
|
message_length_received: 0,
|
||||||
|
@ -66,7 +68,7 @@ var MSP = {
|
||||||
callbacks: [],
|
callbacks: [],
|
||||||
packet_error: 0,
|
packet_error: 0,
|
||||||
|
|
||||||
callbacks_cleanup: function() {
|
callbacks_cleanup: function () {
|
||||||
for (var i = 0; i < this.callbacks.length; i++) {
|
for (var i = 0; i < this.callbacks.length; i++) {
|
||||||
clearInterval(this.callbacks[i].timer);
|
clearInterval(this.callbacks[i].timer);
|
||||||
}
|
}
|
||||||
|
@ -74,7 +76,7 @@ var MSP = {
|
||||||
this.callbacks = [];
|
this.callbacks = [];
|
||||||
},
|
},
|
||||||
|
|
||||||
disconnect_cleanup: function() {
|
disconnect_cleanup: function () {
|
||||||
this.state = 0; // reset packet state for "clean" initial entry (this is only required if user hot-disconnects)
|
this.state = 0; // reset packet state for "clean" initial entry (this is only required if user hot-disconnects)
|
||||||
this.packet_error = 0; // reset CRC packet error counter for next session
|
this.packet_error = 0; // reset CRC packet error counter for next session
|
||||||
|
|
||||||
|
@ -82,7 +84,7 @@ var MSP = {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
MSP.read = function(readInfo) {
|
MSP.read = function (readInfo) {
|
||||||
var data = new Uint8Array(readInfo.data);
|
var data = new Uint8Array(readInfo.data);
|
||||||
|
|
||||||
for (var i = 0; i < data.length; i++) {
|
for (var i = 0; i < data.length; i++) {
|
||||||
|
@ -101,9 +103,9 @@ MSP.read = function(readInfo) {
|
||||||
break;
|
break;
|
||||||
case 2: // direction (should be >)
|
case 2: // direction (should be >)
|
||||||
if (data[i] == 62) { // >
|
if (data[i] == 62) { // >
|
||||||
message_status = 1;
|
this.message_direction = 1;
|
||||||
} else { // unknown
|
} else { // <
|
||||||
message_status = 0;
|
this.message_direction = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.state++;
|
this.state++;
|
||||||
|
@ -158,6 +160,7 @@ MSP.read = function(readInfo) {
|
||||||
};
|
};
|
||||||
|
|
||||||
MSP.process_data = function(code, message_buffer, message_length) {
|
MSP.process_data = function(code, message_buffer, message_length) {
|
||||||
|
'use strict';
|
||||||
var data = new DataView(message_buffer, 0); // DataView (allowing us to view arrayBuffer as struct/union)
|
var data = new DataView(message_buffer, 0); // DataView (allowing us to view arrayBuffer as struct/union)
|
||||||
|
|
||||||
switch (code) {
|
switch (code) {
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
function port_handler() {
|
function port_handler() {
|
||||||
this.main_timeout_reference;
|
this.main_timeout_reference;
|
||||||
this.initial_ports = false;
|
this.initial_ports = false;
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
var PortUsage = {
|
var PortUsage = {
|
||||||
previous_received: 0,
|
previous_received: 0,
|
||||||
previous_sent: 0,
|
previous_sent: 0,
|
||||||
|
|
|
@ -1,18 +1,20 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
function request_delay_balancer(refresh_period) {
|
function request_delay_balancer(refresh_period) {
|
||||||
this.balance_to = refresh_period;
|
this.balance_to = refresh_period;
|
||||||
this.request_t = 0;
|
this.request_t = 0;
|
||||||
this.finished_t = 0;
|
this.finished_t = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
request_delay_balancer.prototype.requested = function() {
|
request_delay_balancer.prototype.requested = function () {
|
||||||
this.request_t = millitime();
|
this.request_t = millitime();
|
||||||
};
|
};
|
||||||
|
|
||||||
request_delay_balancer.prototype.finished = function() {
|
request_delay_balancer.prototype.finished = function () {
|
||||||
this.finished_t = millitime();
|
this.finished_t = millitime();
|
||||||
};
|
};
|
||||||
|
|
||||||
request_delay_balancer.prototype.estimate = function() {
|
request_delay_balancer.prototype.estimate = function () {
|
||||||
var estimate = this.balance_to - (this.finished_t - this.request_t);
|
var estimate = this.balance_to - (this.finished_t - this.request_t);
|
||||||
return (estimate > 0) ? estimate : 0;
|
return (estimate > 0) ? estimate : 0;
|
||||||
};
|
};
|
92
js/serial.js
92
js/serial.js
|
@ -1,3 +1,5 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
var serial = {
|
var serial = {
|
||||||
connectionId: -1,
|
connectionId: -1,
|
||||||
bitrate: 0,
|
bitrate: 0,
|
||||||
|
@ -25,30 +27,30 @@ var serial = {
|
||||||
console.error(info);
|
console.error(info);
|
||||||
googleAnalytics.sendException('Serial: ' + info.error, false);
|
googleAnalytics.sendException('Serial: ' + info.error, false);
|
||||||
|
|
||||||
|
function get_status() {
|
||||||
|
self.getInfo(crunch_status);
|
||||||
|
}
|
||||||
|
|
||||||
|
function crunch_status(info) {
|
||||||
|
if (!info.paused) {
|
||||||
|
console.log('SERIAL: Connection recovered from last onReceiveError');
|
||||||
|
googleAnalytics.sendException('Serial: onReceiveError - recovered', false);
|
||||||
|
} else {
|
||||||
|
console.log('SERIAL: Connection did not recover from last onReceiveError, disconnecting');
|
||||||
|
GUI.log('Unrecoverable <span style="color: red">failure</span> of serial connection, disconnecting...');
|
||||||
|
googleAnalytics.sendException('Serial: onReceiveError - unrecoverable', false);
|
||||||
|
|
||||||
|
if (GUI.connected_to || GUI.connecting_to) {
|
||||||
|
$('a.connect').click();
|
||||||
|
} else {
|
||||||
|
self.disconnect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
switch (info.error) {
|
switch (info.error) {
|
||||||
case 'system_error': // we might be able to recover from this one
|
case 'system_error': // we might be able to recover from this one
|
||||||
chrome.serial.setPaused(self.connectionId, false, get_status);
|
chrome.serial.setPaused(self.connectionId, false, get_status);
|
||||||
|
|
||||||
function get_status() {
|
|
||||||
self.getInfo(crunch_status);
|
|
||||||
}
|
|
||||||
|
|
||||||
function crunch_status(info) {
|
|
||||||
if (!info.paused) {
|
|
||||||
console.log('SERIAL: Connection recovered from last onReceiveError');
|
|
||||||
googleAnalytics.sendException('Serial: onReceiveError - recovered', false);
|
|
||||||
} else {
|
|
||||||
console.log('SERIAL: Connection did not recover from last onReceiveError, disconnecting');
|
|
||||||
GUI.log('Unrecoverable <span style="color: red">failure</span> of serial connection, disconnecting...');
|
|
||||||
googleAnalytics.sendException('Serial: onReceiveError - unrecoverable', false);
|
|
||||||
|
|
||||||
if (GUI.connected_to || GUI.connecting_to) {
|
|
||||||
$('a.connect').click();
|
|
||||||
} else {
|
|
||||||
self.disconnect();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case 'timeout':
|
case 'timeout':
|
||||||
// TODO
|
// TODO
|
||||||
|
@ -125,33 +127,33 @@ var serial = {
|
||||||
var self = this;
|
var self = this;
|
||||||
self.output_buffer.push({'data': data, 'callback': callback});
|
self.output_buffer.push({'data': data, 'callback': callback});
|
||||||
|
|
||||||
|
function sending() {
|
||||||
|
// store inside separate variables in case array gets destroyed
|
||||||
|
var data = self.output_buffer[0].data;
|
||||||
|
var callback = self.output_buffer[0].callback;
|
||||||
|
|
||||||
|
chrome.serial.send(self.connectionId, data, function(sendInfo) {
|
||||||
|
callback(sendInfo);
|
||||||
|
self.output_buffer.shift();
|
||||||
|
|
||||||
|
self.bytes_sent += sendInfo.bytesSent;
|
||||||
|
|
||||||
|
if (self.output_buffer.length) {
|
||||||
|
// keep the buffer withing reasonable limits
|
||||||
|
while (self.output_buffer.length > 500) {
|
||||||
|
self.output_buffer.pop();
|
||||||
|
}
|
||||||
|
|
||||||
|
sending();
|
||||||
|
} else {
|
||||||
|
self.transmitting = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
if (!self.transmitting) {
|
if (!self.transmitting) {
|
||||||
self.transmitting = true;
|
self.transmitting = true;
|
||||||
|
|
||||||
function sending() {
|
|
||||||
// store inside separate variables in case array gets destroyed
|
|
||||||
var data = self.output_buffer[0].data;
|
|
||||||
var callback = self.output_buffer[0].callback;
|
|
||||||
|
|
||||||
chrome.serial.send(self.connectionId, data, function(sendInfo) {
|
|
||||||
callback(sendInfo);
|
|
||||||
self.output_buffer.shift();
|
|
||||||
|
|
||||||
self.bytes_sent += sendInfo.bytesSent;
|
|
||||||
|
|
||||||
if (self.output_buffer.length) {
|
|
||||||
// keep the buffer withing reasonable limits
|
|
||||||
while (self.output_buffer.length > 500) {
|
|
||||||
self.output_buffer.pop();
|
|
||||||
}
|
|
||||||
|
|
||||||
sending();
|
|
||||||
} else {
|
|
||||||
self.transmitting = false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
sending();
|
sending();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
var configuration_received = false;
|
var configuration_received = false;
|
||||||
|
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
|
@ -44,7 +46,7 @@ $(document).ready(function() {
|
||||||
$(this).text(chrome.i18n.getMessage('connect'));
|
$(this).text(chrome.i18n.getMessage('connect'));
|
||||||
$(this).removeClass('active');
|
$(this).removeClass('active');
|
||||||
|
|
||||||
sensor_status(sensors_detected = 0); // reset active sensor indicators
|
sensor_status(0); // reset active sensor indicators
|
||||||
$('#tabs > ul li').removeClass('active'); // de-select any selected tabs
|
$('#tabs > ul li').removeClass('active'); // de-select any selected tabs
|
||||||
|
|
||||||
// detach listeners and remove element data
|
// detach listeners and remove element data
|
||||||
|
|
12
js/usb.js
12
js/usb.js
|
@ -1,10 +1,12 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
var usbDevices = {
|
var usbDevices = {
|
||||||
STM32DFU: {'vendorId': 1155, 'productId': 57105}
|
STM32DFU: {'vendorId': 1155, 'productId': 57105}
|
||||||
};
|
};
|
||||||
var usbPermissions = {permissions: [{'usbDevices': [usbDevices.STM32DFU]}]};
|
var usbPermissions = {permissions: [{'usbDevices': [usbDevices.STM32DFU]}]};
|
||||||
|
|
||||||
function check_usb_permissions(callback) {
|
function check_usb_permissions(callback) {
|
||||||
chrome.permissions.contains(usbPermissions, function(result) {
|
chrome.permissions.contains(usbPermissions, function (result) {
|
||||||
if (result) {
|
if (result) {
|
||||||
GUI.optional_usb_permissions = true;
|
GUI.optional_usb_permissions = true;
|
||||||
} else {
|
} else {
|
||||||
|
@ -15,8 +17,8 @@ function check_usb_permissions(callback) {
|
||||||
$('div.optional_permissions').show();
|
$('div.optional_permissions').show();
|
||||||
|
|
||||||
// UI hooks
|
// UI hooks
|
||||||
document.getElementById("requestOptionalPermissions").addEventListener('click', function() {
|
document.getElementById("requestOptionalPermissions").addEventListener('click', function () {
|
||||||
chrome.permissions.request(usbPermissions, function(result) {
|
chrome.permissions.request(usbPermissions, function (result) {
|
||||||
if (result) {
|
if (result) {
|
||||||
GUI.log(chrome.i18n.getMessage('usb_permissions_granted'));
|
GUI.log(chrome.i18n.getMessage('usb_permissions_granted'));
|
||||||
$('div.optional_permissions').hide();
|
$('div.optional_permissions').hide();
|
||||||
|
@ -27,6 +29,8 @@ function check_usb_permissions(callback) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (callback) callback();
|
if (callback) {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
93
main.js
93
main.js
|
@ -1,6 +1,9 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
// Get access to the background window object
|
// Get access to the background window object
|
||||||
// This object is used to pass variables between active page and background page
|
// This object is used to pass variables between active page and background page
|
||||||
chrome.runtime.getBackgroundPage(function(result) {
|
var backgroundPage;
|
||||||
|
chrome.runtime.getBackgroundPage(function (result) {
|
||||||
backgroundPage = result;
|
backgroundPage = result;
|
||||||
backgroundPage.app_window = window;
|
backgroundPage.app_window = window;
|
||||||
});
|
});
|
||||||
|
@ -9,10 +12,11 @@ chrome.runtime.getBackgroundPage(function(result) {
|
||||||
var googleAnalyticsService = analytics.getService('ice_cream_app');
|
var googleAnalyticsService = analytics.getService('ice_cream_app');
|
||||||
var googleAnalytics = googleAnalyticsService.getTracker(atob("VUEtNTI4MjA5MjAtMQ=="));
|
var googleAnalytics = googleAnalyticsService.getTracker(atob("VUEtNTI4MjA5MjAtMQ=="));
|
||||||
var googleAnalyticsConfig = false;
|
var googleAnalyticsConfig = false;
|
||||||
googleAnalyticsService.getConfig().addCallback(function(config) {
|
googleAnalyticsService.getConfig().addCallback(function (config) {
|
||||||
googleAnalyticsConfig = config;
|
googleAnalyticsConfig = config;
|
||||||
});
|
});
|
||||||
$(document).ready(function() {
|
|
||||||
|
$(document).ready(function () {
|
||||||
googleAnalytics.sendAppView('Application Started');
|
googleAnalytics.sendAppView('Application Started');
|
||||||
|
|
||||||
// translate to user-selected language
|
// translate to user-selected language
|
||||||
|
@ -20,7 +24,7 @@ $(document).ready(function() {
|
||||||
|
|
||||||
// alternative - window.navigator.appVersion.match(/Chrome\/([0-9.]*)/)[1];
|
// alternative - window.navigator.appVersion.match(/Chrome\/([0-9.]*)/)[1];
|
||||||
GUI.log('Running - OS: <strong>' + GUI.operating_system + '</strong>, ' +
|
GUI.log('Running - OS: <strong>' + GUI.operating_system + '</strong>, ' +
|
||||||
'Chrome: <strong>' + window.navigator.appVersion.replace(/.*Chrome\/([0-9.]*).*/,"$1") + '</strong>, ' +
|
'Chrome: <strong>' + window.navigator.appVersion.replace(/.*Chrome\/([0-9.]*).*/, "$1") + '</strong>, ' +
|
||||||
'Configurator: <strong>' + chrome.runtime.getManifest().version + '</strong>');
|
'Configurator: <strong>' + chrome.runtime.getManifest().version + '</strong>');
|
||||||
|
|
||||||
// notification messages for various operating systems
|
// notification messages for various operating systems
|
||||||
|
@ -40,11 +44,10 @@ $(document).ready(function() {
|
||||||
|
|
||||||
// Tabs
|
// Tabs
|
||||||
var ui_tabs = $('#tabs > ul');
|
var ui_tabs = $('#tabs > ul');
|
||||||
$('a', ui_tabs).click(function() {
|
$('a', ui_tabs).click(function () {
|
||||||
if ($(this).parent().hasClass('active') == false && !GUI.tab_switch_in_progress) { // only initialize when the tab isn't already active
|
if ($(this).parent().hasClass('active') == false && !GUI.tab_switch_in_progress) { // only initialize when the tab isn't already active
|
||||||
var self = this;
|
var self = this,
|
||||||
var index = $(self).parent().index();
|
tab = $(self).parent().prop('class');
|
||||||
var tab = $(self).parent().prop('class');
|
|
||||||
|
|
||||||
// if there is no active connection, return
|
// if there is no active connection, return
|
||||||
if (!configuration_received && tab != 'tab_logging') {
|
if (!configuration_received && tab != 'tab_logging') {
|
||||||
|
@ -54,7 +57,7 @@ $(document).ready(function() {
|
||||||
|
|
||||||
GUI.tab_switch_in_progress = true;
|
GUI.tab_switch_in_progress = true;
|
||||||
|
|
||||||
GUI.tab_switch_cleanup(function() {
|
GUI.tab_switch_cleanup(function () {
|
||||||
// disable previously active tab highlight
|
// disable previously active tab highlight
|
||||||
$('li', ui_tabs).removeClass('active');
|
$('li', ui_tabs).removeClass('active');
|
||||||
|
|
||||||
|
@ -68,6 +71,10 @@ $(document).ready(function() {
|
||||||
// display loading screen
|
// display loading screen
|
||||||
$('#cache .data-loading').clone().appendTo(content);
|
$('#cache .data-loading').clone().appendTo(content);
|
||||||
|
|
||||||
|
function content_ready() {
|
||||||
|
GUI.tab_switch_in_progress = false;
|
||||||
|
}
|
||||||
|
|
||||||
switch (tab) {
|
switch (tab) {
|
||||||
case 'tab_initial_setup':
|
case 'tab_initial_setup':
|
||||||
tabs.initial_setup.initialize(content_ready);
|
tabs.initial_setup.initialize(content_ready);
|
||||||
|
@ -100,10 +107,6 @@ $(document).ready(function() {
|
||||||
tabs.logging.initialize(content_ready);
|
tabs.logging.initialize(content_ready);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
function content_ready() {
|
|
||||||
GUI.tab_switch_in_progress = false;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -111,27 +114,27 @@ $(document).ready(function() {
|
||||||
tabs.default.initialize();
|
tabs.default.initialize();
|
||||||
|
|
||||||
// options
|
// options
|
||||||
$('a#options').click(function() {
|
$('a#options').click(function () {
|
||||||
var el = $(this);
|
var el = $(this);
|
||||||
|
|
||||||
if (!el.hasClass('active')) {
|
if (!el.hasClass('active')) {
|
||||||
el.addClass('active');
|
el.addClass('active');
|
||||||
el.after('<div id="options-window"></div>');
|
el.after('<div id="options-window"></div>');
|
||||||
|
|
||||||
$('div#options-window').load('./tabs/options.html', function() {
|
$('div#options-window').load('./tabs/options.html', function () {
|
||||||
googleAnalytics.sendAppView('Options');
|
googleAnalytics.sendAppView('Options');
|
||||||
|
|
||||||
// translate to user-selected language
|
// translate to user-selected language
|
||||||
localize();
|
localize();
|
||||||
|
|
||||||
// if notifications are enabled, or wasn't set, check the notifications checkbox
|
// if notifications are enabled, or wasn't set, check the notifications checkbox
|
||||||
chrome.storage.local.get('update_notify', function(result) {
|
chrome.storage.local.get('update_notify', function (result) {
|
||||||
if (typeof result.update_notify === 'undefined' || result.update_notify) {
|
if (result.update_notify === 'undefined' || result.update_notify) {
|
||||||
$('div.notifications input').prop('checked', true);
|
$('div.notifications input').prop('checked', true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$('div.notifications input').change(function() {
|
$('div.notifications input').change(function () {
|
||||||
var check = $(this).is(':checked');
|
var check = $(this).is(':checked');
|
||||||
|
|
||||||
chrome.storage.local.set({'update_notify': check});
|
chrome.storage.local.set({'update_notify': check});
|
||||||
|
@ -142,7 +145,7 @@ $(document).ready(function() {
|
||||||
$('div.statistics input').prop('checked', true);
|
$('div.statistics input').prop('checked', true);
|
||||||
}
|
}
|
||||||
|
|
||||||
$('div.statistics input').change(function() {
|
$('div.statistics input').change(function () {
|
||||||
var result = $(this).is(':checked');
|
var result = $(this).is(':checked');
|
||||||
googleAnalyticsConfig.setTrackingPermitted(result);
|
googleAnalyticsConfig.setTrackingPermitted(result);
|
||||||
});
|
});
|
||||||
|
@ -151,7 +154,7 @@ $(document).ready(function() {
|
||||||
if (e.type == 'click' && !$.contains($('div#options-window')[0], e.target) || e.type == 'keyup' && e.keyCode == 27) {
|
if (e.type == 'click' && !$.contains($('div#options-window')[0], e.target) || e.type == 'keyup' && e.keyCode == 27) {
|
||||||
$(document).unbind('click keyup', close_and_cleanup);
|
$(document).unbind('click keyup', close_and_cleanup);
|
||||||
|
|
||||||
$('div#options-window').slideUp(function() {
|
$('div#options-window').slideUp(function () {
|
||||||
el.removeClass('active');
|
el.removeClass('active');
|
||||||
$(this).empty().remove();
|
$(this).empty().remove();
|
||||||
});
|
});
|
||||||
|
@ -166,16 +169,16 @@ $(document).ready(function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
// listen to all input change events and adjust the value within limits if necessary
|
// listen to all input change events and adjust the value within limits if necessary
|
||||||
$("#content").on('focus', 'input[type="number"]', function() {
|
$("#content").on('focus', 'input[type="number"]', function () {
|
||||||
var element = $(this);
|
var element = $(this),
|
||||||
var val = element.val();
|
val = element.val();
|
||||||
|
|
||||||
if (!isNaN(val)) {
|
if (!isNaN(val)) {
|
||||||
element.data('previousValue', parseFloat(val));
|
element.data('previousValue', parseFloat(val));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#content").on('keydown', 'input[type="number"]', function(e) {
|
$("#content").on('keydown', 'input[type="number"]', function (e) {
|
||||||
// whitelist all that we need for numeric control
|
// whitelist all that we need for numeric control
|
||||||
var whitelist = [
|
var whitelist = [
|
||||||
96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, // numpad and standard number keypad
|
96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, // numpad and standard number keypad
|
||||||
|
@ -185,24 +188,31 @@ $(document).ready(function() {
|
||||||
37, 38, 39, 40, 13 // arrows and enter
|
37, 38, 39, 40, 13 // arrows and enter
|
||||||
];
|
];
|
||||||
|
|
||||||
if (whitelist.indexOf(e.keyCode) == -1) e.preventDefault();
|
if (whitelist.indexOf(e.keyCode) == -1) {
|
||||||
|
e.preventDefault();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#content").on('change', 'input[type="number"]', function() {
|
$("#content").on('change', 'input[type="number"]', function () {
|
||||||
var element = $(this);
|
var element = $(this),
|
||||||
var min = parseFloat(element.prop('min'));
|
min = parseFloat(element.prop('min')),
|
||||||
var max = parseFloat(element.prop('max'));
|
max = parseFloat(element.prop('max')),
|
||||||
var step = parseFloat(element.prop('step'));
|
step = parseFloat(element.prop('step')),
|
||||||
var val = parseFloat(element.val());
|
val = parseFloat(element.val()),
|
||||||
|
decimal_places;
|
||||||
|
|
||||||
// only adjust minimal end if bound is set
|
// only adjust minimal end if bound is set
|
||||||
if (element.prop('min')) {
|
if (element.prop('min')) {
|
||||||
if (val < min) element.val(min);
|
if (val < min) {
|
||||||
|
element.val(min);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// only adjust maximal end if bound is set
|
// only adjust maximal end if bound is set
|
||||||
if (element.prop('max')) {
|
if (element.prop('max')) {
|
||||||
if (val > max) element.val(max);
|
if (val > max) {
|
||||||
|
element.val(max);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if entered value is illegal use previous value instead
|
// if entered value is illegal use previous value instead
|
||||||
|
@ -219,7 +229,7 @@ $(document).ready(function() {
|
||||||
|
|
||||||
// if step is set and is float and value is int, convert to float, keep decimal places in float according to step *experimental*
|
// if step is set and is float and value is int, convert to float, keep decimal places in float according to step *experimental*
|
||||||
if (!isNaN(step) && step % 1 !== 0) {
|
if (!isNaN(step) && step % 1 !== 0) {
|
||||||
var decimal_places = String(step).split('.')[1].length;
|
decimal_places = String(step).split('.')[1].length;
|
||||||
|
|
||||||
if (val % 1 === 0) {
|
if (val % 1 === 0) {
|
||||||
element.val(val.toFixed(decimal_places));
|
element.val(val.toFixed(decimal_places));
|
||||||
|
@ -243,10 +253,17 @@ function millitime() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function bytesToSize(bytes) {
|
function bytesToSize(bytes) {
|
||||||
if (bytes < 1024) return bytes + ' Bytes';
|
if (bytes < 1024) {
|
||||||
else if (bytes < 1048576) return(bytes / 1024).toFixed(3) + ' KB';
|
bytes = bytes + ' Bytes';
|
||||||
else if (bytes < 1073741824) return(bytes / 1048576).toFixed(3) + ' MB';
|
} else if (bytes < 1048576) {
|
||||||
else return (bytes / 1073741824).toFixed(3) + ' GB';
|
bytes = (bytes / 1024).toFixed(3) + ' KB';
|
||||||
|
} else if (bytes < 1073741824) {
|
||||||
|
bytes = (bytes / 1048576).toFixed(3) + ' MB';
|
||||||
|
} else {
|
||||||
|
bytes = (bytes / 1073741824).toFixed(3) + ' GB';
|
||||||
|
}
|
||||||
|
|
||||||
|
return bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue