diff --git a/.eslintrc b/.eslintrc index 3e9ea2e3ae..3c2579b8fc 100644 --- a/.eslintrc +++ b/.eslintrc @@ -28,6 +28,9 @@ "camelcase": "off", "no-new": "off", "no-shadow": "off", + "no-use-before-define": ["error", "nofunc"], + "no-prototype-builtins": "off", + "new-cap": "off", // ES6 "prefer-rest-params": "off", @@ -36,6 +39,7 @@ "prefer-template": "off", "no-var": "off", "object-shorthand": "off", + "vars-on-top": "off", // TODO "import/no-unresolved": "off", @@ -46,13 +50,9 @@ "global-require": "off", "max-len": "off", "no-param-reassign": "off", - "no-prototype-builtins": "off", - "vars-on-top": "off", "no-restricted-syntax": "off", "no-script-url": "off", - "no-use-before-define": "off", "default-case": "off", - "new-cap": "off", // "no-multi-assign": "off", // "linebreak-style": "off", diff --git a/public/src/admin/general/dashboard.js b/public/src/admin/general/dashboard.js index 10fe6ffc6d..363311c9f9 100644 --- a/public/src/admin/general/dashboard.js +++ b/public/src/admin/general/dashboard.js @@ -24,6 +24,8 @@ define('admin/general/dashboard', ['semver', 'Chart', 'translator'], function (s realtimeInterval: 1500, }; + var usedTopicColors = []; + $(window).on('action:ajaxify.start', function () { clearInterval(intervals.rooms); clearInterval(intervals.graphs); @@ -127,8 +129,8 @@ define('admin/general/dashboard', ['semver', 'Chart', 'translator'], function (s }; var topicColors = ['#bf616a', '#5B90BF', '#d08770', '#ebcb8b', '#a3be8c', '#96b5b4', '#8fa1b3', '#b48ead', '#ab7967', '#46BFBD']; - var usedTopicColors = []; + /* eslint-disable */ // from chartjs.org function lighten(col, amt) { var usePound = false; @@ -157,6 +159,7 @@ define('admin/general/dashboard', ['semver', 'Chart', 'translator'], function (s return (usePound ? '#' : '') + (g | (b << 8) | (r << 16)).toString(16); } + /* eslint-enable */ function setupGraphs() { var trafficCanvas = document.getElementById('analytics-traffic'); diff --git a/public/src/admin/manage/categories.js b/public/src/admin/manage/categories.js index 772af419fe..6434a25aed 100644 --- a/public/src/admin/manage/categories.js +++ b/public/src/admin/manage/categories.js @@ -42,16 +42,6 @@ define('admin/manage/categories', ['vendor/jquery/serializeObject/jquery.ba-seri templates.parse('admin/partials/categories/create', { categories: categories, }, function (html) { - function submit() { - var formData = modal.find('form').serializeObject(); - formData.description = ''; - formData.icon = 'fa-comments'; - - Categories.create(formData); - modal.modal('hide'); - return false; - } - var modal = bootbox.dialog({ title: '[[admin/manage/categories:alert.create]]', message: html, @@ -64,6 +54,16 @@ define('admin/manage/categories', ['vendor/jquery/serializeObject/jquery.ba-seri }, }); + function submit() { + var formData = modal.find('form').serializeObject(); + formData.description = ''; + formData.icon = 'fa-comments'; + + Categories.create(formData); + modal.modal('hide'); + return false; + } + modal.find('form').on('submit', submit); }); }); diff --git a/public/src/admin/manage/category.js b/public/src/admin/manage/category.js index af99bf9748..22fc5d77ec 100644 --- a/public/src/admin/manage/category.js +++ b/public/src/admin/manage/category.js @@ -221,7 +221,7 @@ define('admin/manage/category', [ if (confirm) { Category.setPrivilege(member, privilege, state, checkboxEl); } else { - checkboxEl.prop('checked', checkboxEl.prop('checked') ^ 1); + checkboxEl.prop('checked', !checkboxEl.prop('checked')); } }); } else { @@ -427,13 +427,6 @@ define('admin/manage/category', [ categories: categories, }, function (html) { translator.translate(html, function (html) { - function submit() { - var formData = modal.find('form').serializeObject(); - callback(formData['select-cid']); - modal.modal('hide'); - return false; - } - var modal = bootbox.dialog({ title: 'Select a Category', message: html, @@ -446,6 +439,13 @@ define('admin/manage/category', [ }, }); + function submit() { + var formData = modal.find('form').serializeObject(); + callback(formData['select-cid']); + modal.modal('hide'); + return false; + } + modal.find('form').on('submit', submit); }); }); diff --git a/public/src/admin/manage/groups.js b/public/src/admin/manage/groups.js index 71aaac5175..5aa7b969b7 100644 --- a/public/src/admin/manage/groups.js +++ b/public/src/admin/manage/groups.js @@ -76,6 +76,8 @@ define('admin/manage/groups', ['translator'], function (translator) { }; function handleSearch() { + var queryEl = $('#group-search'); + function doSearch() { if (!queryEl.val()) { return ajaxify.refresh(); @@ -103,8 +105,6 @@ define('admin/manage/groups', ['translator'], function (translator) { }); } - var queryEl = $('#group-search'); - queryEl.on('keyup', function () { if (intervalId) { clearTimeout(intervalId); diff --git a/public/src/ajaxify.js b/public/src/ajaxify.js index c6d04ade07..12ebff1540 100644 --- a/public/src/ajaxify.js +++ b/public/src/ajaxify.js @@ -1,7 +1,7 @@ 'use strict'; -var ajaxify = ajaxify || {}; +var ajaxify = window.ajaxify || {}; $(document).ready(function () { var location = document.location || window.location; @@ -193,14 +193,14 @@ $(document).ready(function () { } ajaxify.end = function (url, tpl_url) { + var count = 2; + function done() { count -= 1; if (count === 0) { $(window).trigger('action:ajaxify.end', { url: url, tpl_url: tpl_url, title: ajaxify.data.title }); } } - var count = 2; - ajaxify.loadScript(tpl_url, done); ajaxify.widgets.render(tpl_url, url, done); @@ -343,6 +343,12 @@ $(document).ready(function () { // Enhancing all anchors to ajaxify... $(document.body).on('click', 'a', function (e) { var _self = this; + if (this.target !== '' || (this.protocol !== 'http:' && this.protocol !== 'https:')) { + return; + } + + var internalLink = utils.isInternalURI(this, window.location, RELATIVE_PATH); + var process = function () { if (!e.ctrlKey && !e.shiftKey && !e.metaKey && e.which === 1) { if (internalLink) { @@ -366,12 +372,6 @@ $(document).ready(function () { } }; - if (this.target !== '' || (this.protocol !== 'http:' && this.protocol !== 'https:')) { - return; - } - - var internalLink = utils.isInternalURI(this, window.location, RELATIVE_PATH); - if ($(this).attr('data-ajaxify') === 'false') { if (!internalLink) { return; diff --git a/public/src/app.js b/public/src/app.js index 8df3941ddb..7112d281da 100644 --- a/public/src/app.js +++ b/public/src/app.js @@ -1,7 +1,7 @@ 'use strict'; -var app = app || {}; +var app = window.app || {}; app.isFocused = true; app.currentRoom = null; diff --git a/public/src/client/topic/postTools.js b/public/src/client/topic/postTools.js index 5753380171..e012b20186 100644 --- a/public/src/client/topic/postTools.js +++ b/public/src/client/topic/postTools.js @@ -230,6 +230,9 @@ define('forum/topic/postTools', [ var selectedNode = getSelectedNode(); showStaleWarning(function () { + var username = getUserName(button); + var toPid = getData(button, 'data-pid'); + function quote(text) { $(window).trigger('action:composer.addQuote', { tid: tid, @@ -240,9 +243,6 @@ define('forum/topic/postTools', [ }); } - var username = getUserName(button); - var toPid = getData(button, 'data-pid'); - if (selectedNode.text && toPid && toPid === selectedNode.pid) { return quote(selectedNode.text); } diff --git a/public/src/overrides.js b/public/src/overrides.js index 144fb63ef3..b74d93efba 100644 --- a/public/src/overrides.js +++ b/public/src/overrides.js @@ -1,7 +1,7 @@ 'use strict'; -var overrides = overrides || {}; +var overrides = window.overrides || {}; if (typeof window !== 'undefined') { (function ($) { diff --git a/public/src/sockets.js b/public/src/sockets.js index 248ce498aa..6b22ce9ac9 100644 --- a/public/src/sockets.js +++ b/public/src/sockets.js @@ -1,7 +1,7 @@ 'use strict'; -var app = app || {}; +var app = window.app || {}; var socket; app.isConnected = false; diff --git a/src/plugins/load.js b/src/plugins/load.js index 33659e714f..49e4b26e2a 100644 --- a/src/plugins/load.js +++ b/src/plugins/load.js @@ -148,6 +148,8 @@ module.exports = function (Plugins) { } function mapStaticDirectories(pluginData, pluginPath, callback) { + var validMappedPath = /^[\w\-_]+$/; + function mapStaticDirs(mappedPath, callback) { if (Plugins.staticDirs[mappedPath]) { winston.warn('[plugins/' + pluginData.id + '] Mapped path (' + mappedPath + ') already specified!'); @@ -170,8 +172,6 @@ module.exports = function (Plugins) { } } - var validMappedPath = /^[\w\-_]+$/; - pluginData.staticDirs = pluginData.staticDirs || {}; var dirs = Object.keys(pluginData.staticDirs);