New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

immybox

Package Overview
Dependencies
Maintainers
2
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

immybox - npm Package Compare versions

Comparing version 1.0.0-beta1 to 1.0.0-beta2

src/immybox.scss

2

bower.json
{
"name": "immybox",
"description": "An autocomplete-like jQuery plugin",
"version": "1.0.0-beta1",
"version": "1.0.0-beta2",
"private": false,

@@ -6,0 +6,0 @@ "license": "MIT",

/*!
* Immybox.js Version 1.0.0-beta1
* Immybox.js Version 1.0.0-beta2
*

@@ -50,2 +50,26 @@ */

/******/
/******/ // identity function for calling harmory imports with the correct context
/******/ __webpack_require__.i = function(value) { return value; };
/******/
/******/ // define getter function for harmory exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__

@@ -62,7 +86,7 @@ /******/ __webpack_require__.p = "";

module.exports = function _isPlaceholder(a) {
return a != null &&
typeof a === 'object' &&
a['@@functional/placeholder'] === true;
};
module.exports = function _isPlaceholder(a) {
return a != null &&
typeof a === 'object' &&
a['@@functional/placeholder'] === true;
};

@@ -72,92 +96,103 @@

/* 1 */
/***/ function(module, exports, __webpack_require__) {
/***/ function(module, exports) {
/* harmony export */ exports["d"] = assert;/* unused harmony export hasClass *//* harmony export */ exports["a"] = addClass;/* harmony export */ exports["c"] = removeClass;/* harmony export */ exports["b"] = nodeOrParentMatchingSelector;/*eslint no-console:0*/
// Polyfills
Number.isNaN = Number.isNaN || function (value) {
return typeof value === 'number' && isNaN(value);
};
if (!Array.prototype.find) {
Array.prototype.find = function (predicate) {
if (this === null) {
throw new TypeError('Array.prototype.find called on null or undefined');
}
if (typeof predicate !== 'function') {
throw new TypeError('predicate must be a function');
}
var list = Object(this);
var length = list.length >>> 0;
var thisArg = arguments[1];
var value;
for (var i = 0; i < length; i++) {
value = list[i];
if (predicate.call(thisArg, value, i, list)) {
return value;
}
}
return undefined;
};
}
if (!Array.prototype.includes) {
Array.prototype.includes = function (searchElement /*, fromIndex*/) {
'use strict';
var O = Object(this);
var len = parseInt(O.length) || 0;
if (len === 0) {
return false;
}
var n = parseInt(arguments[1]) || 0;
var k;
if (n >= 0) {
k = n;
} else {
k = len + n;
if (k < 0) {
k = 0;
}
}
var currentElement;
while (k < len) {
currentElement = O[k];
if (searchElement === currentElement || searchElement !== searchElement && currentElement !== currentElement) {
return true;
}
k++;
}
return false;
};
}
// Exported utility methods
function assert(bool, message) {
if (!bool) throw new Error(message);
}
function hasClass(element, class_name) {
return !!element.className.match(new RegExp('(\\s|^)' + class_name + '(\\s|$)'));
}
function addClass(element, class_name) {
if (!hasClass(element, class_name)) element.className += ' ' + class_name;
}
function removeClass(element, class_name) {
if (hasClass(element, class_name)) {
var reg = new RegExp('(\\s|^)' + class_name + '(\\s|$)');
element.className = element.className.replace(reg, ' ');
}
}
function parentNodeMatchingSelector(element, selector) {
if (!element.parentNode || !element.parentNode.matches) return null;
if (element.parentNode.matches(selector)) return element.parentNode;
return parentNodeMatchingSelector(element.parentNode, selector);
}
function nodeOrParentMatchingSelector(element, selector) {
if (element.matches && element.matches(selector)) return element;
return parentNodeMatchingSelector(element, selector);
}
"use strict";
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.assert = assert;
exports.hasClass = hasClass;
exports.addClass = addClass;
exports.removeClass = removeClass;
exports.nodeOrParentMatchingSelector = nodeOrParentMatchingSelector;
/*eslint no-console:0*/
// Polyfills
Number.isNaN = Number.isNaN || function (value) {
return typeof value === 'number' && isNaN(value);
};
if (!Array.prototype.find) {
Array.prototype.find = function (predicate) {
if (this === null) {
throw new TypeError('Array.prototype.find called on null or undefined');
}
if (typeof predicate !== 'function') {
throw new TypeError('predicate must be a function');
}
var list = Object(this);
var length = list.length >>> 0;
var thisArg = arguments[1];
var value;
for (var i = 0; i < length; i++) {
value = list[i];
if (predicate.call(thisArg, value, i, list)) {
return value;
}
}
return undefined;
};
}
if (!Array.prototype.includes) {
Array.prototype.includes = function (searchElement /*, fromIndex*/) {
'use strict';
var O = Object(this);
var len = parseInt(O.length) || 0;
if (len === 0) {
return false;
}
var n = parseInt(arguments[1]) || 0;
var k;
if (n >= 0) {
k = n;
} else {
k = len + n;
if (k < 0) {
k = 0;
}
}
var currentElement;
while (k < len) {
currentElement = O[k];
if (searchElement === currentElement || searchElement !== searchElement && currentElement !== currentElement) {
return true;
}
k++;
}
return false;
};
}
// Exported utility methods
function assert(bool, message) {
if (!bool) throw new Error(message);
}
function hasClass(element, class_name) {
return !!element.className.match(new RegExp('(\\s|^)' + class_name + '(\\s|$)'));
}
function addClass(element, class_name) {
if (!hasClass(element, class_name)) element.className += ' ' + class_name;
}
function removeClass(element, class_name) {
if (hasClass(element, class_name)) {
var reg = new RegExp('(\\s|^)' + class_name + '(\\s|$)');
element.className = element.className.replace(reg, ' ');
}
}
function parentNodeMatchingSelector(element, selector) {
if (!element.parentNode || !element.parentNode.matches) return null;
if (element.parentNode.matches(selector)) return element.parentNode;
return parentNodeMatchingSelector(element.parentNode, selector);
}
function nodeOrParentMatchingSelector(element, selector) {
if (element.matches && element.matches(selector)) return element;
return parentNodeMatchingSelector(element, selector);
}
/***/ },

@@ -167,642 +202,676 @@ /* 2 */

/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_ramda_src_forEach__ = __webpack_require__(3);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_ramda_src_forEach___default = __WEBPACK_IMPORTED_MODULE_0_ramda_src_forEach__ && __WEBPACK_IMPORTED_MODULE_0_ramda_src_forEach__.__esModule ? function() { return __WEBPACK_IMPORTED_MODULE_0_ramda_src_forEach__['default'] } : function() { return __WEBPACK_IMPORTED_MODULE_0_ramda_src_forEach__; }
/* harmony import */ Object.defineProperty(__WEBPACK_IMPORTED_MODULE_0_ramda_src_forEach___default, 'a', { get: __WEBPACK_IMPORTED_MODULE_0_ramda_src_forEach___default });
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__utils__ = __webpack_require__(1);
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var event_listeners = new Map();
var defaults = {
choices: [],
maxResults: 50,
showArrow: true,
openOnClick: true,
defaultSelectedValue: undefined,
scroll_behavior: 'smooth',
filterFn: function filterFn(query) {
var lower_query = query.toLowerCase();
return function (choice) {
return choice.text.toLowerCase().indexOf(lower_query) >= 0;
};
},
formatChoice: function formatChoice(query) {
if (query) {
var _ret = function () {
var reg = new RegExp(query.replace(/[#-.]|[[-^]|[?|{}]/g, '\\$&'), 'gi');
return {
v: function v(choice) {
return choice.text.replace(reg, '<span class="highlight">$&</span>');
}
};
}();
if ((typeof _ret === 'undefined' ? 'undefined' : _typeof(_ret)) === "object") return _ret.v;
} else return function (choice) {
return choice.text;
};
}
};
var all_objects = new Map();
var plugin_name = 'immybox';
function assignEvent(event_name, event_handler, node, listeners) {
listeners.has(node) || listeners.set(node, new Map());
listeners.get(node).set(event_name, event_handler);
node.addEventListener(event_name, event_handler);
}
function getEventListenerMap(plugin) {
var map = new Map();
event_listeners.set(plugin, map);
return map;
}
var ImmyBox = function () {
function ImmyBox(element, options) {
var _this = this;
_classCallCheck(this, ImmyBox);
/* harmony import */__WEBPACK_IMPORTED_MODULE_1__utils__["a"].bind()(element, plugin_name);
element.setAttribute('autocomplete', 'off');
var listeners = getEventListenerMap(this);
this.element = element;
this.options = Object.assign({}, ImmyBox.defaults, options);
this.choices = this.options.choices;
if (this.options.defaultSelectedValue != null) this.choices = [this.choices.find(function (_ref) {
var value = _ref.value;
return value === _this.options.defaultSelectedValue;
})].concat(_toConsumableArray(this.choices.filter(function (_ref2) {
var value = _ref2.value;
return value !== _this.options.defaultSelectedValue;
}))).filter(function (choice) {
return choice;
});
this.indexed_choices = this.choices.map(function (choice, index) {
return { index: index, choice: choice };
});
this.selectedChoice = null;
if (this.options.showArrow) /* harmony import */__WEBPACK_IMPORTED_MODULE_1__utils__["a"].bind()(this.element, plugin_name + '_witharrow');
this.selectChoiceByValue(this.element.value);
this.queryResultArea = document.createElement('div');
/* harmony import */__WEBPACK_IMPORTED_MODULE_1__utils__["a"].bind()(this.queryResultArea, plugin_name + '_results');
this.queryResultAreaVisible = false;
this._val = this.element.value;
this.oldQuery = this.element.value;
if (this.options.openOnClick) assignEvent('click', this.openResults.bind(this), this.element, listeners);
assignEvent('click', function (event) {
var node = /* harmony import */__WEBPACK_IMPORTED_MODULE_1__utils__["b"].bind()(event.target, 'li.' + plugin_name + '_choice');
if (node) {
var value = _this.valueFromElement(node);
_this.selectChoiceByValue(value);
_this.hideResults();
_this._val = _this.element.value;
_this.element.focus();
}
}, this.queryResultArea, listeners);
assignEvent('mouseenter', function (event) {
var node = /* harmony import */__WEBPACK_IMPORTED_MODULE_1__utils__["b"].bind()(event.target, 'li.' + plugin_name + '_choice');
if (node) {
/* harmony import */__WEBPACK_IMPORTED_MODULE_1__utils__["a"].bind()(node, 'active');
/* harmony import */__WEBPACK_IMPORTED_MODULE_0_ramda_src_forEach___default.a.bind()(function (li) {
return li !== node && /* harmony import */__WEBPACK_IMPORTED_MODULE_1__utils__["c"].bind()(li, 'active');
}, _this.queryResultArea.querySelectorAll('li.' + plugin_name + '_choice.active'));
}
}, this.queryResultArea, listeners);
assignEvent('keyup', this.doQuery.bind(this), this.element, listeners);
assignEvent('change', this.doQuery.bind(this), this.element, listeners);
assignEvent('search', this.doQuery.bind(this), this.element, listeners);
assignEvent('keydown', this.doSelection.bind(this), this.element, listeners);
all_objects.set(this.element, this);
}
_createClass(ImmyBox, [{
key: 'doQuery',
// on 'keyup', 'change', 'search'
// perform a query on the choices
value: function doQuery() {
var query = this.element.value;
if (this._val !== query) {
this._val = query;
this.oldQuery = query;
if (query) {
this.insertFilteredChoiceElements(query);
} else {
this.hideResults();
this.selectChoiceByValue(null);
}
}
}
// on 'keydown'
// select the highlighted choice
}, {
key: 'doSelection',
value: function doSelection(event) {
if (event.which === 27) {
// escape key
this.display();
this.hideResults();
}
if (this.queryResultAreaVisible) {
switch (event.which) {
case 9:
// tab
this.selectHighlightedChoice();
break;
case 13:
// enter
event.preventDefault();
this.selectHighlightedChoice();
break;
case 38:
// up
event.preventDefault();
this.highlightPreviousChoice();
this.scroll();
break;
case 40:
// down
event.preventDefault();
this.highlightNextChoice();
this.scroll();
break;
}
} else {
switch (event.which) {
case 40:
// down
event.preventDefault();
if (this.selectedChoice) this.insertFilteredChoiceElements(this.oldQuery);else this.insertFilteredChoiceElements('');
break;
case 9:
// tab
this.revert();
break;
}
}
}
// on 'click'
// show the results box
}, {
key: 'openResults',
value: function openResults(event) {
event.cancelBubble = true;
event.stopPropogation && event.stopPropogation();
this.revertOtherInstances();
if (this.selectedChoice) {
this.insertFilteredChoiceElements(this.oldQuery);
} else {
this.insertFilteredChoiceElements('');
}
}
// revert or set to null after losing focus
}, {
key: 'revert',
value: function revert() {
if (this.queryResultAreaVisible) {
this.display();
this.hideResults();
} else if (this.element.value === '') this.selectChoiceByValue(null);
}
// if visible, reposition the results area on window resize
}, {
key: 'reposition',
value: function reposition() {
this.queryResultAreaVisible && this.positionResultsArea();
}
}, {
key: 'insertFilteredChoiceElements',
value: function insertFilteredChoiceElements(query) {
var _this2 = this;
var filteredChoices = undefined;
if (query === '') filteredChoices = this.indexed_choices;else {
(function () {
var filter = _this2.options.filterFn(query);
filteredChoices = _this2.indexed_choices.filter(function (_ref3, index) {
var choice = _ref3.choice;
return filter(choice, index);
});
})();
}
var truncatedChoices = filteredChoices.slice(0, this.options.maxResults);
if (this.defaultSelectedChoice) {
if (filteredChoices.indexOf(this.defaultSelectedChoice) >= 0) {
if (truncatedChoices.indexOf(this.defaultSelectedChoice) === -1) {
truncatedChoices.unshift(this.defaultSelectedChoice);
truncatedChoices.pop();
} else {
truncatedChoices = truncatedChoices.filter(function (c) {
return c.choice.value !== _this2.defaultSelectedChoice.value;
});
truncatedChoices.unshift(this.defaultSelectedChoice);
}
}
}
var formatter = this.options.formatChoice(query);
var selected_one = false;
var list = document.createElement('ul');
var results = truncatedChoices.map(function (_ref4) {
var choice = _ref4.choice;
var index = _ref4.index;
var li = document.createElement('li');
li.setAttribute('class', plugin_name + '_choice');
li.setAttribute('data-immybox-value-index', index);
li.innerHTML = formatter(choice);
if (_this2.selectedChoice && index === _this2.selectedChoice.index) {
selected_one = true;
/* harmony import */__WEBPACK_IMPORTED_MODULE_1__utils__["a"].bind()(li, 'active');
}
list.appendChild(li);
return li;
});
if (results.length) {
!selected_one && /* harmony import */__WEBPACK_IMPORTED_MODULE_1__utils__["a"].bind()(results[0], 'active');
} else {
list = document.createElement('p');
list.setAttribute('class', plugin_name + '_noresults');
list.textContent = 'no matches';
}
while (this.queryResultArea.lastChild) {
this.queryResultArea.removeChild(this.queryResultArea.lastChild);
}
this.queryResultArea.appendChild(list);
this.showResults();
}
}, {
key: 'scroll',
value: function scroll() {
this.highlightedChoice && this.highlightedChoice.scrollIntoView({
behavior: this.options.scroll_behavior
});
}
}, {
key: 'positionResultsArea',
value: function positionResultsArea() {
var input_offset = this.element.getBoundingClientRect();
var input_height = this.element.clientHeight;
var input_width = this.element.clientWidth;
var results_height = this.queryResultArea.clientHeight;
var results_bottom = input_offset.top + input_height + results_height;
var window_bottom = window.clientHeight + window.scrollTop;
// set the dimmensions and position
this.queryResultArea.style.width = input_width + 'px';
this.queryResultArea.style.left = input_offset.left + 'px';
if (results_bottom > window_bottom) {
this.queryResultArea.style.top = input_offset.top - results_height + 'px';
} else {
this.queryResultArea.style.top = input_offset.top + input_height + 'px';
}
}
}, {
key: 'highlightNextChoice',
value: function highlightNextChoice() {
var highlighted_choice = this.highlightedChoice;
if (highlighted_choice) {
var next_choice = highlighted_choice.nextSibling;
if (next_choice) {
/* harmony import */__WEBPACK_IMPORTED_MODULE_1__utils__["c"].bind()(highlighted_choice, 'active');
/* harmony import */__WEBPACK_IMPORTED_MODULE_1__utils__["a"].bind()(next_choice, 'active');
}
} else {
var choice = this.queryResultArea.querySelector('li.' + plugin_name + '_choice');
if (choice) /* harmony import */__WEBPACK_IMPORTED_MODULE_1__utils__["a"].bind()(choice, 'active');
}
}
}, {
key: 'highlightPreviousChoice',
value: function highlightPreviousChoice() {
var highlighted_choice = this.highlightedChoice;
if (highlighted_choice) {
var prev_choice = highlighted_choice.previousSibling;
if (prev_choice) {
/* harmony import */__WEBPACK_IMPORTED_MODULE_1__utils__["c"].bind()(highlighted_choice, 'active');
/* harmony import */__WEBPACK_IMPORTED_MODULE_1__utils__["a"].bind()(prev_choice, 'active');
}
} else {
var choice = this.queryResultArea.querySelector('li.' + plugin_name + '_choice:last-child');
if (choice) /* harmony import */__WEBPACK_IMPORTED_MODULE_1__utils__["a"].bind()(choice, 'active');
}
}
}, {
key: 'selectHighlightedChoice',
value: function selectHighlightedChoice() {
var highlighted_choice = this.highlightedChoice;
if (highlighted_choice) {
this.selectChoiceByValue(this.valueFromElement(highlighted_choice));
this.hideResults();
} else this.revert();
}
// display the selected choice in the input box
}, {
key: 'display',
value: function display() {
this.element.value = this.selectedChoice && this.selectedChoice.choice.text || '';
typeof Event !== 'undefined' && this.element.dispatchEvent(new Event('input'));
this._val = this.element.value;
}
// select the first choice with matching value
// Note: values should be unique
}, {
key: 'selectChoiceByValue',
value: function selectChoiceByValue(val) {
var old_val = this.value;
this.selectedChoice = val && this.indexed_choices.find(function (_ref5) {
var choice = _ref5.choice;
return choice.value == val;
}) || null;
var new_val = this.value;
new_val !== old_val && this.element.dispatchEvent(new CustomEvent('update', {
detail: new_val
}));
this.display();
}
}, {
key: 'revertOtherInstances',
value: function revertOtherInstances() {
var _this3 = this;
all_objects.forEach(function (plugin) {
return plugin !== _this3 && plugin.revert();
});
}
}, {
key: 'valueFromElement',
value: function valueFromElement(element) {
var index = parseInt(element.getAttribute('data-immybox-value-index'));
return !Number.isNaN(index) ? this.values[index] : undefined;
}
// public methods
}, {
key: 'showResults',
value: function showResults() {
!this.queryResultAreaVisible && document.body.appendChild(this.queryResultArea);
this.queryResultAreaVisible = true;
this.scroll();
this.positionResultsArea();
}
}, {
key: 'hideResults',
value: function hideResults() {
this.queryResultAreaVisible && document.body.removeChild(this.queryResultArea);
this.queryResultAreaVisible = false;
}
// return array of choices
}, {
key: 'getChoices',
value: function getChoices() {
return this.choices;
}
}, {
key: 'setChoices',
value: function setChoices(newChoices) {
var _this4 = this;
this.choices = newChoices;
if (this.options.defaultSelectedValue != null) {
this.choices = [this.choices.find(function (_ref6) {
var value = _ref6.value;
return value === _this4.options.defaultSelectedValue;
})].concat(_toConsumableArray(this.choices.filter(function (_ref7) {
var value = _ref7.value;
return value !== _this4.options.defaultSelectedValue;
}))).filter(function (choice) {
return choice;
});
}
this.indexed_choices = this.choices.map(function (choice, index) {
return { choice: choice, index: index };
});
this.selectedChoice && this.selectChoiceByValue(this.selectedChoice.choice.value);
this.oldQuery = '';
return this.choices;
}
}, {
key: 'getValue',
value: function getValue() {
return this.value;
}
}, {
key: 'setValue',
value: function setValue(value) {
this.value = value;
}
// get the value of the currently-selected choice
}, {
key: 'destroy',
// destroy this instance of the plugin
value: function destroy() {
// remove event listeners
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = event_listeners.get(this)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var _step$value = _slicedToArray(_step.value, 2);
var node = _step$value[0];
var events = _step$value[1];
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;
try {
for (var _iterator2 = events[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var _step2$value = _slicedToArray(_step2.value, 2);
var event_name = _step2$value[0];
var handler = _step2$value[1];
node.removeEventListener(event_name, handler);
}
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2.return) {
_iterator2.return();
}
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
}
}
}
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
/* harmony import */__WEBPACK_IMPORTED_MODULE_1__utils__["c"].bind()(this.element, plugin_name);
this.queryResultAreaVisible && document.body.removeChild(this.queryResultArea);
all_objects.delete(this.element);
}
}, {
key: 'values',
get: function get() {
return this.choices.map(function (choice) {
return choice.value;
});
}
}, {
key: 'highlightedChoice',
set: function set(choice) {
var highlightedChoice = this.highlightedChoice;
if (highlightedChoice) {
/* harmony import */__WEBPACK_IMPORTED_MODULE_1__utils__["c"].bind()(highlighted_choice, 'active');
/* harmony import */__WEBPACK_IMPORTED_MODULE_1__utils__["a"].bind()(choice, 'active');
}
},
get: function get() {
var choice = this.queryResultArea.querySelector('li.' + plugin_name + '_choice.active');
return choice || null;
}
}, {
key: 'value',
get: function get() {
return this.selectedChoice && this.selectedChoice.choice.value || null;
}
// set the value of the currently-selected choice
,
set: function set(new_value) {
if (this.value !== new_value) {
this.selectChoiceByValue(new_value);
this.oldQuery = '';
}
return this.value;
}
}], [{
key: 'pluginForElement',
value: function pluginForElement(element) {
return all_objects.get(element);
}
}, {
key: 'repositionAll',
value: function repositionAll() {
window.requestAnimationFrame(function () {
all_objects.forEach(function (plugin) {
plugin.queryResultAreaVisible && plugin.reposition();
});
});
}
}, {
key: 'revertAll',
value: function revertAll() {
all_objects.forEach(function (plugin) {
return plugin.revert();
});
}
}, {
key: 'repositionWhenScrolling',
value: function repositionWhenScrolling(container) {
// use one global scoll listener to reposition any result areas that are open
container.addEventListener('scroll', ImmyBox.repositionAll);
}
}, {
key: 'defaults',
set: function set(new_defaults) {
Object.assign(defaults, new_defaults);
},
get: function get() {
return defaults;
}
}, {
key: 'pluginMethods',
get: function get() {
return ['showResults', 'hideResults', 'getChoices', 'setChoices', 'getValue', 'setValue', 'destroy'];
}
}, {
key: 'all_objects',
get: function get() {
return all_objects;
}
}, {
key: 'plugin_name',
get: function get() {
return plugin_name;
}
}]);
return ImmyBox;
}();
/* harmony export */ Object.defineProperty(exports, "ImmyBox", {configurable: false, enumerable: true, get: function() { return ImmyBox; }});
// use one global click event listener to close/revert ones that are open
document.addEventListener('DOMContentLoaded', function () {
document.body.addEventListener('click', ImmyBox.revertAll);
// use one global resize listener to reposition any result areas that are open
window.addEventListener('resize', ImmyBox.repositionAll);
});
"use strict";
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.ImmyBox = undefined;
var _forEach = __webpack_require__(3);
var _forEach2 = _interopRequireDefault(_forEach);
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };
var _utils = __webpack_require__(1);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var event_listeners = new Map();
var defaults = {
choices: [],
maxResults: 50,
showArrow: true,
openOnClick: true,
defaultSelectedValue: undef,
scroll_behavior: 'smooth',
filterFn: function filterFn(query) {
var lower_query = query.toLowerCase();
return function (choice) {
return choice.text.toLowerCase().indexOf(lower_query) >= 0;
};
},
formatChoice: function formatChoice(query) {
if (query) {
var _ret = function () {
var reg = new RegExp(query.replace(/[#-.]|[[-^]|[?|{}]/g, '\\$&'), 'gi');
return {
v: function v(choice) {
return choice.text.replace(reg, '<span class="highlight">$&</span>');
}
};
}();
if ((typeof _ret === 'undefined' ? 'undefined' : _typeof(_ret)) === "object") return _ret.v;
} else return function (choice) {
return choice.text;
};
}
};
var all_objects = new Map();
var plugin_name = 'immybox';
var undef = void 0;
var _noOp = function _noOp() {};
var _dispatchEvent = typeof Event !== 'undefined' ? function (el, name) {
el.dispatchEvent(new Event(name));
} : _noOp;
function assignEvent(event_name, event_handler, node, listeners) {
listeners.has(node) || listeners.set(node, new Map());
listeners.get(node).set(event_name, event_handler);
node.addEventListener(event_name, event_handler);
}
function getEventListenerMap(plugin) {
var map = new Map();
event_listeners.set(plugin, map);
return map;
}
var ImmyBox = exports.ImmyBox = function () {
function ImmyBox(element, options) {
var _this = this;
_classCallCheck(this, ImmyBox);
(0, _utils.addClass)(element, plugin_name);
element.setAttribute('autocomplete', 'off');
var listeners = getEventListenerMap(this);
this.element = element;
this.options = Object.assign({}, ImmyBox.defaults, options);
this.choices = this.options.choices;
if (this.options.defaultSelectedValue != null) this.choices = [this.choices.find(function (_ref) {
var value = _ref.value;
return value === _this.options.defaultSelectedValue;
})].concat(_toConsumableArray(this.choices.filter(function (_ref2) {
var value = _ref2.value;
return value !== _this.options.defaultSelectedValue;
}))).filter(function (choice) {
return choice;
});
this.indexed_choices = this.choices.map(function (choice, index) {
return { index: index, choice: choice };
});
this.selectedChoice = null;
if (this.options.showArrow) (0, _utils.addClass)(this.element, plugin_name + '_witharrow');
this.selectChoiceByValue(this.element.value);
this.queryResultArea = document.createElement('div');
(0, _utils.addClass)(this.queryResultArea, plugin_name + '_results');
this.queryResultAreaVisible = false;
this._val = this.element.value;
this.oldQuery = this.element.value;
if (this.options.openOnClick) assignEvent('click', this.openResults.bind(this), this.element, listeners);
assignEvent('click', function (event) {
var node = (0, _utils.nodeOrParentMatchingSelector)(event.target, 'li.' + plugin_name + '_choice');
if (node) {
var value = _this.valueFromElement(node);
_this.selectChoiceByValue(value);
_this.hideResults();
_this._val = _this.element.value;
_this.element.focus();
}
}, this.queryResultArea, listeners);
assignEvent('mouseenter', function (event) {
var node = (0, _utils.nodeOrParentMatchingSelector)(event.target, 'li.' + plugin_name + '_choice');
if (node) {
(0, _utils.addClass)(node, 'active');
(0, _forEach2.default)(function (li) {
return li !== node && (0, _utils.removeClass)(li, 'active');
}, _this.queryResultArea.querySelectorAll('li.' + plugin_name + '_choice.active'));
}
}, this.queryResultArea, listeners);
assignEvent('keyup', this.doQuery.bind(this), this.element, listeners);
assignEvent('change', this.doQuery.bind(this), this.element, listeners);
assignEvent('search', this.doQuery.bind(this), this.element, listeners);
assignEvent('keydown', this.doSelection.bind(this), this.element, listeners);
all_objects.set(this.element, this);
}
_createClass(ImmyBox, [{
key: 'doQuery',
// on 'keyup', 'change', 'search'
// perform a query on the choices
value: function doQuery() {
var query = this.element.value;
if (this._val !== query) {
this._val = query;
this.oldQuery = query;
if (query) {
this.insertFilteredChoiceElements(query);
} else {
this.hideResults();
this.selectChoiceByValue(null);
}
}
}
// on 'keydown'
// select the highlighted choice
}, {
key: 'doSelection',
value: function doSelection(event) {
if (event.which === 27) {
// escape key
this.display();
this.hideResults();
}
if (this.queryResultAreaVisible) {
switch (event.which) {
case 9:
// tab
this.selectHighlightedChoice();
break;
case 13:
// enter
event.preventDefault();
this.selectHighlightedChoice();
break;
case 38:
// up
event.preventDefault();
this.highlightPreviousChoice();
this.scroll();
break;
case 40:
// down
event.preventDefault();
this.highlightNextChoice();
this.scroll();
break;
}
} else {
switch (event.which) {
case 40:
// down
event.preventDefault();
if (this.selectedChoice) this.insertFilteredChoiceElements(this.oldQuery);else this.insertFilteredChoiceElements('');
break;
case 9:
// tab
this.revert();
break;
}
}
}
// on 'click'
// show the results box
}, {
key: 'openResults',
value: function openResults(event) {
event.cancelBubble = true;
event.stopPropogation && event.stopPropogation();
this.revertOtherInstances();
if (this.selectedChoice) {
this.insertFilteredChoiceElements(this.oldQuery);
} else {
this.insertFilteredChoiceElements('');
}
}
// revert or set to null after losing focus
}, {
key: 'revert',
value: function revert() {
if (this.queryResultAreaVisible) {
this.display();
this.hideResults();
} else if (this.element.value === '') this.selectChoiceByValue(null);
}
// if visible, reposition the results area on window resize
}, {
key: 'reposition',
value: function reposition() {
this.queryResultAreaVisible && this.positionResultsArea();
}
}, {
key: 'insertFilteredChoiceElements',
value: function insertFilteredChoiceElements(query) {
var _this2 = this;
var filteredChoices = void 0;
if (query === '') filteredChoices = this.indexed_choices;else {
(function () {
var filter = _this2.options.filterFn(query);
filteredChoices = _this2.indexed_choices.filter(function (_ref3, index) {
var choice = _ref3.choice;
return filter(choice, index);
});
})();
}
var truncatedChoices = filteredChoices.slice(0, this.options.maxResults);
if (this.defaultSelectedChoice) {
if (filteredChoices.indexOf(this.defaultSelectedChoice) >= 0) {
if (truncatedChoices.indexOf(this.defaultSelectedChoice) === -1) {
truncatedChoices.unshift(this.defaultSelectedChoice);
truncatedChoices.pop();
} else {
truncatedChoices = truncatedChoices.filter(function (c) {
return c.choice.value !== _this2.defaultSelectedChoice.value;
});
truncatedChoices.unshift(this.defaultSelectedChoice);
}
}
}
var formatter = this.options.formatChoice(query);
var selected_one = false;
var list = document.createElement('ul');
var results = truncatedChoices.map(function (_ref4) {
var choice = _ref4.choice;
var index = _ref4.index;
var li = document.createElement('li');
li.setAttribute('class', plugin_name + '_choice');
li.setAttribute('data-immybox-value-index', index);
li.innerHTML = formatter(choice);
if (_this2.selectedChoice && index === _this2.selectedChoice.index) {
selected_one = true;
(0, _utils.addClass)(li, 'active');
}
list.appendChild(li);
return li;
});
if (results.length) {
!selected_one && (0, _utils.addClass)(results[0], 'active');
} else {
list = document.createElement('p');
list.setAttribute('class', plugin_name + '_noresults');
list.textContent = 'no matches';
}
while (this.queryResultArea.lastChild) {
this.queryResultArea.removeChild(this.queryResultArea.lastChild);
}
this.queryResultArea.appendChild(list);
this.showResults();
}
}, {
key: 'scroll',
value: function scroll() {
this.highlightedChoice && this.highlightedChoice.scrollIntoView({
behavior: this.options.scroll_behavior
});
}
}, {
key: 'positionResultsArea',
value: function positionResultsArea() {
var input_offset = this.element.getBoundingClientRect();
var input_height = this.element.clientHeight;
var input_width = this.element.clientWidth;
var results_height = this.queryResultArea.clientHeight;
var results_bottom = input_offset.top + input_height + results_height;
var window_bottom = window.clientHeight + window.scrollTop;
// set the dimmensions and position
this.queryResultArea.style.width = input_width + 'px';
this.queryResultArea.style.left = input_offset.left + 'px';
if (results_bottom > window_bottom) {
this.queryResultArea.style.top = input_offset.top - results_height + 'px';
} else {
this.queryResultArea.style.top = input_offset.top + input_height + 'px';
}
}
}, {
key: 'highlightNextChoice',
value: function highlightNextChoice() {
var highlighted_choice = this.highlightedChoice;
if (highlighted_choice) {
var next_choice = highlighted_choice.nextSibling;
if (next_choice) {
(0, _utils.removeClass)(highlighted_choice, 'active');
(0, _utils.addClass)(next_choice, 'active');
}
} else {
var choice = this.queryResultArea.querySelector('li.' + plugin_name + '_choice');
if (choice) (0, _utils.addClass)(choice, 'active');
}
}
}, {
key: 'highlightPreviousChoice',
value: function highlightPreviousChoice() {
var highlighted_choice = this.highlightedChoice;
if (highlighted_choice) {
var prev_choice = highlighted_choice.previousSibling;
if (prev_choice) {
(0, _utils.removeClass)(highlighted_choice, 'active');
(0, _utils.addClass)(prev_choice, 'active');
}
} else {
var choice = this.queryResultArea.querySelector('li.' + plugin_name + '_choice:last-child');
if (choice) (0, _utils.addClass)(choice, 'active');
}
}
}, {
key: 'selectHighlightedChoice',
value: function selectHighlightedChoice() {
var highlighted_choice = this.highlightedChoice;
if (highlighted_choice) {
this.selectChoiceByValue(this.valueFromElement(highlighted_choice));
this.hideResults();
} else this.revert();
}
// display the selected choice in the input box
}, {
key: 'display',
value: function display() {
this.element.value = this.selectedChoice && this.selectedChoice.choice.text || '';
_dispatchEvent(this.element, 'input');
this._val = this.element.value;
}
// select the first choice with matching value (matching is done via the threequals comparison)
// Note: values should be unique
}, {
key: 'selectChoiceByValue',
value: function selectChoiceByValue(val) {
var old_val = this.value;
if (typeof val === 'undefined') {
this.selectedChoice = undef;
} else {
this.selectedChoice = this.indexed_choices.find(function (_ref5) {
var choice = _ref5.choice;
return choice.value === val;
});
}
var new_val = this.value;
new_val !== old_val && this.element.dispatchEvent(new CustomEvent('update', {
detail: new_val
}));
this.display();
}
}, {
key: 'revertOtherInstances',
value: function revertOtherInstances() {
var _this3 = this;
all_objects.forEach(function (plugin) {
return plugin !== _this3 && plugin.revert();
});
}
}, {
key: 'valueFromElement',
value: function valueFromElement(element) {
var index = parseInt(element.getAttribute('data-immybox-value-index'));
return !Number.isNaN(index) ? this.values[index] : undef;
}
// public methods
}, {
key: 'showResults',
value: function showResults() {
!this.queryResultAreaVisible && document.body.appendChild(this.queryResultArea);
this.queryResultAreaVisible = true;
this.scroll();
this.positionResultsArea();
}
}, {
key: 'open',
value: function open() {
return this.showResults();
}
}, {
key: 'hideResults',
value: function hideResults() {
this.queryResultAreaVisible && document.body.removeChild(this.queryResultArea);
this.queryResultAreaVisible = false;
}
}, {
key: 'close',
value: function close() {
return this.hideResults();
}
// return array of choices
}, {
key: 'getChoices',
value: function getChoices() {
return this.choices;
}
}, {
key: 'setChoices',
value: function setChoices(newChoices) {
this.choices = newChoices;
var default_selected_value = this.options.defaultSelectedValue;
if (default_selected_value != null) {
this.choices = [this.choices.find(function (_ref6) {
var value = _ref6.value;
return value === default_selected_value;
})].concat(_toConsumableArray(this.choices.filter(function (_ref7) {
var value = _ref7.value;
return value !== default_selected_value;
}))).filter(function (choice) {
return choice;
});
}
this.indexed_choices = this.choices.map(function (choice, index) {
return { choice: choice, index: index };
});
this.selectedChoice && this.selectChoiceByValue(this.selectedChoice.choice.value);
this.oldQuery = '';
return this.choices;
}
}, {
key: 'getValue',
value: function getValue() {
return this.value;
}
}, {
key: 'setValue',
value: function setValue(value) {
this.value = value;
}
}, {
key: 'unsetValue',
value: function unsetValue() {
if (typeof this.value !== 'undefined') {
this.value = undef;
}
}
// get the value of the currently-selected choice
}, {
key: 'destroy',
// destroy this instance of the plugin
value: function destroy() {
// remove event listeners
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = event_listeners.get(this)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var _step$value = _slicedToArray(_step.value, 2);
var node = _step$value[0];
var events = _step$value[1];
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;
try {
for (var _iterator2 = events[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var _step2$value = _slicedToArray(_step2.value, 2);
var event_name = _step2$value[0];
var handler = _step2$value[1];
node.removeEventListener(event_name, handler);
}
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2.return) {
_iterator2.return();
}
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
}
}
}
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
(0, _utils.removeClass)(this.element, plugin_name);
this.queryResultAreaVisible && document.body.removeChild(this.queryResultArea);
all_objects.delete(this.element);
}
}, {
key: 'values',
get: function get() {
return this.choices.map(function (choice) {
return choice.value;
});
}
}, {
key: 'highlightedChoice',
set: function set(choice) {
var highlightedChoice = this.highlightedChoice;
if (highlightedChoice) {
(0, _utils.removeClass)(highlightedChoice, 'active');
(0, _utils.addClass)(choice, 'active');
}
},
get: function get() {
var choice = this.queryResultArea.querySelector('li.' + plugin_name + '_choice.active');
return choice || null;
}
}, {
key: 'value',
get: function get() {
return this.selectedChoice && this.selectedChoice.choice.value;
}
// set the value of the currently-selected choice
,
set: function set(new_value) {
if (this.value !== new_value) {
this.selectChoiceByValue(new_value);
this.oldQuery = '';
}
return this.value;
}
}], [{
key: 'pluginForElement',
value: function pluginForElement(element) {
return all_objects.get(element);
}
}, {
key: 'repositionAll',
value: function repositionAll() {
window.requestAnimationFrame(function () {
all_objects.forEach(function (plugin) {
plugin.queryResultAreaVisible && plugin.reposition();
});
});
}
}, {
key: 'revertAll',
value: function revertAll() {
all_objects.forEach(function (plugin) {
return plugin.revert();
});
}
}, {
key: 'repositionWhenScrolling',
value: function repositionWhenScrolling(container) {
// use one global scoll listener to reposition any result areas that are open
container.addEventListener('scroll', ImmyBox.repositionAll);
}
}, {
key: 'defaults',
set: function set(new_defaults) {
Object.assign(defaults, new_defaults);
},
get: function get() {
return defaults;
}
}, {
key: 'pluginMethods',
get: function get() {
return ['showResults', 'open', 'hideResults', 'close', 'getChoices', 'setChoices', 'getValue', 'setValue', 'destroy'];
}
}, {
key: 'all_objects',
get: function get() {
return all_objects;
}
}, {
key: 'plugin_name',
get: function get() {
return plugin_name;
}
}]);
return ImmyBox;
}();
// use one global click event listener to close/revert ones that are open
document.addEventListener('DOMContentLoaded', function () {
document.body.addEventListener('click', ImmyBox.revertAll);
// use one global resize listener to reposition any result areas that are open
window.addEventListener('resize', ImmyBox.repositionAll);
});
/***/ },

@@ -812,50 +881,50 @@ /* 3 */

var _checkForMethod = __webpack_require__(4);
var _curry2 = __webpack_require__(6);
/**
* Iterate over an input `list`, calling a provided function `fn` for each
* element in the list.
*
* `fn` receives one argument: *(value)*.
*
* Note: `R.forEach` does not skip deleted or unassigned indices (sparse
* arrays), unlike the native `Array.prototype.forEach` method. For more
* details on this behavior, see:
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach#Description
*
* Also note that, unlike `Array.prototype.forEach`, Ramda's `forEach` returns
* the original array. In some libraries this function is named `each`.
*
* Dispatches to the `forEach` method of the second argument, if present.
*
* @func
* @memberOf R
* @since v0.1.1
* @category List
* @sig (a -> *) -> [a] -> [a]
* @param {Function} fn The function to invoke. Receives one argument, `value`.
* @param {Array} list The list to iterate over.
* @return {Array} The original list.
* @see R.addIndex
* @example
*
* var printXPlusFive = x => console.log(x + 5);
* R.forEach(printXPlusFive, [1, 2, 3]); //=> [1, 2, 3]
* //-> 6
* //-> 7
* //-> 8
*/
module.exports = _curry2(_checkForMethod('forEach', function forEach(fn, list) {
var len = list.length;
var idx = 0;
while (idx < len) {
fn(list[idx]);
idx += 1;
}
return list;
}));
var _checkForMethod = __webpack_require__(4);
var _curry2 = __webpack_require__(6);
/**
* Iterate over an input `list`, calling a provided function `fn` for each
* element in the list.
*
* `fn` receives one argument: *(value)*.
*
* Note: `R.forEach` does not skip deleted or unassigned indices (sparse
* arrays), unlike the native `Array.prototype.forEach` method. For more
* details on this behavior, see:
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach#Description
*
* Also note that, unlike `Array.prototype.forEach`, Ramda's `forEach` returns
* the original array. In some libraries this function is named `each`.
*
* Dispatches to the `forEach` method of the second argument, if present.
*
* @func
* @memberOf R
* @since v0.1.1
* @category List
* @sig (a -> *) -> [a] -> [a]
* @param {Function} fn The function to invoke. Receives one argument, `value`.
* @param {Array} list The list to iterate over.
* @return {Array} The original list.
* @see R.addIndex
* @example
*
* var printXPlusFive = x => console.log(x + 5);
* R.forEach(printXPlusFive, [1, 2, 3]); //=> [1, 2, 3]
* //-> 6
* //-> 7
* //-> 8
*/
module.exports = _curry2(_checkForMethod('forEach', function forEach(fn, list) {
var len = list.length;
var idx = 0;
while (idx < len) {
fn(list[idx]);
idx += 1;
}
return list;
}));
/***/ },

@@ -865,30 +934,30 @@ /* 4 */

var _isArray = __webpack_require__(7);
var _slice = __webpack_require__(8);
/**
* Similar to hasMethod, this checks whether a function has a [methodname]
* function. If it isn't an array it will execute that function otherwise it
* will default to the ramda implementation.
*
* @private
* @param {Function} fn ramda implemtation
* @param {String} methodname property to check for a custom implementation
* @return {Object} Whatever the return value of the method is.
*/
module.exports = function _checkForMethod(methodname, fn) {
return function() {
var length = arguments.length;
if (length === 0) {
return fn();
}
var obj = arguments[length - 1];
return (_isArray(obj) || typeof obj[methodname] !== 'function') ?
fn.apply(this, arguments) :
obj[methodname].apply(obj, _slice(arguments, 0, length - 1));
};
};
var _isArray = __webpack_require__(7);
var _slice = __webpack_require__(8);
/**
* Similar to hasMethod, this checks whether a function has a [methodname]
* function. If it isn't an array it will execute that function otherwise it
* will default to the ramda implementation.
*
* @private
* @param {Function} fn ramda implemtation
* @param {String} methodname property to check for a custom implementation
* @return {Object} Whatever the return value of the method is.
*/
module.exports = function _checkForMethod(methodname, fn) {
return function() {
var length = arguments.length;
if (length === 0) {
return fn();
}
var obj = arguments[length - 1];
return (_isArray(obj) || typeof obj[methodname] !== 'function') ?
fn.apply(this, arguments) :
obj[methodname].apply(obj, _slice(arguments, 0, length - 1));
};
};
/***/ },

@@ -898,24 +967,24 @@ /* 5 */

var _isPlaceholder = __webpack_require__(0);
/**
* Optimized internal one-arity curry function.
*
* @private
* @category Function
* @param {Function} fn The function to curry.
* @return {Function} The curried function.
*/
module.exports = function _curry1(fn) {
return function f1(a) {
if (arguments.length === 0 || _isPlaceholder(a)) {
return f1;
} else {
return fn.apply(this, arguments);
}
};
};
var _isPlaceholder = __webpack_require__(0);
/**
* Optimized internal one-arity curry function.
*
* @private
* @category Function
* @param {Function} fn The function to curry.
* @return {Function} The curried function.
*/
module.exports = function _curry1(fn) {
return function f1(a) {
if (arguments.length === 0 || _isPlaceholder(a)) {
return f1;
} else {
return fn.apply(this, arguments);
}
};
};
/***/ },

@@ -925,32 +994,32 @@ /* 6 */

var _curry1 = __webpack_require__(5);
var _isPlaceholder = __webpack_require__(0);
/**
* Optimized internal two-arity curry function.
*
* @private
* @category Function
* @param {Function} fn The function to curry.
* @return {Function} The curried function.
*/
module.exports = function _curry2(fn) {
return function f2(a, b) {
switch (arguments.length) {
case 0:
return f2;
case 1:
return _isPlaceholder(a) ? f2
: _curry1(function(_b) { return fn(a, _b); });
default:
return _isPlaceholder(a) && _isPlaceholder(b) ? f2
: _isPlaceholder(a) ? _curry1(function(_a) { return fn(_a, b); })
: _isPlaceholder(b) ? _curry1(function(_b) { return fn(a, _b); })
: fn(a, b);
}
};
};
var _curry1 = __webpack_require__(5);
var _isPlaceholder = __webpack_require__(0);
/**
* Optimized internal two-arity curry function.
*
* @private
* @category Function
* @param {Function} fn The function to curry.
* @return {Function} The curried function.
*/
module.exports = function _curry2(fn) {
return function f2(a, b) {
switch (arguments.length) {
case 0:
return f2;
case 1:
return _isPlaceholder(a) ? f2
: _curry1(function(_b) { return fn(a, _b); });
default:
return _isPlaceholder(a) && _isPlaceholder(b) ? f2
: _isPlaceholder(a) ? _curry1(function(_a) { return fn(_a, b); })
: _isPlaceholder(b) ? _curry1(function(_b) { return fn(a, _b); })
: fn(a, b);
}
};
};
/***/ },

@@ -960,19 +1029,19 @@ /* 7 */

/**
* Tests whether or not an object is an array.
*
* @private
* @param {*} val The object to test.
* @return {Boolean} `true` if `val` is an array, `false` otherwise.
* @example
*
* _isArray([]); //=> true
* _isArray(null); //=> false
* _isArray({}); //=> false
*/
module.exports = Array.isArray || function _isArray(val) {
return (val != null &&
val.length >= 0 &&
Object.prototype.toString.call(val) === '[object Array]');
};
/**
* Tests whether or not an object is an array.
*
* @private
* @param {*} val The object to test.
* @return {Boolean} `true` if `val` is an array, `false` otherwise.
* @example
*
* _isArray([]); //=> true
* _isArray(null); //=> false
* _isArray({}); //=> false
*/
module.exports = Array.isArray || function _isArray(val) {
return (val != null &&
val.length >= 0 &&
Object.prototype.toString.call(val) === '[object Array]');
};

@@ -984,34 +1053,34 @@

/**
* An optimized, private array `slice` implementation.
*
* @private
* @param {Arguments|Array} args The array or arguments object to consider.
* @param {Number} [from=0] The array index to slice from, inclusive.
* @param {Number} [to=args.length] The array index to slice to, exclusive.
* @return {Array} A new, sliced array.
* @example
*
* _slice([1, 2, 3, 4, 5], 1, 3); //=> [2, 3]
*
* var firstThreeArgs = function(a, b, c, d) {
* return _slice(arguments, 0, 3);
* };
* firstThreeArgs(1, 2, 3, 4); //=> [1, 2, 3]
*/
module.exports = function _slice(args, from, to) {
switch (arguments.length) {
case 1: return _slice(args, 0, args.length);
case 2: return _slice(args, from, args.length);
default:
var list = [];
var idx = 0;
var len = Math.max(0, Math.min(args.length, to) - from);
while (idx < len) {
list[idx] = args[from + idx];
idx += 1;
}
return list;
}
};
/**
* An optimized, private array `slice` implementation.
*
* @private
* @param {Arguments|Array} args The array or arguments object to consider.
* @param {Number} [from=0] The array index to slice from, inclusive.
* @param {Number} [to=args.length] The array index to slice to, exclusive.
* @return {Array} A new, sliced array.
* @example
*
* _slice([1, 2, 3, 4, 5], 1, 3); //=> [2, 3]
*
* var firstThreeArgs = function(a, b, c, d) {
* return _slice(arguments, 0, 3);
* };
* firstThreeArgs(1, 2, 3, 4); //=> [1, 2, 3]
*/
module.exports = function _slice(args, from, to) {
switch (arguments.length) {
case 1: return _slice(args, 0, args.length);
case 2: return _slice(args, from, args.length);
default:
var list = [];
var idx = 0;
var len = Math.max(0, Math.min(args.length, to) - from);
while (idx < len) {
list[idx] = args[from + idx];
idx += 1;
}
return list;
}
};

@@ -1024,3 +1093,3 @@

module.exports = __webpack_require__(2);
module.exports = __webpack_require__(2);

@@ -1027,0 +1096,0 @@

@@ -1,1 +0,1 @@

!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var i=t();for(var n in i)("object"==typeof exports?exports:e)[n]=i[n]}}(this,function(){return function(e){function t(n){if(i[n])return i[n].exports;var r=i[n]={i:n,l:!1,exports:{}};return e[n].call(r.exports,r,r.exports,t),r.l=!0,r.exports}var i={};return t.m=e,t.c=i,t.p="",t(t.s=10)}([function(e,t){e.exports=function(e){return null!=e&&"object"==typeof e&&e["@@functional/placeholder"]===!0}},function(e,t,i){function n(e,t){if(!e)throw new Error(t)}function r(e,t){return!!e.className.match(new RegExp("(\\s|^)"+t+"(\\s|$)"))}function s(e,t){r(e,t)||(e.className+=" "+t)}function o(e,t){if(r(e,t)){var i=new RegExp("(\\s|^)"+t+"(\\s|$)");e.className=e.className.replace(i," ")}}function u(e,t){return e.parentNode&&e.parentNode.matches?e.parentNode.matches(t)?e.parentNode:u(e.parentNode,t):null}function l(e,t){return e.matches&&e.matches(t)?e:u(e,t)}t.d=n,t.a=s,t.c=o,t.b=l,Number.isNaN=Number.isNaN||function(e){return"number"==typeof e&&isNaN(e)},Array.prototype.find||(Array.prototype.find=function(e){if(null===this)throw new TypeError("Array.prototype.find called on null or undefined");if("function"!=typeof e)throw new TypeError("predicate must be a function");for(var t,i=Object(this),n=i.length>>>0,r=arguments[1],s=0;n>s;s++)if(t=i[s],e.call(r,t,s,i))return t}),Array.prototype.includes||(Array.prototype.includes=function(e){"use strict";var t=Object(this),i=parseInt(t.length)||0;if(0===i)return!1;var n,r=parseInt(arguments[1])||0;r>=0?n=r:(n=i+r,0>n&&(n=0));for(var s;i>n;){if(s=t[n],e===s||e!==e&&s!==s)return!0;n++}return!1})},function(e,t,i){function n(e){if(Array.isArray(e)){for(var t=0,i=Array(e.length);t<e.length;t++)i[t]=e[t];return i}return Array.from(e)}function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function s(e,t,i,n){n.has(i)||n.set(i,new Map),n.get(i).set(e,t),i.addEventListener(e,t)}function o(e){var t=new Map;return d.set(e,t),t}var u=i(3),l=u&&u.__esModule?function(){return u["default"]}:function(){return u};Object.defineProperty(l,"a",{get:l});var c=i(1),a=function(){function e(e,t){var i=[],n=!0,r=!1,s=void 0;try{for(var o,u=e[Symbol.iterator]();!(n=(o=u.next()).done)&&(i.push(o.value),!t||i.length!==t);n=!0);}catch(l){r=!0,s=l}finally{try{!n&&u["return"]&&u["return"]()}finally{if(r)throw s}}return i}return function(t,i){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return e(t,i);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),h=function(){function e(e,t){for(var i=0;i<t.length;i++){var n=t[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,i,n){return i&&e(t.prototype,i),n&&e(t,n),t}}(),f="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e},d=new Map,v={choices:[],maxResults:50,showArrow:!0,openOnClick:!0,defaultSelectedValue:void 0,scroll_behavior:"smooth",filterFn:function(e){var t=e.toLowerCase();return function(e){return e.text.toLowerCase().indexOf(t)>=0}},formatChoice:function(e){if(!e)return function(e){return e.text};var t=function(){var t=new RegExp(e.replace(/[#-.]|[[-^]|[?|{}]/g,"\\$&"),"gi");return{v:function(e){return e.text.replace(t,'<span class="highlight">$&</span>')}}}();return"object"===("undefined"==typeof t?"undefined":f(t))?t.v:void 0}},y=new Map,p="immybox",m=function(){function e(t,i){var u=this;r(this,e),c.a.bind()(t,p),t.setAttribute("autocomplete","off");var a=o(this);this.element=t,this.options=Object.assign({},e.defaults,i),this.choices=this.options.choices,null!=this.options.defaultSelectedValue&&(this.choices=[this.choices.find(function(e){var t=e.value;return t===u.options.defaultSelectedValue})].concat(n(this.choices.filter(function(e){var t=e.value;return t!==u.options.defaultSelectedValue}))).filter(function(e){return e})),this.indexed_choices=this.choices.map(function(e,t){return{index:t,choice:e}}),this.selectedChoice=null,this.options.showArrow&&c.a.bind()(this.element,p+"_witharrow"),this.selectChoiceByValue(this.element.value),this.queryResultArea=document.createElement("div"),c.a.bind()(this.queryResultArea,p+"_results"),this.queryResultAreaVisible=!1,this._val=this.element.value,this.oldQuery=this.element.value,this.options.openOnClick&&s("click",this.openResults.bind(this),this.element,a),s("click",function(e){var t=c.b.bind()(e.target,"li."+p+"_choice");if(t){var i=u.valueFromElement(t);u.selectChoiceByValue(i),u.hideResults(),u._val=u.element.value,u.element.focus()}},this.queryResultArea,a),s("mouseenter",function(e){var t=c.b.bind()(e.target,"li."+p+"_choice");t&&(c.a.bind()(t,"active"),l.a.bind()(function(e){return e!==t&&c.c.bind()(e,"active")},u.queryResultArea.querySelectorAll("li."+p+"_choice.active")))},this.queryResultArea,a),s("keyup",this.doQuery.bind(this),this.element,a),s("change",this.doQuery.bind(this),this.element,a),s("search",this.doQuery.bind(this),this.element,a),s("keydown",this.doSelection.bind(this),this.element,a),y.set(this.element,this)}return h(e,[{key:"doQuery",value:function(){var e=this.element.value;this._val!==e&&(this._val=e,this.oldQuery=e,e?this.insertFilteredChoiceElements(e):(this.hideResults(),this.selectChoiceByValue(null)))}},{key:"doSelection",value:function(e){if(27===e.which&&(this.display(),this.hideResults()),this.queryResultAreaVisible)switch(e.which){case 9:this.selectHighlightedChoice();break;case 13:e.preventDefault(),this.selectHighlightedChoice();break;case 38:e.preventDefault(),this.highlightPreviousChoice(),this.scroll();break;case 40:e.preventDefault(),this.highlightNextChoice(),this.scroll()}else switch(e.which){case 40:e.preventDefault(),this.selectedChoice?this.insertFilteredChoiceElements(this.oldQuery):this.insertFilteredChoiceElements("");break;case 9:this.revert()}}},{key:"openResults",value:function(e){e.cancelBubble=!0,e.stopPropogation&&e.stopPropogation(),this.revertOtherInstances(),this.selectedChoice?this.insertFilteredChoiceElements(this.oldQuery):this.insertFilteredChoiceElements("")}},{key:"revert",value:function(){this.queryResultAreaVisible?(this.display(),this.hideResults()):""===this.element.value&&this.selectChoiceByValue(null)}},{key:"reposition",value:function(){this.queryResultAreaVisible&&this.positionResultsArea()}},{key:"insertFilteredChoiceElements",value:function(e){var t=this,i=void 0;""===e?i=this.indexed_choices:!function(){var n=t.options.filterFn(e);i=t.indexed_choices.filter(function(e,t){var i=e.choice;return n(i,t)})}();var n=i.slice(0,this.options.maxResults);this.defaultSelectedChoice&&i.indexOf(this.defaultSelectedChoice)>=0&&(-1===n.indexOf(this.defaultSelectedChoice)?(n.unshift(this.defaultSelectedChoice),n.pop()):(n=n.filter(function(e){return e.choice.value!==t.defaultSelectedChoice.value}),n.unshift(this.defaultSelectedChoice)));var r=this.options.formatChoice(e),s=!1,o=document.createElement("ul"),u=n.map(function(e){var i=e.choice,n=e.index,u=document.createElement("li");return u.setAttribute("class",p+"_choice"),u.setAttribute("data-immybox-value-index",n),u.innerHTML=r(i),t.selectedChoice&&n===t.selectedChoice.index&&(s=!0,c.a.bind()(u,"active")),o.appendChild(u),u});for(u.length?!s&&c.a.bind()(u[0],"active"):(o=document.createElement("p"),o.setAttribute("class",p+"_noresults"),o.textContent="no matches");this.queryResultArea.lastChild;)this.queryResultArea.removeChild(this.queryResultArea.lastChild);this.queryResultArea.appendChild(o),this.showResults()}},{key:"scroll",value:function(){this.highlightedChoice&&this.highlightedChoice.scrollIntoView({behavior:this.options.scroll_behavior})}},{key:"positionResultsArea",value:function(){var e=this.element.getBoundingClientRect(),t=this.element.clientHeight,i=this.element.clientWidth,n=this.queryResultArea.clientHeight,r=e.top+t+n,s=window.clientHeight+window.scrollTop;this.queryResultArea.style.width=i+"px",this.queryResultArea.style.left=e.left+"px",r>s?this.queryResultArea.style.top=e.top-n+"px":this.queryResultArea.style.top=e.top+t+"px"}},{key:"highlightNextChoice",value:function(){var e=this.highlightedChoice;if(e){var t=e.nextSibling;t&&(c.c.bind()(e,"active"),c.a.bind()(t,"active"))}else{var i=this.queryResultArea.querySelector("li."+p+"_choice");i&&c.a.bind()(i,"active")}}},{key:"highlightPreviousChoice",value:function(){var e=this.highlightedChoice;if(e){var t=e.previousSibling;t&&(c.c.bind()(e,"active"),c.a.bind()(t,"active"))}else{var i=this.queryResultArea.querySelector("li."+p+"_choice:last-child");i&&c.a.bind()(i,"active")}}},{key:"selectHighlightedChoice",value:function(){var e=this.highlightedChoice;e?(this.selectChoiceByValue(this.valueFromElement(e)),this.hideResults()):this.revert()}},{key:"display",value:function(){this.element.value=this.selectedChoice&&this.selectedChoice.choice.text||"","undefined"!=typeof Event&&this.element.dispatchEvent(new Event("input")),this._val=this.element.value}},{key:"selectChoiceByValue",value:function(e){var t=this.value;this.selectedChoice=e&&this.indexed_choices.find(function(t){var i=t.choice;return i.value==e})||null;var i=this.value;i!==t&&this.element.dispatchEvent(new CustomEvent("update",{detail:i})),this.display()}},{key:"revertOtherInstances",value:function(){var e=this;y.forEach(function(t){return t!==e&&t.revert()})}},{key:"valueFromElement",value:function(e){var t=parseInt(e.getAttribute("data-immybox-value-index"));return Number.isNaN(t)?void 0:this.values[t]}},{key:"showResults",value:function(){!this.queryResultAreaVisible&&document.body.appendChild(this.queryResultArea),this.queryResultAreaVisible=!0,this.scroll(),this.positionResultsArea()}},{key:"hideResults",value:function(){this.queryResultAreaVisible&&document.body.removeChild(this.queryResultArea),this.queryResultAreaVisible=!1}},{key:"getChoices",value:function(){return this.choices}},{key:"setChoices",value:function(e){var t=this;return this.choices=e,null!=this.options.defaultSelectedValue&&(this.choices=[this.choices.find(function(e){var i=e.value;return i===t.options.defaultSelectedValue})].concat(n(this.choices.filter(function(e){var i=e.value;return i!==t.options.defaultSelectedValue}))).filter(function(e){return e})),this.indexed_choices=this.choices.map(function(e,t){return{choice:e,index:t}}),this.selectedChoice&&this.selectChoiceByValue(this.selectedChoice.choice.value),this.oldQuery="",this.choices}},{key:"getValue",value:function(){return this.value}},{key:"setValue",value:function(e){this.value=e}},{key:"destroy",value:function(){var e=!0,t=!1,i=void 0;try{for(var n,r=d.get(this)[Symbol.iterator]();!(e=(n=r.next()).done);e=!0){var s=a(n.value,2),o=s[0],u=s[1],l=!0,h=!1,f=void 0;try{for(var v,m=u[Symbol.iterator]();!(l=(v=m.next()).done);l=!0){var g=a(v.value,2),b=g[0],C=g[1];o.removeEventListener(b,C)}}catch(A){h=!0,f=A}finally{try{!l&&m["return"]&&m["return"]()}finally{if(h)throw f}}}}catch(A){t=!0,i=A}finally{try{!e&&r["return"]&&r["return"]()}finally{if(t)throw i}}c.c.bind()(this.element,p),this.queryResultAreaVisible&&document.body.removeChild(this.queryResultArea),y["delete"](this.element)}},{key:"values",get:function(){return this.choices.map(function(e){return e.value})}},{key:"highlightedChoice",set:function(e){var t=this.highlightedChoice;t&&(c.c.bind()(highlighted_choice,"active"),c.a.bind()(e,"active"))},get:function(){var e=this.queryResultArea.querySelector("li."+p+"_choice.active");return e||null}},{key:"value",get:function(){return this.selectedChoice&&this.selectedChoice.choice.value||null},set:function(e){return this.value!==e&&(this.selectChoiceByValue(e),this.oldQuery=""),this.value}}],[{key:"pluginForElement",value:function(e){return y.get(e)}},{key:"repositionAll",value:function(){window.requestAnimationFrame(function(){y.forEach(function(e){e.queryResultAreaVisible&&e.reposition()})})}},{key:"revertAll",value:function(){y.forEach(function(e){return e.revert()})}},{key:"repositionWhenScrolling",value:function(t){t.addEventListener("scroll",e.repositionAll)}},{key:"defaults",set:function(e){Object.assign(v,e)},get:function(){return v}},{key:"pluginMethods",get:function(){return["showResults","hideResults","getChoices","setChoices","getValue","setValue","destroy"]}},{key:"all_objects",get:function(){return y}},{key:"plugin_name",get:function(){return p}}]),e}();Object.defineProperty(t,"ImmyBox",{configurable:!1,enumerable:!0,get:function(){return m}}),document.addEventListener("DOMContentLoaded",function(){document.body.addEventListener("click",m.revertAll),window.addEventListener("resize",m.repositionAll)})},function(e,t,i){var n=i(4),r=i(6);e.exports=r(n("forEach",function(e,t){for(var i=t.length,n=0;i>n;)e(t[n]),n+=1;return t}))},function(e,t,i){var n=i(7),r=i(8);e.exports=function(e,t){return function(){var i=arguments.length;if(0===i)return t();var s=arguments[i-1];return n(s)||"function"!=typeof s[e]?t.apply(this,arguments):s[e].apply(s,r(arguments,0,i-1))}}},function(e,t,i){var n=i(0);e.exports=function(e){return function t(i){return 0===arguments.length||n(i)?t:e.apply(this,arguments)}}},function(e,t,i){var n=i(5),r=i(0);e.exports=function(e){return function t(i,s){switch(arguments.length){case 0:return t;case 1:return r(i)?t:n(function(t){return e(i,t)});default:return r(i)&&r(s)?t:r(i)?n(function(t){return e(t,s)}):r(s)?n(function(t){return e(i,t)}):e(i,s)}}}},function(e,t){e.exports=Array.isArray||function(e){return null!=e&&e.length>=0&&"[object Array]"===Object.prototype.toString.call(e)}},function(e,t){e.exports=function i(e,t,n){switch(arguments.length){case 1:return i(e,0,e.length);case 2:return i(e,t,e.length);default:for(var r=[],s=0,o=Math.max(0,Math.min(e.length,n)-t);o>s;)r[s]=e[t+s],s+=1;return r}}},,function(e,t,i){e.exports=i(2)}])});
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var i=t();for(var n in i)("object"==typeof exports?exports:e)[n]=i[n]}}(this,function(){return function(e){function t(n){if(i[n])return i[n].exports;var r=i[n]={i:n,l:!1,exports:{}};return e[n].call(r.exports,r,r.exports,t),r.l=!0,r.exports}var i={};return t.m=e,t.c=i,t.i=function(e){return e},t.d=function(e,t,i){Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:i})},t.n=function(e){var i=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(i,"a",i),i},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=10)}([function(e,t){e.exports=function(e){return null!=e&&"object"==typeof e&&e["@@functional/placeholder"]===!0}},function(e,t){"use strict";function i(e,t){if(!e)throw new Error(t)}function n(e,t){return!!e.className.match(new RegExp("(\\s|^)"+t+"(\\s|$)"))}function r(e,t){n(e,t)||(e.className+=" "+t)}function s(e,t){if(n(e,t)){var i=new RegExp("(\\s|^)"+t+"(\\s|$)");e.className=e.className.replace(i," ")}}function o(e,t){return e.parentNode&&e.parentNode.matches?e.parentNode.matches(t)?e.parentNode:o(e.parentNode,t):null}function l(e,t){return e.matches&&e.matches(t)?e:o(e,t)}Object.defineProperty(t,"__esModule",{value:!0}),t.assert=i,t.hasClass=n,t.addClass=r,t.removeClass=s,t.nodeOrParentMatchingSelector=l,Number.isNaN=Number.isNaN||function(e){return"number"==typeof e&&isNaN(e)},Array.prototype.find||(Array.prototype.find=function(e){if(null===this)throw new TypeError("Array.prototype.find called on null or undefined");if("function"!=typeof e)throw new TypeError("predicate must be a function");for(var t,i=Object(this),n=i.length>>>0,r=arguments[1],s=0;s<n;s++)if(t=i[s],e.call(r,t,s,i))return t}),Array.prototype.includes||(Array.prototype.includes=function(e){var t=Object(this),i=parseInt(t.length)||0;if(0===i)return!1;var n,r=parseInt(arguments[1])||0;r>=0?n=r:(n=i+r,n<0&&(n=0));for(var s;n<i;){if(s=t[n],e===s||e!==e&&s!==s)return!0;n++}return!1})},function(e,t,i){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}function r(e){if(Array.isArray(e)){for(var t=0,i=Array(e.length);t<e.length;t++)i[t]=e[t];return i}return Array.from(e)}function s(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t,i,n){n.has(i)||n.set(i,new Map),n.get(i).set(e,t),i.addEventListener(e,t)}function l(e){var t=new Map;return v.set(e,t),t}Object.defineProperty(t,"__esModule",{value:!0}),t.ImmyBox=void 0;var u=i(3),c=n(u),a=function(){function e(e,t){var i=[],n=!0,r=!1,s=void 0;try{for(var o,l=e[Symbol.iterator]();!(n=(o=l.next()).done)&&(i.push(o.value),!t||i.length!==t);n=!0);}catch(e){r=!0,s=e}finally{try{!n&&l.return&&l.return()}finally{if(r)throw s}}return i}return function(t,i){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return e(t,i);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),h=function(){function e(e,t){for(var i=0;i<t.length;i++){var n=t[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,i,n){return i&&e(t.prototype,i),n&&e(t,n),t}}(),f="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e},d=i(1),v=new Map,y={choices:[],maxResults:50,showArrow:!0,openOnClick:!0,defaultSelectedValue:g,scroll_behavior:"smooth",filterFn:function(e){var t=e.toLowerCase();return function(e){return e.text.toLowerCase().indexOf(t)>=0}},formatChoice:function(e){if(!e)return function(e){return e.text};var t=function(){var t=new RegExp(e.replace(/[#-.]|[[-^]|[?|{}]/g,"\\$&"),"gi");return{v:function(e){return e.text.replace(t,'<span class="highlight">$&</span>')}}}();return"object"===("undefined"==typeof t?"undefined":f(t))?t.v:void 0}},p=new Map,m="immybox",g=void 0,C=function(){},b="undefined"!=typeof Event?function(e,t){e.dispatchEvent(new Event(t))}:C,A=t.ImmyBox=function(){function e(t,i){var n=this;s(this,e),(0,d.addClass)(t,m),t.setAttribute("autocomplete","off");var u=l(this);this.element=t,this.options=Object.assign({},e.defaults,i),this.choices=this.options.choices,null!=this.options.defaultSelectedValue&&(this.choices=[this.choices.find(function(e){var t=e.value;return t===n.options.defaultSelectedValue})].concat(r(this.choices.filter(function(e){var t=e.value;return t!==n.options.defaultSelectedValue}))).filter(function(e){return e})),this.indexed_choices=this.choices.map(function(e,t){return{index:t,choice:e}}),this.selectedChoice=null,this.options.showArrow&&(0,d.addClass)(this.element,m+"_witharrow"),this.selectChoiceByValue(this.element.value),this.queryResultArea=document.createElement("div"),(0,d.addClass)(this.queryResultArea,m+"_results"),this.queryResultAreaVisible=!1,this._val=this.element.value,this.oldQuery=this.element.value,this.options.openOnClick&&o("click",this.openResults.bind(this),this.element,u),o("click",function(e){var t=(0,d.nodeOrParentMatchingSelector)(e.target,"li."+m+"_choice");if(t){var i=n.valueFromElement(t);n.selectChoiceByValue(i),n.hideResults(),n._val=n.element.value,n.element.focus()}},this.queryResultArea,u),o("mouseenter",function(e){var t=(0,d.nodeOrParentMatchingSelector)(e.target,"li."+m+"_choice");t&&((0,d.addClass)(t,"active"),(0,c.default)(function(e){return e!==t&&(0,d.removeClass)(e,"active")},n.queryResultArea.querySelectorAll("li."+m+"_choice.active")))},this.queryResultArea,u),o("keyup",this.doQuery.bind(this),this.element,u),o("change",this.doQuery.bind(this),this.element,u),o("search",this.doQuery.bind(this),this.element,u),o("keydown",this.doSelection.bind(this),this.element,u),p.set(this.element,this)}return h(e,[{key:"doQuery",value:function(){var e=this.element.value;this._val!==e&&(this._val=e,this.oldQuery=e,e?this.insertFilteredChoiceElements(e):(this.hideResults(),this.selectChoiceByValue(null)))}},{key:"doSelection",value:function(e){if(27===e.which&&(this.display(),this.hideResults()),this.queryResultAreaVisible)switch(e.which){case 9:this.selectHighlightedChoice();break;case 13:e.preventDefault(),this.selectHighlightedChoice();break;case 38:e.preventDefault(),this.highlightPreviousChoice(),this.scroll();break;case 40:e.preventDefault(),this.highlightNextChoice(),this.scroll()}else switch(e.which){case 40:e.preventDefault(),this.selectedChoice?this.insertFilteredChoiceElements(this.oldQuery):this.insertFilteredChoiceElements("");break;case 9:this.revert()}}},{key:"openResults",value:function(e){e.cancelBubble=!0,e.stopPropogation&&e.stopPropogation(),this.revertOtherInstances(),this.selectedChoice?this.insertFilteredChoiceElements(this.oldQuery):this.insertFilteredChoiceElements("")}},{key:"revert",value:function(){this.queryResultAreaVisible?(this.display(),this.hideResults()):""===this.element.value&&this.selectChoiceByValue(null)}},{key:"reposition",value:function(){this.queryResultAreaVisible&&this.positionResultsArea()}},{key:"insertFilteredChoiceElements",value:function(e){var t=this,i=void 0;""===e?i=this.indexed_choices:!function(){var n=t.options.filterFn(e);i=t.indexed_choices.filter(function(e,t){var i=e.choice;return n(i,t)})}();var n=i.slice(0,this.options.maxResults);this.defaultSelectedChoice&&i.indexOf(this.defaultSelectedChoice)>=0&&(n.indexOf(this.defaultSelectedChoice)===-1?(n.unshift(this.defaultSelectedChoice),n.pop()):(n=n.filter(function(e){return e.choice.value!==t.defaultSelectedChoice.value}),n.unshift(this.defaultSelectedChoice)));var r=this.options.formatChoice(e),s=!1,o=document.createElement("ul"),l=n.map(function(e){var i=e.choice,n=e.index,l=document.createElement("li");return l.setAttribute("class",m+"_choice"),l.setAttribute("data-immybox-value-index",n),l.innerHTML=r(i),t.selectedChoice&&n===t.selectedChoice.index&&(s=!0,(0,d.addClass)(l,"active")),o.appendChild(l),l});for(l.length?!s&&(0,d.addClass)(l[0],"active"):(o=document.createElement("p"),o.setAttribute("class",m+"_noresults"),o.textContent="no matches");this.queryResultArea.lastChild;)this.queryResultArea.removeChild(this.queryResultArea.lastChild);this.queryResultArea.appendChild(o),this.showResults()}},{key:"scroll",value:function(){this.highlightedChoice&&this.highlightedChoice.scrollIntoView({behavior:this.options.scroll_behavior})}},{key:"positionResultsArea",value:function(){var e=this.element.getBoundingClientRect(),t=this.element.clientHeight,i=this.element.clientWidth,n=this.queryResultArea.clientHeight,r=e.top+t+n,s=window.clientHeight+window.scrollTop;this.queryResultArea.style.width=i+"px",this.queryResultArea.style.left=e.left+"px",r>s?this.queryResultArea.style.top=e.top-n+"px":this.queryResultArea.style.top=e.top+t+"px"}},{key:"highlightNextChoice",value:function(){var e=this.highlightedChoice;if(e){var t=e.nextSibling;t&&((0,d.removeClass)(e,"active"),(0,d.addClass)(t,"active"))}else{var i=this.queryResultArea.querySelector("li."+m+"_choice");i&&(0,d.addClass)(i,"active")}}},{key:"highlightPreviousChoice",value:function(){var e=this.highlightedChoice;if(e){var t=e.previousSibling;t&&((0,d.removeClass)(e,"active"),(0,d.addClass)(t,"active"))}else{var i=this.queryResultArea.querySelector("li."+m+"_choice:last-child");i&&(0,d.addClass)(i,"active")}}},{key:"selectHighlightedChoice",value:function(){var e=this.highlightedChoice;e?(this.selectChoiceByValue(this.valueFromElement(e)),this.hideResults()):this.revert()}},{key:"display",value:function(){this.element.value=this.selectedChoice&&this.selectedChoice.choice.text||"",b(this.element,"input"),this._val=this.element.value}},{key:"selectChoiceByValue",value:function(e){var t=this.value;"undefined"==typeof e?this.selectedChoice=g:this.selectedChoice=this.indexed_choices.find(function(t){var i=t.choice;return i.value===e});var i=this.value;i!==t&&this.element.dispatchEvent(new CustomEvent("update",{detail:i})),this.display()}},{key:"revertOtherInstances",value:function(){var e=this;p.forEach(function(t){return t!==e&&t.revert()})}},{key:"valueFromElement",value:function(e){var t=parseInt(e.getAttribute("data-immybox-value-index"));return Number.isNaN(t)?g:this.values[t]}},{key:"showResults",value:function(){!this.queryResultAreaVisible&&document.body.appendChild(this.queryResultArea),this.queryResultAreaVisible=!0,this.scroll(),this.positionResultsArea()}},{key:"open",value:function(){return this.showResults()}},{key:"hideResults",value:function(){this.queryResultAreaVisible&&document.body.removeChild(this.queryResultArea),this.queryResultAreaVisible=!1}},{key:"close",value:function(){return this.hideResults()}},{key:"getChoices",value:function(){return this.choices}},{key:"setChoices",value:function(e){this.choices=e;var t=this.options.defaultSelectedValue;return null!=t&&(this.choices=[this.choices.find(function(e){var i=e.value;return i===t})].concat(r(this.choices.filter(function(e){var i=e.value;return i!==t}))).filter(function(e){return e})),this.indexed_choices=this.choices.map(function(e,t){return{choice:e,index:t}}),this.selectedChoice&&this.selectChoiceByValue(this.selectedChoice.choice.value),this.oldQuery="",this.choices}},{key:"getValue",value:function(){return this.value}},{key:"setValue",value:function(e){this.value=e}},{key:"unsetValue",value:function(){"undefined"!=typeof this.value&&(this.value=g)}},{key:"destroy",value:function(){var e=!0,t=!1,i=void 0;try{for(var n,r=v.get(this)[Symbol.iterator]();!(e=(n=r.next()).done);e=!0){var s=a(n.value,2),o=s[0],l=s[1],u=!0,c=!1,h=void 0;try{for(var f,y=l[Symbol.iterator]();!(u=(f=y.next()).done);u=!0){var g=a(f.value,2),C=g[0],b=g[1];o.removeEventListener(C,b)}}catch(e){c=!0,h=e}finally{try{!u&&y.return&&y.return()}finally{if(c)throw h}}}}catch(e){t=!0,i=e}finally{try{!e&&r.return&&r.return()}finally{if(t)throw i}}(0,d.removeClass)(this.element,m),this.queryResultAreaVisible&&document.body.removeChild(this.queryResultArea),p.delete(this.element)}},{key:"values",get:function(){return this.choices.map(function(e){return e.value})}},{key:"highlightedChoice",set:function(e){var t=this.highlightedChoice;t&&((0,d.removeClass)(t,"active"),(0,d.addClass)(e,"active"))},get:function(){var e=this.queryResultArea.querySelector("li."+m+"_choice.active");return e||null}},{key:"value",get:function(){return this.selectedChoice&&this.selectedChoice.choice.value},set:function(e){return this.value!==e&&(this.selectChoiceByValue(e),this.oldQuery=""),this.value}}],[{key:"pluginForElement",value:function(e){return p.get(e)}},{key:"repositionAll",value:function(){window.requestAnimationFrame(function(){p.forEach(function(e){e.queryResultAreaVisible&&e.reposition()})})}},{key:"revertAll",value:function(){p.forEach(function(e){return e.revert()})}},{key:"repositionWhenScrolling",value:function(t){t.addEventListener("scroll",e.repositionAll)}},{key:"defaults",set:function(e){Object.assign(y,e)},get:function(){return y}},{key:"pluginMethods",get:function(){return["showResults","open","hideResults","close","getChoices","setChoices","getValue","setValue","destroy"]}},{key:"all_objects",get:function(){return p}},{key:"plugin_name",get:function(){return m}}]),e}();document.addEventListener("DOMContentLoaded",function(){document.body.addEventListener("click",A.revertAll),window.addEventListener("resize",A.repositionAll)})},function(e,t,i){var n=i(4),r=i(6);e.exports=r(n("forEach",function(e,t){for(var i=t.length,n=0;n<i;)e(t[n]),n+=1;return t}))},function(e,t,i){var n=i(7),r=i(8);e.exports=function(e,t){return function(){var i=arguments.length;if(0===i)return t();var s=arguments[i-1];return n(s)||"function"!=typeof s[e]?t.apply(this,arguments):s[e].apply(s,r(arguments,0,i-1))}}},function(e,t,i){var n=i(0);e.exports=function(e){return function t(i){return 0===arguments.length||n(i)?t:e.apply(this,arguments)}}},function(e,t,i){var n=i(5),r=i(0);e.exports=function(e){return function t(i,s){switch(arguments.length){case 0:return t;case 1:return r(i)?t:n(function(t){return e(i,t)});default:return r(i)&&r(s)?t:r(i)?n(function(t){return e(t,s)}):r(s)?n(function(t){return e(i,t)}):e(i,s)}}}},function(e,t){e.exports=Array.isArray||function(e){return null!=e&&e.length>=0&&"[object Array]"===Object.prototype.toString.call(e)}},function(e,t){e.exports=function e(t,i,n){switch(arguments.length){case 1:return e(t,0,t.length);case 2:return e(t,i,t.length);default:for(var r=[],s=0,o=Math.max(0,Math.min(t.length,n)-i);s<o;)r[s]=t[i+s],s+=1;return r}}},,function(e,t,i){e.exports=i(2)}])});
/*!
* Immybox.js Version 1.0.0-beta1
* Immybox.js Version 1.0.0-beta2
*

@@ -50,2 +50,26 @@ */

/******/
/******/ // identity function for calling harmory imports with the correct context
/******/ __webpack_require__.i = function(value) { return value; };
/******/
/******/ // define getter function for harmory exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__

@@ -62,7 +86,7 @@ /******/ __webpack_require__.p = "";

module.exports = function _isPlaceholder(a) {
return a != null &&
typeof a === 'object' &&
a['@@functional/placeholder'] === true;
};
module.exports = function _isPlaceholder(a) {
return a != null &&
typeof a === 'object' &&
a['@@functional/placeholder'] === true;
};

@@ -72,92 +96,103 @@

/* 1 */
/***/ function(module, exports, __webpack_require__) {
/***/ function(module, exports) {
/* harmony export */ exports["d"] = assert;/* unused harmony export hasClass *//* harmony export */ exports["a"] = addClass;/* harmony export */ exports["c"] = removeClass;/* harmony export */ exports["b"] = nodeOrParentMatchingSelector;/*eslint no-console:0*/
// Polyfills
Number.isNaN = Number.isNaN || function (value) {
return typeof value === 'number' && isNaN(value);
};
if (!Array.prototype.find) {
Array.prototype.find = function (predicate) {
if (this === null) {
throw new TypeError('Array.prototype.find called on null or undefined');
}
if (typeof predicate !== 'function') {
throw new TypeError('predicate must be a function');
}
var list = Object(this);
var length = list.length >>> 0;
var thisArg = arguments[1];
var value;
for (var i = 0; i < length; i++) {
value = list[i];
if (predicate.call(thisArg, value, i, list)) {
return value;
}
}
return undefined;
};
}
if (!Array.prototype.includes) {
Array.prototype.includes = function (searchElement /*, fromIndex*/) {
'use strict';
var O = Object(this);
var len = parseInt(O.length) || 0;
if (len === 0) {
return false;
}
var n = parseInt(arguments[1]) || 0;
var k;
if (n >= 0) {
k = n;
} else {
k = len + n;
if (k < 0) {
k = 0;
}
}
var currentElement;
while (k < len) {
currentElement = O[k];
if (searchElement === currentElement || searchElement !== searchElement && currentElement !== currentElement) {
return true;
}
k++;
}
return false;
};
}
// Exported utility methods
function assert(bool, message) {
if (!bool) throw new Error(message);
}
function hasClass(element, class_name) {
return !!element.className.match(new RegExp('(\\s|^)' + class_name + '(\\s|$)'));
}
function addClass(element, class_name) {
if (!hasClass(element, class_name)) element.className += ' ' + class_name;
}
function removeClass(element, class_name) {
if (hasClass(element, class_name)) {
var reg = new RegExp('(\\s|^)' + class_name + '(\\s|$)');
element.className = element.className.replace(reg, ' ');
}
}
function parentNodeMatchingSelector(element, selector) {
if (!element.parentNode || !element.parentNode.matches) return null;
if (element.parentNode.matches(selector)) return element.parentNode;
return parentNodeMatchingSelector(element.parentNode, selector);
}
function nodeOrParentMatchingSelector(element, selector) {
if (element.matches && element.matches(selector)) return element;
return parentNodeMatchingSelector(element, selector);
}
"use strict";
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.assert = assert;
exports.hasClass = hasClass;
exports.addClass = addClass;
exports.removeClass = removeClass;
exports.nodeOrParentMatchingSelector = nodeOrParentMatchingSelector;
/*eslint no-console:0*/
// Polyfills
Number.isNaN = Number.isNaN || function (value) {
return typeof value === 'number' && isNaN(value);
};
if (!Array.prototype.find) {
Array.prototype.find = function (predicate) {
if (this === null) {
throw new TypeError('Array.prototype.find called on null or undefined');
}
if (typeof predicate !== 'function') {
throw new TypeError('predicate must be a function');
}
var list = Object(this);
var length = list.length >>> 0;
var thisArg = arguments[1];
var value;
for (var i = 0; i < length; i++) {
value = list[i];
if (predicate.call(thisArg, value, i, list)) {
return value;
}
}
return undefined;
};
}
if (!Array.prototype.includes) {
Array.prototype.includes = function (searchElement /*, fromIndex*/) {
'use strict';
var O = Object(this);
var len = parseInt(O.length) || 0;
if (len === 0) {
return false;
}
var n = parseInt(arguments[1]) || 0;
var k;
if (n >= 0) {
k = n;
} else {
k = len + n;
if (k < 0) {
k = 0;
}
}
var currentElement;
while (k < len) {
currentElement = O[k];
if (searchElement === currentElement || searchElement !== searchElement && currentElement !== currentElement) {
return true;
}
k++;
}
return false;
};
}
// Exported utility methods
function assert(bool, message) {
if (!bool) throw new Error(message);
}
function hasClass(element, class_name) {
return !!element.className.match(new RegExp('(\\s|^)' + class_name + '(\\s|$)'));
}
function addClass(element, class_name) {
if (!hasClass(element, class_name)) element.className += ' ' + class_name;
}
function removeClass(element, class_name) {
if (hasClass(element, class_name)) {
var reg = new RegExp('(\\s|^)' + class_name + '(\\s|$)');
element.className = element.className.replace(reg, ' ');
}
}
function parentNodeMatchingSelector(element, selector) {
if (!element.parentNode || !element.parentNode.matches) return null;
if (element.parentNode.matches(selector)) return element.parentNode;
return parentNodeMatchingSelector(element.parentNode, selector);
}
function nodeOrParentMatchingSelector(element, selector) {
if (element.matches && element.matches(selector)) return element;
return parentNodeMatchingSelector(element, selector);
}
/***/ },

@@ -167,642 +202,676 @@ /* 2 */

/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_ramda_src_forEach__ = __webpack_require__(3);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_ramda_src_forEach___default = __WEBPACK_IMPORTED_MODULE_0_ramda_src_forEach__ && __WEBPACK_IMPORTED_MODULE_0_ramda_src_forEach__.__esModule ? function() { return __WEBPACK_IMPORTED_MODULE_0_ramda_src_forEach__['default'] } : function() { return __WEBPACK_IMPORTED_MODULE_0_ramda_src_forEach__; }
/* harmony import */ Object.defineProperty(__WEBPACK_IMPORTED_MODULE_0_ramda_src_forEach___default, 'a', { get: __WEBPACK_IMPORTED_MODULE_0_ramda_src_forEach___default });
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__utils__ = __webpack_require__(1);
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var event_listeners = new Map();
var defaults = {
choices: [],
maxResults: 50,
showArrow: true,
openOnClick: true,
defaultSelectedValue: undefined,
scroll_behavior: 'smooth',
filterFn: function filterFn(query) {
var lower_query = query.toLowerCase();
return function (choice) {
return choice.text.toLowerCase().indexOf(lower_query) >= 0;
};
},
formatChoice: function formatChoice(query) {
if (query) {
var _ret = function () {
var reg = new RegExp(query.replace(/[#-.]|[[-^]|[?|{}]/g, '\\$&'), 'gi');
return {
v: function v(choice) {
return choice.text.replace(reg, '<span class="highlight">$&</span>');
}
};
}();
if ((typeof _ret === 'undefined' ? 'undefined' : _typeof(_ret)) === "object") return _ret.v;
} else return function (choice) {
return choice.text;
};
}
};
var all_objects = new Map();
var plugin_name = 'immybox';
function assignEvent(event_name, event_handler, node, listeners) {
listeners.has(node) || listeners.set(node, new Map());
listeners.get(node).set(event_name, event_handler);
node.addEventListener(event_name, event_handler);
}
function getEventListenerMap(plugin) {
var map = new Map();
event_listeners.set(plugin, map);
return map;
}
var ImmyBox = function () {
function ImmyBox(element, options) {
var _this = this;
_classCallCheck(this, ImmyBox);
/* harmony import */__WEBPACK_IMPORTED_MODULE_1__utils__["a"].bind()(element, plugin_name);
element.setAttribute('autocomplete', 'off');
var listeners = getEventListenerMap(this);
this.element = element;
this.options = Object.assign({}, ImmyBox.defaults, options);
this.choices = this.options.choices;
if (this.options.defaultSelectedValue != null) this.choices = [this.choices.find(function (_ref) {
var value = _ref.value;
return value === _this.options.defaultSelectedValue;
})].concat(_toConsumableArray(this.choices.filter(function (_ref2) {
var value = _ref2.value;
return value !== _this.options.defaultSelectedValue;
}))).filter(function (choice) {
return choice;
});
this.indexed_choices = this.choices.map(function (choice, index) {
return { index: index, choice: choice };
});
this.selectedChoice = null;
if (this.options.showArrow) /* harmony import */__WEBPACK_IMPORTED_MODULE_1__utils__["a"].bind()(this.element, plugin_name + '_witharrow');
this.selectChoiceByValue(this.element.value);
this.queryResultArea = document.createElement('div');
/* harmony import */__WEBPACK_IMPORTED_MODULE_1__utils__["a"].bind()(this.queryResultArea, plugin_name + '_results');
this.queryResultAreaVisible = false;
this._val = this.element.value;
this.oldQuery = this.element.value;
if (this.options.openOnClick) assignEvent('click', this.openResults.bind(this), this.element, listeners);
assignEvent('click', function (event) {
var node = /* harmony import */__WEBPACK_IMPORTED_MODULE_1__utils__["b"].bind()(event.target, 'li.' + plugin_name + '_choice');
if (node) {
var value = _this.valueFromElement(node);
_this.selectChoiceByValue(value);
_this.hideResults();
_this._val = _this.element.value;
_this.element.focus();
}
}, this.queryResultArea, listeners);
assignEvent('mouseenter', function (event) {
var node = /* harmony import */__WEBPACK_IMPORTED_MODULE_1__utils__["b"].bind()(event.target, 'li.' + plugin_name + '_choice');
if (node) {
/* harmony import */__WEBPACK_IMPORTED_MODULE_1__utils__["a"].bind()(node, 'active');
/* harmony import */__WEBPACK_IMPORTED_MODULE_0_ramda_src_forEach___default.a.bind()(function (li) {
return li !== node && /* harmony import */__WEBPACK_IMPORTED_MODULE_1__utils__["c"].bind()(li, 'active');
}, _this.queryResultArea.querySelectorAll('li.' + plugin_name + '_choice.active'));
}
}, this.queryResultArea, listeners);
assignEvent('keyup', this.doQuery.bind(this), this.element, listeners);
assignEvent('change', this.doQuery.bind(this), this.element, listeners);
assignEvent('search', this.doQuery.bind(this), this.element, listeners);
assignEvent('keydown', this.doSelection.bind(this), this.element, listeners);
all_objects.set(this.element, this);
}
_createClass(ImmyBox, [{
key: 'doQuery',
// on 'keyup', 'change', 'search'
// perform a query on the choices
value: function doQuery() {
var query = this.element.value;
if (this._val !== query) {
this._val = query;
this.oldQuery = query;
if (query) {
this.insertFilteredChoiceElements(query);
} else {
this.hideResults();
this.selectChoiceByValue(null);
}
}
}
// on 'keydown'
// select the highlighted choice
}, {
key: 'doSelection',
value: function doSelection(event) {
if (event.which === 27) {
// escape key
this.display();
this.hideResults();
}
if (this.queryResultAreaVisible) {
switch (event.which) {
case 9:
// tab
this.selectHighlightedChoice();
break;
case 13:
// enter
event.preventDefault();
this.selectHighlightedChoice();
break;
case 38:
// up
event.preventDefault();
this.highlightPreviousChoice();
this.scroll();
break;
case 40:
// down
event.preventDefault();
this.highlightNextChoice();
this.scroll();
break;
}
} else {
switch (event.which) {
case 40:
// down
event.preventDefault();
if (this.selectedChoice) this.insertFilteredChoiceElements(this.oldQuery);else this.insertFilteredChoiceElements('');
break;
case 9:
// tab
this.revert();
break;
}
}
}
// on 'click'
// show the results box
}, {
key: 'openResults',
value: function openResults(event) {
event.cancelBubble = true;
event.stopPropogation && event.stopPropogation();
this.revertOtherInstances();
if (this.selectedChoice) {
this.insertFilteredChoiceElements(this.oldQuery);
} else {
this.insertFilteredChoiceElements('');
}
}
// revert or set to null after losing focus
}, {
key: 'revert',
value: function revert() {
if (this.queryResultAreaVisible) {
this.display();
this.hideResults();
} else if (this.element.value === '') this.selectChoiceByValue(null);
}
// if visible, reposition the results area on window resize
}, {
key: 'reposition',
value: function reposition() {
this.queryResultAreaVisible && this.positionResultsArea();
}
}, {
key: 'insertFilteredChoiceElements',
value: function insertFilteredChoiceElements(query) {
var _this2 = this;
var filteredChoices = undefined;
if (query === '') filteredChoices = this.indexed_choices;else {
(function () {
var filter = _this2.options.filterFn(query);
filteredChoices = _this2.indexed_choices.filter(function (_ref3, index) {
var choice = _ref3.choice;
return filter(choice, index);
});
})();
}
var truncatedChoices = filteredChoices.slice(0, this.options.maxResults);
if (this.defaultSelectedChoice) {
if (filteredChoices.indexOf(this.defaultSelectedChoice) >= 0) {
if (truncatedChoices.indexOf(this.defaultSelectedChoice) === -1) {
truncatedChoices.unshift(this.defaultSelectedChoice);
truncatedChoices.pop();
} else {
truncatedChoices = truncatedChoices.filter(function (c) {
return c.choice.value !== _this2.defaultSelectedChoice.value;
});
truncatedChoices.unshift(this.defaultSelectedChoice);
}
}
}
var formatter = this.options.formatChoice(query);
var selected_one = false;
var list = document.createElement('ul');
var results = truncatedChoices.map(function (_ref4) {
var choice = _ref4.choice;
var index = _ref4.index;
var li = document.createElement('li');
li.setAttribute('class', plugin_name + '_choice');
li.setAttribute('data-immybox-value-index', index);
li.innerHTML = formatter(choice);
if (_this2.selectedChoice && index === _this2.selectedChoice.index) {
selected_one = true;
/* harmony import */__WEBPACK_IMPORTED_MODULE_1__utils__["a"].bind()(li, 'active');
}
list.appendChild(li);
return li;
});
if (results.length) {
!selected_one && /* harmony import */__WEBPACK_IMPORTED_MODULE_1__utils__["a"].bind()(results[0], 'active');
} else {
list = document.createElement('p');
list.setAttribute('class', plugin_name + '_noresults');
list.textContent = 'no matches';
}
while (this.queryResultArea.lastChild) {
this.queryResultArea.removeChild(this.queryResultArea.lastChild);
}
this.queryResultArea.appendChild(list);
this.showResults();
}
}, {
key: 'scroll',
value: function scroll() {
this.highlightedChoice && this.highlightedChoice.scrollIntoView({
behavior: this.options.scroll_behavior
});
}
}, {
key: 'positionResultsArea',
value: function positionResultsArea() {
var input_offset = this.element.getBoundingClientRect();
var input_height = this.element.clientHeight;
var input_width = this.element.clientWidth;
var results_height = this.queryResultArea.clientHeight;
var results_bottom = input_offset.top + input_height + results_height;
var window_bottom = window.clientHeight + window.scrollTop;
// set the dimmensions and position
this.queryResultArea.style.width = input_width + 'px';
this.queryResultArea.style.left = input_offset.left + 'px';
if (results_bottom > window_bottom) {
this.queryResultArea.style.top = input_offset.top - results_height + 'px';
} else {
this.queryResultArea.style.top = input_offset.top + input_height + 'px';
}
}
}, {
key: 'highlightNextChoice',
value: function highlightNextChoice() {
var highlighted_choice = this.highlightedChoice;
if (highlighted_choice) {
var next_choice = highlighted_choice.nextSibling;
if (next_choice) {
/* harmony import */__WEBPACK_IMPORTED_MODULE_1__utils__["c"].bind()(highlighted_choice, 'active');
/* harmony import */__WEBPACK_IMPORTED_MODULE_1__utils__["a"].bind()(next_choice, 'active');
}
} else {
var choice = this.queryResultArea.querySelector('li.' + plugin_name + '_choice');
if (choice) /* harmony import */__WEBPACK_IMPORTED_MODULE_1__utils__["a"].bind()(choice, 'active');
}
}
}, {
key: 'highlightPreviousChoice',
value: function highlightPreviousChoice() {
var highlighted_choice = this.highlightedChoice;
if (highlighted_choice) {
var prev_choice = highlighted_choice.previousSibling;
if (prev_choice) {
/* harmony import */__WEBPACK_IMPORTED_MODULE_1__utils__["c"].bind()(highlighted_choice, 'active');
/* harmony import */__WEBPACK_IMPORTED_MODULE_1__utils__["a"].bind()(prev_choice, 'active');
}
} else {
var choice = this.queryResultArea.querySelector('li.' + plugin_name + '_choice:last-child');
if (choice) /* harmony import */__WEBPACK_IMPORTED_MODULE_1__utils__["a"].bind()(choice, 'active');
}
}
}, {
key: 'selectHighlightedChoice',
value: function selectHighlightedChoice() {
var highlighted_choice = this.highlightedChoice;
if (highlighted_choice) {
this.selectChoiceByValue(this.valueFromElement(highlighted_choice));
this.hideResults();
} else this.revert();
}
// display the selected choice in the input box
}, {
key: 'display',
value: function display() {
this.element.value = this.selectedChoice && this.selectedChoice.choice.text || '';
typeof Event !== 'undefined' && this.element.dispatchEvent(new Event('input'));
this._val = this.element.value;
}
// select the first choice with matching value
// Note: values should be unique
}, {
key: 'selectChoiceByValue',
value: function selectChoiceByValue(val) {
var old_val = this.value;
this.selectedChoice = val && this.indexed_choices.find(function (_ref5) {
var choice = _ref5.choice;
return choice.value == val;
}) || null;
var new_val = this.value;
new_val !== old_val && this.element.dispatchEvent(new CustomEvent('update', {
detail: new_val
}));
this.display();
}
}, {
key: 'revertOtherInstances',
value: function revertOtherInstances() {
var _this3 = this;
all_objects.forEach(function (plugin) {
return plugin !== _this3 && plugin.revert();
});
}
}, {
key: 'valueFromElement',
value: function valueFromElement(element) {
var index = parseInt(element.getAttribute('data-immybox-value-index'));
return !Number.isNaN(index) ? this.values[index] : undefined;
}
// public methods
}, {
key: 'showResults',
value: function showResults() {
!this.queryResultAreaVisible && document.body.appendChild(this.queryResultArea);
this.queryResultAreaVisible = true;
this.scroll();
this.positionResultsArea();
}
}, {
key: 'hideResults',
value: function hideResults() {
this.queryResultAreaVisible && document.body.removeChild(this.queryResultArea);
this.queryResultAreaVisible = false;
}
// return array of choices
}, {
key: 'getChoices',
value: function getChoices() {
return this.choices;
}
}, {
key: 'setChoices',
value: function setChoices(newChoices) {
var _this4 = this;
this.choices = newChoices;
if (this.options.defaultSelectedValue != null) {
this.choices = [this.choices.find(function (_ref6) {
var value = _ref6.value;
return value === _this4.options.defaultSelectedValue;
})].concat(_toConsumableArray(this.choices.filter(function (_ref7) {
var value = _ref7.value;
return value !== _this4.options.defaultSelectedValue;
}))).filter(function (choice) {
return choice;
});
}
this.indexed_choices = this.choices.map(function (choice, index) {
return { choice: choice, index: index };
});
this.selectedChoice && this.selectChoiceByValue(this.selectedChoice.choice.value);
this.oldQuery = '';
return this.choices;
}
}, {
key: 'getValue',
value: function getValue() {
return this.value;
}
}, {
key: 'setValue',
value: function setValue(value) {
this.value = value;
}
// get the value of the currently-selected choice
}, {
key: 'destroy',
// destroy this instance of the plugin
value: function destroy() {
// remove event listeners
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = event_listeners.get(this)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var _step$value = _slicedToArray(_step.value, 2);
var node = _step$value[0];
var events = _step$value[1];
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;
try {
for (var _iterator2 = events[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var _step2$value = _slicedToArray(_step2.value, 2);
var event_name = _step2$value[0];
var handler = _step2$value[1];
node.removeEventListener(event_name, handler);
}
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2.return) {
_iterator2.return();
}
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
}
}
}
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
/* harmony import */__WEBPACK_IMPORTED_MODULE_1__utils__["c"].bind()(this.element, plugin_name);
this.queryResultAreaVisible && document.body.removeChild(this.queryResultArea);
all_objects.delete(this.element);
}
}, {
key: 'values',
get: function get() {
return this.choices.map(function (choice) {
return choice.value;
});
}
}, {
key: 'highlightedChoice',
set: function set(choice) {
var highlightedChoice = this.highlightedChoice;
if (highlightedChoice) {
/* harmony import */__WEBPACK_IMPORTED_MODULE_1__utils__["c"].bind()(highlighted_choice, 'active');
/* harmony import */__WEBPACK_IMPORTED_MODULE_1__utils__["a"].bind()(choice, 'active');
}
},
get: function get() {
var choice = this.queryResultArea.querySelector('li.' + plugin_name + '_choice.active');
return choice || null;
}
}, {
key: 'value',
get: function get() {
return this.selectedChoice && this.selectedChoice.choice.value || null;
}
// set the value of the currently-selected choice
,
set: function set(new_value) {
if (this.value !== new_value) {
this.selectChoiceByValue(new_value);
this.oldQuery = '';
}
return this.value;
}
}], [{
key: 'pluginForElement',
value: function pluginForElement(element) {
return all_objects.get(element);
}
}, {
key: 'repositionAll',
value: function repositionAll() {
window.requestAnimationFrame(function () {
all_objects.forEach(function (plugin) {
plugin.queryResultAreaVisible && plugin.reposition();
});
});
}
}, {
key: 'revertAll',
value: function revertAll() {
all_objects.forEach(function (plugin) {
return plugin.revert();
});
}
}, {
key: 'repositionWhenScrolling',
value: function repositionWhenScrolling(container) {
// use one global scoll listener to reposition any result areas that are open
container.addEventListener('scroll', ImmyBox.repositionAll);
}
}, {
key: 'defaults',
set: function set(new_defaults) {
Object.assign(defaults, new_defaults);
},
get: function get() {
return defaults;
}
}, {
key: 'pluginMethods',
get: function get() {
return ['showResults', 'hideResults', 'getChoices', 'setChoices', 'getValue', 'setValue', 'destroy'];
}
}, {
key: 'all_objects',
get: function get() {
return all_objects;
}
}, {
key: 'plugin_name',
get: function get() {
return plugin_name;
}
}]);
return ImmyBox;
}();
/* harmony export */ Object.defineProperty(exports, "ImmyBox", {configurable: false, enumerable: true, get: function() { return ImmyBox; }});
// use one global click event listener to close/revert ones that are open
document.addEventListener('DOMContentLoaded', function () {
document.body.addEventListener('click', ImmyBox.revertAll);
// use one global resize listener to reposition any result areas that are open
window.addEventListener('resize', ImmyBox.repositionAll);
});
"use strict";
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.ImmyBox = undefined;
var _forEach = __webpack_require__(3);
var _forEach2 = _interopRequireDefault(_forEach);
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };
var _utils = __webpack_require__(1);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var event_listeners = new Map();
var defaults = {
choices: [],
maxResults: 50,
showArrow: true,
openOnClick: true,
defaultSelectedValue: undef,
scroll_behavior: 'smooth',
filterFn: function filterFn(query) {
var lower_query = query.toLowerCase();
return function (choice) {
return choice.text.toLowerCase().indexOf(lower_query) >= 0;
};
},
formatChoice: function formatChoice(query) {
if (query) {
var _ret = function () {
var reg = new RegExp(query.replace(/[#-.]|[[-^]|[?|{}]/g, '\\$&'), 'gi');
return {
v: function v(choice) {
return choice.text.replace(reg, '<span class="highlight">$&</span>');
}
};
}();
if ((typeof _ret === 'undefined' ? 'undefined' : _typeof(_ret)) === "object") return _ret.v;
} else return function (choice) {
return choice.text;
};
}
};
var all_objects = new Map();
var plugin_name = 'immybox';
var undef = void 0;
var _noOp = function _noOp() {};
var _dispatchEvent = typeof Event !== 'undefined' ? function (el, name) {
el.dispatchEvent(new Event(name));
} : _noOp;
function assignEvent(event_name, event_handler, node, listeners) {
listeners.has(node) || listeners.set(node, new Map());
listeners.get(node).set(event_name, event_handler);
node.addEventListener(event_name, event_handler);
}
function getEventListenerMap(plugin) {
var map = new Map();
event_listeners.set(plugin, map);
return map;
}
var ImmyBox = exports.ImmyBox = function () {
function ImmyBox(element, options) {
var _this = this;
_classCallCheck(this, ImmyBox);
(0, _utils.addClass)(element, plugin_name);
element.setAttribute('autocomplete', 'off');
var listeners = getEventListenerMap(this);
this.element = element;
this.options = Object.assign({}, ImmyBox.defaults, options);
this.choices = this.options.choices;
if (this.options.defaultSelectedValue != null) this.choices = [this.choices.find(function (_ref) {
var value = _ref.value;
return value === _this.options.defaultSelectedValue;
})].concat(_toConsumableArray(this.choices.filter(function (_ref2) {
var value = _ref2.value;
return value !== _this.options.defaultSelectedValue;
}))).filter(function (choice) {
return choice;
});
this.indexed_choices = this.choices.map(function (choice, index) {
return { index: index, choice: choice };
});
this.selectedChoice = null;
if (this.options.showArrow) (0, _utils.addClass)(this.element, plugin_name + '_witharrow');
this.selectChoiceByValue(this.element.value);
this.queryResultArea = document.createElement('div');
(0, _utils.addClass)(this.queryResultArea, plugin_name + '_results');
this.queryResultAreaVisible = false;
this._val = this.element.value;
this.oldQuery = this.element.value;
if (this.options.openOnClick) assignEvent('click', this.openResults.bind(this), this.element, listeners);
assignEvent('click', function (event) {
var node = (0, _utils.nodeOrParentMatchingSelector)(event.target, 'li.' + plugin_name + '_choice');
if (node) {
var value = _this.valueFromElement(node);
_this.selectChoiceByValue(value);
_this.hideResults();
_this._val = _this.element.value;
_this.element.focus();
}
}, this.queryResultArea, listeners);
assignEvent('mouseenter', function (event) {
var node = (0, _utils.nodeOrParentMatchingSelector)(event.target, 'li.' + plugin_name + '_choice');
if (node) {
(0, _utils.addClass)(node, 'active');
(0, _forEach2.default)(function (li) {
return li !== node && (0, _utils.removeClass)(li, 'active');
}, _this.queryResultArea.querySelectorAll('li.' + plugin_name + '_choice.active'));
}
}, this.queryResultArea, listeners);
assignEvent('keyup', this.doQuery.bind(this), this.element, listeners);
assignEvent('change', this.doQuery.bind(this), this.element, listeners);
assignEvent('search', this.doQuery.bind(this), this.element, listeners);
assignEvent('keydown', this.doSelection.bind(this), this.element, listeners);
all_objects.set(this.element, this);
}
_createClass(ImmyBox, [{
key: 'doQuery',
// on 'keyup', 'change', 'search'
// perform a query on the choices
value: function doQuery() {
var query = this.element.value;
if (this._val !== query) {
this._val = query;
this.oldQuery = query;
if (query) {
this.insertFilteredChoiceElements(query);
} else {
this.hideResults();
this.selectChoiceByValue(null);
}
}
}
// on 'keydown'
// select the highlighted choice
}, {
key: 'doSelection',
value: function doSelection(event) {
if (event.which === 27) {
// escape key
this.display();
this.hideResults();
}
if (this.queryResultAreaVisible) {
switch (event.which) {
case 9:
// tab
this.selectHighlightedChoice();
break;
case 13:
// enter
event.preventDefault();
this.selectHighlightedChoice();
break;
case 38:
// up
event.preventDefault();
this.highlightPreviousChoice();
this.scroll();
break;
case 40:
// down
event.preventDefault();
this.highlightNextChoice();
this.scroll();
break;
}
} else {
switch (event.which) {
case 40:
// down
event.preventDefault();
if (this.selectedChoice) this.insertFilteredChoiceElements(this.oldQuery);else this.insertFilteredChoiceElements('');
break;
case 9:
// tab
this.revert();
break;
}
}
}
// on 'click'
// show the results box
}, {
key: 'openResults',
value: function openResults(event) {
event.cancelBubble = true;
event.stopPropogation && event.stopPropogation();
this.revertOtherInstances();
if (this.selectedChoice) {
this.insertFilteredChoiceElements(this.oldQuery);
} else {
this.insertFilteredChoiceElements('');
}
}
// revert or set to null after losing focus
}, {
key: 'revert',
value: function revert() {
if (this.queryResultAreaVisible) {
this.display();
this.hideResults();
} else if (this.element.value === '') this.selectChoiceByValue(null);
}
// if visible, reposition the results area on window resize
}, {
key: 'reposition',
value: function reposition() {
this.queryResultAreaVisible && this.positionResultsArea();
}
}, {
key: 'insertFilteredChoiceElements',
value: function insertFilteredChoiceElements(query) {
var _this2 = this;
var filteredChoices = void 0;
if (query === '') filteredChoices = this.indexed_choices;else {
(function () {
var filter = _this2.options.filterFn(query);
filteredChoices = _this2.indexed_choices.filter(function (_ref3, index) {
var choice = _ref3.choice;
return filter(choice, index);
});
})();
}
var truncatedChoices = filteredChoices.slice(0, this.options.maxResults);
if (this.defaultSelectedChoice) {
if (filteredChoices.indexOf(this.defaultSelectedChoice) >= 0) {
if (truncatedChoices.indexOf(this.defaultSelectedChoice) === -1) {
truncatedChoices.unshift(this.defaultSelectedChoice);
truncatedChoices.pop();
} else {
truncatedChoices = truncatedChoices.filter(function (c) {
return c.choice.value !== _this2.defaultSelectedChoice.value;
});
truncatedChoices.unshift(this.defaultSelectedChoice);
}
}
}
var formatter = this.options.formatChoice(query);
var selected_one = false;
var list = document.createElement('ul');
var results = truncatedChoices.map(function (_ref4) {
var choice = _ref4.choice;
var index = _ref4.index;
var li = document.createElement('li');
li.setAttribute('class', plugin_name + '_choice');
li.setAttribute('data-immybox-value-index', index);
li.innerHTML = formatter(choice);
if (_this2.selectedChoice && index === _this2.selectedChoice.index) {
selected_one = true;
(0, _utils.addClass)(li, 'active');
}
list.appendChild(li);
return li;
});
if (results.length) {
!selected_one && (0, _utils.addClass)(results[0], 'active');
} else {
list = document.createElement('p');
list.setAttribute('class', plugin_name + '_noresults');
list.textContent = 'no matches';
}
while (this.queryResultArea.lastChild) {
this.queryResultArea.removeChild(this.queryResultArea.lastChild);
}
this.queryResultArea.appendChild(list);
this.showResults();
}
}, {
key: 'scroll',
value: function scroll() {
this.highlightedChoice && this.highlightedChoice.scrollIntoView({
behavior: this.options.scroll_behavior
});
}
}, {
key: 'positionResultsArea',
value: function positionResultsArea() {
var input_offset = this.element.getBoundingClientRect();
var input_height = this.element.clientHeight;
var input_width = this.element.clientWidth;
var results_height = this.queryResultArea.clientHeight;
var results_bottom = input_offset.top + input_height + results_height;
var window_bottom = window.clientHeight + window.scrollTop;
// set the dimmensions and position
this.queryResultArea.style.width = input_width + 'px';
this.queryResultArea.style.left = input_offset.left + 'px';
if (results_bottom > window_bottom) {
this.queryResultArea.style.top = input_offset.top - results_height + 'px';
} else {
this.queryResultArea.style.top = input_offset.top + input_height + 'px';
}
}
}, {
key: 'highlightNextChoice',
value: function highlightNextChoice() {
var highlighted_choice = this.highlightedChoice;
if (highlighted_choice) {
var next_choice = highlighted_choice.nextSibling;
if (next_choice) {
(0, _utils.removeClass)(highlighted_choice, 'active');
(0, _utils.addClass)(next_choice, 'active');
}
} else {
var choice = this.queryResultArea.querySelector('li.' + plugin_name + '_choice');
if (choice) (0, _utils.addClass)(choice, 'active');
}
}
}, {
key: 'highlightPreviousChoice',
value: function highlightPreviousChoice() {
var highlighted_choice = this.highlightedChoice;
if (highlighted_choice) {
var prev_choice = highlighted_choice.previousSibling;
if (prev_choice) {
(0, _utils.removeClass)(highlighted_choice, 'active');
(0, _utils.addClass)(prev_choice, 'active');
}
} else {
var choice = this.queryResultArea.querySelector('li.' + plugin_name + '_choice:last-child');
if (choice) (0, _utils.addClass)(choice, 'active');
}
}
}, {
key: 'selectHighlightedChoice',
value: function selectHighlightedChoice() {
var highlighted_choice = this.highlightedChoice;
if (highlighted_choice) {
this.selectChoiceByValue(this.valueFromElement(highlighted_choice));
this.hideResults();
} else this.revert();
}
// display the selected choice in the input box
}, {
key: 'display',
value: function display() {
this.element.value = this.selectedChoice && this.selectedChoice.choice.text || '';
_dispatchEvent(this.element, 'input');
this._val = this.element.value;
}
// select the first choice with matching value (matching is done via the threequals comparison)
// Note: values should be unique
}, {
key: 'selectChoiceByValue',
value: function selectChoiceByValue(val) {
var old_val = this.value;
if (typeof val === 'undefined') {
this.selectedChoice = undef;
} else {
this.selectedChoice = this.indexed_choices.find(function (_ref5) {
var choice = _ref5.choice;
return choice.value === val;
});
}
var new_val = this.value;
new_val !== old_val && this.element.dispatchEvent(new CustomEvent('update', {
detail: new_val
}));
this.display();
}
}, {
key: 'revertOtherInstances',
value: function revertOtherInstances() {
var _this3 = this;
all_objects.forEach(function (plugin) {
return plugin !== _this3 && plugin.revert();
});
}
}, {
key: 'valueFromElement',
value: function valueFromElement(element) {
var index = parseInt(element.getAttribute('data-immybox-value-index'));
return !Number.isNaN(index) ? this.values[index] : undef;
}
// public methods
}, {
key: 'showResults',
value: function showResults() {
!this.queryResultAreaVisible && document.body.appendChild(this.queryResultArea);
this.queryResultAreaVisible = true;
this.scroll();
this.positionResultsArea();
}
}, {
key: 'open',
value: function open() {
return this.showResults();
}
}, {
key: 'hideResults',
value: function hideResults() {
this.queryResultAreaVisible && document.body.removeChild(this.queryResultArea);
this.queryResultAreaVisible = false;
}
}, {
key: 'close',
value: function close() {
return this.hideResults();
}
// return array of choices
}, {
key: 'getChoices',
value: function getChoices() {
return this.choices;
}
}, {
key: 'setChoices',
value: function setChoices(newChoices) {
this.choices = newChoices;
var default_selected_value = this.options.defaultSelectedValue;
if (default_selected_value != null) {
this.choices = [this.choices.find(function (_ref6) {
var value = _ref6.value;
return value === default_selected_value;
})].concat(_toConsumableArray(this.choices.filter(function (_ref7) {
var value = _ref7.value;
return value !== default_selected_value;
}))).filter(function (choice) {
return choice;
});
}
this.indexed_choices = this.choices.map(function (choice, index) {
return { choice: choice, index: index };
});
this.selectedChoice && this.selectChoiceByValue(this.selectedChoice.choice.value);
this.oldQuery = '';
return this.choices;
}
}, {
key: 'getValue',
value: function getValue() {
return this.value;
}
}, {
key: 'setValue',
value: function setValue(value) {
this.value = value;
}
}, {
key: 'unsetValue',
value: function unsetValue() {
if (typeof this.value !== 'undefined') {
this.value = undef;
}
}
// get the value of the currently-selected choice
}, {
key: 'destroy',
// destroy this instance of the plugin
value: function destroy() {
// remove event listeners
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = event_listeners.get(this)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var _step$value = _slicedToArray(_step.value, 2);
var node = _step$value[0];
var events = _step$value[1];
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;
try {
for (var _iterator2 = events[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var _step2$value = _slicedToArray(_step2.value, 2);
var event_name = _step2$value[0];
var handler = _step2$value[1];
node.removeEventListener(event_name, handler);
}
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2.return) {
_iterator2.return();
}
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
}
}
}
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
(0, _utils.removeClass)(this.element, plugin_name);
this.queryResultAreaVisible && document.body.removeChild(this.queryResultArea);
all_objects.delete(this.element);
}
}, {
key: 'values',
get: function get() {
return this.choices.map(function (choice) {
return choice.value;
});
}
}, {
key: 'highlightedChoice',
set: function set(choice) {
var highlightedChoice = this.highlightedChoice;
if (highlightedChoice) {
(0, _utils.removeClass)(highlightedChoice, 'active');
(0, _utils.addClass)(choice, 'active');
}
},
get: function get() {
var choice = this.queryResultArea.querySelector('li.' + plugin_name + '_choice.active');
return choice || null;
}
}, {
key: 'value',
get: function get() {
return this.selectedChoice && this.selectedChoice.choice.value;
}
// set the value of the currently-selected choice
,
set: function set(new_value) {
if (this.value !== new_value) {
this.selectChoiceByValue(new_value);
this.oldQuery = '';
}
return this.value;
}
}], [{
key: 'pluginForElement',
value: function pluginForElement(element) {
return all_objects.get(element);
}
}, {
key: 'repositionAll',
value: function repositionAll() {
window.requestAnimationFrame(function () {
all_objects.forEach(function (plugin) {
plugin.queryResultAreaVisible && plugin.reposition();
});
});
}
}, {
key: 'revertAll',
value: function revertAll() {
all_objects.forEach(function (plugin) {
return plugin.revert();
});
}
}, {
key: 'repositionWhenScrolling',
value: function repositionWhenScrolling(container) {
// use one global scoll listener to reposition any result areas that are open
container.addEventListener('scroll', ImmyBox.repositionAll);
}
}, {
key: 'defaults',
set: function set(new_defaults) {
Object.assign(defaults, new_defaults);
},
get: function get() {
return defaults;
}
}, {
key: 'pluginMethods',
get: function get() {
return ['showResults', 'open', 'hideResults', 'close', 'getChoices', 'setChoices', 'getValue', 'setValue', 'destroy'];
}
}, {
key: 'all_objects',
get: function get() {
return all_objects;
}
}, {
key: 'plugin_name',
get: function get() {
return plugin_name;
}
}]);
return ImmyBox;
}();
// use one global click event listener to close/revert ones that are open
document.addEventListener('DOMContentLoaded', function () {
document.body.addEventListener('click', ImmyBox.revertAll);
// use one global resize listener to reposition any result areas that are open
window.addEventListener('resize', ImmyBox.repositionAll);
});
/***/ },

@@ -812,50 +881,50 @@ /* 3 */

var _checkForMethod = __webpack_require__(4);
var _curry2 = __webpack_require__(6);
/**
* Iterate over an input `list`, calling a provided function `fn` for each
* element in the list.
*
* `fn` receives one argument: *(value)*.
*
* Note: `R.forEach` does not skip deleted or unassigned indices (sparse
* arrays), unlike the native `Array.prototype.forEach` method. For more
* details on this behavior, see:
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach#Description
*
* Also note that, unlike `Array.prototype.forEach`, Ramda's `forEach` returns
* the original array. In some libraries this function is named `each`.
*
* Dispatches to the `forEach` method of the second argument, if present.
*
* @func
* @memberOf R
* @since v0.1.1
* @category List
* @sig (a -> *) -> [a] -> [a]
* @param {Function} fn The function to invoke. Receives one argument, `value`.
* @param {Array} list The list to iterate over.
* @return {Array} The original list.
* @see R.addIndex
* @example
*
* var printXPlusFive = x => console.log(x + 5);
* R.forEach(printXPlusFive, [1, 2, 3]); //=> [1, 2, 3]
* //-> 6
* //-> 7
* //-> 8
*/
module.exports = _curry2(_checkForMethod('forEach', function forEach(fn, list) {
var len = list.length;
var idx = 0;
while (idx < len) {
fn(list[idx]);
idx += 1;
}
return list;
}));
var _checkForMethod = __webpack_require__(4);
var _curry2 = __webpack_require__(6);
/**
* Iterate over an input `list`, calling a provided function `fn` for each
* element in the list.
*
* `fn` receives one argument: *(value)*.
*
* Note: `R.forEach` does not skip deleted or unassigned indices (sparse
* arrays), unlike the native `Array.prototype.forEach` method. For more
* details on this behavior, see:
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach#Description
*
* Also note that, unlike `Array.prototype.forEach`, Ramda's `forEach` returns
* the original array. In some libraries this function is named `each`.
*
* Dispatches to the `forEach` method of the second argument, if present.
*
* @func
* @memberOf R
* @since v0.1.1
* @category List
* @sig (a -> *) -> [a] -> [a]
* @param {Function} fn The function to invoke. Receives one argument, `value`.
* @param {Array} list The list to iterate over.
* @return {Array} The original list.
* @see R.addIndex
* @example
*
* var printXPlusFive = x => console.log(x + 5);
* R.forEach(printXPlusFive, [1, 2, 3]); //=> [1, 2, 3]
* //-> 6
* //-> 7
* //-> 8
*/
module.exports = _curry2(_checkForMethod('forEach', function forEach(fn, list) {
var len = list.length;
var idx = 0;
while (idx < len) {
fn(list[idx]);
idx += 1;
}
return list;
}));
/***/ },

@@ -865,30 +934,30 @@ /* 4 */

var _isArray = __webpack_require__(7);
var _slice = __webpack_require__(8);
/**
* Similar to hasMethod, this checks whether a function has a [methodname]
* function. If it isn't an array it will execute that function otherwise it
* will default to the ramda implementation.
*
* @private
* @param {Function} fn ramda implemtation
* @param {String} methodname property to check for a custom implementation
* @return {Object} Whatever the return value of the method is.
*/
module.exports = function _checkForMethod(methodname, fn) {
return function() {
var length = arguments.length;
if (length === 0) {
return fn();
}
var obj = arguments[length - 1];
return (_isArray(obj) || typeof obj[methodname] !== 'function') ?
fn.apply(this, arguments) :
obj[methodname].apply(obj, _slice(arguments, 0, length - 1));
};
};
var _isArray = __webpack_require__(7);
var _slice = __webpack_require__(8);
/**
* Similar to hasMethod, this checks whether a function has a [methodname]
* function. If it isn't an array it will execute that function otherwise it
* will default to the ramda implementation.
*
* @private
* @param {Function} fn ramda implemtation
* @param {String} methodname property to check for a custom implementation
* @return {Object} Whatever the return value of the method is.
*/
module.exports = function _checkForMethod(methodname, fn) {
return function() {
var length = arguments.length;
if (length === 0) {
return fn();
}
var obj = arguments[length - 1];
return (_isArray(obj) || typeof obj[methodname] !== 'function') ?
fn.apply(this, arguments) :
obj[methodname].apply(obj, _slice(arguments, 0, length - 1));
};
};
/***/ },

@@ -898,24 +967,24 @@ /* 5 */

var _isPlaceholder = __webpack_require__(0);
/**
* Optimized internal one-arity curry function.
*
* @private
* @category Function
* @param {Function} fn The function to curry.
* @return {Function} The curried function.
*/
module.exports = function _curry1(fn) {
return function f1(a) {
if (arguments.length === 0 || _isPlaceholder(a)) {
return f1;
} else {
return fn.apply(this, arguments);
}
};
};
var _isPlaceholder = __webpack_require__(0);
/**
* Optimized internal one-arity curry function.
*
* @private
* @category Function
* @param {Function} fn The function to curry.
* @return {Function} The curried function.
*/
module.exports = function _curry1(fn) {
return function f1(a) {
if (arguments.length === 0 || _isPlaceholder(a)) {
return f1;
} else {
return fn.apply(this, arguments);
}
};
};
/***/ },

@@ -925,32 +994,32 @@ /* 6 */

var _curry1 = __webpack_require__(5);
var _isPlaceholder = __webpack_require__(0);
/**
* Optimized internal two-arity curry function.
*
* @private
* @category Function
* @param {Function} fn The function to curry.
* @return {Function} The curried function.
*/
module.exports = function _curry2(fn) {
return function f2(a, b) {
switch (arguments.length) {
case 0:
return f2;
case 1:
return _isPlaceholder(a) ? f2
: _curry1(function(_b) { return fn(a, _b); });
default:
return _isPlaceholder(a) && _isPlaceholder(b) ? f2
: _isPlaceholder(a) ? _curry1(function(_a) { return fn(_a, b); })
: _isPlaceholder(b) ? _curry1(function(_b) { return fn(a, _b); })
: fn(a, b);
}
};
};
var _curry1 = __webpack_require__(5);
var _isPlaceholder = __webpack_require__(0);
/**
* Optimized internal two-arity curry function.
*
* @private
* @category Function
* @param {Function} fn The function to curry.
* @return {Function} The curried function.
*/
module.exports = function _curry2(fn) {
return function f2(a, b) {
switch (arguments.length) {
case 0:
return f2;
case 1:
return _isPlaceholder(a) ? f2
: _curry1(function(_b) { return fn(a, _b); });
default:
return _isPlaceholder(a) && _isPlaceholder(b) ? f2
: _isPlaceholder(a) ? _curry1(function(_a) { return fn(_a, b); })
: _isPlaceholder(b) ? _curry1(function(_b) { return fn(a, _b); })
: fn(a, b);
}
};
};
/***/ },

@@ -960,19 +1029,19 @@ /* 7 */

/**
* Tests whether or not an object is an array.
*
* @private
* @param {*} val The object to test.
* @return {Boolean} `true` if `val` is an array, `false` otherwise.
* @example
*
* _isArray([]); //=> true
* _isArray(null); //=> false
* _isArray({}); //=> false
*/
module.exports = Array.isArray || function _isArray(val) {
return (val != null &&
val.length >= 0 &&
Object.prototype.toString.call(val) === '[object Array]');
};
/**
* Tests whether or not an object is an array.
*
* @private
* @param {*} val The object to test.
* @return {Boolean} `true` if `val` is an array, `false` otherwise.
* @example
*
* _isArray([]); //=> true
* _isArray(null); //=> false
* _isArray({}); //=> false
*/
module.exports = Array.isArray || function _isArray(val) {
return (val != null &&
val.length >= 0 &&
Object.prototype.toString.call(val) === '[object Array]');
};

@@ -984,34 +1053,34 @@

/**
* An optimized, private array `slice` implementation.
*
* @private
* @param {Arguments|Array} args The array or arguments object to consider.
* @param {Number} [from=0] The array index to slice from, inclusive.
* @param {Number} [to=args.length] The array index to slice to, exclusive.
* @return {Array} A new, sliced array.
* @example
*
* _slice([1, 2, 3, 4, 5], 1, 3); //=> [2, 3]
*
* var firstThreeArgs = function(a, b, c, d) {
* return _slice(arguments, 0, 3);
* };
* firstThreeArgs(1, 2, 3, 4); //=> [1, 2, 3]
*/
module.exports = function _slice(args, from, to) {
switch (arguments.length) {
case 1: return _slice(args, 0, args.length);
case 2: return _slice(args, from, args.length);
default:
var list = [];
var idx = 0;
var len = Math.max(0, Math.min(args.length, to) - from);
while (idx < len) {
list[idx] = args[from + idx];
idx += 1;
}
return list;
}
};
/**
* An optimized, private array `slice` implementation.
*
* @private
* @param {Arguments|Array} args The array or arguments object to consider.
* @param {Number} [from=0] The array index to slice from, inclusive.
* @param {Number} [to=args.length] The array index to slice to, exclusive.
* @return {Array} A new, sliced array.
* @example
*
* _slice([1, 2, 3, 4, 5], 1, 3); //=> [2, 3]
*
* var firstThreeArgs = function(a, b, c, d) {
* return _slice(arguments, 0, 3);
* };
* firstThreeArgs(1, 2, 3, 4); //=> [1, 2, 3]
*/
module.exports = function _slice(args, from, to) {
switch (arguments.length) {
case 1: return _slice(args, 0, args.length);
case 2: return _slice(args, from, args.length);
default:
var list = [];
var idx = 0;
var len = Math.max(0, Math.min(args.length, to) - from);
while (idx < len) {
list[idx] = args[from + idx];
idx += 1;
}
return list;
}
};

@@ -1023,29 +1092,32 @@

/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__immybox__ = __webpack_require__(2);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__utils__ = __webpack_require__(1);
/*eslint no-console:0*/
(function ($) {
$.fn.immybox = function (options) {
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
var outputs = [];
this.each(function (i, element) {
var plugin = /* harmony import */__WEBPACK_IMPORTED_MODULE_0__immybox__["ImmyBox"].all_objects.get(element);
if (plugin) {
// calling a method on a pre-immyboxed element
/* harmony import */__WEBPACK_IMPORTED_MODULE_1__utils__["d"].bind()(typeof options === 'string', /* harmony import */__WEBPACK_IMPORTED_MODULE_0__immybox__["ImmyBox"].plugin_name + ' already intitialized for this element');
/* harmony import */__WEBPACK_IMPORTED_MODULE_1__utils__["d"].bind()(/* harmony import */__WEBPACK_IMPORTED_MODULE_0__immybox__["ImmyBox"].pluginMethods.includes(options), /* harmony import */__WEBPACK_IMPORTED_MODULE_0__immybox__["ImmyBox"].plugin_name + ' has no method \'' + options + '\'');
outputs.push(plugin[options].apply(plugin, args));
} else {
new /* harmony import */__WEBPACK_IMPORTED_MODULE_0__immybox__["ImmyBox"](element, options);
}
});
return outputs.length ? outputs.length === 1 ? outputs[0] : outputs : this;
};
})(jQuery);
"use strict";
'use strict';
var _immybox = __webpack_require__(2);
var _utils = __webpack_require__(1);
/*eslint no-console:0*/
(function ($) {
$.fn.immybox = function (options) {
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
var outputs = [];
this.each(function (i, element) {
var plugin = _immybox.ImmyBox.all_objects.get(element);
if (plugin) {
// calling a method on a pre-immyboxed element
(0, _utils.assert)(typeof options === 'string', _immybox.ImmyBox.plugin_name + ' already intitialized for this element');
(0, _utils.assert)(_immybox.ImmyBox.pluginMethods.includes(options), _immybox.ImmyBox.plugin_name + ' has no method \'' + options + '\'');
outputs.push(plugin[options].apply(plugin, args));
} else {
new _immybox.ImmyBox(element, options);
}
});
return outputs.length ? outputs.length === 1 ? outputs[0] : outputs : this;
};
})(jQuery);
/***/ }

@@ -1052,0 +1124,0 @@ /******/ ])

{
"name": "immybox",
"version": "1.0.0-beta1",
"version": "1.0.0-beta2",
"main": "build/immybox.js",
"scripts": {
"uglify:js": "chalk blue '=> uglifying JS' && uglifyjs -c -m -o build/immybox.min.js -- build/immybox.js && chalk green 'Done!'",
"build:less": "chalk blue '=> compiling less' && lessc src/immybox.less build/immybox.css && chalk green 'Done!'",
"build:css": "chalk blue '=> compiling scss to css' && node-sass src/immybox.scss --output-style expanded > build/immybox.css && chalk green 'Done!'",
"build:js": "chalk blue '=> transpiling ES6' && webpack && chalk green 'Done!'",
"build": "npm run build:less -s && npm run build:js -s && npm run uglify:js -s",
"build": "npm run build:css -s && npm run build:js -s && npm run uglify:js -s",
"lint": "chalk blue '=> linting' && eslint src && chalk green 'All good!'",

@@ -15,16 +15,14 @@ "watch": "chalk blue '=> building on changes to /src' && watch 'npm run lint -s && npm run build -s' src",

"devDependencies": {
"babel-core": "^6.5.2",
"babel-loader": "^6.2.2",
"babel-plugin-ramda": "^1.1.1",
"babel-preset-es2015": "^6.5.0",
"babel-preset-es2015-native-modules": "^6.6.0",
"babel-preset-es2015-webpack": "^6.4.1",
"chalk-cli": "1.x",
"eslint": "1.x",
"eslint-plugin-babel": "2.x",
"less": "git://github.com/less/less.js#ec04a03f1cba3a092d5cd7f7c5d8e28bb43c1932",
"requirejs": "^2.1.22",
"uglify-js": "^2.6.1",
"webpack": "2.1.0-beta.6"
"babel-core": "6.x",
"babel-loader": "6.x",
"babel-plugin-ramda": "1.x",
"babel-preset-es2015": "6.x",
"chalk-cli": "3.x",
"eslint": "3.x",
"eslint-plugin-babel": "3.x",
"node-sass": "3.x",
"requirejs": "2.x",
"uglify-js": "2.x",
"webpack": "2.1.0-beta.20"
}
}

@@ -12,3 +12,3 @@ import {addClass, removeClass, nodeOrParentMatchingSelector} from './utils';

openOnClick: true,
defaultSelectedValue: undefined,
defaultSelectedValue: undef,
scroll_behavior: 'smooth',

@@ -32,2 +32,10 @@ filterFn(query) {

const undef = void 0;
const _noOp = function() {};
const _dispatchEvent = typeof Event !== 'undefined' ? function(el, name) {
el.dispatchEvent(new Event(name));
} : _noOp;
function assignEvent(event_name, event_handler, node, listeners) {

@@ -280,3 +288,3 @@ listeners.has(node) || listeners.set(node, new Map());

if (highlightedChoice) {
removeClass(highlighted_choice, 'active');
removeClass(highlightedChoice, 'active');
addClass(choice, 'active');

@@ -330,13 +338,15 @@ }

this.element.value = this.selectedChoice && this.selectedChoice.choice.text || '';
typeof Event !== 'undefined' && this.element.dispatchEvent(new Event('input'));
_dispatchEvent(this.element, 'input');
this._val = this.element.value;
}
// select the first choice with matching value
// select the first choice with matching value (matching is done via the threequals comparison)
// Note: values should be unique
selectChoiceByValue(val) {
let old_val = this.value;
this.selectedChoice = (val && this.indexed_choices.find(({choice}) => {
return choice.value == val;
}) || null);
if (typeof val === 'undefined') {
this.selectedChoice = undef;
} else {
this.selectedChoice = this.indexed_choices.find(({choice}) => choice.value === val);
}
let new_val = this.value;

@@ -355,3 +365,3 @@ new_val !== old_val && this.element.dispatchEvent(new CustomEvent('update', {

let index = parseInt(element.getAttribute('data-immybox-value-index'));
return !Number.isNaN(index) ? this.values[index] : undefined;
return !Number.isNaN(index) ? this.values[index] : undef;
}

@@ -368,2 +378,6 @@

open() {
return this.showResults();
}
hideResults() {

@@ -374,2 +388,6 @@ this.queryResultAreaVisible && document.body.removeChild(this.queryResultArea);

close() {
return this.hideResults();
}
// return array of choices

@@ -382,11 +400,8 @@ getChoices() {

this.choices = newChoices;
if (this.options.defaultSelectedValue != null) {
const default_selected_value = this.options.defaultSelectedValue;
if (default_selected_value != null) {
this.choices = [
this.choices.find(({value}) => {
return value === this.options.defaultSelectedValue;
}), ...(
this.choices.filter(({value}) => {
return value !== this.options.defaultSelectedValue;
}))
].filter(choice => choice);
this.choices.find(({value}) => value === default_selected_value),
...this.choices.filter(({value}) => value !== default_selected_value)
].filter(choice => choice);
}

@@ -407,5 +422,11 @@ this.indexed_choices = this.choices.map((choice, index) => ({choice, index}));

unsetValue() {
if (typeof this.value !== 'undefined') {
this.value = undef;
}
}
// get the value of the currently-selected choice
get value() {
return this.selectedChoice && this.selectedChoice.choice.value || null;
return this.selectedChoice && this.selectedChoice.choice.value;
}

@@ -442,3 +463,13 @@

static get pluginMethods() {
return ['showResults', 'hideResults', 'getChoices', 'setChoices', 'getValue', 'setValue', 'destroy'];
return [
'showResults',
'open',
'hideResults',
'close',
'getChoices',
'setChoices',
'getValue',
'setValue',
'destroy'
];
}

@@ -445,0 +476,0 @@ static pluginForElement(element) {

@@ -11,5 +11,6 @@ {

],
"devDependencies": {
"jasmine-jquery": "~2.1.1"
"dependencies": {
"jasmine-core": "jasmine#^2.4.1",
"jquery": "^3.1.0"
}
}

@@ -177,3 +177,3 @@ var fixture;

it('accepts objects as choices', () => {
it('accepts object values in choices', () => {
const foo = {foo: 'foo'};

@@ -196,2 +196,3 @@ const bar = {bar: 'bar'};

expect(immybox.value).toEqual(foo);
expect(el.value).toEqual('foo');

@@ -202,2 +203,3 @@ el.value = 'bar';

expect(immybox.value).toEqual(bar);
expect(el.value).toEqual('bar');

@@ -208,4 +210,35 @@ el.value = 'baz';

expect(immybox.value).toEqual(baz);
expect(el.value).toEqual('baz');
});
it('accepts falsey values in choices', () => {
const opts = {
choices: [
{text: 'null', value: null},
{text: '0', value: 0},
{text: '1', value: 1}
]
};
immybox = new ImmyBox(el, opts);
el.click();
el.value = 'null';
el.dispatchEvent(new Event("keyup", {"bubbles":true, "cancelable":false}));
immybox.queryResultArea.querySelector('li:first-of-type').click();
expect(immybox.value).toEqual(null);
expect(el.value).toEqual("null");
el.value = '0';
el.dispatchEvent(new Event("keyup", {"bubbles":true, "cancelable":false}));
immybox.queryResultArea.querySelector('li:first-of-type').click();
expect(immybox.value).toEqual(0);
expect(el.value).toEqual("0");
el.value = '1';
el.dispatchEvent(new Event("keyup", {"bubbles":true, "cancelable":false}));
immybox.queryResultArea.querySelector('li:first-of-type').click();
expect(immybox.value).toEqual(1);
expect(el.value).toEqual("1");
});
it('allows choices to be reset', () => {

@@ -225,2 +258,3 @@ const opts = {

expect(immybox.value).toEqual('foo');
expect(el.value).toEqual('foo');

@@ -231,3 +265,4 @@ immybox.setChoices([

]);
expect(immybox.value).toEqual(null);
expect(immybox.value).toEqual(undefined);
expect(el.value).toEqual('');

@@ -239,4 +274,24 @@ el.click();

expect(immybox.value).toEqual('quux');
expect(el.value).toEqual('quux');
});
});
describe('jquery.immybox', () => {
describe('#open() and #close()', () => {
it('opens and closes the query result area', () => {
const opts = {
choices: [
{text: 'foo', value: 'foo'},
{text: 'bar', value: 'bar'}
]
};
$('#input-1').immybox(opts);
immybox = ImmyBox.all_objects.get(el);
$('#input-1').immybox('open');
expect(document.querySelector('.immybox_results')).not.toBeNull();
$('#input-1').immybox('close');
expect(document.querySelector('.immybox_results')).toBeNull();
});
});
});
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc