Skip to content

Firefly III: a personal finances manager

Add JSHint stuff. [skip ci]

James Cole8daccbfbb420
diff --git a/.jshintrc b/.jshintrc
new file mode 100644
index 0000000000..e6395a276a
--- /dev/null
+++ b/.jshintrc
@@ -0,0 +1,22 @@
+{
+ "undef": true,
+ "unused": false,
+ "strict": true,
+ "browser": true,
+ "jquery": true,
+ "devel": true,
+ "globals": [
+ "language",
+ "token",
+ "currencyCode",
+ "$",
+ "token",
+ "accountID",
+ "billID",
+ "currentMonthName",
+ "previousMonthName",
+ "nextMonthName",
+ "everything",
+ "moment"
+ ]
+}
\ No newline at end of file
diff --git a/public/js/accounts.js b/public/js/accounts.js
index 5435c2d6b9..ae240b8500 100644
--- a/public/js/accounts.js
+++ b/public/js/accounts.js
@@ -1,11 +1,23 @@
-$(function () {
+/* global $ */
+
+
+// Return a helper with preserved width of cells
+var fixHelper = function (e, ui) {
+ "use strict";
+ ui.children().each(function () {
+ $(this).width($(this).width());
+ });
+ return ui;
+};
+$(function () {
+ "use strict";
if (typeof(googleLineChart) === "function" && typeof accountID !== 'undefined') {
googleLineChart('chart/account/' + accountID, 'overview-chart');
}
// sortable!
- if (typeof $(".sortable-table tbody").sortable != "undefined") {
+ if (typeof $(".sortable-table tbody").sortable !== "undefined") {
$(".sortable-table tbody").sortable(
{
helper: fixHelper,
@@ -19,23 +31,14 @@ $(function () {
});
-// Return a helper with preserved width of cells
-var fixHelper = function (e, ui) {
- ui.children().each(function () {
- $(this).width($(this).width());
- });
- return ui;
-};
-
function sortStop(event, ui) {
+ "use strict";
var current = $(ui.item);
var thisDate = current.data('date');
var originalBG = current.css('backgroundColor');
- if (current.prev().data('date') != thisDate && current.next().data('date') != thisDate) {
- //console.log('False!');
- //console.log('[' + current.prev().data('date') + '] [' + thisDate + '] [' + current.next().data('date') + ']');
+ if (current.prev().data('date') !== thisDate && current.next().data('date') !== thisDate) {
// animate something with color:
current.animate({
backgroundColor: "#d9534f"
@@ -59,10 +62,6 @@ function sortStop(event, ui) {
// do extra animation when done?
$.post('/transaction/reorder', {items: submit, date: thisDate, _token: token});
- console.log(submit);
-
- //console.log('TRUE!');
- //console.log('[' + current.prev().data('date') + '] [' + thisDate + '] [' + current.next().data('date') + ']');
current.animate({
backgroundColor: "#5cb85c"
diff --git a/public/js/bills.js b/public/js/bills.js
index 5f45f2a90b..58dd7ae943 100644
--- a/public/js/bills.js
+++ b/public/js/bills.js
@@ -1,7 +1,9 @@
-$(document).ready(function () {
+/* global googleComboChart, billID */
- if (typeof(googleComboChart) === 'function' && typeof(billID) !== 'undefined') {
- googleComboChart('chart/bill/' + billID, 'bill-overview');
- }
- }
+$(document).ready(function () {
+ "use strict";
+ if (typeof(googleComboChart) === 'function' && typeof(billID) !== 'undefined') {
+ googleComboChart('chart/bill/' + billID, 'bill-overview');
+ }
+ }
);
\ No newline at end of file
diff --git a/public/js/budgets.js b/public/js/budgets.js
index 1ab91d8b23..0c8f20f43f 100644
--- a/public/js/budgets.js
+++ b/public/js/budgets.js
@@ -1,4 +1,7 @@
+/* globals $, token, budgetID, repetitionID */
+
$(function () {
+ "use strict";
updateRanges();
//$('input[type="range"]').change(updateSingleRange);
$('input[type="range"]').on('input', updateSingleRange);
@@ -18,6 +21,7 @@ $(function () {
function updateSingleRange(e) {
+ "use strict";
// get some values:
var input = $(e.target);
var id = input.data('id');
@@ -63,6 +67,7 @@ function updateSingleRange(e) {
}
function updateTotal() {
+ "use strict";
var sum = 0;
$('input[type="range"]').each(function (i, v) {
// get some values:
@@ -94,7 +99,8 @@ function updateTotal() {
}
-function updateIncome(e) {
+function updateIncome() {
+ "use strict";
$('#monthlyBudgetModal').empty().load('budgets/income', function () {
$('#monthlyBudgetModal').modal('show');
});
@@ -103,6 +109,7 @@ function updateIncome(e) {
}
function updateRanges() {
+ "use strict";
/**
* Update all ranges.
*/
@@ -133,8 +140,9 @@ function updateRanges() {
* Update total sum:
*/
var totalAmount = parseInt($('#totalAmount').data('value'));
+ var pct;
if (sum <= totalAmount) {
- var pct = sum / totalAmount * 100;
+ pct = sum / totalAmount * 100;
$('#progress-bar-default').css('width', pct + '%');
$('#progress-bar-warning').css('width', '0');
$('#progress-bar-danger').css('width', '0');
@@ -142,7 +150,7 @@ function updateRanges() {
} else {
// we gaan er X overheen,
- var pct = totalAmount / sum * 100;
+ pct = totalAmount / sum * 100;
var danger = 100 - pct;
var err = 100 - danger;
$('#progress-bar-default').css('width', 0);
diff --git a/public/js/categories.js b/public/js/categories.js
index d4fb5c692f..073b8e2355 100644
--- a/public/js/categories.js
+++ b/public/js/categories.js
@@ -1,5 +1,6 @@
+/* globals $, categoryID */
$(function () {
-
+ "use strict";
if (typeof categoryID !== 'undefined') {
googleColumnChart('chart/category/' + categoryID + '/all', 'all');
googleColumnChart('chart/category/' + categoryID + '/month', 'month');
diff --git a/public/js/firefly.js b/public/js/firefly.js
index a8c075a761..c01a3269c7 100644
--- a/public/js/firefly.js
+++ b/public/js/firefly.js
@@ -1,8 +1,9 @@
+/* globals start, end, dateRangeURL, everything, firstDate, moment, currentMonthName, $, previousMonthName, nextMonthName, applyLabel, cancelLabel, toLabel, customRangeLabel, fromLabel, */
$(function () {
-
+ "use strict";
$('.currencySelect').click(currencySelect);
- ranges = {};
+ var ranges = {};
ranges[currentMonthName] = [moment().startOf('month'), moment().endOf('month')];
ranges[previousMonthName] = [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')];
ranges[nextMonthName] = [moment().add(1, 'month').startOf('month'), moment().add(1, 'month').endOf('month')];
@@ -10,11 +11,6 @@ $(function () {
$('#daterange').daterangepicker(
{
- //View::share('currentMonthName', $current);
- //View::share('previousMonthName', $prev);
- //View::share('nextMonthName', $next);
-
-
ranges: ranges,
opens: 'left',
locale: {
@@ -54,6 +50,7 @@ $(function () {
});
function currencySelect(e) {
+ "use strict";
var target = $(e.target);
var symbol = target.data('symbol');
var code = target.data('code');
diff --git a/public/js/gcharts.js b/public/js/gcharts.js
index 065c4975ad..c51700d9b9 100644
--- a/public/js/gcharts.js
+++ b/public/js/gcharts.js
@@ -1,13 +1,16 @@
+/* globals currencyCode, language, defaultPieChartOptions, defaultLineChartOptions, defaultColumnChartOptions, defaultBarChartOptions, defaultStackedColumnChartOptions, defaultComboChartOptions */
+/* exported googleLineChart, googleBarChart, googleColumnChart, googleStackedColumnChart, googleComboChart, googlePieChart */
var google = google || {};
google.load('visualization', '1.1', {'packages': ['corechart', 'bar', 'line'],'language': language });
function googleChart(chartType, URL, container, options) {
+ "use strict";
if ($('#' + container).length === 1) {
$.getJSON(URL).success(function (data) {
/*
Get the data from the JSON
*/
- gdata = new google.visualization.DataTable(data);
+ var gdata = new google.visualization.DataTable(data);
/*
Format as money
@@ -67,25 +70,32 @@ function googleChart(chartType, URL, container, options) {
function googleLineChart(URL, container, options) {
+ "use strict";
return googleChart('line', URL, container, options);
}
+
function googleBarChart(URL, container, options) {
+ "use strict";
return googleChart('bar', URL, container, options);
}
function googleColumnChart(URL, container, options) {
+ "use strict";
return googleChart('column', URL, container, options);
}
function googleStackedColumnChart(URL, container, options) {
+ "use strict";
return googleChart('stackedColumn', URL, container, options);
}
function googleComboChart(URL, container, options) {
+ "use strict";
return googleChart('combo', URL, container, options);
}
function googlePieChart(URL, container, options) {
+ "use strict";
return googleChart('pie', URL, container, options);
}
diff --git a/public/js/gcharts.options.js b/public/js/gcharts.options.js
index b6cd11b95b..996c2849b8 100644
--- a/public/js/gcharts.options.js
+++ b/public/js/gcharts.options.js
@@ -1,3 +1,5 @@
+/* exported defaultLineChartOptions, defaultBarChartOptions, defaultComboChartOptions, defaultColumnChartOptions, defaultStackedColumnChartOptions, defaultPieChartOptions */
+
var defaultLineChartOptions = {
curveType: 'function',
legend: {
@@ -69,7 +71,7 @@ var defaultBarChartOptions = {
legend: {
position: 'none'
- },
+ }
};
var defaultComboChartOptions = {
@@ -127,7 +129,7 @@ var defaultColumnChartOptions = {
},
legend: {
position: 'none'
- },
+ }
};
var defaultStackedColumnChartOptions = {
diff --git a/public/js/help.js b/public/js/help.js
index cfe25448b4..d4762b43e8 100644
--- a/public/js/help.js
+++ b/public/js/help.js
@@ -1,13 +1,16 @@
$(function () {
+ "use strict";
$('#help').click(showHelp);
$(function () {
- $('[data-toggle="tooltip"]').tooltip()
- })
+
+ $('[data-toggle="tooltip"]').tooltip();
+ });
});
function showHelp(e) {
- target = $(e.target);
- route = target.data('route');
+ "use strict";
+ var target = $(e.target);
+ var route = target.data('route');
//
$('#helpBody').html('<i class="fa fa-refresh fa-spin"></i>');
$('#helpTitle').html('Please hold...');
diff --git a/public/js/index.js b/public/js/index.js
index ec5579ee23..d1291a77a4 100644
--- a/public/js/index.js
+++ b/public/js/index.js
@@ -1,3 +1,4 @@
+/* globals google */
google.setOnLoadCallback(drawChart);
@@ -12,13 +13,20 @@ function drawChart() {
}
function getBoxAmounts() {
+ "use strict";
var boxes = ['in', 'out', 'bills-unpaid', 'bills-paid'];
- for (x in boxes) {
+ for (var x in boxes) {
var box = boxes[x];
- $.getJSON('/json/box/' + box).success(function (data) {
- $('#box-' + data.box).html(data.amount);
- }).fail(function () {
- console.log('Failed to get box!')
- });
+ $.getJSON('/json/box/' + box).success(putData).fail(failData);
}
}
+
+function putData(data) {
+ "use strict";
+ $('#box-' + data.box).html(data.amount);
+}
+
+function failData() {
+ "use strict";
+ console.log('Failed to get box!');
+}
\ No newline at end of file
diff --git a/public/js/piggy-banks.js b/public/js/piggy-banks.js
index cefb43d0f6..d34bf49760 100644
--- a/public/js/piggy-banks.js
+++ b/public/js/piggy-banks.js
@@ -1,3 +1,14 @@
+// Return a helper with preserved width of cells
+var fixHelper = function(e, tr) {
+ var $originals = tr.children();
+ var $helper = tr.clone();
+ $helper.children().each(function (index) {
+ // Set helper cell sizes to match the original sizes
+ $(this).width($originals.eq(index).width());
+ });
+ return $helper;
+};
+
$(function () {
$('.addMoney').on('click', addMoney);
$('.removeMoney').on('click', removeMoney);
@@ -31,16 +42,7 @@ $(function () {
);
});
-// Return a helper with preserved width of cells
-var fixHelper = function(e, tr) {
- var $originals = tr.children();
- var $helper = tr.clone();
- $helper.children().each(function (index) {
- // Set helper cell sizes to match the original sizes
- $(this).width($originals.eq(index).width());
- });
- return $helper;
-}
+
function addMoney(e) {
var pigID = parseInt($(e.target).data('id'));
diff --git a/public/js/reports.js b/public/js/reports.js
index 0517d4951d..dfcbee44a1 100644
--- a/public/js/reports.js
+++ b/public/js/reports.js
@@ -1,4 +1,4 @@
-if (typeof(google) != 'undefined') {
+if (typeof(google) !== 'undefined') {
google.setOnLoadCallback(drawChart);
}
diff --git a/public/js/transactions.js b/public/js/transactions.js
index 20e7b6eaee..446bde7043 100644
--- a/public/js/transactions.js
+++ b/public/js/transactions.js
@@ -28,7 +28,7 @@ $(document).ready(function () {
});
}
- if ($('input[name="description"]').length > 0 && what != undefined) {
+ if ($('input[name="description"]').length > 0 && what !== undefined) {
$.getJSON('json/transaction-journals/' + what).success(function (data) {
$('input[name="description"]').typeahead({source: data});
});