Remove last dependencies on zepto

This commit is contained in:
Timothy Warren 2016-02-08 20:21:41 -05:00
parent cbc7555cf2
commit a9f5e48bb2
7 changed files with 59 additions and 58 deletions

View File

@ -26,8 +26,10 @@ return [
), ),
*/ */
'base' => [ 'base' => [
'lib/zepto.js', //'base/AnimeClient.js',
'base/base.js', 'base/base.js',
'base/event.js',
'base/ajax.js',
], ],
'event' => [ 'event' => [
'base/events.js', 'base/events.js',

View File

@ -20,9 +20,6 @@ return [
// Specify default paths and views // Specify default paths and views
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
'route_config' => [ '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, // Path to public directory, where images/css/javascript are located,
// appended to the url // appended to the url
'asset_path' => '/public', 'asset_path' => '/public',
@ -120,9 +117,10 @@ return [
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
// Default / Shared routes // Default / Shared routes
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
'login' => [ 'login_form' => [
'path' => '/{controller}/login', 'path' => '/{controller}/login',
'action' => 'login', 'action' => 'login',
'verb' => 'get'
], ],
'login_post' => [ 'login_post' => [
'path' => '/{controller}/login', 'path' => '/{controller}/login',

View File

@ -1,12 +1,12 @@
(($, AnimeClient) => { ((_) => {
'use strict'; 'use strict';
const search = (tempHtml, query) => { const search = (tempHtml, query) => {
$('.cssload-loader').removeAttr('hidden'); _.$('.cssload-loader')[0].removeAttribute('hidden');
AnimeClient.get(AnimeClient.url('/collection/search'), {'query':query}, (searchResults, status) => { _.get(_.url('/collection/search'), {'query':query}, (searchResults, status) => {
searchResults = JSON.parse(searchResults); searchResults = JSON.parse(searchResults);
$('.cssload-loader').attr('hidden', 'hidden'); _.$('.cssload-loader')[0].setAttribute('hidden', 'hidden');
// Give mustache a key to iterate over // Give mustache a key to iterate over
searchResults = { searchResults = {
@ -14,12 +14,12 @@
}; };
Mustache.parse(tempHtml); 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 => { _.get('/public/templates/anime-ajax-search-results.html', tempHtml => {
AnimeClient.on('#search', 'keyup', AnimeClient.throttle(250, function(e) { _.on('#search', 'keyup', _.throttle(250, function(e) {
let query = encodeURIComponent(this.value); let query = encodeURIComponent(this.value);
if (query === '') { if (query === '') {
return; return;
@ -29,4 +29,4 @@
})); }));
}); });
})(Zepto, AnimeClient); })(AnimeClient);

View File

@ -1,23 +1,22 @@
/** /**
* Javascript for editing anime, if logged in * Javascript for editing anime, if logged in
*/ */
(($, AnimeClient) => { ((_) => {
'use strict'; 'use strict';
// Action to increment episode count // Action to increment episode count
AnimeClient.on('body.anime.list', 'click', '.plus_one', function(e) { _.on('body.anime.list', 'click', '.plus_one', function(e) {
let self = this; let this_sel = this;
let this_sel = $(this); let parent_sel = this.parentElement;
let parent_sel = $(this).closest('article, td');
let watched_count = parseInt(parent_sel.find('.completed_number').text(), 10); let watched_count = parseInt(_.$('.completed_number', parent_sel)[0].textContent, 10);
let total_count = parseInt(parent_sel.find('.total_number').text(), 10); let total_count = parseInt(_.$('.total_number', parent_sel)[0].textContent, 10);
let title = parent_sel.find('.name a').text(); let title = _.$('.name a', parent_sel)[0].textContent;
// Setup the update data // Setup the update data
let data = { let data = {
id: this_sel.parent('article, td').attr('id'), id: parent_sel.id,
increment_episodes: true increment_episodes: true
}; };
@ -34,26 +33,26 @@
} }
// okay, lets actually make some changes! // okay, lets actually make some changes!
AnimeClient.ajax(AnimeClient.url('/anime/update'), { _.ajax(_.url('/anime/update'), {
data: data, data: data,
dataType: 'json', dataType: 'json',
type: 'POST', type: 'POST',
mimeType: 'application/json', mimeType: 'application/json',
success: (res) => { success: (res) => {
if (res.status === 'completed') { if (res.status === 'completed') {
$(this).closest('article, tr').hide(); this.parentElement.addAttribute('hidden', 'hidden');
} }
AnimeClient.showMessage('success', `Sucessfully updated ${title}`); _.showMessage('success', `Sucessfully updated ${title}`);
parent_sel.find('.completed_number').text(++watched_count); _.$('.completed_number', parent_sel)[0].textContent = ++watched_count;
AnimeClient.scrollToTop(); _.scrollToTop();
}, },
error: (xhr, errorType, error) => { error: (xhr, errorType, error) => {
console.error(error); console.error(error);
AnimeClient.showMessage('error', `Failed to updated ${title}. `); _.showMessage('error', `Failed to updated ${title}. `);
AnimeClient.scrollToTop(); _.scrollToTop();
} }
}); });
}); });
})(Zepto, AnimeClient); })(AnimeClient);

View File

@ -50,6 +50,7 @@ var AnimeClient = (function(w) {
* @return {void} * @return {void}
*/ */
showMessage(type, message) { showMessage(type, message) {
let template = ` let template = `
<div class="message ${type}"> <div class="message ${type}">
<span class="icon"></span> <span class="icon"></span>
@ -57,11 +58,12 @@ var AnimeClient = (function(w) {
<span class="close"></span> <span class="close"></span>
</div>`; </div>`;
if ($(".message").length > 0) { let sel = AnimeClient.$('.message')[0];
$(".message").replaceWith(template); if (sel !== undefined) {
$(".message").show(); sel.innerHTML = template;
sel.removeAttribute('hidden');
} else { } else {
$("header").append(template); AnimeClient.$('header')[0].insertAdjacentHTML('beforeend', template);
} }
}, },
/** /**

View File

@ -1,20 +1,20 @@
(($, AnimeClient) => { ((_) => {
'use strict'; 'use strict';
const search = (tempHtml, query) => { const search = (tempHtml, query) => {
$('.cssload-loader').removeAttr('hidden'); _.$('.cssload-loader')[0].removeAttribute('hidden');
AnimeClient.get(AnimeClient.url('/manga/search'), {'query':query,}, (searchResults, status) => { _.get(_.url('/manga/search'), {'query':query,}, (searchResults, status) => {
searchResults = JSON.parse(searchResults); searchResults = JSON.parse(searchResults);
$('.cssload-loader').attr('hidden', 'hidden'); _.$('.cssload-loader')[0].setAttribute('hidden', 'hidden');
Mustache.parse(tempHtml); 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 => { _.get('/public/templates/manga-ajax-search-results.html', tempHtml => {
AnimeClient.on('#search', 'keyup', AnimeClient.throttle(250, function(e) { _.on('#search', 'keyup', _.throttle(250, function(e) {
let query = encodeURIComponent(this.value); let query = encodeURIComponent(this.value);
if (query === '') { if (query === '') {
return; return;
@ -24,4 +24,4 @@
})); }));
}); });
})(Zepto, AnimeClient); })(AnimeClient);

View File

@ -1,18 +1,18 @@
/** /**
* Javascript for editing manga, if logged in * Javascript for editing manga, if logged in
*/ */
(($, AnimeClient) => { ((_) => {
'use strict'; 'use strict';
AnimeClient.on('.manga.list', 'click', '.edit_buttons button', function(e) { _.on('.manga.list', 'click', '.edit_buttons button', function(e) {
let this_sel = $(this); let this_sel = this;
let parent_sel = $(this).closest("article"); let parent_sel = this.parentElement.parentElement;
let manga_id = parent_sel.attr("id").replace("manga-", ""); let manga_id = parent_sel.id.replace("manga-", "");
let type = this_sel.is(".plus_one_chapter") ? 'chapter' : 'volume'; let type = this_sel.classList.contains("plus_one_chapter") ? 'chapter' : 'volume';
let completed = parseInt(parent_sel.find(`.${type}s_read`).text(), 10); let completed = parseInt(_.$(`.${type}s_read`, parent_sel)[0].textContent, 10);
let total = parseInt(parent_sel.find(`.${type}_count`).text(), 10); let total = parseInt(_.$(`.${type}_count`, parent_sel)[0].textContent, 10);
let manga_name = parent_sel.find('.name').text(); let manga_name = _.$('.name', parent_sel)[0].textContent;
if (isNaN(completed)) { if (isNaN(completed)) {
completed = 0; completed = 0;
@ -25,22 +25,22 @@
// Update the total count // Update the total count
data[type + "s_read"] = ++completed; data[type + "s_read"] = ++completed;
AnimeClient.ajax(AnimeClient.url('/manga/update'), { _.ajax(_.url('/manga/update'), {
data: data, data: data,
dataType: 'json', dataType: 'json',
type: 'POST', type: 'POST',
mimeType: 'application/json', mimeType: 'application/json',
success: (res) => { success: (res) => {
parent_sel.find(`.${type}s_read`).text(completed); _.$(`.${type}s_read`, parent_sel)[0].textContent = completed;
AnimeClient.showMessage('success', `Sucessfully updated ${manga_name}`); _.showMessage('success', `Sucessfully updated ${manga_name}`);
AnimeClient.scrollToTop(); _.scrollToTop();
}, },
error: (xhr, errorType, error) => { error: (xhr, errorType, error) => {
console.error(error); console.error(error);
AnimeClient.showMessage('error', `Failed to updated ${manga_name}`); _.showMessage('error', `Failed to updated ${manga_name}`);
AnimeClient.scrollToTop(); _.scrollToTop();
} }
}); });
}); });
})(Zepto, AnimeClient); })(AnimeClient);