Merge remote-tracking branch 'origin/master' into develop

This commit is contained in:
Timothy Warren 2016-02-16 12:26:54 -05:00
commit 1ba302999d
3 changed files with 44 additions and 5 deletions

View File

@ -40,7 +40,7 @@
mimeType: 'application/json', mimeType: 'application/json',
success: (res) => { success: (res) => {
if (res.status === 'completed') { if (res.status === 'completed') {
this.parentElement.addAttribute('hidden', 'hidden'); _.hide(parent_sel);
} }
_.showMessage('success', `Sucessfully updated ${title}`); _.showMessage('success', `Sucessfully updated ${title}`);

View File

@ -2,8 +2,6 @@ var AnimeClient = (function(w) {
'use strict'; 'use strict';
const slice = Array.prototype.slice;
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
// ! Base // ! Base
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
@ -40,7 +38,7 @@ var AnimeClient = (function(w) {
if (selector.match(/^#([\w]+$)/)) { if (selector.match(/^#([\w]+$)/)) {
elements.push(document.getElementById(selector.split('#')[1])); elements.push(document.getElementById(selector.split('#')[1]));
} else { } else {
elements = slice.apply(context.querySelectorAll(selector)); elements = [].slice.apply(context.querySelectorAll(selector));
} }
return elements; return elements;
@ -53,6 +51,24 @@ var AnimeClient = (function(w) {
scrollToTop() { scrollToTop() {
w.scroll(0,0); 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 * 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) { _.on = function (sel, event, target, listener) {
if (arguments.length === 3) { if (arguments.length === 3) {
listener = target; listener = target;
@ -203,6 +228,20 @@ var AnimeClient = (function(w) {
return pairs.join("&"); 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) { _.ajax = function(url, config) {
// Set some sane defaults // Set some sane defaults
config = config || {}; config = config || {};

View File

@ -7,7 +7,7 @@
// Close event for messages // Close event for messages
ac.on('header', 'click', '.message', function () { ac.on('header', 'click', '.message', function () {
this.setAttribute('hidden', 'hidden'); ac.hide(this);
}); });
})(AnimeClient); })(AnimeClient);