mirror of
https://github.com/Choices-js/Choices.git
synced 2024-04-26 11:20:33 +02:00
Move to 2 space indentation + editorconfig
This commit is contained in:
parent
9bb9e0b4c2
commit
d40841d8dd
9
.editorconfig
Normal file
9
.editorconfig
Normal file
|
@ -0,0 +1,9 @@
|
|||
|
||||
root = true
|
||||
|
||||
[*]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
|
@ -10,7 +10,7 @@
|
|||
"rules": {
|
||||
"quotes": [2, "single"],
|
||||
"strict": [2, "never"],
|
||||
"indent": ["error", 4, {"SwitchCase": 1}],
|
||||
"indent": ["error", 2, {"SwitchCase": 1}],
|
||||
"eol-last": "off",
|
||||
"arrow-body-style": "off",
|
||||
"no-underscore-dangle": "off",
|
||||
|
|
|
@ -9,7 +9,8 @@ import {
|
|||
activateChoices,
|
||||
addGroup,
|
||||
clearAll,
|
||||
} from './actions/index';
|
||||
}
|
||||
from './actions/index';
|
||||
import {
|
||||
isScrolledIntoView,
|
||||
getAdjacentEl,
|
||||
|
@ -21,14 +22,16 @@ import {
|
|||
getWidthOfInput,
|
||||
sortByAlpha,
|
||||
sortByScore,
|
||||
} from './lib/utils.js';
|
||||
}
|
||||
from './lib/utils.js';
|
||||
import './lib/polyfills.js';
|
||||
|
||||
|
||||
/**
|
||||
* Choices
|
||||
*/
|
||||
export default class Choices {
|
||||
export
|
||||
default class Choices {
|
||||
constructor(element = '[data-choice]', userConfig = {}) {
|
||||
// If there are multiple elements, create a new 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._triggerChange(lastItem.value);
|
||||
} else {
|
||||
if (!hasHighlightedItems) { this.highlightItem(lastItem); }
|
||||
if (!hasHighlightedItems) {
|
||||
this.highlightItem(lastItem);
|
||||
}
|
||||
this.removeHighlightedItems();
|
||||
}
|
||||
}
|
||||
|
@ -2045,7 +2050,9 @@ export default class Choices {
|
|||
this._highlightChoice();
|
||||
} else {
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
/* eslint-disable */
|
||||
|
||||
// Production steps of ECMA-262, Edition 6, 22.1.2.1
|
||||
// Reference: https://people.mozilla.org/~jorendorff/es6-draft.html#sec-array.from
|
||||
if (!Array.from) {
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
/* eslint-disable */
|
||||
|
||||
/**
|
||||
* Capitalises the first letter of each word in a string
|
||||
* @param {String} str String to capitalise
|
||||
* @return {String} Capitalised string
|
||||
*/
|
||||
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();
|
||||
});
|
||||
};
|
||||
|
@ -30,7 +29,7 @@ export const isType = function(type, obj) {
|
|||
export const isNode = (o) => {
|
||||
return (
|
||||
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) => {
|
||||
return (
|
||||
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
|
||||
* @param {Object} obj Object to merge into extended object
|
||||
*/
|
||||
let merge = function (obj) {
|
||||
let merge = function(obj) {
|
||||
for (let prop in obj) {
|
||||
if (Object.prototype.hasOwnProperty.call(obj, prop)) {
|
||||
// If deep merge and property is an object, merge properties
|
||||
if (deep && isType('Object', obj[prop])) {
|
||||
extended[prop] = extend( true, extended[prop], obj[prop]);
|
||||
extended[prop] = extend(true, extended[prop], obj[prop]);
|
||||
} else {
|
||||
extended[prop] = obj[prop];
|
||||
}
|
||||
|
@ -93,19 +92,19 @@ export const extend = function() {
|
|||
* CSS transition end event listener
|
||||
* @return
|
||||
*/
|
||||
export const whichTransitionEvent = function(){
|
||||
export const whichTransitionEvent = function() {
|
||||
var t,
|
||||
el = document.createElement("fakeelement");
|
||||
|
||||
var transitions = {
|
||||
"transition" : "transitionend",
|
||||
"OTransition" : "oTransitionEnd",
|
||||
"MozTransition" : "transitionend",
|
||||
"transition": "transitionend",
|
||||
"OTransition": "oTransitionEnd",
|
||||
"MozTransition": "transitionend",
|
||||
"WebkitTransition": "webkitTransitionEnd"
|
||||
}
|
||||
|
||||
for (t in transitions){
|
||||
if (el.style[t] !== undefined){
|
||||
for (t in transitions) {
|
||||
if (el.style[t] !== undefined) {
|
||||
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');
|
||||
if (element.nextSibling) {
|
||||
element.parentNode.insertBefore(wrapper, element.nextSibling);
|
||||
|
@ -230,12 +229,12 @@ export const wrap = function (element, wrapper) {
|
|||
return wrapper.appendChild(element);
|
||||
};
|
||||
|
||||
export const getSiblings = function (elem) {
|
||||
export const getSiblings = function(elem) {
|
||||
var siblings = [];
|
||||
var sibling = elem.parentNode.firstChild;
|
||||
for ( ; sibling; sibling = sibling.nextSibling ) {
|
||||
if ( sibling.nodeType === 1 && sibling !== elem ) {
|
||||
siblings.push( sibling );
|
||||
for (; sibling; sibling = sibling.nextSibling) {
|
||||
if (sibling.nodeType === 1 && sibling !== elem) {
|
||||
siblings.push(sibling);
|
||||
}
|
||||
}
|
||||
return siblings;
|
||||
|
@ -300,10 +299,10 @@ export const getElemDistance = function(el) {
|
|||
*/
|
||||
export const getElementOffset = function(el, offset) {
|
||||
var elOffset = offset;
|
||||
if(elOffset > 1) elOffset = 1;
|
||||
if(elOffset > 0) elOffset = 0;
|
||||
if (elOffset > 1) elOffset = 1;
|
||||
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
|
||||
*/
|
||||
export const getAdjacentEl = (startEl, className, direction = 1) => {
|
||||
if(!startEl || !className) return;
|
||||
if (!startEl || !className) return;
|
||||
|
||||
const parent = startEl.parentNode.parentNode;
|
||||
const children = Array.from(parent.querySelectorAll(className));
|
||||
|
@ -331,7 +330,7 @@ export const getAdjacentEl = (startEl, className, direction = 1) => {
|
|||
* @return {String} Position of scroll
|
||||
*/
|
||||
export const getScrollPosition = function(position) {
|
||||
if(position === 'bottom') {
|
||||
if (position === 'bottom') {
|
||||
// Scroll position from the bottom of the viewport
|
||||
return Math.max((window.scrollY || window.pageYOffset) + (window.innerHeight || document.documentElement.clientHeight));
|
||||
} else {
|
||||
|
@ -359,13 +358,13 @@ export const isInView = function(el, position, offset) {
|
|||
* @return {Boolean}
|
||||
*/
|
||||
export const isScrolledIntoView = (el, parent, direction = 1) => {
|
||||
if(!el) return;
|
||||
if (!el) return;
|
||||
|
||||
let isVisible;
|
||||
|
||||
if(direction > 0) {
|
||||
if (direction > 0) {
|
||||
// In view from bottom
|
||||
isVisible = (parent.scrollTop + parent.offsetHeight) >= (el.offsetTop + el.offsetHeight) ;
|
||||
isVisible = (parent.scrollTop + parent.offsetHeight) >= (el.offsetTop + el.offsetHeight);
|
||||
} else {
|
||||
// In view from top
|
||||
isVisible = el.offsetTop >= parent.scrollTop;
|
||||
|
@ -442,7 +441,7 @@ export const getWidthOfInput = (input) => {
|
|||
const value = input.value || input.placeholder;
|
||||
let width = input.offsetWidth;
|
||||
|
||||
if(value) {
|
||||
if (value) {
|
||||
const testEl = strToEl(`<span>${ value }</span>`);
|
||||
testEl.style.position = 'absolute';
|
||||
testEl.style.padding = '0';
|
||||
|
@ -453,7 +452,7 @@ export const getWidthOfInput = (input) => {
|
|||
|
||||
document.body.appendChild(testEl);
|
||||
|
||||
if(value && testEl.offsetWidth !== input.offsetWidth) {
|
||||
if (value && testEl.offsetWidth !== input.offsetWidth) {
|
||||
width = testEl.offsetWidth + 4;
|
||||
}
|
||||
|
||||
|
|
|
@ -4,8 +4,8 @@ import rootReducer from './../reducers/index.js';
|
|||
export default class Store {
|
||||
constructor() {
|
||||
this.store = createStore(
|
||||
rootReducer,
|
||||
window.devToolsExtension ? window.devToolsExtension() : undefined
|
||||
rootReducer
|
||||
, window.devToolsExtension ? window.devToolsExtension() : undefined
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue