Remove last dependencies on zepto

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

View File

@ -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',

View File

@ -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',

View File

@ -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);
})(AnimeClient);

View File

@ -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);
})(AnimeClient);

View File

@ -50,6 +50,7 @@ var AnimeClient = (function(w) {
* @return {void}
*/
showMessage(type, message) {
let template = `
<div class="message ${type}">
<span class="icon"></span>
@ -57,11 +58,12 @@ var AnimeClient = (function(w) {
<span class="close"></span>
</div>`;
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);
}
},
/**

View File

@ -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);
})(AnimeClient);

View File

@ -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);
})(AnimeClient);