Cleanup javascript into fewer files, add show/description link to search pages

This commit is contained in:
Timothy Warren 2018-08-22 12:54:06 -04:00
parent ca3fa85df3
commit 153230580e
17 changed files with 212 additions and 204 deletions

File diff suppressed because one or more lines are too long

View File

@ -605,6 +605,10 @@ a:hover, a:active {
background-repeat: no-repeat;
}
.media.search > .row {
z-index: 6;
}
.big-check {
display: none;
}

View File

@ -5,17 +5,18 @@ e.iteratorFromArray=function(c,f){e.initSymbolIterator();c instanceof String&&(c
e.polyfill=function(c,f){if(f){var k=e.global;c=c.split(".");for(var g=0;g<c.length-1;g++){var m=c[g];m in k||(k[m]={});k=k[m]}c=c[c.length-1];g=k[c];f=f(g);f!=g&&null!=f&&e.defineProperty(k,c,{configurable:!0,writable:!0,value:f})}};e.polyfill("Array.prototype.keys",function(c){return c?c:function(){return e.iteratorFromArray(this,function(c){return c})}},"es6","es3");
(function(){function c(d){a.$(".cssload-loader")[0].removeAttribute("hidden");a.get(a.url("/manga/search"),{query:d},function(b){b=JSON.parse(b);a.$(".cssload-loader")[0].setAttribute("hidden","hidden");a.$("#series_list")[0].innerHTML=n(b.data)})}function f(d){a.$(".cssload-loader")[0].removeAttribute("hidden");a.get(a.url("/anime-collection/search"),{query:d},function(b){b=JSON.parse(b);a.$(".cssload-loader")[0].setAttribute("hidden","hidden");a.$("#series_list")[0].innerHTML=p(b.data)})}function k(d,
b,a){b.match(/^([\w\-]+)$/)||b.split(" ").forEach(function(b){k(d,b,a)});d.addEventListener(b,a,!1)}function g(d,b,l,c){k(d,l,function(l){a.$(b,d).forEach(function(b){l.target==b&&(c.call(b,l),l.stopPropagation())})})}function m(d){var b=[];Object.keys(d).forEach(function(a){var l=d[a].toString();a=encodeURIComponent(a);l=encodeURIComponent(l);b.push(a+"\x3d"+l)});return b.join("\x26")}function p(a){var b=[];a.forEach(function(a){var d=a.attributes,l=d.titles.reduce(function(b,a){return b+(a+"\x3cbr /\x3e")},
[]);b.push('\n\t\t\t\x3carticle class\x3d"media search"\x3e\n\t\t\t\t\x3cdiv class\x3d"name"\x3e\n\t\t\t\t\t\x3cinput type\x3d"radio" class\x3d"big-check" id\x3d"'+d.slug+'" name\x3d"id" value\x3d"'+a.id+'" /\x3e\n\t\t\t\t\t\x3clabel for\x3d"'+d.slug+'"\x3e\n\t\t\t\t\t\t\x3cimg src\x3d"/public/images/anime/'+a.id+'.jpg" alt\x3d"" width\x3d"220" /\x3e\n\t\t\t\t\t\t\x3cspan class\x3d"name"\x3e\n\t\t\t\t\t\t\t'+d.canonicalTitle+"\x3cbr /\x3e\n\t\t\t\t\t\t\t\x3csmall\x3e"+l+"\x3c/small\x3e\n\t\t\t\t\t\t\x3c/span\x3e\n\t\t\t\t\t\x3c/label\x3e\n\t\t\t\t\x3c/div\x3e\n\t\t\t\x3c/article\x3e\n\t\t")});
return b.join("")}function n(a){var b=[];a.forEach(function(a){var d=a.attributes,l=d.titles.reduce(function(b,a){return b+(a+"\x3cbr /\x3e")},[]);b.push('\n\t\t\t\x3carticle class\x3d"media search"\x3e\n\t\t\t\t\x3cdiv class\x3d"name"\x3e\n\t\t\t\t\t\x3cinput type\x3d"radio" class\x3d"big-check" id\x3d"'+d.slug+'" name\x3d"id" value\x3d"'+a.id+'" /\x3e\n\t\t\t\t\t\x3clabel for\x3d"'+d.slug+'"\x3e\n\t\t\t\t\t\t\x3cimg src\x3d"/public/images/manga/'+a.id+'.jpg" alt\x3d"" width\x3d"220" /\x3e\n\t\t\t\t\t\t\x3cspan class\x3d"name"\x3e\n\t\t\t\t\t\t\t'+
d.canonicalTitle+"\x3cbr /\x3e\n\t\t\t\t\t\t\t\x3csmall\x3e"+l+"\x3c/small\x3e\n\t\t\t\t\t\t\x3c/span\x3e\n\t\t\t\t\t\x3c/label\x3e\n\t\t\t\t\x3c/div\x3e\n\t\t\t\x3c/article\x3e\n\t\t")});return b.join("")}var a={noop:function(){},$:function(a,b){b=void 0===b?null:b;if("string"!==typeof a)return a;b=null!==b&&1===b.nodeType?b:document;var d=[];a.match(/^#([\w]+$)/)?d.push(document.getElementById(a.split("#")[1])):d=[].slice.apply(b.querySelectorAll(a));return d},hasElement:function(d){return 0<a.$(d).length},
scrollToTop:function(){window.scroll(0,0)},hide:function(a){a.setAttribute("hidden","hidden")},show:function(a){a.removeAttribute("hidden")},showMessage:function(d,b){d="\x3cdiv class\x3d'message "+d+"'\x3e\n\t\t\t\t\x3cspan class\x3d'icon'\x3e\x3c/span\x3e\n\t\t\t\t"+b+"\n\t\t\t\t\x3cspan class\x3d'close'\x3e\x3c/span\x3e\n\t\t\t\x3c/div\x3e";b=a.$(".message");void 0!==b[0]&&b[0].remove();a.$("header")[0].insertAdjacentHTML("beforeend",d)},closestParent:function(a,b){if(void 0!==Element.prototype.closest)return a.closest(b);
for(;a!==document.documentElement;){for(var d=a,c=(d.document||d.ownerDocument).querySelectorAll(b),h=c.length;0<=--h&&c.item(h)!==d;);if(-1<h)return a;a=a.parentElement}return null},url:function(a){var b="//"+document.location.host;return b+="/"===a.charAt(0)?a:"/"+a},throttle:function(a,b,l){var d=!1;return function(c){for(var h=[],f=0;f<arguments.length;++f)h[f-0]=arguments[f];f=l||this;d||(b.apply(f,h),d=!0,setTimeout(function(){d=!1},a))}},on:function(d,b,l,c){3===arguments.length?(c=l,a.$(d).forEach(function(a){k(a,
[]);b.push('\n\t\t\t\x3carticle class\x3d"media search"\x3e\n\t\t\t\t\x3cdiv class\x3d"name"\x3e\n\t\t\t\t\t\x3cinput type\x3d"radio" class\x3d"big-check" id\x3d"'+d.slug+'" name\x3d"id" value\x3d"'+a.id+'" /\x3e\n\t\t\t\t\t\x3clabel for\x3d"'+d.slug+'"\x3e\n\t\t\t\t\t\t\x3cimg src\x3d"/public/images/anime/'+a.id+'.jpg" alt\x3d"" width\x3d"220" /\x3e\n\t\t\t\t\t\t\x3cspan class\x3d"name"\x3e\n\t\t\t\t\t\t\t'+d.canonicalTitle+"\x3cbr /\x3e\n\t\t\t\t\t\t\t\x3csmall\x3e"+l+'\x3c/small\x3e\n\t\t\t\t\t\t\x3c/span\x3e\n\t\t\t\t\t\x3c/label\x3e\n\t\t\t\t\x3c/div\x3e\n\t\t\t\t\x3cdiv class\x3d"table"\x3e\n\t\t\t\t\t\x3cdiv class\x3d"row"\x3e\n\t\t\t\t\t\t\x3cspan class\x3d"edit"\x3e\n\t\t\t\t\t\t\t\x3ca class\x3d"bracketed" href\x3d"/anime/details/'+
d.slug+'"\x3eInfo Page\x3c/a\x3e\n\t\t\t\t\t\t\x3c/span\x3e\n\t\t\t\t\t\x3c/div\x3e\n\t\t\t\t\x3c/div\x3e\n\t\t\t\x3c/article\x3e\n\t\t')});return b.join("")}function n(a){var b=[];a.forEach(function(a){var d=a.attributes,l=d.titles.reduce(function(b,a){return b+(a+"\x3cbr /\x3e")},[]);b.push('\n\t\t\t\x3carticle class\x3d"media search"\x3e\n\t\t\t\t\x3cdiv class\x3d"name"\x3e\n\t\t\t\t\t\x3cinput type\x3d"radio" class\x3d"big-check" id\x3d"'+d.slug+'" name\x3d"id" value\x3d"'+a.id+'" /\x3e\n\t\t\t\t\t\x3clabel for\x3d"'+
d.slug+'"\x3e\n\t\t\t\t\t\t\x3cimg src\x3d"/public/images/manga/'+a.id+'.jpg" alt\x3d"" width\x3d"220" /\x3e\n\t\t\t\t\t\t\x3cspan class\x3d"name"\x3e\n\t\t\t\t\t\t\t'+d.canonicalTitle+"\x3cbr /\x3e\n\t\t\t\t\t\t\t\x3csmall\x3e"+l+'\x3c/small\x3e\n\t\t\t\t\t\t\x3c/span\x3e\n\t\t\t\t\t\x3c/label\x3e\n\t\t\t\t\x3c/div\x3e\n\t\t\t\t\x3cdiv class\x3d"table"\x3e\n\t\t\t\t\t\x3cdiv class\x3d"row"\x3e\n\t\t\t\t\t\t\x3cspan class\x3d"edit"\x3e\n\t\t\t\t\t\t\t\x3ca class\x3d"bracketed" href\x3d"/manga/details/'+
d.slug+'"\x3eInfo Page\x3c/a\x3e\n\t\t\t\t\t\t\x3c/span\x3e\n\t\t\t\t\t\x3c/div\x3e\n\t\t\t\t\x3c/div\x3e\n\t\t\t\x3c/article\x3e\n\t\t')});return b.join("")}var a={noop:function(){},$:function(a,b){b=void 0===b?null:b;if("string"!==typeof a)return a;b=null!==b&&1===b.nodeType?b:document;var d=[];a.match(/^#([\w]+$)/)?d.push(document.getElementById(a.split("#")[1])):d=[].slice.apply(b.querySelectorAll(a));return d},hasElement:function(d){return 0<a.$(d).length},scrollToTop:function(){window.scroll(0,
0)},hide:function(a){a.setAttribute("hidden","hidden")},show:function(a){a.removeAttribute("hidden")},showMessage:function(d,b){d="\x3cdiv class\x3d'message "+d+"'\x3e\n\t\t\t\t\x3cspan class\x3d'icon'\x3e\x3c/span\x3e\n\t\t\t\t"+b+"\n\t\t\t\t\x3cspan class\x3d'close'\x3e\x3c/span\x3e\n\t\t\t\x3c/div\x3e";b=a.$(".message");void 0!==b[0]&&b[0].remove();a.$("header")[0].insertAdjacentHTML("beforeend",d)},closestParent:function(a,b){if(void 0!==Element.prototype.closest)return a.closest(b);for(;a!==
document.documentElement;){for(var d=a,c=(d.document||d.ownerDocument).querySelectorAll(b),h=c.length;0<=--h&&c.item(h)!==d;);if(-1<h)return a;a=a.parentElement}return null},url:function(a){var b="//"+document.location.host;return b+="/"===a.charAt(0)?a:"/"+a},throttle:function(a,b,l){var d=!1;return function(c){for(var h=[],f=0;f<arguments.length;++f)h[f-0]=arguments[f];f=l||this;d||(b.apply(f,h),d=!0,setTimeout(function(){d=!1},a))}},on:function(d,b,l,c){3===arguments.length?(c=l,a.$(d).forEach(function(a){k(a,
b,c)})):a.$(d).forEach(function(a){g(a,l,b,c)})},ajax:function(d,b){b=b||{};b.data=b.data||{};b.type=b.type||"GET";b.dataType=b.dataType||"";b.success=b.success||a.noop;b.mimeType=b.mimeType||"application/x-www-form-urlencoded";b.error=b.error||a.noop;var c=new XMLHttpRequest,f=String(b.type).toUpperCase();"GET"===f&&(d+=d.match(/\?/)?m(b.data):"?"+m(b.data));c.open(f,d);c.onreadystatechange=function(){if(4===c.readyState){var a="json"===c.responseType?JSON.parse(c.responseText):c.responseText;299<
c.status?b.error.call(null,c.status,a,c.response):b.success.call(null,a,c.status)}};"json"===b.dataType?(b.data=JSON.stringify(b.data),b.mimeType="application/json"):b.data=m(b.data);c.setRequestHeader("Content-Type",b.mimeType);switch(f){case "GET":c.send(null);break;default:c.send(b.data)}},get:function(d,b,c){c=void 0===c?null:c;null===c&&(c=b,b={});return a.ajax(d,{data:b,success:c})}};a.on("header","click",".message",function(){a.hide(this)});a.on("form.js-delete","submit",function(a){!1===confirm("Are you ABSOLUTELY SURE you want to delete this item?")&&
(a.preventDefault(),a.stopPropagation())});a.on(".js-clear-cache","click",function(){a.get("/cache_purge",function(){a.showMessage("success","Successfully purged api cache")})});"serviceWorker"in navigator&&navigator.serviceWorker.register("/sw.js").then(function(a){console.log("Service worker registered",a.scope)}).catch(function(a){console.error("Failed to register service worker",a)});if(a.hasElement(".anime #search"))a.on("#search","keyup",a.throttle(250,function(){var a=encodeURIComponent(this.value);
""!==a&&f(a)}));a.on("body.anime.list","click",".plus_one",function(c){var b=a.closestParent(c.target,"article"),d=parseInt(a.$(".completed_number",b)[0].textContent,10)||0;c=parseInt(a.$(".total_number",b)[0].textContent,10);var f=a.$(".name a",b)[0].textContent,h={id:b.dataset.kitsuId,mal_id:b.dataset.malId,data:{progress:d+1}};if(isNaN(d)||0===d)h.data.status="current";isNaN(d)||d+1!==c||(h.data.status="completed");a.show(a.$("#loading-shadow")[0]);a.ajax(a.url("/anime/update"),{data:h,dataType:"json",
type:"POST",success:function(c){c=JSON.parse(c);c.errors?(a.hide(a.$("#loading-shadow")[0]),a.showMessage("error","Failed to update "+f+". ")):("completed"===c.data.attributes.status&&a.hide(b),a.hide(a.$("#loading-shadow")[0]),a.showMessage("success","Successfully updated "+f),a.$(".completed_number",b)[0].textContent=++d);a.scrollToTop()},error:function(){a.hide(a.$("#loading-shadow")[0]);a.showMessage("error","Failed to update "+f+". ");a.scrollToTop()}})});if(a.hasElement(".manga #search"))a.on("#search",
"keyup",a.throttle(250,function(){var a=encodeURIComponent(this.value);""!==a&&c(a)}));a.on(".manga.list","click",".edit_buttons button",function(c){var b=c.target,d=a.closestParent(c.target,"article"),f=b.classList.contains("plus_one_chapter")?"chapter":"volume",h=parseInt(a.$("."+f+"s_read",d)[0].textContent,10)||0;c=parseInt(a.$("."+f+"_count",d)[0].textContent,10);var k=a.$(".name",d)[0].textContent;isNaN(h)&&(h=0);var g={id:d.dataset.kitsuId,mal_id:d.dataset.malId,data:{progress:h}};if(isNaN(h)||
0===h)g.data.status="current";isNaN(h)||h+1!==c||(g.data.status="completed");g.data.progress=++h;a.show(a.$("#loading-shadow")[0]);a.ajax(a.url("/manga/update"),{data:g,dataType:"json",type:"POST",mimeType:"application/json",success:function(){"completed"===g.data.status&&a.hide(d);a.hide(a.$("#loading-shadow")[0]);a.$("."+f+"s_read",d)[0].textContent=h;a.showMessage("success","Sucessfully updated "+k);a.scrollToTop()},error:function(){a.hide(a.$("#loading-shadow")[0]);a.showMessage("error","Failed to update "+
0===h)g.data.status="current";isNaN(h)||h+1!==c||(g.data.status="completed");g.data.progress=++h;a.show(a.$("#loading-shadow")[0]);a.ajax(a.url("/manga/update"),{data:g,dataType:"json",type:"POST",mimeType:"application/json",success:function(){"completed"===g.data.status&&a.hide(d);a.hide(a.$("#loading-shadow")[0]);a.$("."+f+"s_read",d)[0].textContent=h;a.showMessage("success","Successfully updated "+k);a.scrollToTop()},error:function(){a.hide(a.$("#loading-shadow")[0]);a.showMessage("error","Failed to update "+
k);a.scrollToTop()}})})})();
//# sourceMappingURL=scripts-authed.min.js.map

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,14 +1,39 @@
/**
* Javascript for editing anime, if logged in
*/
import _ from './base/AnimeClient';
import _ from './base/AnimeClient'
import { renderAnimeSearchResults } from './template-helpers'
const search = (query) => {
// Show the loader
_.$('.cssload-loader')[ 0 ].removeAttribute('hidden');
// Do the api search
_.get(_.url('/anime-collection/search'), { query }, (searchResults, status) => {
searchResults = JSON.parse(searchResults);
// Hide the loader
_.$('.cssload-loader')[ 0 ].setAttribute('hidden', 'hidden');
// Show the results
_.$('#series_list')[ 0 ].innerHTML = renderAnimeSearchResults(searchResults.data);
});
};
if (_.hasElement('.anime #search')) {
_.on('#search', 'keyup', _.throttle(250, function () {
const query = encodeURIComponent(this.value);
if (query === '') {
return;
}
search(query);
}));
}
// Action to increment episode count
_.on('body.anime.list', 'click', '.plus_one', (e) => {
let parentSel = _.closestParent(e.target, 'article');
let watchedCount = parseInt(_.$('.completed_number', parentSel)[0].textContent, 10) || 0;
let totalCount = parseInt(_.$('.total_number', parentSel)[0].textContent, 10);
let title = _.$('.name a', parentSel)[0].textContent;
let watchedCount = parseInt(_.$('.completed_number', parentSel)[ 0 ].textContent, 10) || 0;
let totalCount = parseInt(_.$('.total_number', parentSel)[ 0 ].textContent, 10);
let title = _.$('.name a', parentSel)[ 0 ].textContent;
// Setup the update data
let data = {
@ -26,11 +51,11 @@ _.on('body.anime.list', 'click', '.plus_one', (e) => {
}
// 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';
}
_.show(_.$('#loading-shadow')[0]);
_.show(_.$('#loading-shadow')[ 0 ]);
// okay, lets actually make some changes!
_.ajax(_.url('/anime/update'), {
@ -51,16 +76,16 @@ _.on('body.anime.list', 'click', '.plus_one', (e) => {
_.hide(parentSel);
}
_.hide(_.$('#loading-shadow')[0]);
_.hide(_.$('#loading-shadow')[ 0 ]);
_.showMessage('success', `Successfully updated ${title}`);
_.$('.completed_number', parentSel)[0].textContent = ++watchedCount;
_.$('.completed_number', parentSel)[ 0 ].textContent = ++watchedCount;
_.scrollToTop();
},
error: (xhr, errorType, error) => {
_.hide(_.$('#loading-shadow')[0]);
_.hide(_.$('#loading-shadow')[ 0 ]);
_.showMessage('error', `Failed to update ${title}. `);
_.scrollToTop();
}
});
});
});

View File

@ -1,30 +0,0 @@
import _ from './base/AnimeClient';
import { render_anime_search_results } from './anime_search_results';
const search = (query) => {
// Show the loader
_.$('.cssload-loader')[ 0 ].removeAttribute('hidden');
// Do the api search
_.get(_.url('/anime-collection/search'), { query }, (searchResults, status) => {
searchResults = JSON.parse(searchResults);
// Hide the loader
_.$('.cssload-loader')[ 0 ].setAttribute('hidden', 'hidden');
// Show the results
_.$('#series_list')[ 0 ].innerHTML = render_anime_search_results(searchResults.data);
});
};
if (_.hasElement('.anime #search')) {
_.on('#search', 'keyup', _.throttle(250, function () {
const query = encodeURIComponent(this.value);
if (query === '') {
return;
}
search(query);
}));
}

View File

@ -1,27 +0,0 @@
export function render_anime_search_results (data) {
const results = [];
data.forEach(x => {
const item = x.attributes;
const titles = item.titles.reduce((prev, current) => {
return prev + `${current}<br />`;
}, []);
results.push(`
<article class="media search">
<div class="name">
<input type="radio" class="big-check" id="${item.slug}" name="id" value="${x.id}" />
<label for="${item.slug}">
<img src="/public/images/anime/${x.id}.jpg" alt="" width="220" />
<span class="name">
${item.canonicalTitle}<br />
<small>${titles}</small>
</span>
</label>
</div>
</article>
`);
});
return results.join('');
}

View File

@ -5,7 +5,7 @@
const matches = (elm, selector) => {
let matches = (elm.document || elm.ownerDocument).querySelectorAll(selector),
i = matches.length;
while (--i >= 0 && matches.item(i) !== elm);
while (--i >= 0 && matches.item(i) !== elm) {};
return i > -1;
}

View File

@ -2,9 +2,7 @@ const LightTableSorter = (() => {
let th = null;
let cellIndex = null;
let order = '';
const text = (row) => {
return row.cells.item(cellIndex).textContent.toLowerCase();
};
const text = (row) => row.cells.item(cellIndex).textContent.toLowerCase();
const sort = (a, b) => {
let textA = text(a);
let textB = text(b);

View File

@ -1,7 +1,4 @@
import './index';
import './anime_collection';
import './anime_edit';
import './manga_collection';
import './manga_edit';
import './anime';
import './manga';

86
public/js/src/manga.js Normal file
View File

@ -0,0 +1,86 @@
import _ from './base/AnimeClient'
import { renderMangaSearchResults } from './template-helpers'
const search = (query) => {
_.$('.cssload-loader')[ 0 ].removeAttribute('hidden');
_.get(_.url('/manga/search'), { query }, (searchResults, status) => {
searchResults = JSON.parse(searchResults);
_.$('.cssload-loader')[ 0 ].setAttribute('hidden', 'hidden');
_.$('#series_list')[ 0 ].innerHTML = renderMangaSearchResults(searchResults.data);
});
};
if (_.hasElement('.manga #search')) {
_.on('#search', 'keyup', _.throttle(250, function (e) {
let query = encodeURIComponent(this.value);
if (query === '') {
return;
}
search(query);
}));
}
/**
* Javascript for editing manga, if logged in
*/
_.on('.manga.list', 'click', '.edit_buttons button', (e) => {
let thisSel = e.target;
let parentSel = _.closestParent(e.target, 'article');
let type = thisSel.classList.contains('plus_one_chapter') ? 'chapter' : 'volume';
let completed = parseInt(_.$(`.${type}s_read`, parentSel)[ 0 ].textContent, 10) || 0;
let total = parseInt(_.$(`.${type}_count`, parentSel)[ 0 ].textContent, 10);
let mangaName = _.$('.name', parentSel)[ 0 ].textContent;
if (isNaN(completed)) {
completed = 0;
}
// Setup the update data
let data = {
id: parentSel.dataset.kitsuId,
mal_id: parentSel.dataset.malId,
data: {
progress: completed
}
};
// If the episode count is 0, and incremented,
// change status to currently reading
if (isNaN(completed) || completed === 0) {
data.data.status = 'current';
}
// If you increment at the last chapter, mark as completed
if ((!isNaN(completed)) && (completed + 1) === total) {
data.data.status = 'completed';
}
// Update the total count
data.data.progress = ++completed;
_.show(_.$('#loading-shadow')[ 0 ]);
_.ajax(_.url('/manga/update'), {
data,
dataType: 'json',
type: 'POST',
mimeType: 'application/json',
success: () => {
if (data.data.status === 'completed') {
_.hide(parentSel);
}
_.hide(_.$('#loading-shadow')[ 0 ]);
_.$(`.${type}s_read`, parentSel)[ 0 ].textContent = completed;
_.showMessage('success', `Successfully updated ${mangaName}`);
_.scrollToTop();
},
error: () => {
_.hide(_.$('#loading-shadow')[ 0 ]);
_.showMessage('error', `Failed to update ${mangaName}`);
_.scrollToTop();
}
});
});

View File

@ -1,24 +0,0 @@
import _ from './base/AnimeClient';
import { render_manga_search_results } from './manga_search_results'
const search = (query) => {
_.$('.cssload-loader')[0].removeAttribute('hidden');
_.get(_.url('/manga/search'), {query}, (searchResults, status) => {
searchResults = JSON.parse(searchResults);
_.$('.cssload-loader')[0].setAttribute('hidden', 'hidden');
_.$('#series_list')[0].innerHTML = render_manga_search_results(searchResults.data);
});
};
if (_.hasElement('.manga #search')) {
_.on('#search', 'keyup', _.throttle(250, function (e) {
let query = encodeURIComponent(this.value);
if (query === '') {
return;
}
search(query);
}));
}

View File

@ -1,64 +0,0 @@
import _ from './base/AnimeClient';
/**
* Javascript for editing manga, if logged in
*/
_.on('.manga.list', 'click', '.edit_buttons button', (e) => {
let thisSel = e.target;
let parentSel = _.closestParent(e.target, 'article');
let type = thisSel.classList.contains('plus_one_chapter') ? 'chapter' : 'volume';
let completed = parseInt(_.$(`.${type}s_read`, parentSel)[0].textContent, 10) || 0;
let total = parseInt(_.$(`.${type}_count`, parentSel)[0].textContent, 10);
let mangaName = _.$('.name', parentSel)[0].textContent;
if (isNaN(completed)) {
completed = 0;
}
// Setup the update data
let data = {
id: parentSel.dataset.kitsuId,
mal_id: parentSel.dataset.malId,
data: {
progress: completed
}
};
// If the episode count is 0, and incremented,
// change status to currently reading
if (isNaN(completed) || completed === 0) {
data.data.status = 'current';
}
// If you increment at the last chapter, mark as completed
if (( ! isNaN(completed)) && (completed + 1) === total) {
data.data.status = 'completed';
}
// Update the total count
data.data.progress = ++completed;
_.show(_.$('#loading-shadow')[0]);
_.ajax(_.url('/manga/update'), {
data,
dataType: 'json',
type: 'POST',
mimeType: 'application/json',
success: () => {
if (data.data.status === 'completed') {
_.hide(parentSel);
}
_.hide(_.$('#loading-shadow')[0]);
_.$(`.${type}s_read`, parentSel)[0].textContent = completed;
_.showMessage('success', `Sucessfully updated ${mangaName}`);
_.scrollToTop();
},
error: () => {
_.hide(_.$('#loading-shadow')[0]);
_.showMessage('error', `Failed to update ${mangaName}`);
_.scrollToTop();
}
});
});

View File

@ -1,27 +0,0 @@
export function render_manga_search_results (data) {
const results = [];
data.forEach(x => {
const item = x.attributes;
const titles = item.titles.reduce((prev, current) => {
return prev + `${current}<br />`;
}, []);
results.push(`
<article class="media search">
<div class="name">
<input type="radio" class="big-check" id="${item.slug}" name="id" value="${x.id}" />
<label for="${item.slug}">
<img src="/public/images/manga/${x.id}.jpg" alt="" width="220" />
<span class="name">
${item.canonicalTitle}<br />
<small>${titles}</small>
</span>
</label>
</div>
</article>
`);
});
return results.join('');
}

View File

@ -0,0 +1,69 @@
export function renderAnimeSearchResults (data) {
const results = [];
data.forEach(x => {
const item = x.attributes;
const titles = item.titles.reduce((prev, current) => {
return prev + `${current}<br />`;
}, []);
results.push(`
<article class="media search">
<div class="name">
<input type="radio" class="big-check" id="${item.slug}" name="id" value="${x.id}" />
<label for="${item.slug}">
<img src="/public/images/anime/${x.id}.jpg" alt="" width="220" />
<span class="name">
${item.canonicalTitle}<br />
<small>${titles}</small>
</span>
</label>
</div>
<div class="table">
<div class="row">
<span class="edit">
<a class="bracketed" href="/anime/details/${item.slug}">Info Page</a>
</span>
</div>
</div>
</article>
`);
});
return results.join('');
}
export function renderMangaSearchResults (data) {
const results = [];
data.forEach(x => {
const item = x.attributes;
const titles = item.titles.reduce((prev, current) => {
return prev + `${current}<br />`;
}, []);
results.push(`
<article class="media search">
<div class="name">
<input type="radio" class="big-check" id="${item.slug}" name="id" value="${x.id}" />
<label for="${item.slug}">
<img src="/public/images/manga/${x.id}.jpg" alt="" width="220" />
<span class="name">
${item.canonicalTitle}<br />
<small>${titles}</small>
</span>
</label>
</div>
<div class="table">
<div class="row">
<span class="edit">
<a class="bracketed" href="/manga/details/${item.slug}">Info Page</a>
</span>
</div>
</div>
</article>
`);
});
return results.join('');
}

View File

@ -1 +1 @@
{"version":3,"file":"tables.min.js.map","sources":["src/base/sort_tables.js"],"sourcesContent":["const LightTableSorter = (() => {\n\tlet th = null;\n\tlet cellIndex = null;\n\tlet order = '';\n\tconst text = (row) => {\n\t\treturn row.cells.item(cellIndex).textContent.toLowerCase();\n\t};\n\tconst sort = (a, b) => {\n\t\tlet textA = text(a);\n\t\tlet textB = text(b);\n\t\tconst n = parseInt(textA, 10);\n\t\tif (n) {\n\t\t\ttextA = n;\n\t\t\ttextB = parseInt(textB, 10);\n\t\t}\n\t\tif (textA > textB) {\n\t\t\treturn 1;\n\t\t}\n\t\tif (textA < textB) {\n\t\t\treturn -1;\n\t\t}\n\t\treturn 0;\n\t};\n\tconst toggle = () => {\n\t\tconst c = order !== 'sorting_asc' ? 'sorting_asc' : 'sorting_desc';\n\t\tth.className = (th.className.replace(order, '') + ' ' + c).trim();\n\t\treturn order = c;\n\t};\n\tconst reset = () => {\n\t\tth.classList.remove('sorting_asc', 'sorting_desc');\n\t\tth.classList.add('sorting');\n\t\treturn order = '';\n\t};\n\tconst onClickEvent = (e) => {\n\t\tif (th && (cellIndex !== e.target.cellIndex)) {\n\t\t\treset();\n\t\t}\n\t\tth = e.target;\n\t\tif (th.nodeName.toLowerCase() === 'th') {\n\t\t\tcellIndex = th.cellIndex;\n\t\t\tconst tbody = th.offsetParent.getElementsByTagName('tbody')[0];\n\t\t\tlet rows = Array.from(tbody.rows);\n\t\t\tif (rows) {\n\t\t\t\trows.sort(sort);\n\t\t\t\tif (order === 'sorting_asc') {\n\t\t\t\t\trows.reverse();\n\t\t\t\t}\n\t\t\t\ttoggle();\n\t\t\t\ttbody.innerHtml = '';\n\n\t\t\t\trows.forEach(row => {\n\t\t\t\t\ttbody.appendChild(row);\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t};\n\treturn {\n\t\tinit: () => {\n\t\t\tlet ths = document.getElementsByTagName('th');\n\t\t\tlet results = [];\n\t\t\tfor (let i = 0, len = ths.length; i < len; i++) {\n\t\t\t\tlet th = ths[i];\n\t\t\t\tth.classList.add('sorting');\n\t\t\t\tresults.push(th.onclick = onClickEvent);\n\t\t\t}\n\t\t\treturn results;\n\t\t}\n\t};\n})();\n\nLightTableSorter.init();"],"names":[],"mappings":"IAsBG,GAAA;;;;;;"}
{"version":3,"file":"tables.min.js.map","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;"}