IE11 flag

This commit is contained in:
Josh Johnson 2017-08-01 16:55:38 +01:00
parent 153cd1bc56
commit cf3c2e67dd
4 changed files with 147 additions and 50 deletions

View file

@ -218,6 +218,7 @@ return /******/ (function(modules) { // webpackBootstrap
this.isSelectMultipleElement = this.passedElement.type === 'select-multiple';
this.isSelectElement = this.isSelectOneElement || this.isSelectMultipleElement;
this.isValidElementType = this.isTextElement || this.isSelectElement;
this.isIe11 = !!(navigator.userAgent.match(/Trident/) && navigator.userAgent.match(/rv[ :]11/));
if (!this.passedElement) {
if (!this.config.silent) {
@ -1603,6 +1604,10 @@ return /******/ (function(modules) { // webpackBootstrap
document.addEventListener('mousedown', this._onMouseDown);
document.addEventListener('mouseover', this._onMouseOver);
if (this.isIe11) {
document.addEventListener('focus', this._onDocumentFocus);
}
if (this.isSelectOneElement) {
this.containerOuter.addEventListener('focus', this._onFocus);
this.containerOuter.addEventListener('blur', this._onBlur);
@ -1631,6 +1636,10 @@ return /******/ (function(modules) { // webpackBootstrap
document.removeEventListener('mousedown', this._onMouseDown);
document.removeEventListener('mouseover', this._onMouseOver);
if (this.isIe11) {
document.removeEventListener('focus', this._onDocumentFocus);
}
if (this.isSelectOneElement) {
this.containerOuter.removeEventListener('focus', this._onFocus);
this.containerOuter.removeEventListener('blur', this._onBlur);
@ -2050,6 +2059,48 @@ return /******/ (function(modules) { // webpackBootstrap
}
}
/**
* Focus event on everything in the document
* @param {Object} e Event
* @return
* @private
*/
}, {
key: '_onDocumentFocus',
value: function _onDocumentFocus(e) {
var _this17 = this;
var target = e.target;
var hasActiveDropdown = this.dropdown.classList.contains(this.config.classNames.activeState);
var blurActions = {
text: function text() {
if (target !== _this17.input) {
if (hasActiveDropdown) {
_this17.hideDropdown();
}
}
},
'select-one': function selectOne() {
if (target !== _this17.containerOuter) {
if (hasActiveDropdown && !_this17.canSearch) {
_this17.hideDropdown();
}
}
},
'select-multiple': function selectMultiple() {
if (target !== _this17.input) {
if (hasActiveDropdown) {
_this17.hideDropdown();
}
}
}
};
blurActions[this.passedElement.type]();
}
/**
* Paste event
* @param {Object} e Event
@ -2076,7 +2127,7 @@ return /******/ (function(modules) { // webpackBootstrap
}, {
key: '_onFocus',
value: function _onFocus(e) {
var _this17 = this;
var _this18 = this;
var target = e.target;
// If target is something that concerns us
@ -2084,27 +2135,27 @@ return /******/ (function(modules) { // webpackBootstrap
var hasActiveDropdown = this.dropdown.classList.contains(this.config.classNames.activeState);
var focusActions = {
text: function text() {
if (target === _this17.input) {
_this17.containerOuter.classList.add(_this17.config.classNames.focusState);
if (target === _this18.input) {
_this18.containerOuter.classList.add(_this18.config.classNames.focusState);
}
},
'select-one': function selectOne() {
_this17.containerOuter.classList.add(_this17.config.classNames.focusState);
if (target === _this17.input) {
_this18.containerOuter.classList.add(_this18.config.classNames.focusState);
if (target === _this18.input) {
// Show dropdown if it isn't already showing
if (!hasActiveDropdown) {
_this17.showDropdown();
_this18.showDropdown();
}
}
},
'select-multiple': function selectMultiple() {
if (target === _this17.input) {
if (target === _this18.input) {
// If element is a select box, the focused element is the container and the dropdown
// isn't already open, focus and show dropdown
_this17.containerOuter.classList.add(_this17.config.classNames.focusState);
_this18.containerOuter.classList.add(_this18.config.classNames.focusState);
if (!hasActiveDropdown) {
_this17.showDropdown(true);
_this18.showDropdown(true);
}
}
}
@ -2124,7 +2175,7 @@ return /******/ (function(modules) { // webpackBootstrap
}, {
key: '_onBlur',
value: function _onBlur(e) {
var _this18 = this;
var _this19 = this;
var target = e.target;
// If target is something that concerns us
@ -2136,43 +2187,43 @@ return /******/ (function(modules) { // webpackBootstrap
});
var blurActions = {
text: function text() {
if (target === _this18.input) {
if (target === _this19.input) {
// Remove the focus state
_this18.containerOuter.classList.remove(_this18.config.classNames.focusState);
_this19.containerOuter.classList.remove(_this19.config.classNames.focusState);
// De-select any highlighted items
if (hasHighlightedItems) {
_this18.unhighlightAll();
_this19.unhighlightAll();
}
// Hide dropdown if it is showing
if (hasActiveDropdown) {
_this18.hideDropdown();
_this19.hideDropdown();
}
}
},
'select-one': function selectOne() {
_this18.containerOuter.classList.remove(_this18.config.classNames.focusState);
if (target === _this18.containerOuter) {
_this19.containerOuter.classList.remove(_this19.config.classNames.focusState);
if (target === _this19.containerOuter) {
// Hide dropdown if it is showing
if (hasActiveDropdown && !_this18.canSearch) {
_this18.hideDropdown();
if (hasActiveDropdown && !_this19.canSearch) {
_this19.hideDropdown();
}
}
if (target === _this18.input && hasActiveDropdown) {
if (target === _this19.input && hasActiveDropdown) {
// Hide dropdown if it is showing
_this18.hideDropdown();
_this19.hideDropdown();
}
},
'select-multiple': function selectMultiple() {
if (target === _this18.input) {
if (target === _this19.input) {
// Remove the focus state
_this18.containerOuter.classList.remove(_this18.config.classNames.focusState);
_this19.containerOuter.classList.remove(_this19.config.classNames.focusState);
// Hide dropdown if it is showing
if (hasActiveDropdown) {
_this18.hideDropdown();
_this19.hideDropdown();
}
// De-select any highlighted items
if (hasHighlightedItems) {
_this18.unhighlightAll();
_this19.unhighlightAll();
}
}
}
@ -2212,7 +2263,7 @@ return /******/ (function(modules) { // webpackBootstrap
}, {
key: '_scrollToChoice',
value: function _scrollToChoice(choice, direction) {
var _this19 = this;
var _this20 = this;
if (!choice) {
return;
@ -2229,7 +2280,7 @@ return /******/ (function(modules) { // webpackBootstrap
var animateScroll = function animateScroll() {
var strength = 4;
var choiceListScrollTop = _this19.choiceList.scrollTop;
var choiceListScrollTop = _this20.choiceList.scrollTop;
var continueAnimation = false;
var easing = void 0;
var distance = void 0;
@ -2238,7 +2289,7 @@ return /******/ (function(modules) { // webpackBootstrap
easing = (endPoint - choiceListScrollTop) / strength;
distance = easing > 1 ? easing : 1;
_this19.choiceList.scrollTop = choiceListScrollTop + distance;
_this20.choiceList.scrollTop = choiceListScrollTop + distance;
if (choiceListScrollTop < endPoint) {
continueAnimation = true;
}
@ -2246,7 +2297,7 @@ return /******/ (function(modules) { // webpackBootstrap
easing = (choiceListScrollTop - endPoint) / strength;
distance = easing > 1 ? easing : 1;
_this19.choiceList.scrollTop = choiceListScrollTop - distance;
_this20.choiceList.scrollTop = choiceListScrollTop - distance;
if (choiceListScrollTop > endPoint) {
continueAnimation = true;
}
@ -2274,7 +2325,7 @@ return /******/ (function(modules) { // webpackBootstrap
}, {
key: '_highlightChoice',
value: function _highlightChoice() {
var _this20 = this;
var _this21 = this;
var el = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
@ -2287,7 +2338,7 @@ return /******/ (function(modules) { // webpackBootstrap
// Remove any highlighted choices
highlightedChoices.forEach(function (choice) {
choice.classList.remove(_this20.config.classNames.highlightedState);
choice.classList.remove(_this21.config.classNames.highlightedState);
choice.setAttribute('aria-selected', 'false');
});
@ -2490,7 +2541,7 @@ return /******/ (function(modules) { // webpackBootstrap
}, {
key: '_addGroup',
value: function _addGroup(group, id) {
var _this21 = this;
var _this22 = this;
var valueKey = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'value';
var labelKey = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'label';
@ -2506,7 +2557,7 @@ return /******/ (function(modules) { // webpackBootstrap
var isOptDisabled = option.disabled || option.parentNode && option.parentNode.disabled;
var label = (0, _utils.isType)('Object', option) ? option[labelKey] : option.innerHTML;
_this21._addChoice(option[valueKey], label, option.selected, isOptDisabled, groupId, option.customProperties);
_this22._addChoice(option[valueKey], label, option.selected, isOptDisabled, groupId, option.customProperties);
});
} else {
this.store.dispatch((0, _index3.addGroup)(group.label, group.id, false, group.disabled));
@ -2545,12 +2596,12 @@ return /******/ (function(modules) { // webpackBootstrap
}, {
key: '_createTemplates',
value: function _createTemplates() {
var _this22 = this;
var _this23 = this;
var globalClasses = this.config.classNames;
var templates = {
containerOuter: function containerOuter(direction) {
return (0, _utils.strToEl)('\n <div\n class="' + globalClasses.containerOuter + '"\n ' + (_this22.isSelectElement ? _this22.config.searchEnabled ? 'role="combobox" aria-autocomplete="list"' : 'role="listbox"' : '') + '\n data-type="' + _this22.passedElement.type + '"\n ' + (_this22.isSelectOneElement ? 'tabindex="0"' : '') + '\n aria-haspopup="true"\n aria-expanded="false"\n dir="' + direction + '"\n >\n </div>\n ');
return (0, _utils.strToEl)('\n <div\n class="' + globalClasses.containerOuter + '"\n ' + (_this23.isSelectElement ? _this23.config.searchEnabled ? 'role="combobox" aria-autocomplete="list"' : 'role="listbox"' : '') + '\n data-type="' + _this23.passedElement.type + '"\n ' + (_this23.isSelectOneElement ? 'tabindex="0"' : '') + '\n aria-haspopup="true"\n aria-expanded="false"\n dir="' + direction + '"\n >\n </div>\n ');
},
containerInner: function containerInner() {
return (0, _utils.strToEl)('\n <div class="' + globalClasses.containerInner + '"></div>\n ');
@ -2558,7 +2609,7 @@ return /******/ (function(modules) { // webpackBootstrap
itemList: function itemList() {
var _classNames;
var localClasses = (0, _classnames2.default)(globalClasses.list, (_classNames = {}, _defineProperty(_classNames, globalClasses.listSingle, _this22.isSelectOneElement), _defineProperty(_classNames, globalClasses.listItems, !_this22.isSelectOneElement), _classNames));
var localClasses = (0, _classnames2.default)(globalClasses.list, (_classNames = {}, _defineProperty(_classNames, globalClasses.listSingle, _this23.isSelectOneElement), _defineProperty(_classNames, globalClasses.listItems, !_this23.isSelectOneElement), _classNames));
return (0, _utils.strToEl)('\n <div class="' + localClasses + '"></div>\n ');
},
@ -2570,7 +2621,7 @@ return /******/ (function(modules) { // webpackBootstrap
var localClasses = (0, _classnames2.default)(globalClasses.item, (_classNames2 = {}, _defineProperty(_classNames2, globalClasses.highlightedState, data.highlighted), _defineProperty(_classNames2, globalClasses.itemSelectable, !data.highlighted), _classNames2));
if (_this22.config.removeItemButton) {
if (_this23.config.removeItemButton) {
var _classNames3;
localClasses = (0, _classnames2.default)(globalClasses.item, (_classNames3 = {}, _defineProperty(_classNames3, globalClasses.highlightedState, data.highlighted), _defineProperty(_classNames3, globalClasses.itemSelectable, !data.disabled), _classNames3));
@ -2581,7 +2632,7 @@ return /******/ (function(modules) { // webpackBootstrap
return (0, _utils.strToEl)('\n <div\n class="' + localClasses + '"\n data-item\n data-id="' + data.id + '"\n data-value="' + data.value + '"\n ' + (data.active ? 'aria-selected="true"' : '') + '\n ' + (data.disabled ? 'aria-disabled="true"' : '') + '\n >\n ' + data.label + '\n </div>\n ');
},
choiceList: function choiceList() {
return (0, _utils.strToEl)('\n <div\n class="' + globalClasses.list + '"\n dir="ltr"\n role="listbox"\n ' + (!_this22.isSelectOneElement ? 'aria-multiselectable="true"' : '') + '\n >\n </div>\n ');
return (0, _utils.strToEl)('\n <div\n class="' + globalClasses.list + '"\n dir="ltr"\n role="listbox"\n ' + (!_this23.isSelectOneElement ? 'aria-multiselectable="true"' : '') + '\n >\n </div>\n ');
},
choiceGroup: function choiceGroup(data) {
var localClasses = (0, _classnames2.default)(globalClasses.group, _defineProperty({}, globalClasses.itemDisabled, data.disabled));
@ -2593,7 +2644,7 @@ return /******/ (function(modules) { // webpackBootstrap
var localClasses = (0, _classnames2.default)(globalClasses.item, globalClasses.itemChoice, (_classNames5 = {}, _defineProperty(_classNames5, globalClasses.itemDisabled, data.disabled), _defineProperty(_classNames5, globalClasses.itemSelectable, !data.disabled), _classNames5));
return (0, _utils.strToEl)('\n <div\n class="' + localClasses + '"\n data-select-text="' + _this22.config.itemSelectText + '"\n data-choice\n data-id="' + data.id + '"\n data-value="' + data.value + '"\n ' + (data.disabled ? 'data-choice-disabled aria-disabled="true"' : 'data-choice-selectable') + '\n id="' + data.elementId + '"\n ' + (data.groupId > 0 ? 'role="treeitem"' : 'role="option"') + '\n >\n ' + data.label + '\n </div>\n ');
return (0, _utils.strToEl)('\n <div\n class="' + localClasses + '"\n data-select-text="' + _this23.config.itemSelectText + '"\n data-choice\n data-id="' + data.id + '"\n data-value="' + data.value + '"\n ' + (data.disabled ? 'data-choice-disabled aria-disabled="true"' : 'data-choice-selectable') + '\n id="' + data.elementId + '"\n ' + (data.groupId > 0 ? 'role="treeitem"' : 'role="option"') + '\n >\n ' + data.label + '\n </div>\n ');
},
input: function input() {
var localClasses = (0, _classnames2.default)(globalClasses.input, globalClasses.inputCloned);
@ -2634,7 +2685,7 @@ return /******/ (function(modules) { // webpackBootstrap
}, {
key: '_createInput',
value: function _createInput() {
var _this23 = this;
var _this24 = this;
var direction = this.passedElement.getAttribute('dir') || 'ltr';
var containerOuter = this._getTemplate('containerOuter', direction);
@ -2709,7 +2760,7 @@ return /******/ (function(modules) { // webpackBootstrap
if (passedGroups && passedGroups.length) {
passedGroups.forEach(function (group) {
_this23._addGroup(group, group.id || null);
_this24._addGroup(group, group.id || null);
});
} else {
var passedOptions = Array.from(this.passedElement.options);
@ -2739,17 +2790,17 @@ return /******/ (function(modules) { // webpackBootstrap
// Add each choice
allChoices.forEach(function (choice, index) {
// Pre-select first choice if it's a single select
if (_this23.isSelectOneElement) {
if (_this24.isSelectOneElement) {
if (hasSelectedChoice || !hasSelectedChoice && index > 0) {
// If there is a selected choice already or the choice is not
// the first in the array, add each choice normally
_this23._addChoice(choice.value, choice.label, choice.selected, choice.disabled, undefined, choice.customProperties);
_this24._addChoice(choice.value, choice.label, choice.selected, choice.disabled, undefined, choice.customProperties);
} else {
// Otherwise pre-select the first choice in the array
_this23._addChoice(choice.value, choice.label, true, false, undefined, choice.customProperties);
_this24._addChoice(choice.value, choice.label, true, false, undefined, choice.customProperties);
}
} else {
_this23._addChoice(choice.value, choice.label, choice.selected, choice.disabled, undefined, choice.customProperties);
_this24._addChoice(choice.value, choice.label, choice.selected, choice.disabled, undefined, choice.customProperties);
}
});
}
@ -2761,9 +2812,9 @@ return /******/ (function(modules) { // webpackBootstrap
if (!item.value) {
return;
}
_this23._addItem(item.value, item.label, item.id, undefined, item.customProperties);
_this24._addItem(item.value, item.label, item.id, undefined, item.customProperties);
} else if (itemType === 'String') {
_this23._addItem(item);
_this24._addItem(item);
}
});
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -155,6 +155,7 @@ class Choices {
this.isSelectMultipleElement = this.passedElement.type === 'select-multiple';
this.isSelectElement = this.isSelectOneElement || this.isSelectMultipleElement;
this.isValidElementType = this.isTextElement || this.isSelectElement;
this.isIe11 = !!(navigator.userAgent.match(/Trident/) && navigator.userAgent.match(/rv[ :]11/));
if (!this.passedElement) {
if (!this.config.silent) {
@ -1476,6 +1477,10 @@ class Choices {
document.addEventListener('mousedown', this._onMouseDown);
document.addEventListener('mouseover', this._onMouseOver);
if (this.isIe11) {
document.addEventListener('focus', this._onDocumentFocus);
}
if (this.isSelectOneElement) {
this.containerOuter.addEventListener('focus', this._onFocus);
this.containerOuter.addEventListener('blur', this._onBlur);
@ -1501,6 +1506,10 @@ class Choices {
document.removeEventListener('mousedown', this._onMouseDown);
document.removeEventListener('mouseover', this._onMouseOver);
if (this.isIe11) {
document.removeEventListener('focus', this._onDocumentFocus);
}
if (this.isSelectOneElement) {
this.containerOuter.removeEventListener('focus', this._onFocus);
this.containerOuter.removeEventListener('blur', this._onBlur);
@ -1904,6 +1913,43 @@ class Choices {
}
}
/**
* Focus event on everything in the document
* @param {Object} e Event
* @return
* @private
*/
_onDocumentFocus (e) {
const target = e.target;
const hasActiveDropdown = this.dropdown.classList.contains(this.config.classNames.activeState);
const blurActions = {
text: () => {
if (target !== this.input) {
if (hasActiveDropdown) {
this.hideDropdown();
}
}
},
'select-one': () => {
if (target !== this.containerOuter) {
if (hasActiveDropdown && !this.canSearch) {
this.hideDropdown();
}
}
},
'select-multiple': () => {
if (target !== this.input) {
if (hasActiveDropdown) {
this.hideDropdown();
}
}
},
};
blurActions[this.passedElement.type]();
}
/**
* Paste event
* @param {Object} e Event