Merge pull request #128 from kostkobv/custom-templates-fix

Custom templates fix
This commit is contained in:
Josh Johnson 2017-03-13 10:01:38 +00:00 committed by GitHub
commit 27b907ae19
5 changed files with 59 additions and 19 deletions

View file

@ -777,7 +777,7 @@ return /******/ (function(modules) { // webpackBootstrap
this.input.focus();
}
(0, _utils.triggerEvent)(this.passedElement, "showDropdown", {});
(0, _utils.triggerEvent)(this.passedElement, 'showDropdown', {});
return this;
}
@ -809,7 +809,7 @@ return /******/ (function(modules) { // webpackBootstrap
this.input.blur();
}
(0, _utils.triggerEvent)(this.passedElement, "hideDropdown", {});
(0, _utils.triggerEvent)(this.passedElement, 'hideDropdown', {});
return this;
}
@ -1811,11 +1811,12 @@ return /******/ (function(modules) { // webpackBootstrap
if (this.containerOuter.contains(target) && target !== this.input) {
var activeItems = this.store.getItemsFilteredByActive();
var hasShiftKey = e.shiftKey;
var foundTarget = void 0;
if (target.hasAttribute('data-item')) {
this._handleItemAction(activeItems, target, hasShiftKey);
} else if (target.hasAttribute('data-choice')) {
this._handleChoiceAction(activeItems, target);
if (foundTarget = (0, _utils.findAncestorByAttr)(target, 'data-item')) {
this._handleItemAction(activeItems, foundTarget, hasShiftKey);
} else if (foundTarget = (0, _utils.findAncestorByAttr)(target, 'data-choice')) {
this._handleChoiceAction(activeItems, foundTarget);
}
e.preventDefault();
@ -2670,10 +2671,7 @@ return /******/ (function(modules) { // webpackBootstrap
* @param {!Object<string, *>} options
*/
function Fuse (list, options) {
var i
var len
var key
var keys
this.list = list
this.options = options = options || {}
@ -2692,7 +2690,7 @@ return /******/ (function(modules) { // webpackBootstrap
}
}
Fuse.VERSION = '2.6.0'
Fuse.VERSION = '2.6.2'
/**
* Sets a new list for Fuse to match against.
@ -5290,6 +5288,26 @@ return /******/ (function(modules) { // webpackBootstrap
return el;
};
/**
* Find ancestor in DOM tree by attribute name
* @param {NodeElement} el Element to start search from
* @param {string} attr Attribute name of parent
* @return {?NodeElement} Found parent element or null
*/
var findAncestorByAttr = exports.findAncestorByAttr = function findAncestorByAttr(el, attr) {
var target = el;
while (target) {
if (target.hasAttribute(attr)) {
return target;
}
target = target.parentElement;
}
return null;
};
/**
* Debounce an event handler.
* @param {Function} func Function to run after wait

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -25,6 +25,7 @@ import {
sortByAlpha,
sortByScore,
triggerEvent,
findAncestorByAttrName
}
from './lib/utils.js';
import './lib/polyfills.js';
@ -653,7 +654,7 @@ class Choices {
this.input.focus();
}
triggerEvent(this.passedElement, "showDropdown", {});
triggerEvent(this.passedElement, 'showDropdown', {});
return this;
}
@ -680,7 +681,7 @@ class Choices {
this.input.blur();
}
triggerEvent(this.passedElement, "hideDropdown", {});
triggerEvent(this.passedElement, 'hideDropdown', {});
return this;
}
@ -1575,13 +1576,14 @@ class Choices {
_onMouseDown(e) {
const target = e.target;
if (this.containerOuter.contains(target) && target !== this.input) {
let foundTarget;
const activeItems = this.store.getItemsFilteredByActive();
const hasShiftKey = e.shiftKey;
if (target.hasAttribute('data-item')) {
this._handleItemAction(activeItems, target, hasShiftKey);
} else if (target.hasAttribute('data-choice')) {
this._handleChoiceAction(activeItems, target);
if (foundTarget = findAncestorByAttrName(target, 'data-item')) {
this._handleItemAction(activeItems, foundTarget, hasShiftKey);
} else if (foundTarget = findAncestorByAttrName(target, 'data-choice')) {
this._handleChoiceAction(activeItems, foundTarget);
}
e.preventDefault();

View file

@ -258,6 +258,26 @@ export const findAncestor = function(el, cls) {
return el;
};
/**
* Find ancestor in DOM tree by attribute name
* @param {NodeElement} el Element to start search from
* @param {string} attr Attribute name of parent
* @return {?NodeElement} Found parent element or null
*/
export const findAncestorByAttrName = function(el, attr) {
let target = el;
while (target) {
if (target.hasAttribute(attr)) {
return target;
}
target = target.parentElement;
}
return null;
};
/**
* Debounce an event handler.
* @param {Function} func Function to run after wait