From 9cc491a05e8e8f3cfe97fe7985f1b55d0e082ea3 Mon Sep 17 00:00:00 2001 From: "Timothy J. Warren" Date: Wed, 10 Feb 2016 17:50:07 -0500 Subject: [PATCH 1/2] Minor style fixes, and fix double message issue --- public/css/base.css | 10 ++-------- public/css/base.myth.css | 10 ++-------- public/js/base/AnimeClient.js | 11 +++++------ 3 files changed, 9 insertions(+), 22 deletions(-) diff --git a/public/css/base.css b/public/css/base.css index 356b8453..8514e4ec 100644 --- a/public/css/base.css +++ b/public/css/base.css @@ -452,7 +452,7 @@ h1 a { } .media > .name > a { - text-align: justify; + /*text-align:justify;*/ background: none; color: #fff; text-shadow: 1px 2px 1px rgba(0, 0, 0, 0.85); @@ -466,13 +466,7 @@ h1 a { .manga .name { text-align: center; width: 100%; - padding: 0.5em 0; -} - -.anime .name > a { - text-align: center; - width: 100%; - padding: 0.5em 1em; + padding: 0.5em 0.25em; } .anime .media_type, diff --git a/public/css/base.myth.css b/public/css/base.myth.css index 95dc85b9..39522d4f 100644 --- a/public/css/base.myth.css +++ b/public/css/base.myth.css @@ -333,7 +333,7 @@ a:hover, a:active { } .media > .name > a { - text-align:justify; + /*text-align:justify;*/ background:none; color:#fff; text-shadow: var(--shadow); @@ -347,15 +347,9 @@ a:hover, a:active { .anime .name, .manga .name { text-align:center; width:100%; - padding:0.5em 0; + padding:0.5em 0.25em; } - .anime .name > a { - text-align:center; - width:100%; - padding:0.5em 1em; - } - .anime .media_type, .anime .airing_status, .anime .user_rating, diff --git a/public/js/base/AnimeClient.js b/public/js/base/AnimeClient.js index 51d84158..815976e2 100644 --- a/public/js/base/AnimeClient.js +++ b/public/js/base/AnimeClient.js @@ -68,13 +68,12 @@ var AnimeClient = (function(w) { `; - let sel = AnimeClient.$('.message')[0]; - if (sel !== undefined) { - sel.innerHTML = template; - sel.removeAttribute('hidden'); - } else { - _.$('header')[0].insertAdjacentHTML('beforeend', template); + let sel = AnimeClient.$('.message'); + if (sel[0] !== undefined) { + sel[0].remove(); } + + _.$('header')[0].insertAdjacentHTML('beforeend', template); }, /** * Finds the closest parent element matching the passed selector From 197a1f8326ed46714856473117c41e3158337516 Mon Sep 17 00:00:00 2001 From: "Timothy J. Warren" Date: Tue, 16 Feb 2016 12:07:01 -0500 Subject: [PATCH 2/2] Update some javascript documentation, and add show/hide methods --- public/js/anime_edit.js | 2 +- public/js/base/AnimeClient.js | 45 ++++++++++++++++++++++++++++++++--- public/js/base/events.js | 2 +- 3 files changed, 44 insertions(+), 5 deletions(-) diff --git a/public/js/anime_edit.js b/public/js/anime_edit.js index c35e930e..61235b09 100755 --- a/public/js/anime_edit.js +++ b/public/js/anime_edit.js @@ -40,7 +40,7 @@ mimeType: 'application/json', success: (res) => { if (res.status === 'completed') { - this.parentElement.addAttribute('hidden', 'hidden'); + _.hide(parent_sel); } _.showMessage('success', `Sucessfully updated ${title}`); diff --git a/public/js/base/AnimeClient.js b/public/js/base/AnimeClient.js index 815976e2..11fac8aa 100644 --- a/public/js/base/AnimeClient.js +++ b/public/js/base/AnimeClient.js @@ -2,8 +2,6 @@ var AnimeClient = (function(w) { 'use strict'; - const slice = Array.prototype.slice; - // ------------------------------------------------------------------------- // ! Base // ------------------------------------------------------------------------- @@ -40,7 +38,7 @@ var AnimeClient = (function(w) { if (selector.match(/^#([\w]+$)/)) { elements.push(document.getElementById(selector.split('#')[1])); } else { - elements = slice.apply(context.querySelectorAll(selector)); + elements = [].slice.apply(context.querySelectorAll(selector)); } return elements; @@ -53,6 +51,24 @@ var AnimeClient = (function(w) { scrollToTop() { w.scroll(0,0); }, + /** + * Hide the selected element + * + * @param {string|Element} sel - the selector of the element to hide + * @return {void} + */ + hide(sel) { + sel.setAttribute('hidden', 'hidden'); + }, + /** + * UnHide the selected element + * + * @param {string|Element} sel - the selector of the element to hide + * @return {void} + */ + show(sel) { + sel.removeAttribute('hidden'); + }, /** * Display a message box * @@ -164,6 +180,15 @@ var AnimeClient = (function(w) { }); } + /** + * Add an event listener + * + * @param {string|element} sel - the parent selector to bind to + * @param {string} event - event name(s) to bind + * @param {string|element} [target] - the element to directly bind the event to + * @param {function} listener - event listener callback + * @return {void} + */ _.on = function (sel, event, target, listener) { if (arguments.length === 3) { listener = target; @@ -203,6 +228,20 @@ var AnimeClient = (function(w) { return pairs.join("&"); }; + /** + * Make an ajax request + * + * Config:{ + * data: // data to send with the request + * type: // http verb of the request, defaults to GET + * success: // success callback + * error: // error callback + * } + * + * @param {string} url - the url to request + * @param {Object} config - the configuration object + * @return {void} + */ _.ajax = function(url, config) { // Set some sane defaults config = config || {}; diff --git a/public/js/base/events.js b/public/js/base/events.js index 22fc3715..541238c1 100644 --- a/public/js/base/events.js +++ b/public/js/base/events.js @@ -7,7 +7,7 @@ // Close event for messages ac.on('header', 'click', '.message', function () { - this.setAttribute('hidden', 'hidden'); + ac.hide(this); }); })(AnimeClient); \ No newline at end of file