Clean code.

This commit is contained in:
Lars Jung 2015-04-14 01:38:49 +02:00
parent 6137120b2e
commit cdca37e59d
19 changed files with 53 additions and 47 deletions

31
.jshintrc Normal file
View File

@ -0,0 +1,31 @@
{
"bitwise": true,
"curly": true,
"eqeqeq": true,
"forin": true,
"freeze": true,
"futurehostile": true,
"latedef": true,
"maxdepth": 3,
"noarg": true,
"nocomma": true,
"nonbsp": true,
"nonew": true,
"plusplus": true,
"strict": false,
"supernew": true,
"trailing": true,
"undef": true,
"unused": true,
"browser": true,
"globals": {
"jQuery": false,
"marked": false,
"Modernizr": false,
"modulejs": false,
"Prism": false,
"_": false
}
}

View File

@ -70,28 +70,11 @@ module.exports = function (suite) {
suite.target('lint', [], 'lint all JavaScript files with JSHint').task(function () {
var jshint = {
// Enforcing Options
bitwise: true,
curly: true,
eqeqeq: true,
forin: true,
latedef: true,
newcap: true,
noempty: true,
plusplus: true,
trailing: true,
undef: true,
// Environments
browser: true
};
var globals = {
modulejs: true
};
var fs = require('fs');
var jshint = JSON.parse(fs.readFileSync('.jshintrc', 'utf8'));
$(src + '/_h5ai/client/js: **/*.js, ! lib/**')
.jshint(jshint, globals);
.jshint(jshint, jshint.globals);
});

View File

@ -23,7 +23,7 @@ modulejs.define('core/event', ['_'], function (_) {
}
}
function pub(topic, data) {
function pub(topic) {
var args = slice.call(arguments, 1);

View File

@ -81,9 +81,9 @@ modulejs.define('ext/contextmenu', ['_', '$', 'core/settings', 'core/resource'],
var overlayWidth = $overlay.outerWidth(true);
var overlayHeight = $overlay.outerHeight(true);
var panelOffset = $panel.offset();
var panelLeft = panelOffset.left;
var panelTop = panelOffset.top;
// var panelOffset = $panel.offset();
// var panelLeft = panelOffset.left;
// var panelTop = panelOffset.top;
var panelWidth = $panel.outerWidth(true);
var panelHeight = $panel.outerHeight(true);

View File

@ -1,4 +1,4 @@
modulejs.define('ext/custom', ['_', '$', 'marked', 'core/settings', 'core/server', 'core/event', 'core/resource'], function (_, $, marked, allsettings, server, event, resource) {
modulejs.define('ext/custom', ['_', '$', 'marked', 'core/settings', 'core/server', 'core/event'], function (_, $, marked, allsettings, server, event) {
var settings = _.extend({
enabled: false

View File

@ -25,7 +25,7 @@ modulejs.define('ext/download', ['_', '$', 'core/settings', 'core/resource', 'co
}
}
function onClick(event) {
function onClick() {
var type = settings.type;
var name = settings.packageName;

View File

@ -27,7 +27,6 @@ modulejs.define('ext/info', ['_', '$', 'modernizr', 'core/settings', 'core/resou
'<img src="' + resource.image('info-toggle') + '" alt="view-info"/>' +
'</div>' +
'</div>';
var sepTemplate = '<span class="sep"/>';
var storekey = 'ext/info';
var $img;
var $label;
@ -108,7 +107,7 @@ modulejs.define('ext/info', ['_', '$', 'modernizr', 'core/settings', 'core/resou
update(item);
}
function onMouseleave(item) {
function onMouseleave() {
update(currentFolder);
}

View File

@ -103,7 +103,7 @@ modulejs.define('ext/preview-audio', ['_', '$', 'core/settings', 'core/event', '
_.each(item.content, initItem);
}
function onLocationRefreshed(item, added, removed) {
function onLocationRefreshed(item, added) {
_.each(added, initItem);
}

View File

@ -5,7 +5,6 @@ modulejs.define('ext/preview-img', ['_', '$', 'core/settings', 'core/event', 'co
size: null,
types: []
}, allsettings['preview-img']);
var templateLoading = '<img id="pv-img-image" class="loading"/>';
var spinnerThreshold = 200;
var spinnerTimeoutId;
var currentItems;
@ -139,7 +138,7 @@ modulejs.define('ext/preview-img', ['_', '$', 'core/settings', 'core/event', 'co
_.each(item.content, initItem);
}
function onLocationRefreshed(item, added, removed) {
function onLocationRefreshed(item, added) {
_.each(added, initItem);
}

View File

@ -19,7 +19,7 @@ modulejs.define('ext/preview-txt', ['_', '$', 'marked', 'prism', 'core/settings'
callback(content);
// setTimeout(function () { callback(content); }, 1000); // for testing
})
.fail(function (jqXHR, textStatus, errorThrown) {
.fail(function (jqXHR, textStatus) {
callback('[ajax error] ' + textStatus);
});
@ -119,7 +119,7 @@ modulejs.define('ext/preview-txt', ['_', '$', 'marked', 'prism', 'core/settings'
_.each(item.content, initItem);
}
function onLocationRefreshed(item, added, removed) {
function onLocationRefreshed(item, added) {
_.each(added, initItem);
}

View File

@ -104,7 +104,7 @@ modulejs.define('ext/preview-vid', ['_', '$', 'core/settings', 'core/event', 'ex
_.each(item.content, initItem);
}
function onLocationRefreshed(item, added, removed) {
function onLocationRefreshed(item, added) {
_.each(added, initItem);
}

View File

@ -22,8 +22,6 @@ modulejs.define('ext/preview', ['_', '$', 'core/settings', 'core/resource', 'cor
'</div>' +
'</div>';
var storekey = 'ext/preview';
var currentEntries = [];
var currentIdx = 0;
var isFullscreen = store.get(storekey) || false;
var userAliveTimeoutId = null;
var onIndexChange = null;

View File

@ -207,7 +207,7 @@ modulejs.define('ext/select', ['_', '$', 'core/settings', 'core/resource', 'core
ev.stopImmediatePropagation();
ev.preventDefault();
})
.on('click', function (ev) {
.on('click', function () {
$('#items .item').removeClass('selected');
publish();

View File

@ -110,7 +110,7 @@ modulejs.define('ext/sort', ['_', '$', 'core/settings', 'core/resource', 'core/e
}
}
function onContentChanged(item) {
function onContentChanged() {
var order = store.get(storekey);
var column = order && order.column || settings.column;

View File

@ -1,4 +1,4 @@
modulejs.define('ext/thumbnails', ['_', 'core/settings', 'core/event', 'core/server', 'core/resource'], function (_, allsettings, event, server, resource) {
modulejs.define('ext/thumbnails', ['_', 'core/settings', 'core/event', 'core/server'], function (_, allsettings, event, server) {
var settings = _.extend({
enabled: false,
@ -71,7 +71,7 @@ modulejs.define('ext/thumbnails', ['_', 'core/settings', 'core/event', 'core/ser
}, settings.delay);
}
function onLocationRefreshed(item, added, removed) {
function onLocationRefreshed(item, added) {
_.each(added, checkItem);
}

View File

@ -109,8 +109,6 @@ modulejs.define('ext/tree', ['_', '$', 'core/settings', 'core/resource', 'core/s
function createOnIndicatorClick() {
var $tree = $('#tree');
function slide(item, $indicator, $content, down) {
item.isContentVisible = down;

View File

@ -1,4 +1,4 @@
modulejs.define('view/ensure', ['$', 'config', 'core/event'], function ($, config, event) {
modulejs.define('view/ensure', ['$', 'config'], function ($, config) {
var templateTopbar =
'<div id="topbar">' +

View File

@ -16,7 +16,6 @@ modulejs.define('view/items', ['_', '$', 'core/settings', 'core/resource', 'core
'<span class="size"/>' +
'</a>' +
'</li>';
var hintTemplate = '<span class="hint"/>';
var contentTemplate =
'<div id="content">' +
'<div id="view">' +
@ -149,7 +148,7 @@ modulejs.define('view/items', ['_', '$', 'core/settings', 'core/resource', 'core
var $content = $(contentTemplate);
var $view = $content.find('#view');
var $items = $view.find('#items');
var $emtpy = $view.find('.empty').hide();
$view.find('.empty').hide();
format.setDefaultMetric(settings.binaryPrefix);

View File

@ -9,12 +9,11 @@
(function () {
'use strict';
/*global jQuery, marked, Modernizr, Prism, _ */
modulejs.define('$', function () { return jQuery; });
modulejs.define('_', function () { return _; });
modulejs.define('marked', function () { return marked; });
modulejs.define('modernizr', function () { return Modernizr; });
modulejs.define('prism', function () { return Prism; });
modulejs.define('_', function () { return _; });
// @include "inc/**/*.js"