From 39ea94daa867f36a28d4f9cf5a3f203ed8401219 Mon Sep 17 00:00:00 2001 From: Lars Jung Date: Wed, 18 Nov 2015 23:16:58 +0100 Subject: [PATCH] Fix a lot eslint errors. --- .eslintrc | 5 +- CHANGELOG.md | 11 +- README.md | 12 +- ghu.js | 12 +- package.json | 1 - src/.eslintrc | 43 + src/_h5ai/public/js/lib/boot.js | 10 +- src/_h5ai/public/js/lib/core/event.js | 9 - src/_h5ai/public/js/lib/core/format.js | 64 +- src/_h5ai/public/js/lib/core/langs.js | 1 - src/_h5ai/public/js/lib/core/location.js | 100 +-- src/_h5ai/public/js/lib/core/modernizr.js | 3 - src/_h5ai/public/js/lib/core/resource.js | 3 - src/_h5ai/public/js/lib/core/server.js | 6 - src/_h5ai/public/js/lib/core/settings.js | 1 - src/_h5ai/public/js/lib/core/store.js | 7 +- src/_h5ai/public/js/lib/core/types.js | 6 - src/_h5ai/public/js/lib/core/util.js | 12 +- src/_h5ai/public/js/lib/ext/autorefresh.js | 11 +- src/_h5ai/public/js/lib/ext/contextmenu.js | 16 +- src/_h5ai/public/js/lib/ext/crumb.js | 12 +- src/_h5ai/public/js/lib/ext/custom.js | 8 +- src/_h5ai/public/js/lib/ext/download.js | 27 +- src/_h5ai/public/js/lib/ext/filter.js | 15 +- .../public/js/lib/ext/google-analytics.js | 46 +- src/_h5ai/public/js/lib/ext/info.js | 20 +- src/_h5ai/public/js/lib/ext/l10n.js | 94 +- src/_h5ai/public/js/lib/ext/peer5.js | 10 +- .../public/js/lib/ext/piwik-analytics.js | 14 +- src/_h5ai/public/js/lib/ext/preview-aud.js | 75 +- src/_h5ai/public/js/lib/ext/preview-img.js | 32 +- src/_h5ai/public/js/lib/ext/preview-txt.js | 54 +- src/_h5ai/public/js/lib/ext/preview-vid.js | 75 +- src/_h5ai/public/js/lib/ext/preview.js | 70 +- src/_h5ai/public/js/lib/ext/search.js | 16 +- src/_h5ai/public/js/lib/ext/select.js | 62 +- src/_h5ai/public/js/lib/ext/sort.js | 40 +- src/_h5ai/public/js/lib/ext/thumbnails.js | 29 +- src/_h5ai/public/js/lib/ext/title.js | 7 +- src/_h5ai/public/js/lib/ext/tree.js | 49 +- src/_h5ai/public/js/lib/main/index.js | 2 - src/_h5ai/public/js/lib/main/info.js | 14 +- src/_h5ai/public/js/lib/model/item.js | 71 +- src/_h5ai/public/js/lib/view/content.js | 1 - src/_h5ai/public/js/lib/view/mainrow.js | 1 - src/_h5ai/public/js/lib/view/notification.js | 2 - src/_h5ai/public/js/lib/view/root.js | 1 - src/_h5ai/public/js/lib/view/sidebar.js | 2 - src/_h5ai/public/js/lib/view/topbar.js | 1 - src/_h5ai/public/js/lib/view/view.js | 143 ++- src/_h5ai/public/js/lib/view/viewmode.js | 12 +- src/_h5ai/public/js/scripts.js | 2 +- test/.eslintrc | 51 ++ test/index.html.jade | 14 +- test/scripts.js | 13 +- test/tests/integration/view.js | 187 ++-- test/tests/premisses.js | 138 ++- test/tests/unit/boot.js | 201 ++--- test/tests/unit/config.js | 80 +- test/tests/unit/core/event.js | 195 ++--- test/tests/unit/core/format.js | 373 ++++---- test/tests/unit/core/langs.js | 91 +- test/tests/unit/core/location.js | 539 ++++++------ test/tests/unit/core/modernizr.js | 125 ++- test/tests/unit/core/resource.js | 169 ++-- test/tests/unit/core/server.js | 334 ++++--- test/tests/unit/core/settings.js | 153 ++-- test/tests/unit/core/store.js | 203 ++--- test/tests/unit/core/types.js | 161 ++-- test/tests/unit/core/util.js | 407 ++++----- test/tests/unit/ext/title.js | 183 ++-- test/tests/unit/libs.js | 42 +- test/tests/unit/main/index.js | 177 ++-- test/tests/unit/main/info.js | 309 +++---- test/tests/unit/model/item.js | 708 +++++++-------- test/tests/unit/modulejs.js | 72 +- test/tests/unit/view/content.js | 130 ++- test/tests/unit/view/mainrow.js | 130 ++- test/tests/unit/view/notification.js | 189 ++-- test/tests/unit/view/root.js | 152 ++-- test/tests/unit/view/sidebar.js | 225 +++-- test/tests/unit/view/topbar.js | 240 +++-- test/tests/unit/view/view.js | 818 ++++++++---------- test/tests/unit/view/viewmode.js | 366 ++++---- test/util/assert.js | 21 +- test/util/mocha.js | 179 ++-- test/util/modulejs.js | 28 +- test/util/pin.js | 59 +- 88 files changed, 3872 insertions(+), 4930 deletions(-) create mode 100644 src/.eslintrc create mode 100644 test/.eslintrc diff --git a/.eslintrc b/.eslintrc index 29933dee..b9abad3a 100644 --- a/.eslintrc +++ b/.eslintrc @@ -7,9 +7,6 @@ es6: true node: true - globals: - modulejs: false - ecmaFeatures: arrowFunctions: true binaryLiterals: true @@ -68,7 +65,7 @@ max-nested-callbacks: [1, 3] max-params: [1, 5] ### max-statements: [1, 80] ### - new-cap: 1 + new-cap: 0 new-parens: 2 newline-after-var: 0 no-alert: 2 diff --git a/CHANGELOG.md b/CHANGELOG.md index e70f8c27..c7598e39 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,8 @@ * fixes preview bottom bar for small screen widths * lots of code cleanup and refactorings * changes API -* updates build process +* updates build process, now uses [ghu](https://larsjung.de/ghu/) +* switches from jshint and jscs to [eslint](http://eslint.org/) * updates `lodash` to 3.8.0 (adds debounce and trim) * updates h5bp styles to 5.1.0 * updates `normalize.css` to 3.0.3 @@ -40,7 +41,7 @@ * improves drag-select * improves image preview * prevents listing `_h5ai` folder and subfolders -* updates build process, now uses [mkr](http://larsjung.de/mkr/) and [fQuery](http://larsjung.de/fquery/) +* updates build process, now uses [mkr](https://larsjung.de/mkr/) and [fQuery](https://larsjung.de/fquery/) * updates `jQuery` to 2.1.3 * updates `jQuery.qrcode` to 0.11.0 * updates `Lo-Dash` to 3.6.0 @@ -222,9 +223,9 @@ * changes language code `gr` to `el` * adds localization for filter placeholder * adds `hu` translation by [Rodolffo](https://github.com/Rodolffo) -* updates to [jQuery.qrcode](http://larsjung.de/qrcode/) 0.2 -* updates to [jQuery.scrollpanel](http://larsjung.de/scrollpanel/) 0.1 -* updates to [modulejs](http://larsjung.de/modulejs/) 0.2 +* updates to [jQuery.qrcode](https://larsjung.de/qrcode/) 0.2 +* updates to [jQuery.scrollpanel](https://larsjung.de/scrollpanel/) 0.1 +* updates to [modulejs](https://larsjung.de/modulejs/) 0.2 * updates to [Moment.js](http://momentjs.com) 1.7.0 * updates to [Underscore.js](http://underscorejs.org) 1.3.3 diff --git a/README.md b/README.md index 3cfec0af..dc3ff2ab 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ To build the frontend test suite run `npm run build-test`. This will output a The MIT License (MIT) -Copyright (c) 2015 Lars Jung (http://larsjung.de) +Copyright (c) 2015 Lars Jung (https://larsjung.de) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -67,14 +67,14 @@ THE SOFTWARE. too. Exceptions are the [Material Design icons][material-design-icons] (CC BY 4.0). -[web]: http://larsjung.de/h5ai/ +[web]: https://larsjung.de/h5ai/ [github]: https://github.com/lrsjng/h5ai [github-issues]: https://github.com/lrsjng/h5ai/issues -[release]: http://release.larsjung.de/h5ai/ -[develop]: http://release.larsjung.de/h5ai/develop/ -[git]: http://git-scm.com +[release]: https://release.larsjung.de/h5ai/ +[develop]: https://release.larsjung.de/h5ai/develop/ +[git]: https://git-scm.com [node]: https://nodejs.org -[mkr]: http://larsjung.de/mkr/ +[mkr]: https://larsjung.de/mkr/ [material-design-icons]: https://github.com/google/material-design-icons [license-img]: https://img.shields.io/badge/license-MIT-a0a060.svg?style=flat-square diff --git a/ghu.js b/ghu.js index cd81ed94..9d3a7268 100644 --- a/ghu.js +++ b/ghu.js @@ -2,12 +2,13 @@ import {resolve, join} from 'path'; import dateformat from 'dateformat'; import ghu from 'ghu'; import { - autoprefixer, babel, cssmin, ife, includeit, jade, jszip, + autoprefixer, cssmin, ife, includeit, jade, jszip, less, mapfn, newerThan, read, remove, run, uglify, watch, wrap, write } from 'ghu'; const ROOT = resolve(__dirname); const SRC = join(ROOT, 'src'); +const TEST = join(ROOT, 'test'); const BUILD = join(ROOT, 'build'); const mapper = mapfn.p(SRC, BUILD).s('.less', '.css').s('.jade', ''); @@ -54,7 +55,6 @@ ghu.task('build:scripts', runtime => { return read(`${SRC}/_h5ai/public/js/*.js`) .then(newerThan(mapper, `${SRC}/_h5ai/public/js/**`)) .then(includeit()) - // .then(babel({compact: false})) .then(ife(() => runtime.args.production, uglify())) .then(wrap(runtime.commentJs)) .then(write(mapper, {overwrite: true})); @@ -100,19 +100,19 @@ ghu.task('build:copy', runtime => { ghu.task('build:tests', ['build:scripts', 'build:styles'], 'build the test suite', runtime => { return Promise.all([ - read(`${ROOT}/test/scripts.js`) + read(`${TEST}/scripts.js`) .then(newerThan(`${BUILD}/test/scripts.js`)) .then(includeit()) .then(write(`${BUILD}/test/scripts.js`, {overwrite: true})), - read(`${ROOT}/test/styles.less`) + read(`${TEST}/styles.less`) .then(newerThan(`${BUILD}/test/styles.css`)) .then(includeit()) .then(less()) .then(autoprefixer()) .then(write(`${BUILD}/test/styles.css`, {overwrite: true})), - read(`${ROOT}/test/index.html.jade`) + read(`${TEST}/index.html.jade`) .then(newerThan(`${BUILD}/test/index.html`)) .then(jade({pkg: runtime.pkg})) .then(write(`${BUILD}/test/index.html`, {overwrite: true})), @@ -146,7 +146,7 @@ ghu.task('deploy', ['build'], 'deploy to a specified path with :dest=/some/path' }); ghu.task('watch', runtime => { - return watch([SRC], () => ghu.run(runtime.sequence.filter(x => x !== 'watch'), runtime.args, true)); + return watch([SRC, TEST], () => ghu.run(runtime.sequence.filter(x => x !== 'watch'), runtime.args, true)); }); ghu.task('release', ['force-production', 'clean', 'build'], 'create a zipball', runtime => { diff --git a/package.json b/package.json index 5006a17f..e0849d51 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,6 @@ { "name": "h5ai", "version": "0.27.0", - "develop": true, "description": "A modern HTTP web server index.", "homepage": "https://larsjung.de/h5ai/", "bugs": "https://github.com/lrsjng/h5ai/issues", diff --git a/src/.eslintrc b/src/.eslintrc new file mode 100644 index 00000000..f6c585b8 --- /dev/null +++ b/src/.eslintrc @@ -0,0 +1,43 @@ +--- + env: + es6: false + node: false + browser: true + mocha: false + + globals: + modulejs: false + + ecmaFeatures: + arrowFunctions: false + binaryLiterals: false + blockBindings: false + classes: false + defaultParams: false + destructuring: false + forOf: false + generators: false + globalReturn: false + jsx: false + modules: false + objectLiteralComputedProperties: false + objectLiteralDuplicateProperties: false + objectLiteralShorthandMethods: false + objectLiteralShorthandProperties: false + octalLiterals: false + regexUFlag: false + regexYFlag: false + spread: false + superInFunctions: false + templateStrings: false + unicodeCodePointEscapes: false + + rules: + consistent-this: 0 + func-names: 0 + max-params: [1, 10] + no-invalid-this: 0 + no-var: 0 + object-shorthand: 0 + prefer-arrow-callback: 0 + prefer-reflect: 0 diff --git a/src/_h5ai/public/js/lib/boot.js b/src/_h5ai/public/js/lib/boot.js index d82a3cf6..5666bd1b 100644 --- a/src/_h5ai/public/js/lib/boot.js +++ b/src/_h5ai/public/js/lib/boot.js @@ -1,11 +1,11 @@ modulejs.define('boot', ['$', 'core/server'], function ($, server) { var module = $('script[data-module]').data('module'); var data = { - action: 'get', - setup: true, - options: true, - types: true - }; + action: 'get', + setup: true, + options: true, + types: true + }; if (module === 'index') { data.theme = true; diff --git a/src/_h5ai/public/js/lib/core/event.js b/src/_h5ai/public/js/lib/core/event.js index 1165242e..046e8da1 100644 --- a/src/_h5ai/public/js/lib/core/event.js +++ b/src/_h5ai/public/js/lib/core/event.js @@ -1,13 +1,9 @@ modulejs.define('core/event', ['_'], function (_) { - var slice = Array.prototype.slice; var subscriptions = {}; - function sub(topic, callback) { - if (_.isString(topic) && _.isFunction(callback)) { - if (!subscriptions[topic]) { subscriptions[topic] = []; } @@ -16,21 +12,16 @@ modulejs.define('core/event', ['_'], function (_) { } function unsub(topic, callback) { - if (_.isString(topic) && _.isFunction(callback) && subscriptions[topic]) { - subscriptions[topic] = _.without(subscriptions[topic], callback); } } function pub(topic) { - var args = slice.call(arguments, 1); if (_.isString(topic) && subscriptions[topic]) { - _.each(subscriptions[topic], function (callback) { - callback.apply(topic, args); }); } diff --git a/src/_h5ai/public/js/lib/core/format.js b/src/_h5ai/public/js/lib/core/format.js index 2e237734..4290ae93 100644 --- a/src/_h5ai/public/js/lib/core/format.js +++ b/src/_h5ai/public/js/lib/core/format.js @@ -1,41 +1,38 @@ modulejs.define('core/format', ['_'], function (_) { - var decimalMetric = { - t: 1000.0, - k: 1000.0, - u: ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'] - }; + t: 1000.0, + k: 1000.0, + u: ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'] + }; var binaryMetric = { - t: 1024.0, - k: 1024.0, - u: ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'] - }; + t: 1024.0, + k: 1024.0, + u: ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'] + }; var defaultMetric = decimalMetric; var datePatterns = [ - [/YYYY/, 'Y', 4], - [/YY/, 'Y', 2], - [/Y/, 'Y', 0], - [/MM/, 'M', 2], - [/M/, 'M', 0], - [/DD/, 'D', 2], - [/D/, 'D', 0], - [/HH/, 'H', 2], - [/H/, 'H', 0], - [/mm/, 'm', 2], - [/m/, 'm', 0], - [/ss/, 's', 2], - [/s/, 's', 0] - ]; + [/YYYY/, 'Y', 4], + [/YY/, 'Y', 2], + [/Y/, 'Y', 0], + [/MM/, 'M', 2], + [/M/, 'M', 0], + [/DD/, 'D', 2], + [/D/, 'D', 0], + [/HH/, 'H', 2], + [/H/, 'H', 0], + [/mm/, 'm', 2], + [/m/, 'm', 0], + [/ss/, 's', 2], + [/s/, 's', 0] + ]; var defaultDateFormat = 'YYYY-MM-DD HH:mm'; function setDefaultMetric(useBinaryMetric) { - defaultMetric = useBinaryMetric ? binaryMetric : decimalMetric; } function formatSize(size, metric) { - metric = metric || defaultMetric; if (!_.isNumber(size) || size < 0) { @@ -53,12 +50,10 @@ modulejs.define('core/format', ['_'], function (_) { } function setDefaultDateFormat(dateFormat) { - defaultDateFormat = dateFormat; } function formatNumber(number, padding) { - var str = String(number); if (padding) { str = ('000' + str).substr(-padding); @@ -67,7 +62,6 @@ modulejs.define('core/format', ['_'], function (_) { } function formatDate(millis, format) { - if (!millis || !_.isNumber(millis)) { return ''; } @@ -76,13 +70,13 @@ modulejs.define('core/format', ['_'], function (_) { var date = new Date(millis); var d = { - Y: date.getFullYear(), - M: date.getMonth() + 1, - D: date.getDate(), - H: date.getHours(), - m: date.getMinutes(), - s: date.getSeconds() - }; + Y: date.getFullYear(), + M: date.getMonth() + 1, + D: date.getDate(), + H: date.getHours(), + m: date.getMinutes(), + s: date.getSeconds() + }; datePatterns.forEach(function (pattern) { format = format.replace(pattern[0], formatNumber(d[pattern[1]], pattern[2])); diff --git a/src/_h5ai/public/js/lib/core/langs.js b/src/_h5ai/public/js/lib/core/langs.js index 468ea99b..84193cf1 100644 --- a/src/_h5ai/public/js/lib/core/langs.js +++ b/src/_h5ai/public/js/lib/core/langs.js @@ -1,4 +1,3 @@ modulejs.define('core/langs', ['_', 'config'], function (_, config) { - return _.extend({}, config.langs); }); diff --git a/src/_h5ai/public/js/lib/core/location.js b/src/_h5ai/public/js/lib/core/location.js index 88ef1fc3..1a9d7452 100644 --- a/src/_h5ai/public/js/lib/core/location.js +++ b/src/_h5ai/public/js/lib/core/location.js @@ -1,50 +1,45 @@ modulejs.define('core/location', ['_', 'core/event', 'core/modernizr', 'core/settings', 'view/notification'], function (_, event, modernizr, allsettings, notification) { - var settings = _.extend({ - fastBrowsing: true, - unmanagedInNewWindow: true - }, allsettings.view); + fastBrowsing: true, + unmanagedInNewWindow: true + }, allsettings.view); var doc = document; var history = settings.fastBrowsing && modernizr.history ? window.history : null; var reUriToPathname = /^.*:\/\/[^\/]*|[^\/]*$/g; var absHref = null; var reForceEncoding = [ - [/\/+/g, '/'], - [/ /g, '%20'], - [/!/g, '%21'], - [/#/g, '%23'], - [/\$/g, '%24'], - [/&/g, '%26'], - [/'/g, '%27'], - [/\(/g, '%28'], - [/\)/g, '%29'], - [/\*/g, '%2A'], - [/\+/g, '%2B'], - [/\,/g, '%2C'], - [/:/g, '%3A'], - [/;/g, '%3B'], - [/=/g, '%3D'], - [/\?/g, '%3F'], - [/@/g, '%40'], - [/\[/g, '%5B'], - [/\]/g, '%5D'] - ]; + [/\/+/g, '/'], + [/ /g, '%20'], + [/!/g, '%21'], + [/#/g, '%23'], + [/\$/g, '%24'], + [/&/g, '%26'], + [/'/g, '%27'], + [/\(/g, '%28'], + [/\)/g, '%29'], + [/\*/g, '%2A'], + [/\+/g, '%2B'], + [/\,/g, '%2C'], + [/:/g, '%3A'], + [/;/g, '%3B'], + [/\=/g, '%3D'], + [/\?/g, '%3F'], + [/@/g, '%40'], + [/\[/g, '%5B'], + [/\]/g, '%5D'] + ]; function forceEncoding(href) { - - return reForceEncoding.reduce(function (href, data) { - - return href.replace(data[0], data[1]); + return reForceEncoding.reduce(function (nuHref, data) { + return nuHref.replace(data[0], data[1]); }, href); } function uriToPathname(uri) { - return uri.replace(reUriToPathname, ''); } var hrefsAreDecoded = (function () { - var testpathname = '/a b'; var a = doc.createElement('a'); @@ -53,7 +48,6 @@ modulejs.define('core/location', ['_', 'core/event', 'core/modernizr', 'core/set }()); function encodedHref(href) { - var a = doc.createElement('a'); var location; @@ -68,39 +62,31 @@ modulejs.define('core/location', ['_', 'core/event', 'core/modernizr', 'core/set } function getDomain() { - return doc.domain; } function getAbsHref() { - return absHref; } function getItem() { - return modulejs.require('model/item').get(absHref); } function load(callback) { - modulejs.require('core/server').request({action: 'get', items: {href: absHref, what: 1}}, function (json) { - var Item = modulejs.require('model/item'); var item = Item.get(absHref); if (json) { - var found = {}; _.each(json.items, function (jsonItem) { - var e = Item.get(jsonItem); found[e.absHref] = true; }); _.each(item.content, function (e) { - if (!found[e.absHref]) { Item.remove(e.absHref); } @@ -112,8 +98,22 @@ modulejs.define('core/location', ['_', 'core/event', 'core/modernizr', 'core/set }); } - function setLocation(newAbsHref, keepBrowserUrl) { + function refresh() { + var item = getItem(); + var oldItems = _.values(item.content); + event.pub('location.beforeRefresh'); + + load(function () { + var newItems = _.values(item.content); + var added = _.difference(newItems, oldItems); + var removed = _.difference(oldItems, newItems); + + event.pub('location.refreshed', item, added, removed); + }); + } + + function setLocation(newAbsHref, keepBrowserUrl) { event.pub('location.beforeChange'); newAbsHref = encodedHref(newAbsHref); @@ -144,30 +144,11 @@ modulejs.define('core/location', ['_', 'core/event', 'core/modernizr', 'core/set } } - function refresh() { - - var item = getItem(); - var oldItems = _.values(item.content); - - event.pub('location.beforeRefresh'); - - load(function () { - - var newItems = _.values(item.content); - var added = _.difference(newItems, oldItems); - var removed = _.difference(oldItems, newItems); - - event.pub('location.refreshed', item, added, removed); - }); - } - function setLink($el, item) { - $el.attr('href', item.absHref); if (history && item.isFolder() && item.isManaged) { $el.on('click', function () { - setLocation(item.absHref); return false; }); @@ -179,7 +160,6 @@ modulejs.define('core/location', ['_', 'core/event', 'core/modernizr', 'core/set } function onPopState(ev) { - if (ev.state && ev.state.absHref) { setLocation(ev.state.absHref, true); } diff --git a/src/_h5ai/public/js/lib/core/modernizr.js b/src/_h5ai/public/js/lib/core/modernizr.js index 9ac6f5a0..c68e3c21 100644 --- a/src/_h5ai/public/js/lib/core/modernizr.js +++ b/src/_h5ai/public/js/lib/core/modernizr.js @@ -1,7 +1,5 @@ modulejs.define('core/modernizr', function () { - var hasCanvas = (function () { - var elem = document.createElement('canvas'); return Boolean(elem.getContext && elem.getContext('2d')); }()); @@ -9,7 +7,6 @@ modulejs.define('core/modernizr', function () { var hasHistory = Boolean(window.history && history.pushState); var hasLocalStorage = (function () { - var key = '#test#'; try { localStorage.setItem(key, key); diff --git a/src/_h5ai/public/js/lib/core/resource.js b/src/_h5ai/public/js/lib/core/resource.js index 16a856da..92053bdf 100644 --- a/src/_h5ai/public/js/lib/core/resource.js +++ b/src/_h5ai/public/js/lib/core/resource.js @@ -1,5 +1,4 @@ modulejs.define('core/resource', ['_', 'config', 'core/settings'], function (_, config, settings) { - var imagesHref = settings.publicHref + 'images/'; var uiHref = imagesHref + 'ui/'; var themesHref = imagesHref + 'themes/'; @@ -8,12 +7,10 @@ modulejs.define('core/resource', ['_', 'config', 'core/settings'], function (_, function image(id) { - return uiHref + id + '.svg'; } function icon(id) { - var baseId = (id || '').split('-')[0]; var href = config.theme[id] || config.theme[baseId]; diff --git a/src/_h5ai/public/js/lib/core/server.js b/src/_h5ai/public/js/lib/core/server.js index 1de94806..59269469 100644 --- a/src/_h5ai/public/js/lib/core/server.js +++ b/src/_h5ai/public/js/lib/core/server.js @@ -1,7 +1,5 @@ modulejs.define('core/server', ['_', '$'], function (_, $) { - function request(data, callback) { - $.ajax({ url: '?', data: data, @@ -9,21 +7,17 @@ modulejs.define('core/server', ['_', '$'], function (_, $) { dataType: 'json' }) .done(function (json) { - callback(json); }) .fail(function () { - callback(); }); } function formRequest(data) { - var $form = $('
'); _.each(data, function (val, key) { - $('') .attr('name', key) .attr('value', val) diff --git a/src/_h5ai/public/js/lib/core/settings.js b/src/_h5ai/public/js/lib/core/settings.js index 2b5aa0f7..f459c472 100644 --- a/src/_h5ai/public/js/lib/core/settings.js +++ b/src/_h5ai/public/js/lib/core/settings.js @@ -1,5 +1,4 @@ modulejs.define('core/settings', ['_', 'config'], function (_, config) { - return _.extend({}, config.options, { publicHref: config.setup.PUBLIC_HREF, rootHref: config.setup.ROOT_HREF diff --git a/src/_h5ai/public/js/lib/core/store.js b/src/_h5ai/public/js/lib/core/store.js index 90f1f835..e9990869 100644 --- a/src/_h5ai/public/js/lib/core/store.js +++ b/src/_h5ai/public/js/lib/core/store.js @@ -1,31 +1,26 @@ modulejs.define('core/store', ['core/modernizr'], function (modernizr) { - var store = modernizr.localstorage ? window.localStorage : {}; var storekey = '_h5ai'; function load() { - try { return JSON.parse(store[storekey]); - } catch (e) {} + } catch (e) {/* skip */} return {}; } function save(obj) { - store[storekey] = JSON.stringify(obj); } function put(key, value) { - var obj = load(); obj[key] = value; save(obj); } function get(key) { - return load()[key]; } diff --git a/src/_h5ai/public/js/lib/core/types.js b/src/_h5ai/public/js/lib/core/types.js index 6f63eb86..f66f2d68 100644 --- a/src/_h5ai/public/js/lib/core/types.js +++ b/src/_h5ai/public/js/lib/core/types.js @@ -1,26 +1,21 @@ modulejs.define('core/types', ['_', 'config'], function (_, config) { - var reEndsWithSlash = /\/$/; var regexps = {}; function escapeRegExp(sequence) { - return sequence.replace(/[\-\[\]\/\{\}\(\)\+\?\.\\\^\$]/g, '\\$&'); // return sequence.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&'); } function parse(types) { - _.each(types, function (patterns, type) { - var pattern = '^(' + _.map(patterns, function (p) { return '(' + escapeRegExp(p).replace(/\*/g, '.*') + ')'; }).join('|') + ')$'; regexps[type] = new RegExp(pattern, 'i'); }); } function getType(sequence) { - if (reEndsWithSlash.test(sequence)) { return 'folder'; } @@ -30,7 +25,6 @@ modulejs.define('core/types', ['_', 'config'], function (_, config) { var result; _.each(regexps, function (regexp, type) { - if (regexps[type].test(name)) { result = type; return false; diff --git a/src/_h5ai/public/js/lib/core/util.js b/src/_h5ai/public/js/lib/core/util.js index 6ab4f6a5..386aa9c5 100644 --- a/src/_h5ai/public/js/lib/core/util.js +++ b/src/_h5ai/public/js/lib/core/util.js @@ -1,8 +1,5 @@ modulejs.define('core/util', ['_'], function (_) { - - function regularCmpFn(val1, val2) { - if (val1 < val2) { return -1; } @@ -17,7 +14,6 @@ modulejs.define('core/util', ['_'], function (_) { // // Modified to make it work with h5ai function naturalCmpFn(val1, val2) { - var re = /(^-?[0-9]+(\.?[0-9]*)[df]?e?[0-9]?$|^0x[0-9a-f]+$|[0-9]+)/gi; var sre = /(^[ ]*|[ ]*$)/g; var dre = /(^([\w ]+,?[\w ]+)?[\w ]+,?[\w ]+\d+:\d+(:\d+)?[\w ]?|^\d{1,4}[\/\-]\d{1,4}[\/\-]\d{1,4}|^\w+, \w+ \d+, \d{4})/; @@ -30,7 +26,7 @@ modulejs.define('core/util', ['_'], function (_) { var xN = x.replace(re, '\0$1\0').replace(/\0$/, '').replace(/^\0/, '').split('\0'); var yN = y.replace(re, '\0$1\0').replace(/\0$/, '').replace(/^\0/, '').split('\0'); // numeric, hex or date detection - var xD = parseInt(x.match(hre), 10) || (xN.length !== 1 && x.match(dre) && Date.parse(x)); + var xD = parseInt(x.match(hre), 10) || xN.length !== 1 && x.match(dre) && Date.parse(x); var yD = parseInt(y.match(hre), 10) || xD && y.match(dre) && Date.parse(y) || null; var oFxNcL; var oFyNcL; @@ -49,7 +45,7 @@ modulejs.define('core/util', ['_'], function (_) { oFyNcL = !(yN[cLoc] || '').match(ore) && parseFloat(yN[cLoc]) || yN[cLoc] || 0; // handle numeric vs string comparison - number < string - (Kyle Adams) if (isNaN(oFxNcL) !== isNaN(oFyNcL)) { - return (isNaN(oFxNcL)) ? 1 : -1; + return isNaN(oFxNcL) ? 1 : -1; } else if (typeof oFxNcL !== typeof oFyNcL) { // rely on string comparison if different types - i.e. '02' < 2 != '02' < '2' oFxNcL += ''; @@ -66,12 +62,10 @@ modulejs.define('core/util', ['_'], function (_) { } function escapePattern(sequence) { - return sequence.replace(/[\-\[\]{}()*+?.,\\$\^|#\s]/g, '\\$&'); } function parsePattern(sequence, advanced) { - if (!advanced) { return escapePattern(sequence); } @@ -81,9 +75,7 @@ modulejs.define('core/util', ['_'], function (_) { } sequence = _.map(_.trim(sequence).split(/\s+/), function (part) { - return _.map(part.split(''), function (character) { - return escapePattern(character); }).join('.*?'); }).join('|'); diff --git a/src/_h5ai/public/js/lib/ext/autorefresh.js b/src/_h5ai/public/js/lib/ext/autorefresh.js index 34fcd61b..14da8242 100644 --- a/src/_h5ai/public/js/lib/ext/autorefresh.js +++ b/src/_h5ai/public/js/lib/ext/autorefresh.js @@ -1,30 +1,25 @@ modulejs.define('ext/autorefresh', ['_', '$', 'core/event', 'core/location', 'core/settings'], function (_, $, event, location, allsettings) { - var settings = _.extend({ - enabled: false, - interval: 5000 - }, allsettings.autorefresh); + enabled: false, + interval: 5000 + }, allsettings.autorefresh); var timeoutId = null; function heartbeat() { - location.refresh(); } function before() { - clearTimeout(timeoutId); } function after() { - clearTimeout(timeoutId); timeoutId = setTimeout(heartbeat, settings.interval); } function init() { - if (!settings.enabled) { return; } diff --git a/src/_h5ai/public/js/lib/ext/contextmenu.js b/src/_h5ai/public/js/lib/ext/contextmenu.js index 7161c94b..c2b9bb9a 100644 --- a/src/_h5ai/public/js/lib/ext/contextmenu.js +++ b/src/_h5ai/public/js/lib/ext/contextmenu.js @@ -1,8 +1,7 @@ modulejs.define('ext/contextmenu', ['_', '$', 'core/resource', 'core/settings'], function (_, $, resource, allsettings) { - var settings = _.extend({ - enabled: false - }, allsettings.contextmenu); + enabled: false + }, allsettings.contextmenu); var templateOverlay = '
'; var templatePanel = '
    '; var templateSep = '
  • '; @@ -11,12 +10,10 @@ modulejs.define('ext/contextmenu', ['_', '$', 'core/resource', 'core/settings'], function createOverlay(callback) { - var $overlay = $(templateOverlay); $overlay .on('click contextmenu', function (ev) { - ev.stopPropagation(); ev.preventDefault(); @@ -32,20 +29,16 @@ modulejs.define('ext/contextmenu', ['_', '$', 'core/resource', 'core/settings'], } function createPanel(menu) { - var $panel = $(templatePanel); var $ul = $panel.find('ul'); var $li; _.each(menu, function (entry) { - if (entry.type === '-') { $(templateSep).appendTo($ul); - } else if (entry.type === 'l') { $(templateLabel).appendTo($ul) .find('.cm-text').text(entry.text); - } else if (entry.type === 'e') { $li = $(templateEntry).appendTo($ul); $li.data('cm-id', entry.id); @@ -62,7 +55,6 @@ modulejs.define('ext/contextmenu', ['_', '$', 'core/resource', 'core/settings'], } function positionPanel($overlay, $panel, x, y) { - var margin = 4; $panel.css({ @@ -123,7 +115,6 @@ modulejs.define('ext/contextmenu', ['_', '$', 'core/resource', 'core/settings'], } function showMenuAt(x, y, menu, callback) { - var $overlay = createOverlay(callback); var $panel = createPanel(menu); $overlay.append($panel).appendTo('body'); @@ -131,20 +122,17 @@ modulejs.define('ext/contextmenu', ['_', '$', 'core/resource', 'core/settings'], } function init() { - // settings.enabled = true; if (!settings.enabled) { return; } $(document).on('contextmenu', function (ev) { - ev.stopPropagation(); ev.preventDefault(); $(ev.target).trigger($.Event('h5ai-contextmenu', { originalEvent: ev, showMenu: function (menu, callback) { - showMenuAt(ev.pageX, ev.pageY, menu, callback); } })); diff --git a/src/_h5ai/public/js/lib/ext/crumb.js b/src/_h5ai/public/js/lib/ext/crumb.js index 51ec4b99..06c812e6 100644 --- a/src/_h5ai/public/js/lib/ext/crumb.js +++ b/src/_h5ai/public/js/lib/ext/crumb.js @@ -1,8 +1,7 @@ modulejs.define('ext/crumb', ['_', '$', 'core/event', 'core/location', 'core/resource', 'core/settings', 'view/topbar'], function (_, $, event, location, resource, allsettings, topbar) { - var settings = _.extend({ - enabled: false - }, allsettings.crumb); + enabled: false + }, allsettings.crumb); var crumbTemplate = '' + '>' + @@ -13,7 +12,6 @@ modulejs.define('ext/crumb', ['_', '$', 'core/event', 'core/location', 'core/res function createHtml(item) { - var $html = $(crumbTemplate).data('item', item); item.$crumb = $html; location.setLink($html, item); @@ -32,7 +30,6 @@ modulejs.define('ext/crumb', ['_', '$', 'core/event', 'core/location', 'core/res } function onLocationChanged(item) { - var $crumb = item.$crumb; if ($crumb && $crumb.parent()[0] === $crumbbar[0]) { @@ -40,14 +37,13 @@ modulejs.define('ext/crumb', ['_', '$', 'core/event', 'core/location', 'core/res $crumb.addClass('active'); } else { $crumbbar.empty(); - _.each(item.getCrumb(), function (item) { - $crumbbar.append(createHtml(item)); + _.each(item.getCrumb(), function (crumbItem) { + $crumbbar.append(createHtml(crumbItem)); }); } } function init() { - if (!settings.enabled) { return; } diff --git a/src/_h5ai/public/js/lib/ext/custom.js b/src/_h5ai/public/js/lib/ext/custom.js index 26427c22..13138f27 100644 --- a/src/_h5ai/public/js/lib/ext/custom.js +++ b/src/_h5ai/public/js/lib/ext/custom.js @@ -1,17 +1,14 @@ modulejs.define('ext/custom', ['_', '$', 'marked', 'core/event', 'core/server', 'core/settings'], function (_, $, marked, event, server, allsettings) { - var settings = _.extend({ - enabled: false - }, allsettings.custom); + enabled: false + }, allsettings.custom); var $header; var $footer; var duration = 200; function onLocationChanged(item) { - server.request({action: 'get', custom: item.absHref}, function (response) { - var custom = response && response.custom; var hasHeader; var hasFooter; @@ -50,7 +47,6 @@ modulejs.define('ext/custom', ['_', '$', 'marked', 'core/event', 'core/server', } function init() { - if (!settings.enabled) { return; } diff --git a/src/_h5ai/public/js/lib/ext/download.js b/src/_h5ai/public/js/lib/ext/download.js index 4c031ff2..62f5cd6b 100644 --- a/src/_h5ai/public/js/lib/ext/download.js +++ b/src/_h5ai/public/js/lib/ext/download.js @@ -1,11 +1,10 @@ modulejs.define('ext/download', ['_', '$', 'core/event', 'core/location', 'core/resource', 'core/server', 'core/settings'], function (_, $, event, location, resource, server, allsettings) { - var settings = _.extend({ - enabled: false, - type: 'php-tar', - packageName: 'package', - alwaysVisible: false - }, allsettings.download); + enabled: false, + type: 'php-tar', + packageName: 'package', + alwaysVisible: false + }, allsettings.download); var template = '
    ' + 'download' + @@ -15,7 +14,6 @@ modulejs.define('ext/download', ['_', '$', 'core/event', 'core/location', 'core/ function onSelection(items) { - selectedItems = items.slice(0); if (selectedItems.length) { $download.show(); @@ -25,10 +23,9 @@ modulejs.define('ext/download', ['_', '$', 'core/event', 'core/location', 'core/ } function onClick() { - var type = settings.type; var name = settings.packageName; - var extension = (type === 'shell-zip') ? 'zip' : 'tar'; + var extension = type === 'shell-zip' ? 'zip' : 'tar'; if (!name) { if (selectedItems.length === 1) { @@ -39,14 +36,13 @@ modulejs.define('ext/download', ['_', '$', 'core/event', 'core/location', 'core/ } var query = { - action: 'download', - as: name + '.' + extension, - type: type, - baseHref: location.getAbsHref() - }; + action: 'download', + as: name + '.' + extension, + type: type, + baseHref: location.getAbsHref() + }; _.each(selectedItems, function (item, idx) { - query['hrefs[' + idx + ']'] = item.absHref; }); @@ -54,7 +50,6 @@ modulejs.define('ext/download', ['_', '$', 'core/event', 'core/location', 'core/ } function init() { - if (!settings.enabled) { return; } diff --git a/src/_h5ai/public/js/lib/ext/filter.js b/src/_h5ai/public/js/lib/ext/filter.js index 84fe90ad..2b640059 100644 --- a/src/_h5ai/public/js/lib/ext/filter.js +++ b/src/_h5ai/public/js/lib/ext/filter.js @@ -1,10 +1,9 @@ modulejs.define('ext/filter', ['_', '$', 'core/event', 'core/location', 'core/resource', 'core/settings', 'core/util', 'view/view'], function (_, $, event, location, resource, allsettings, util, view) { - var settings = _.extend({ - enabled: false, - advanced: false, - debounceTime: 100 - }, allsettings.filter); + enabled: false, + advanced: false, + debounceTime: 100 + }, allsettings.filter); var template = '
    ' + 'filter' + @@ -17,7 +16,6 @@ modulejs.define('ext/filter', ['_', '$', 'core/event', 'core/location', 'core/re function filter(pattern) { - pattern = pattern || ''; if (pattern === prevPattern) { return; @@ -35,7 +33,6 @@ modulejs.define('ext/filter', ['_', '$', 'core/event', 'core/location', 'core/re var matchedItems = []; _.each(location.getItem().content, function (item) { - if (re.test(item.label)) { matchedItems.push(item); } @@ -47,7 +44,6 @@ modulejs.define('ext/filter', ['_', '$', 'core/event', 'core/location', 'core/re } function update() { - if (inputIsVisible) { $filter.addClass('active'); $input.focus(); @@ -59,20 +55,17 @@ modulejs.define('ext/filter', ['_', '$', 'core/event', 'core/location', 'core/re } function toggle() { - inputIsVisible = !inputIsVisible; update(); } function reset() { - inputIsVisible = false; $input.val(''); update(); } function init() { - if (!settings.enabled) { return; } diff --git a/src/_h5ai/public/js/lib/ext/google-analytics.js b/src/_h5ai/public/js/lib/ext/google-analytics.js index cbef8f53..d6729bc4 100644 --- a/src/_h5ai/public/js/lib/ext/google-analytics.js +++ b/src/_h5ai/public/js/lib/ext/google-analytics.js @@ -1,49 +1,37 @@ modulejs.define('ext/google-analytics-ua', ['_', 'core/event', 'core/settings'], function (_, event, allsettings) { - var settings = _.extend({ - enabled: false, - id: 'UA-000000-0' - }, allsettings['google-analytics-ua']); - var win = window; - var doc = document; - var scriptLiteral = 'script'; - var id = 'h5ai-ga'; + enabled: false, + id: 'UA-000000-0' + }, allsettings['google-analytics-ua']); + function snippet() { + /* eslint-disable */ + (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ + (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), + m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) + })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); + /* eslint-enable */ + } function init() { - if (!settings.enabled) { return; } - var el; - var firstScriptElement; + snippet(); - win.GoogleAnalyticsObject = id; - win[id] = win[id] || function () { - (win[id].q = win[id].q || []).push(arguments); - }; - win[id].l = 1 * new Date(); - - el = doc.createElement(scriptLiteral); - el.async = true; - el.src = '//www.google-analytics.com/analytics.js'; - - firstScriptElement = doc.getElementsByTagName(scriptLiteral)[0]; - firstScriptElement.parentNode.insertBefore(el, firstScriptElement); - - win[id]('create', settings.id, 'auto'); + var WIN = window; + var GA = 'ga'; + WIN[GA]('create', settings.id, 'auto'); event.sub('location.changed', function (item) { - - var loc = win.location; - win[id]('send', 'pageview', { + var loc = WIN.location; + WIN[GA]('send', 'pageview', { location: loc.protocol + '//' + loc.host + item.absHref, title: _.pluck(item.getCrumb(), 'label').join(' > ') }); }); } - init(); }); diff --git a/src/_h5ai/public/js/lib/ext/info.js b/src/_h5ai/public/js/lib/ext/info.js index c904993f..e101e56d 100644 --- a/src/_h5ai/public/js/lib/ext/info.js +++ b/src/_h5ai/public/js/lib/ext/info.js @@ -1,11 +1,10 @@ modulejs.define('ext/info', ['_', '$', 'core/event', 'core/format', 'core/modernizr', 'core/resource', 'core/settings', 'core/store'], function (_, $, event, format, modernizr, resource, allsettings, store) { - var settings = _.extend({ - enabled: false, - show: false, - qrcode: true, - qrColor: '#999' - }, allsettings.info); + enabled: false, + show: false, + qrcode: true, + qrColor: '#999' + }, allsettings.info); var template = '
    ' + '
    ' + @@ -40,7 +39,6 @@ modulejs.define('ext/info', ['_', '$', 'core/event', 'core/format', 'core/modern function updateSettings() { - if (store.get(storekey)) { $('#view-info').addClass('active'); $('#info').show(); @@ -51,7 +49,6 @@ modulejs.define('ext/info', ['_', '$', 'core/event', 'core/format', 'core/modern } function update(item) { - var src = item.thumbRational || item.icon; var isThumb = Boolean(item.thumbRational); @@ -101,23 +98,19 @@ modulejs.define('ext/info', ['_', '$', 'core/event', 'core/format', 'core/modern } function onMouseenter(item) { - update(item); } function onMouseleave() { - update(currentFolder); } function onLocationChanged(item) { - currentFolder = item; update(currentFolder); } function init() { - if (!settings.enabled) { return; } @@ -140,14 +133,13 @@ modulejs.define('ext/info', ['_', '$', 'core/event', 'core/format', 'core/modern .appendTo('#sidebar') .find('#view-info') .on('click', function (ev) { - store.put(storekey, !store.get(storekey)); updateSettings(); ev.preventDefault(); }); // ensure stored value is boolean, otherwise set default - if (typeof (store.get(storekey)) !== 'boolean') { + if (typeof store.get(storekey) !== 'boolean') { store.put(storekey, settings.show); } updateSettings(); diff --git a/src/_h5ai/public/js/lib/ext/l10n.js b/src/_h5ai/public/js/lib/ext/l10n.js index 2c301672..da6e0e4d 100644 --- a/src/_h5ai/public/js/lib/ext/l10n.js +++ b/src/_h5ai/public/js/lib/ext/l10n.js @@ -1,44 +1,43 @@ -modulejs.define('ext/l10n', ['_', '$', 'core/event', 'core/format', 'core/langs', 'core/server', 'core/settings', 'core/store'], function (_, $, event, format, langs, server, allsettings, store) { - +modulejs.define('ext/l10n', ['_', '$', 'core/event', 'core/format', 'core/langs', 'core/server', 'core/settings', 'core/store'], +function (_, $, event, format, langs, server, allsettings, store) { var settings = _.extend({ - enabled: false, - lang: 'en', - useBrowserLang: true - }, allsettings.l10n); + enabled: false, + lang: 'en', + useBrowserLang: true + }, allsettings.l10n); var defaultTranslations = { - isoCode: 'en', - lang: 'english', + isoCode: 'en', + lang: 'english', - dateFormat: 'YYYY-MM-DD HH:mm', - details: 'details', - download: 'download', - empty: 'empty', - files: 'files', - filter: 'filter', - folders: 'folders', - grid: 'grid', - icons: 'icons', - language: 'Language', - lastModified: 'Last modified', - name: 'Name', - noMatch: 'no match', - parentDirectory: 'Parent Directory', - search: 'search', - size: 'Size', - tree: 'Tree', - view: 'View' - }; + dateFormat: 'YYYY-MM-DD HH:mm', + details: 'details', + download: 'download', + empty: 'empty', + files: 'files', + filter: 'filter', + folders: 'folders', + grid: 'grid', + icons: 'icons', + language: 'Language', + lastModified: 'Last modified', + name: 'Name', + noMatch: 'no match', + parentDirectory: 'Parent Directory', + search: 'search', + size: 'Size', + tree: 'Tree', + view: 'View' + }; var blockTemplate = '

    Language