From a9f5e48bb2b08b5c90e114b08e6080eb4d28cf28 Mon Sep 17 00:00:00 2001 From: "Timothy J. Warren" Date: Mon, 8 Feb 2016 20:21:41 -0500 Subject: [PATCH] Remove last dependencies on zepto --- app/config/minify_js_groups.php | 4 +++- app/config/routes.php | 6 ++---- public/js/anime_collection.js | 16 ++++++++-------- public/js/anime_edit.js | 33 ++++++++++++++++----------------- public/js/base/base.js | 10 ++++++---- public/js/manga_collection.js | 16 ++++++++-------- public/js/manga_edit.js | 32 ++++++++++++++++---------------- 7 files changed, 59 insertions(+), 58 deletions(-) diff --git a/app/config/minify_js_groups.php b/app/config/minify_js_groups.php index 549a3d19..72ddfd75 100644 --- a/app/config/minify_js_groups.php +++ b/app/config/minify_js_groups.php @@ -26,8 +26,10 @@ return [ ), */ 'base' => [ - 'lib/zepto.js', + //'base/AnimeClient.js', 'base/base.js', + 'base/event.js', + 'base/ajax.js', ], 'event' => [ 'base/events.js', diff --git a/app/config/routes.php b/app/config/routes.php index 5736a4eb..06dd7056 100644 --- a/app/config/routes.php +++ b/app/config/routes.php @@ -20,9 +20,6 @@ return [ // Specify default paths and views // ------------------------------------------------------------------------- 'route_config' => [ - // Subfolder prefix for url, if in a subdirectory of the web root - 'subfolder_prefix' => '', - // Path to public directory, where images/css/javascript are located, // appended to the url 'asset_path' => '/public', @@ -120,9 +117,10 @@ return [ // --------------------------------------------------------------------- // Default / Shared routes // --------------------------------------------------------------------- - 'login' => [ + 'login_form' => [ 'path' => '/{controller}/login', 'action' => 'login', + 'verb' => 'get' ], 'login_post' => [ 'path' => '/{controller}/login', diff --git a/public/js/anime_collection.js b/public/js/anime_collection.js index 5436e8b0..7132b136 100755 --- a/public/js/anime_collection.js +++ b/public/js/anime_collection.js @@ -1,12 +1,12 @@ -(($, AnimeClient) => { +((_) => { 'use strict'; const search = (tempHtml, query) => { - $('.cssload-loader').removeAttr('hidden'); - AnimeClient.get(AnimeClient.url('/collection/search'), {'query':query}, (searchResults, status) => { + _.$('.cssload-loader')[0].removeAttribute('hidden'); + _.get(_.url('/collection/search'), {'query':query}, (searchResults, status) => { searchResults = JSON.parse(searchResults); - $('.cssload-loader').attr('hidden', 'hidden'); + _.$('.cssload-loader')[0].setAttribute('hidden', 'hidden'); // Give mustache a key to iterate over searchResults = { @@ -14,12 +14,12 @@ }; Mustache.parse(tempHtml); - $('#series_list').html(Mustache.render(tempHtml, searchResults)); + _.$('#series_list')[0].innerHTML = Mustache.render(tempHtml, searchResults); }); }; - AnimeClient.get('/public/templates/anime-ajax-search-results.html', tempHtml => { - AnimeClient.on('#search', 'keyup', AnimeClient.throttle(250, function(e) { + _.get('/public/templates/anime-ajax-search-results.html', tempHtml => { + _.on('#search', 'keyup', _.throttle(250, function(e) { let query = encodeURIComponent(this.value); if (query === '') { return; @@ -29,4 +29,4 @@ })); }); -})(Zepto, AnimeClient); \ No newline at end of file +})(AnimeClient); \ No newline at end of file diff --git a/public/js/anime_edit.js b/public/js/anime_edit.js index 91c0dc7b..fc67cbe6 100755 --- a/public/js/anime_edit.js +++ b/public/js/anime_edit.js @@ -1,23 +1,22 @@ /** * Javascript for editing anime, if logged in */ -(($, AnimeClient) => { +((_) => { 'use strict'; // Action to increment episode count - AnimeClient.on('body.anime.list', 'click', '.plus_one', function(e) { - let self = this; - let this_sel = $(this); - let parent_sel = $(this).closest('article, td'); + _.on('body.anime.list', 'click', '.plus_one', function(e) { + let this_sel = this; + let parent_sel = this.parentElement; - let watched_count = parseInt(parent_sel.find('.completed_number').text(), 10); - let total_count = parseInt(parent_sel.find('.total_number').text(), 10); - let title = parent_sel.find('.name a').text(); + let watched_count = parseInt(_.$('.completed_number', parent_sel)[0].textContent, 10); + let total_count = parseInt(_.$('.total_number', parent_sel)[0].textContent, 10); + let title = _.$('.name a', parent_sel)[0].textContent; // Setup the update data let data = { - id: this_sel.parent('article, td').attr('id'), + id: parent_sel.id, increment_episodes: true }; @@ -34,26 +33,26 @@ } // okay, lets actually make some changes! - AnimeClient.ajax(AnimeClient.url('/anime/update'), { + _.ajax(_.url('/anime/update'), { data: data, dataType: 'json', type: 'POST', mimeType: 'application/json', success: (res) => { if (res.status === 'completed') { - $(this).closest('article, tr').hide(); + this.parentElement.addAttribute('hidden', 'hidden'); } - AnimeClient.showMessage('success', `Sucessfully updated ${title}`); - parent_sel.find('.completed_number').text(++watched_count); - AnimeClient.scrollToTop(); + _.showMessage('success', `Sucessfully updated ${title}`); + _.$('.completed_number', parent_sel)[0].textContent = ++watched_count; + _.scrollToTop(); }, error: (xhr, errorType, error) => { console.error(error); - AnimeClient.showMessage('error', `Failed to updated ${title}. `); - AnimeClient.scrollToTop(); + _.showMessage('error', `Failed to updated ${title}. `); + _.scrollToTop(); } }); }); -})(Zepto, AnimeClient); \ No newline at end of file +})(AnimeClient); \ No newline at end of file diff --git a/public/js/base/base.js b/public/js/base/base.js index 9c006ba3..4c46b479 100644 --- a/public/js/base/base.js +++ b/public/js/base/base.js @@ -50,6 +50,7 @@ var AnimeClient = (function(w) { * @return {void} */ showMessage(type, message) { + let template = `
@@ -57,11 +58,12 @@ var AnimeClient = (function(w) {
`; - if ($(".message").length > 0) { - $(".message").replaceWith(template); - $(".message").show(); + let sel = AnimeClient.$('.message')[0]; + if (sel !== undefined) { + sel.innerHTML = template; + sel.removeAttribute('hidden'); } else { - $("header").append(template); + AnimeClient.$('header')[0].insertAdjacentHTML('beforeend', template); } }, /** diff --git a/public/js/manga_collection.js b/public/js/manga_collection.js index 729ea8b7..137ea46c 100644 --- a/public/js/manga_collection.js +++ b/public/js/manga_collection.js @@ -1,20 +1,20 @@ -(($, AnimeClient) => { +((_) => { 'use strict'; const search = (tempHtml, query) => { - $('.cssload-loader').removeAttr('hidden'); - AnimeClient.get(AnimeClient.url('/manga/search'), {'query':query,}, (searchResults, status) => { + _.$('.cssload-loader')[0].removeAttribute('hidden'); + _.get(_.url('/manga/search'), {'query':query,}, (searchResults, status) => { searchResults = JSON.parse(searchResults); - $('.cssload-loader').attr('hidden', 'hidden'); + _.$('.cssload-loader')[0].setAttribute('hidden', 'hidden'); Mustache.parse(tempHtml); - $('#series_list').html(Mustache.render(tempHtml, searchResults)); + _.$('#series_list')[0].innerHTML = Mustache.render(tempHtml, searchResults); }); }; - AnimeClient.get('/public/templates/manga-ajax-search-results.html', tempHtml => { - AnimeClient.on('#search', 'keyup', AnimeClient.throttle(250, function(e) { + _.get('/public/templates/manga-ajax-search-results.html', tempHtml => { + _.on('#search', 'keyup', _.throttle(250, function(e) { let query = encodeURIComponent(this.value); if (query === '') { return; @@ -24,4 +24,4 @@ })); }); -})(Zepto, AnimeClient); \ No newline at end of file +})(AnimeClient); \ No newline at end of file diff --git a/public/js/manga_edit.js b/public/js/manga_edit.js index de61fbb6..80393b37 100755 --- a/public/js/manga_edit.js +++ b/public/js/manga_edit.js @@ -1,18 +1,18 @@ /** * Javascript for editing manga, if logged in */ -(($, AnimeClient) => { +((_) => { 'use strict'; - AnimeClient.on('.manga.list', 'click', '.edit_buttons button', function(e) { - let this_sel = $(this); - let parent_sel = $(this).closest("article"); - let manga_id = parent_sel.attr("id").replace("manga-", ""); - let type = this_sel.is(".plus_one_chapter") ? 'chapter' : 'volume'; - let completed = parseInt(parent_sel.find(`.${type}s_read`).text(), 10); - let total = parseInt(parent_sel.find(`.${type}_count`).text(), 10); - let manga_name = parent_sel.find('.name').text(); + _.on('.manga.list', 'click', '.edit_buttons button', function(e) { + let this_sel = this; + let parent_sel = this.parentElement.parentElement; + let manga_id = parent_sel.id.replace("manga-", ""); + let type = this_sel.classList.contains("plus_one_chapter") ? 'chapter' : 'volume'; + let completed = parseInt(_.$(`.${type}s_read`, parent_sel)[0].textContent, 10); + let total = parseInt(_.$(`.${type}_count`, parent_sel)[0].textContent, 10); + let manga_name = _.$('.name', parent_sel)[0].textContent; if (isNaN(completed)) { completed = 0; @@ -25,22 +25,22 @@ // Update the total count data[type + "s_read"] = ++completed; - AnimeClient.ajax(AnimeClient.url('/manga/update'), { + _.ajax(_.url('/manga/update'), { data: data, dataType: 'json', type: 'POST', mimeType: 'application/json', success: (res) => { - parent_sel.find(`.${type}s_read`).text(completed); - AnimeClient.showMessage('success', `Sucessfully updated ${manga_name}`); - AnimeClient.scrollToTop(); + _.$(`.${type}s_read`, parent_sel)[0].textContent = completed; + _.showMessage('success', `Sucessfully updated ${manga_name}`); + _.scrollToTop(); }, error: (xhr, errorType, error) => { console.error(error); - AnimeClient.showMessage('error', `Failed to updated ${manga_name}`); - AnimeClient.scrollToTop(); + _.showMessage('error', `Failed to updated ${manga_name}`); + _.scrollToTop(); } }); }); -})(Zepto, AnimeClient); \ No newline at end of file +})(AnimeClient); \ No newline at end of file