From 9ac62aec310cf31be81774669f0eda34e5b9ae41 Mon Sep 17 00:00:00 2001 From: Josh Johnson Date: Tue, 29 May 2018 20:08:05 +0100 Subject: [PATCH] Codebeat fixes --- README.md | 6 +----- src/scripts/choices.js | 43 +++++++++++++++--------------------------- 2 files changed, 16 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index ec11665..761223c 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,8 @@ -# Choices.js ![Build Status](https://travis-ci.org/jshjohnson/Choices.svg?branch=master) [![CDNJS](https://img.shields.io/cdnjs/v/choices.js.svg)](https://cdnjs.com/libraries/choices.js) [![npm](https://img.shields.io/npm/v/choices.js.svg)](https://www.npmjs.com/package/choices.js) +# Choices.js ![Build Status](https://travis-ci.org/jshjohnson/Choices.svg?branch=master) [![CDNJS](https://img.shields.io/cdnjs/v/choices.js.svg)](https://cdnjs.com/libraries/choices.js) [![npm](https://img.shields.io/npm/v/choices.js.svg)](https://www.npmjs.com/package/choices.js) [![codebeat badge](https://codebeat.co/badges/07c7b2d9-d5aa-4772-9fbb-a153e62d0f81)](https://codebeat.co/projects/github-com-jshjohnson-choices-develop) A vanilla, lightweight (~20kb gzipped 🎉), configurable select box/text input plugin. Similar to Select2 and Selectize but without the jQuery dependency. [Demo](https://joshuajohnson.co.uk/Choices/) ---- -### 👉 Please use [develop](https://github.com/jshjohnson/Choices/tree/develop) as the base branch for pull requests 👈 ---- - ## TL;DR * Lightweight * No jQuery dependency diff --git a/src/scripts/choices.js b/src/scripts/choices.js index 91ce846..d0e76a1 100644 --- a/src/scripts/choices.js +++ b/src/scripts/choices.js @@ -117,6 +117,7 @@ class Choices { this._wasTap = true; this._placeholderValue = this._generatePlaceholderValue(); this._baseId = generateId(this.passedElement.element, 'choices-'); + this._direction = this.passedElement.element.getAttribute('dir') || 'ltr'; this._idNames = { itemChoice: 'item-choice', }; @@ -1658,54 +1659,43 @@ class Choices { } _createElements() { - const direction = this.passedElement.element.getAttribute('dir') || 'ltr'; - const containerOuter = this._getTemplate( - 'containerOuter', - direction, - this._isSelectElement, - this._isSelectOneElement, - this.config.searchEnabled, - this.passedElement.element.type, - ); - const containerInner = this._getTemplate('containerInner'); - const itemList = this._getTemplate('itemList', this._isSelectOneElement); - const choiceList = this._getTemplate( - 'choiceList', - this._isSelectOneElement, - ); - const input = this._getTemplate('input'); - const dropdown = this._getTemplate('dropdown'); - this.containerOuter = new Container({ - element: containerOuter, + element: this._getTemplate( + 'containerOuter', + this._direction, + this._isSelectElement, + this._isSelectOneElement, + this.config.searchEnabled, + this.passedElement.element.type, + ), classNames: this.config.classNames, type: this.passedElement.element.type, position: this.config.position, }); this.containerInner = new Container({ - element: containerInner, + element: this._getTemplate('containerInner'), classNames: this.config.classNames, type: this.passedElement.element.type, position: this.config.position, }); this.input = new Input({ - element: input, + element: this._getTemplate('input'), classNames: this.config.classNames, type: this.passedElement.element.type, }); this.choiceList = new List({ - element: choiceList, + element: this._getTemplate('choiceList', this._isSelectOneElement), }); this.itemList = new List({ - element: itemList, + element: this._getTemplate('itemList', this._isSelectOneElement), }); this.dropdown = new Dropdown({ - element: dropdown, + element: this._getTemplate('dropdown'), classNames: this.config.classNames, type: this.passedElement.element.type, }); @@ -1853,10 +1843,7 @@ class Choices { _addPredefinedItems() { const handlePresetItem = item => { const itemType = getType(item); - if (itemType === 'Object') { - if (!item.value) { - return; - } + if (itemType === 'Object' && item.value) { this._addItem({ value: item.value, label: item.label,