From 6ed755e2520f9057e4a65b0263777f36feda82ae Mon Sep 17 00:00:00 2001 From: "Timothy J. Warren" Date: Thu, 16 Feb 2017 11:47:54 -0500 Subject: [PATCH] JS style fixes --- public/js/anime_collection.js | 4 ++-- public/js/anime_edit.js | 8 ++++---- public/js/base/AnimeClient.js | 16 ++++++++-------- public/js/base/events.js | 6 +++--- public/js/manga_edit.js | 11 +++++------ 5 files changed, 22 insertions(+), 23 deletions(-) diff --git a/public/js/anime_collection.js b/public/js/anime_collection.js index d0e51155..8869e247 100644 --- a/public/js/anime_collection.js +++ b/public/js/anime_collection.js @@ -4,7 +4,7 @@ const search = (tempHtml, query) => { _.$('.cssload-loader')[0].removeAttribute('hidden'); - _.get(_.url('/collection/search'), {'query':query}, (searchResults, status) => { + _.get(_.url('/collection/search'), {query}, (searchResults, status) => { searchResults = JSON.parse(searchResults); _.$('.cssload-loader')[0].setAttribute('hidden', 'hidden'); @@ -18,7 +18,7 @@ }); }; - _.get('/public/templates/anime-ajax-search-results.html', tempHtml => { + _.get('/public/templates/anime-ajax-search-results.html', (tempHtml) => { _.on('#search', 'keyup', _.throttle(250, function(e) { let query = encodeURIComponent(this.value); if (query === '') { diff --git a/public/js/anime_edit.js b/public/js/anime_edit.js index 57cc24ad..911cd4d3 100644 --- a/public/js/anime_edit.js +++ b/public/js/anime_edit.js @@ -6,7 +6,7 @@ 'use strict'; // Action to increment episode count - _.on('body.anime.list', 'click', '.plus_one', e => { + _.on('body.anime.list', 'click', '.plus_one', (e) => { let parentSel = _.closestParent(e.target, 'article'); let watchedCount = parseInt(_.$('.completed_number', parentSel)[0].textContent, 10); let totalCount = parseInt(_.$('.total_number', parentSel)[0].textContent, 10); @@ -28,17 +28,17 @@ } // If you increment at the last episode, mark as completed - if (( ! isNaN(watchedCount)) && (watchedCount + 1) == totalCount) { + if (( ! isNaN(watchedCount)) && (watchedCount + 1) === totalCount) { data.data.status = 'completed'; } // okay, lets actually make some changes! _.ajax(_.url('/anime/update'), { - data: data, + data, dataType: 'json', type: 'POST', success: () => { - if (data.data.status == 'completed') { + if (data.data.status === 'completed') { _.hide(parentSel); } diff --git a/public/js/base/AnimeClient.js b/public/js/base/AnimeClient.js index 92614baf..b8d85fa2 100644 --- a/public/js/base/AnimeClient.js +++ b/public/js/base/AnimeClient.js @@ -26,7 +26,7 @@ var AnimeClient = (function(w) { * @return {array} - array of dom elements */ $(selector, context) { - if (typeof selector !== "string") { + if (typeof selector !== 'string') { return selector; } @@ -78,10 +78,10 @@ var AnimeClient = (function(w) { */ showMessage(type, message) { let template = - `
- + `
+ ${message} - +
`; let sel = AnimeClient.$('.message'); @@ -225,7 +225,7 @@ var AnimeClient = (function(w) { pairs.push(`${name}=${value}`); }); - return pairs.join("&"); + return pairs.join('&'); }; /** @@ -255,7 +255,7 @@ var AnimeClient = (function(w) { let request = new XMLHttpRequest(); let method = String(config.type).toUpperCase(); - if (method === "GET") { + if (method === 'GET') { url += (url.match(/\?/)) ? ajaxSerialize(config.data) : `?${ajaxSerialize(config.data)}`; @@ -267,7 +267,7 @@ var AnimeClient = (function(w) { if (request.readyState === 4) { let responseText = ''; - if (request.responseType == 'json') { + if (request.responseType === 'json') { responseText = JSON.parse(request.responseText); } else { responseText = request.responseText; @@ -291,7 +291,7 @@ var AnimeClient = (function(w) { request.setRequestHeader('Content-Type', config.mimeType); switch (method) { - case "GET": + case 'GET': request.send(null); break; diff --git a/public/js/base/events.js b/public/js/base/events.js index a59ce1c0..ae30ebb7 100644 --- a/public/js/base/events.js +++ b/public/js/base/events.js @@ -11,8 +11,8 @@ }); // Confirm deleting of list or library items - ac.on('form.js-delete', 'submit', event => { - let proceed = confirm("Are you ABSOLUTELY SURE you want to delete this item?"); + ac.on('form.js-delete', 'submit', (event) => { + const proceed = confirm("Are you ABSOLUTELY SURE you want to delete this item?"); if (proceed === false) { event.preventDefault(); @@ -23,7 +23,7 @@ // Clear the api cache ac.on('.js-clear-cache', 'click', () => { ac.get('/cache_purge', () => { - ac.showMessage('success', `Successfully purged api cache`); + ac.showMessage('success', 'Successfully purged api cache'); }); }); diff --git a/public/js/manga_edit.js b/public/js/manga_edit.js index 2bd2f492..b0fdf222 100644 --- a/public/js/manga_edit.js +++ b/public/js/manga_edit.js @@ -5,7 +5,7 @@ 'use strict'; - _.on('.manga.list', 'click', '.edit_buttons button', e => { + _.on('.manga.list', 'click', '.edit_buttons button', (e) => { let thisSel = e.target; let parentSel = _.closestParent(e.target, 'article'); let mangaId = parentSel.id.replace("manga-", ""); @@ -33,7 +33,7 @@ } // If you increment at the last chapter, mark as completed - if (( ! isNaN(completed)) && (completed + 1) == total) { + if (( ! isNaN(completed)) && (completed + 1) === total) { data.data.status = 'completed'; } @@ -41,12 +41,12 @@ data.data.progress = ++completed; _.ajax(_.url('/manga/update'), { - data: data, + data, dataType: 'json', type: 'POST', mimeType: 'application/json', success: () => { - if (data.data.status == 'completed') { + if (data.data.status === 'completed') { _.hide(parentSel); } @@ -54,8 +54,7 @@ _.showMessage('success', `Sucessfully updated ${mangaName}`); _.scrollToTop(); }, - error: (xhr, errorType, error) => { - console.error(error); + error: () => { _.showMessage('error', `Failed to updated ${mangaName}`); _.scrollToTop(); }