1
0
mirror of https://github.com/locomotivemtl/locomotive-boilerplate.git synced 2026-01-15 00:55:08 +08:00

Updated EditorConfig Recommendations

Applied 4-spaces for everything as per: https://locomotivemtl.teamwork.com/tasks/7113032
This commit is contained in:
Chauncey McAskill
2016-08-22 10:30:46 -04:00
parent 3953fbca7b
commit 79219e0659
48 changed files with 1595 additions and 1589 deletions

View File

@@ -4,18 +4,18 @@ import { arrayContains, findByKeyValue, removeFromArray } from './array';
import { $document, $window, $html, $body } from './environment';
const CALLBACKS = {
hidden: [],
visible: []
hidden: [],
visible: []
};
const ACTIONS = [
'addCallback',
'removeCallback'
'addCallback',
'removeCallback'
];
const STATES = [
'visible',
'hidden'
'visible',
'hidden'
];
const PREFIX = 'v-';
@@ -24,11 +24,11 @@ let UUID = 0;
// Main event
$document.on('visibilitychange', function(event) {
if (document.hidden) {
onDocumentChange('hidden');
} else {
onDocumentChange('visible');
}
if (document.hidden) {
onDocumentChange('hidden');
} else {
onDocumentChange('visible');
}
});
/**
@@ -38,21 +38,21 @@ $document.on('visibilitychange', function(event) {
* @return {string} ident
*/
function addCallback (state, options) {
let callback = options.callback || '';
let callback = options.callback || '';
if (!isFunction(callback)) {
console.warn('Callback is not a function');
return false;
}
if (!isFunction(callback)) {
console.warn('Callback is not a function');
return false;
}
let ident = PREFIX + UUID++;
let ident = PREFIX + UUID++;
CALLBACKS[state].push({
ident: ident,
callback: callback
});
CALLBACKS[state].push({
ident: ident,
callback: callback
});
return ident;
return ident;
}
/**
@@ -62,25 +62,25 @@ function addCallback (state, options) {
* @return {boolean} If operation was a success
*/
function removeCallback (state, options) {
let ident = options.ident || '';
let ident = options.ident || '';
if (typeof(ident) === 'undefined' || ident === '') {
console.warn('Need ident to remove callback');
return false;
}
if (typeof(ident) === 'undefined' || ident === '') {
console.warn('Need ident to remove callback');
return false;
}
let index = findByKeyValue(CALLBACKS[state], 'ident', ident)[0];
let index = findByKeyValue(CALLBACKS[state], 'ident', ident)[0];
// console.log(ident)
// console.log(CALLBACKS[state])
// console.log(ident)
// console.log(CALLBACKS[state])
if (typeof(index) !== 'undefined') {
removeFromArray(CALLBACKS[state], index);
return true;
} else {
console.warn('Callback could not be found');
return false;
}
if (typeof(index) !== 'undefined') {
removeFromArray(CALLBACKS[state], index);
return true;
} else {
console.warn('Callback could not be found');
return false;
}
}
/**
@@ -88,13 +88,13 @@ function removeCallback (state, options) {
* @param {string} state Visible or hidden
*/
function onDocumentChange (state) {
let callbackArray = CALLBACKS[state];
let i = 0;
let len = callbackArray.length;
let callbackArray = CALLBACKS[state];
let i = 0;
let len = callbackArray.length;
for (; i < len; i++) {
callbackArray[i].callback();
}
for (; i < len; i++) {
callbackArray[i].callback();
}
}
/**
@@ -103,28 +103,28 @@ function onDocumentChange (state) {
* @return {boolean|integer} Unique identifier for the callback or boolean indicating success or failure
*/
function visibilityApi (options) {
let action = options.action || '';
let state = options.state || '';
let ret;
let action = options.action || '';
let state = options.state || '';
let ret;
// Type and value checking
if (!arrayContains(ACTIONS, action)) {
console.warn('Action does not exist');
return false;
}
if (!arrayContains(STATES, state)) {
console.warn('State does not exist');
return false;
}
// Type and value checking
if (!arrayContains(ACTIONS, action)) {
console.warn('Action does not exist');
return false;
}
if (!arrayContains(STATES, state)) {
console.warn('State does not exist');
return false;
}
// @todo Magic call function pls
if (action === 'addCallback') {
ret = addCallback(state, options);
} else if (action === 'removeCallback') {
ret = removeCallback(state, options);
}
// @todo Magic call function pls
if (action === 'addCallback') {
ret = addCallback(state, options);
} else if (action === 'removeCallback') {
ret = removeCallback(state, options);
}
return ret;
return ret;
}
export { visibilityApi };