Add JSHint stuff. [skip ci]

This commit is contained in:
James Cole 2015-05-24 18:22:41 +02:00
parent 285b77dcb7
commit 8daccbfbb4
13 changed files with 112 additions and 58 deletions

22
.jshintrc Normal file
View File

@ -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"
]
}

View File

@ -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"

View File

@ -1,5 +1,7 @@
$(document).ready(function () {
/* global googleComboChart, billID */
$(document).ready(function () {
"use strict";
if (typeof(googleComboChart) === 'function' && typeof(billID) !== 'undefined') {
googleComboChart('chart/bill/' + billID, 'bill-overview');
}

View File

@ -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);

View File

@ -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');

View File

@ -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');

View File

@ -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);
}

View File

@ -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 = {

View File

@ -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...');

View File

@ -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) {
$.getJSON('/json/box/' + box).success(putData).fail(failData);
}
}
function putData(data) {
"use strict";
$('#box-' + data.box).html(data.amount);
}).fail(function () {
console.log('Failed to get box!')
});
}
function failData() {
"use strict";
console.log('Failed to get box!');
}

View File

@ -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'));

View File

@ -1,4 +1,4 @@
if (typeof(google) != 'undefined') {
if (typeof(google) !== 'undefined') {
google.setOnLoadCallback(drawChart);
}

View File

@ -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});
});