Version 5.1 - All the GraphQL #32

Closed
timw4mail wants to merge 1160 commits from develop into master
4 changed files with 32 additions and 26 deletions
Showing only changes of commit 664a9ec14a - Show all commits

View File

@ -18,8 +18,8 @@ const search = (query) => {
}; };
if (_.hasElement('.anime #search')) { if (_.hasElement('.anime #search')) {
_.on('#search', 'keyup', _.throttle(250, function () { _.on('#search', 'keyup', _.throttle(250, (e) => {
const query = encodeURIComponent(this.value); const query = encodeURIComponent(e.target.value);
if (query === '') { if (query === '') {
return; return;
} }
@ -82,7 +82,7 @@ _.on('body.anime.list', 'click', '.plus_one', (e) => {
_.$('.completed_number', parentSel)[ 0 ].textContent = ++watchedCount; _.$('.completed_number', parentSel)[ 0 ].textContent = ++watchedCount;
_.scrollToTop(); _.scrollToTop();
}, },
error: (xhr, errorType, error) => { error: () => {
_.hide(_.$('#loading-shadow')[ 0 ]); _.hide(_.$('#loading-shadow')[ 0 ]);
_.showMessage('error', `Failed to update ${title}. `); _.showMessage('error', `Failed to update ${title}. `);
_.scrollToTop(); _.scrollToTop();

View File

@ -45,7 +45,7 @@ export const AnimeClient = {
* @param {string} selector * @param {string} selector
* @returns {boolean} * @returns {boolean}
*/ */
hasElement(selector) { hasElement (selector) {
return AnimeClient.$(selector).length > 0; return AnimeClient.$(selector).length > 0;
}, },
/** /**
@ -53,7 +53,7 @@ export const AnimeClient = {
* *
* @return {void} * @return {void}
*/ */
scrollToTop() { scrollToTop () {
window.scroll(0,0); window.scroll(0,0);
}, },
/** /**
@ -62,7 +62,7 @@ export const AnimeClient = {
* @param {string|Element} sel - the selector of the element to hide * @param {string|Element} sel - the selector of the element to hide
* @return {void} * @return {void}
*/ */
hide(sel) { hide (sel) {
sel.setAttribute('hidden', 'hidden'); sel.setAttribute('hidden', 'hidden');
}, },
/** /**
@ -71,7 +71,7 @@ export const AnimeClient = {
* @param {string|Element} sel - the selector of the element to hide * @param {string|Element} sel - the selector of the element to hide
* @return {void} * @return {void}
*/ */
show(sel) { show (sel) {
sel.removeAttribute('hidden'); sel.removeAttribute('hidden');
}, },
/** /**
@ -81,7 +81,7 @@ export const AnimeClient = {
* @param {string} message - the message itself * @param {string} message - the message itself
* @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>
@ -103,7 +103,7 @@ export const AnimeClient = {
* @param {string} parentSelector - selector for the parent element * @param {string} parentSelector - selector for the parent element
* @return {HTMLElement|null} - the parent element * @return {HTMLElement|null} - the parent element
*/ */
closestParent(current, parentSelector) { closestParent (current, parentSelector) {
if (Element.prototype.closest !== undefined) { if (Element.prototype.closest !== undefined) {
return current.closest(parentSelector); return current.closest(parentSelector);
} }
@ -124,7 +124,7 @@ export const AnimeClient = {
* @param {string} path - url path * @param {string} path - url path
* @return {string} - full url * @return {string} - full url
*/ */
url(path) { url (path) {
let uri = `//${document.location.host}`; let uri = `//${document.location.host}`;
uri += (path.charAt(0) === '/') ? path : `/${path}`; uri += (path.charAt(0) === '/') ? path : `/${path}`;
@ -140,7 +140,7 @@ export const AnimeClient = {
* @param {Object} [scope] - the 'this' object for the function * @param {Object} [scope] - the 'this' object for the function
* @return {Function} * @return {Function}
*/ */
throttle(interval, fn, scope) { throttle (interval, fn, scope) {
let wait = false; let wait = false;
return function (...args) { return function (...args) {
const context = scope || this; const context = scope || this;
@ -193,8 +193,8 @@ function delegateEvent(sel, target, event, listener) {
* @param {function} [listener] - event listener callback * @param {function} [listener] - event listener callback
* @return {void} * @return {void}
*/ */
AnimeClient.on = function (sel, event, target, listener) { AnimeClient.on = (sel, event, target, listener) => {
if (arguments.length === 3) { if (listener === undefined) {
listener = target; listener = target;
AnimeClient.$(sel).forEach((el) => { AnimeClient.$(sel).forEach((el) => {
addEvent(el, event, listener); addEvent(el, event, listener);
@ -246,15 +246,21 @@ function ajaxSerialize(data) {
* @param {Object} config - the configuration object * @param {Object} config - the configuration object
* @return {void} * @return {void}
*/ */
AnimeClient.ajax = function(url, config) { AnimeClient.ajax = (url, config) => {
// Set some sane defaults // Set some sane defaults
config = config || {}; const defaultConfig = {
config.data = config.data || {}; data: {},
config.type = config.type || 'GET'; type: 'GET',
config.dataType = config.dataType || ''; dataType: '',
config.success = config.success || AnimeClient.noop; success: AnimeClient.noop,
config.mimeType = config.mimeType || 'application/x-www-form-urlencoded'; mimeType: 'application/x-www-form-urlencoded',
config.error = config.error || AnimeClient.noop; error: AnimeClient.noop
}
config = {
...defaultConfig,
...config,
}
let request = new XMLHttpRequest(); let request = new XMLHttpRequest();
let method = String(config.type).toUpperCase(); let method = String(config.type).toUpperCase();
@ -312,7 +318,7 @@ AnimeClient.ajax = function(url, config) {
* @param {object|function} data * @param {object|function} data
* @param {function} [callback] * @param {function} [callback]
*/ */
AnimeClient.get = function(url, data, callback = null) { AnimeClient.get = (url, data, callback = null) => {
if (callback === null) { if (callback === null) {
callback = data; callback = data;
data = {}; data = {};

View File

@ -3,8 +3,8 @@ import _ from './AnimeClient.js';
* Event handlers * Event handlers
*/ */
// Close event for messages // Close event for messages
_.on('header', 'click', '.message', function () { _.on('header', 'click', '.message', (e) => {
_.hide(this); _.hide(e.target);
}); });
// Confirm deleting of list or library items // Confirm deleting of list or library items

View File

@ -11,8 +11,8 @@ const search = (query) => {
}; };
if (_.hasElement('.manga #search')) { if (_.hasElement('.manga #search')) {
_.on('#search', 'keyup', _.throttle(250, function (e) { _.on('#search', 'keyup', _.throttle(250, (e) => {
let query = encodeURIComponent(this.value); let query = encodeURIComponent(e.target.value);
if (query === '') { if (query === '') {
return; return;
} }