Move to 2 space indentation + editorconfig

This commit is contained in:
Josh Johnson 2016-09-05 22:04:15 +01:00
parent 9bb9e0b4c2
commit d40841d8dd
11 changed files with 2659 additions and 2645 deletions

9
.editorconfig Normal file
View file

@ -0,0 +1,9 @@
root = true
[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true

View file

@ -10,7 +10,7 @@
"rules": { "rules": {
"quotes": [2, "single"], "quotes": [2, "single"],
"strict": [2, "never"], "strict": [2, "never"],
"indent": ["error", 4, {"SwitchCase": 1}], "indent": ["error", 2, {"SwitchCase": 1}],
"eol-last": "off", "eol-last": "off",
"arrow-body-style": "off", "arrow-body-style": "off",
"no-underscore-dangle": "off", "no-underscore-dangle": "off",

View file

@ -9,7 +9,8 @@ import {
activateChoices, activateChoices,
addGroup, addGroup,
clearAll, clearAll,
} from './actions/index'; }
from './actions/index';
import { import {
isScrolledIntoView, isScrolledIntoView,
getAdjacentEl, getAdjacentEl,
@ -21,14 +22,16 @@ import {
getWidthOfInput, getWidthOfInput,
sortByAlpha, sortByAlpha,
sortByScore, sortByScore,
} from './lib/utils.js'; }
from './lib/utils.js';
import './lib/polyfills.js'; import './lib/polyfills.js';
/** /**
* Choices * Choices
*/ */
export default class Choices { export
default class Choices {
constructor(element = '[data-choice]', userConfig = {}) { constructor(element = '[data-choice]', userConfig = {}) {
// If there are multiple elements, create a new instance // If there are multiple elements, create a new instance
// for each element besides the first one (as that already has an instance) // for each element besides the first one (as that already has an instance)
@ -808,7 +811,9 @@ export default class Choices {
this._removeItem(lastItem); this._removeItem(lastItem);
this._triggerChange(lastItem.value); this._triggerChange(lastItem.value);
} else { } else {
if (!hasHighlightedItems) { this.highlightItem(lastItem); } if (!hasHighlightedItems) {
this.highlightItem(lastItem);
}
this.removeHighlightedItems(); this.removeHighlightedItems();
} }
} }
@ -2045,7 +2050,9 @@ export default class Choices {
this._highlightChoice(); this._highlightChoice();
} else { } else {
// Otherwise show a notice // Otherwise show a notice
const dropdownItem = this.isSearching ? this._getTemplate('notice', this.config.noResultsText) : this._getTemplate('notice', this.config.noChoicesText); const dropdownItem = this.isSearching ?
this._getTemplate('notice', this.config.noResultsText) :
this._getTemplate('notice', this.config.noChoicesText);
this.choiceList.appendChild(dropdownItem); this.choiceList.appendChild(dropdownItem);
} }
} }

View file

@ -1,5 +1,4 @@
/* eslint-disable */ /* eslint-disable */
// Production steps of ECMA-262, Edition 6, 22.1.2.1 // Production steps of ECMA-262, Edition 6, 22.1.2.1
// Reference: https://people.mozilla.org/~jorendorff/es6-draft.html#sec-array.from // Reference: https://people.mozilla.org/~jorendorff/es6-draft.html#sec-array.from
if (!Array.from) { if (!Array.from) {

View file

@ -1,12 +1,11 @@
/* eslint-disable */ /* eslint-disable */
/** /**
* Capitalises the first letter of each word in a string * Capitalises the first letter of each word in a string
* @param {String} str String to capitalise * @param {String} str String to capitalise
* @return {String} Capitalised string * @return {String} Capitalised string
*/ */
export const capitalise = function(str) { export const capitalise = function(str) {
return str.replace(/\w\S*/g, function(txt){ return str.replace(/\w\S*/g, function(txt) {
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase(); return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
}); });
}; };
@ -30,7 +29,7 @@ export const isType = function(type, obj) {
export const isNode = (o) => { export const isNode = (o) => {
return ( return (
typeof Node === "object" ? o instanceof Node : typeof Node === "object" ? o instanceof Node :
o && typeof o === "object" && typeof o.nodeType === "number" && typeof o.nodeName==="string" o && typeof o === "object" && typeof o.nodeType === "number" && typeof o.nodeName === "string"
); );
}; };
@ -42,7 +41,7 @@ export const isNode = (o) => {
export const isElement = (o) => { export const isElement = (o) => {
return ( return (
typeof HTMLElement === "object" ? o instanceof HTMLElement : //DOM2 typeof HTMLElement === "object" ? o instanceof HTMLElement : //DOM2
o && typeof o === "object" && o !== null && o.nodeType === 1 && typeof o.nodeName==="string" o && typeof o === "object" && o !== null && o.nodeType === 1 && typeof o.nodeName === "string"
); );
}; };
@ -60,12 +59,12 @@ export const extend = function() {
* Merge one object into another * Merge one object into another
* @param {Object} obj Object to merge into extended object * @param {Object} obj Object to merge into extended object
*/ */
let merge = function (obj) { let merge = function(obj) {
for (let prop in obj) { for (let prop in obj) {
if (Object.prototype.hasOwnProperty.call(obj, prop)) { if (Object.prototype.hasOwnProperty.call(obj, prop)) {
// If deep merge and property is an object, merge properties // If deep merge and property is an object, merge properties
if (deep && isType('Object', obj[prop])) { if (deep && isType('Object', obj[prop])) {
extended[prop] = extend( true, extended[prop], obj[prop]); extended[prop] = extend(true, extended[prop], obj[prop]);
} else { } else {
extended[prop] = obj[prop]; extended[prop] = obj[prop];
} }
@ -93,19 +92,19 @@ export const extend = function() {
* CSS transition end event listener * CSS transition end event listener
* @return * @return
*/ */
export const whichTransitionEvent = function(){ export const whichTransitionEvent = function() {
var t, var t,
el = document.createElement("fakeelement"); el = document.createElement("fakeelement");
var transitions = { var transitions = {
"transition" : "transitionend", "transition": "transitionend",
"OTransition" : "oTransitionEnd", "OTransition": "oTransitionEnd",
"MozTransition" : "transitionend", "MozTransition": "transitionend",
"WebkitTransition": "webkitTransitionEnd" "WebkitTransition": "webkitTransitionEnd"
} }
for (t in transitions){ for (t in transitions) {
if (el.style[t] !== undefined){ if (el.style[t] !== undefined) {
return transitions[t]; return transitions[t];
} }
} }
@ -220,7 +219,7 @@ export const getParentsUntil = function(elem, parent, selector) {
} }
}; };
export const wrap = function (element, wrapper) { export const wrap = function(element, wrapper) {
wrapper = wrapper || document.createElement('div'); wrapper = wrapper || document.createElement('div');
if (element.nextSibling) { if (element.nextSibling) {
element.parentNode.insertBefore(wrapper, element.nextSibling); element.parentNode.insertBefore(wrapper, element.nextSibling);
@ -230,12 +229,12 @@ export const wrap = function (element, wrapper) {
return wrapper.appendChild(element); return wrapper.appendChild(element);
}; };
export const getSiblings = function (elem) { export const getSiblings = function(elem) {
var siblings = []; var siblings = [];
var sibling = elem.parentNode.firstChild; var sibling = elem.parentNode.firstChild;
for ( ; sibling; sibling = sibling.nextSibling ) { for (; sibling; sibling = sibling.nextSibling) {
if ( sibling.nodeType === 1 && sibling !== elem ) { if (sibling.nodeType === 1 && sibling !== elem) {
siblings.push( sibling ); siblings.push(sibling);
} }
} }
return siblings; return siblings;
@ -300,10 +299,10 @@ export const getElemDistance = function(el) {
*/ */
export const getElementOffset = function(el, offset) { export const getElementOffset = function(el, offset) {
var elOffset = offset; var elOffset = offset;
if(elOffset > 1) elOffset = 1; if (elOffset > 1) elOffset = 1;
if(elOffset > 0) elOffset = 0; if (elOffset > 0) elOffset = 0;
return Math.max(el.offsetHeight*elOffset); return Math.max(el.offsetHeight * elOffset);
}; };
/** /**
@ -314,7 +313,7 @@ export const getElementOffset = function(el, offset) {
* @return {[HTMLElement} Found element * @return {[HTMLElement} Found element
*/ */
export const getAdjacentEl = (startEl, className, direction = 1) => { export const getAdjacentEl = (startEl, className, direction = 1) => {
if(!startEl || !className) return; if (!startEl || !className) return;
const parent = startEl.parentNode.parentNode; const parent = startEl.parentNode.parentNode;
const children = Array.from(parent.querySelectorAll(className)); const children = Array.from(parent.querySelectorAll(className));
@ -331,7 +330,7 @@ export const getAdjacentEl = (startEl, className, direction = 1) => {
* @return {String} Position of scroll * @return {String} Position of scroll
*/ */
export const getScrollPosition = function(position) { export const getScrollPosition = function(position) {
if(position === 'bottom') { if (position === 'bottom') {
// Scroll position from the bottom of the viewport // Scroll position from the bottom of the viewport
return Math.max((window.scrollY || window.pageYOffset) + (window.innerHeight || document.documentElement.clientHeight)); return Math.max((window.scrollY || window.pageYOffset) + (window.innerHeight || document.documentElement.clientHeight));
} else { } else {
@ -359,13 +358,13 @@ export const isInView = function(el, position, offset) {
* @return {Boolean} * @return {Boolean}
*/ */
export const isScrolledIntoView = (el, parent, direction = 1) => { export const isScrolledIntoView = (el, parent, direction = 1) => {
if(!el) return; if (!el) return;
let isVisible; let isVisible;
if(direction > 0) { if (direction > 0) {
// In view from bottom // In view from bottom
isVisible = (parent.scrollTop + parent.offsetHeight) >= (el.offsetTop + el.offsetHeight) ; isVisible = (parent.scrollTop + parent.offsetHeight) >= (el.offsetTop + el.offsetHeight);
} else { } else {
// In view from top // In view from top
isVisible = el.offsetTop >= parent.scrollTop; isVisible = el.offsetTop >= parent.scrollTop;
@ -442,7 +441,7 @@ export const getWidthOfInput = (input) => {
const value = input.value || input.placeholder; const value = input.value || input.placeholder;
let width = input.offsetWidth; let width = input.offsetWidth;
if(value) { if (value) {
const testEl = strToEl(`<span>${ value }</span>`); const testEl = strToEl(`<span>${ value }</span>`);
testEl.style.position = 'absolute'; testEl.style.position = 'absolute';
testEl.style.padding = '0'; testEl.style.padding = '0';
@ -453,7 +452,7 @@ export const getWidthOfInput = (input) => {
document.body.appendChild(testEl); document.body.appendChild(testEl);
if(value && testEl.offsetWidth !== input.offsetWidth) { if (value && testEl.offsetWidth !== input.offsetWidth) {
width = testEl.offsetWidth + 4; width = testEl.offsetWidth + 4;
} }

View file

@ -4,8 +4,8 @@ import rootReducer from './../reducers/index.js';
export default class Store { export default class Store {
constructor() { constructor() {
this.store = createStore( this.store = createStore(
rootReducer, rootReducer
window.devToolsExtension ? window.devToolsExtension() : undefined , window.devToolsExtension ? window.devToolsExtension() : undefined
); );
} }