2016-12-13 22:55:25 -05:00
|
|
|
/* eslint-disable */
|
2016-12-13 22:36:54 -05:00
|
|
|
// Determine where to place this
|
|
|
|
if (typeof Object.assign != 'function') {
|
|
|
|
Object.assign = function (target, varArgs) { // .length of function is 2
|
|
|
|
'use strict';
|
|
|
|
if (target == null) { // TypeError if undefined or null
|
|
|
|
throw new TypeError('Cannot convert undefined or null to object');
|
|
|
|
}
|
|
|
|
|
|
|
|
var to = Object(target);
|
|
|
|
|
|
|
|
for (var index = 1; index < arguments.length; index++) {
|
|
|
|
var nextSource = arguments[index];
|
|
|
|
|
|
|
|
if (nextSource != null) { // Skip over if undefined or null
|
|
|
|
for (var nextKey in nextSource) {
|
|
|
|
// Avoid bugs when hasOwnProperty is shadowed
|
|
|
|
if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
|
|
|
|
to[nextKey] = nextSource[nextKey];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return to;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-11-09 15:44:11 -05:00
|
|
|
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.droplab = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
|
|
|
|
var DATA_TRIGGER = 'data-dropdown-trigger';
|
|
|
|
var DATA_DROPDOWN = 'data-dropdown';
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
DATA_TRIGGER: DATA_TRIGGER,
|
|
|
|
DATA_DROPDOWN: DATA_DROPDOWN,
|
|
|
|
}
|
|
|
|
|
|
|
|
},{}],2:[function(require,module,exports){
|
|
|
|
// Custom event support for IE
|
|
|
|
if ( typeof CustomEvent === "function" ) {
|
|
|
|
module.exports = CustomEvent;
|
|
|
|
} else {
|
|
|
|
require('./window')(function(w){
|
|
|
|
var CustomEvent = function ( event, params ) {
|
|
|
|
params = params || { bubbles: false, cancelable: false, detail: undefined };
|
|
|
|
var evt = document.createEvent( 'CustomEvent' );
|
|
|
|
evt.initCustomEvent( event, params.bubbles, params.cancelable, params.detail );
|
|
|
|
return evt;
|
|
|
|
}
|
|
|
|
CustomEvent.prototype = w.Event.prototype;
|
|
|
|
|
|
|
|
w.CustomEvent = CustomEvent;
|
|
|
|
});
|
|
|
|
module.exports = CustomEvent;
|
|
|
|
}
|
|
|
|
|
|
|
|
},{"./window":11}],3:[function(require,module,exports){
|
|
|
|
var CustomEvent = require('./custom_event_polyfill');
|
|
|
|
var utils = require('./utils');
|
|
|
|
|
2016-12-10 12:13:17 -05:00
|
|
|
var DropDown = function(list) {
|
2017-01-20 09:20:29 -05:00
|
|
|
this.currentIndex = 0;
|
2016-11-09 15:44:11 -05:00
|
|
|
this.hidden = true;
|
|
|
|
this.list = list;
|
|
|
|
this.items = [];
|
|
|
|
this.getItems();
|
2017-01-20 17:59:40 -05:00
|
|
|
this.initTemplateString();
|
2016-11-09 15:44:11 -05:00
|
|
|
this.addEvents();
|
2016-12-02 16:02:54 -05:00
|
|
|
this.initialState = list.innerHTML;
|
2016-11-09 15:44:11 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
Object.assign(DropDown.prototype, {
|
|
|
|
getItems: function() {
|
|
|
|
this.items = [].slice.call(this.list.querySelectorAll('li'));
|
|
|
|
return this.items;
|
|
|
|
},
|
|
|
|
|
2017-01-20 17:59:40 -05:00
|
|
|
initTemplateString: function() {
|
|
|
|
var items = this.items || this.getItems();
|
|
|
|
|
|
|
|
var templateString = '';
|
|
|
|
if(items.length > 0) {
|
|
|
|
templateString = items[items.length - 1].outerHTML;
|
|
|
|
}
|
|
|
|
this.templateString = templateString;
|
|
|
|
return this.templateString;
|
|
|
|
},
|
|
|
|
|
2016-12-09 14:17:19 -05:00
|
|
|
clickEvent: function(e) {
|
|
|
|
// climb up the tree to find the LI
|
|
|
|
var selected = utils.closest(e.target, 'LI');
|
|
|
|
|
|
|
|
if(selected) {
|
|
|
|
e.preventDefault();
|
|
|
|
this.hide();
|
|
|
|
var listEvent = new CustomEvent('click.dl', {
|
|
|
|
detail: {
|
|
|
|
list: this,
|
|
|
|
selected: selected,
|
|
|
|
data: e.target.dataset,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
this.list.dispatchEvent(listEvent);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-11-09 15:44:11 -05:00
|
|
|
addEvents: function() {
|
2016-12-09 14:17:19 -05:00
|
|
|
this.clickWrapper = this.clickEvent.bind(this);
|
2016-11-09 15:44:11 -05:00
|
|
|
// event delegation.
|
2016-12-09 14:17:19 -05:00
|
|
|
this.list.addEventListener('click', this.clickWrapper);
|
2016-11-09 15:44:11 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
toggle: function() {
|
|
|
|
if(this.hidden) {
|
|
|
|
this.show();
|
|
|
|
} else {
|
|
|
|
this.hide();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-12-02 16:02:54 -05:00
|
|
|
setData: function(data) {
|
|
|
|
this.data = data;
|
|
|
|
this.render(data);
|
|
|
|
},
|
|
|
|
|
2016-11-09 15:44:11 -05:00
|
|
|
addData: function(data) {
|
|
|
|
this.data = (this.data || []).concat(data);
|
2017-01-20 17:59:40 -05:00
|
|
|
this.render(this.data);
|
2016-11-09 15:44:11 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
// call render manually on data;
|
|
|
|
render: function(data){
|
2016-12-09 14:17:19 -05:00
|
|
|
// debugger
|
2016-11-09 15:44:11 -05:00
|
|
|
// empty the list first
|
2017-01-20 17:59:40 -05:00
|
|
|
var templateString = this.templateString;
|
2016-11-09 15:44:11 -05:00
|
|
|
var newChildren = [];
|
|
|
|
var toAppend;
|
|
|
|
|
2017-01-20 17:59:40 -05:00
|
|
|
newChildren = (data ||[]).map(function(dat){
|
|
|
|
var html = utils.t(templateString, dat);
|
2016-12-13 22:36:54 -05:00
|
|
|
var template = document.createElement('div');
|
2016-11-09 15:44:11 -05:00
|
|
|
template.innerHTML = html;
|
2016-12-02 17:20:01 -05:00
|
|
|
|
|
|
|
// Help set the image src template
|
2016-12-13 22:36:54 -05:00
|
|
|
var imageTags = template.querySelectorAll('img[data-src]');
|
|
|
|
// debugger
|
2016-12-02 17:20:01 -05:00
|
|
|
for(var i = 0; i < imageTags.length; i++) {
|
2016-12-05 13:18:02 -05:00
|
|
|
var imageTag = imageTags[i];
|
2016-12-02 17:20:01 -05:00
|
|
|
imageTag.src = imageTag.getAttribute('data-src');
|
|
|
|
imageTag.removeAttribute('data-src');
|
|
|
|
}
|
|
|
|
|
2016-11-09 15:44:11 -05:00
|
|
|
if(dat.hasOwnProperty('droplab_hidden') && dat.droplab_hidden){
|
2016-12-13 22:36:54 -05:00
|
|
|
template.firstChild.style.display = 'none'
|
2016-11-09 15:44:11 -05:00
|
|
|
}else{
|
2016-12-13 22:36:54 -05:00
|
|
|
template.firstChild.style.display = 'block';
|
2016-11-09 15:44:11 -05:00
|
|
|
}
|
2016-12-13 22:36:54 -05:00
|
|
|
return template.firstChild.outerHTML;
|
2016-11-09 15:44:11 -05:00
|
|
|
});
|
|
|
|
toAppend = this.list.querySelector('ul[data-dynamic]');
|
|
|
|
if(toAppend) {
|
|
|
|
toAppend.innerHTML = newChildren.join('');
|
|
|
|
} else {
|
2017-01-20 14:00:34 -05:00
|
|
|
this.list.innerHTML = newChildren.join('');
|
2016-11-09 15:44:11 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
show: function() {
|
2017-01-20 12:57:31 -05:00
|
|
|
if (this.hidden) {
|
|
|
|
// debugger
|
|
|
|
this.list.style.display = 'block';
|
|
|
|
this.currentIndex = 0;
|
|
|
|
this.hidden = false;
|
|
|
|
}
|
2016-11-09 15:44:11 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
hide: function() {
|
2017-01-20 12:57:31 -05:00
|
|
|
if (!this.hidden) {
|
|
|
|
// debugger
|
|
|
|
this.list.style.display = 'none';
|
|
|
|
this.currentIndex = 0;
|
|
|
|
this.hidden = true;
|
|
|
|
}
|
2016-11-09 15:44:11 -05:00
|
|
|
},
|
2016-12-09 12:44:09 -05:00
|
|
|
|
|
|
|
destroy: function() {
|
2017-01-20 17:59:40 -05:00
|
|
|
this.hide();
|
2016-12-09 14:17:19 -05:00
|
|
|
this.list.removeEventListener('click', this.clickWrapper);
|
2016-12-09 12:44:09 -05:00
|
|
|
}
|
2016-11-09 15:44:11 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = DropDown;
|
|
|
|
|
|
|
|
},{"./custom_event_polyfill":2,"./utils":10}],4:[function(require,module,exports){
|
|
|
|
require('./window')(function(w){
|
|
|
|
module.exports = function(deps) {
|
|
|
|
deps = deps || {};
|
|
|
|
var window = deps.window || w;
|
|
|
|
var document = deps.document || window.document;
|
|
|
|
var CustomEvent = deps.CustomEvent || require('./custom_event_polyfill');
|
|
|
|
var HookButton = deps.HookButton || require('./hook_button');
|
|
|
|
var HookInput = deps.HookInput || require('./hook_input');
|
|
|
|
var utils = deps.utils || require('./utils');
|
|
|
|
var DATA_TRIGGER = require('./constants').DATA_TRIGGER;
|
|
|
|
|
|
|
|
var DropLab = function(hook){
|
|
|
|
if (!(this instanceof DropLab)) return new DropLab(hook);
|
|
|
|
this.ready = false;
|
|
|
|
this.hooks = [];
|
|
|
|
this.queuedData = [];
|
|
|
|
this.config = {};
|
2016-12-08 16:36:54 -05:00
|
|
|
this.loadWrapper;
|
2016-11-09 15:44:11 -05:00
|
|
|
if(typeof hook !== 'undefined'){
|
|
|
|
this.addHook(hook);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-12-08 16:36:54 -05:00
|
|
|
|
2016-11-09 15:44:11 -05:00
|
|
|
Object.assign(DropLab.prototype, {
|
2016-12-08 16:36:54 -05:00
|
|
|
load: function() {
|
|
|
|
this.loadWrapper();
|
|
|
|
},
|
|
|
|
|
|
|
|
loadWrapper: function(){
|
|
|
|
var dropdownTriggers = [].slice.apply(document.querySelectorAll('['+DATA_TRIGGER+']'));
|
|
|
|
this.addHooks(dropdownTriggers).init();
|
2016-11-09 15:44:11 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
addData: function () {
|
|
|
|
var args = [].slice.apply(arguments);
|
2016-12-02 16:02:54 -05:00
|
|
|
this.applyArgs(args, '_addData');
|
|
|
|
},
|
|
|
|
|
|
|
|
setData: function() {
|
|
|
|
var args = [].slice.apply(arguments);
|
|
|
|
this.applyArgs(args, '_setData');
|
|
|
|
},
|
|
|
|
|
2016-12-08 16:36:54 -05:00
|
|
|
destroy: function() {
|
2016-12-13 22:36:54 -05:00
|
|
|
for(var i = 0; i < this.hooks.length; i++) {
|
|
|
|
this.hooks[i].destroy();
|
|
|
|
}
|
2016-12-08 16:36:54 -05:00
|
|
|
this.hooks = [];
|
|
|
|
this.removeEvents();
|
|
|
|
},
|
|
|
|
|
2016-12-02 16:02:54 -05:00
|
|
|
applyArgs: function(args, methodName) {
|
2016-11-09 15:44:11 -05:00
|
|
|
if(this.ready) {
|
2016-12-02 16:02:54 -05:00
|
|
|
this[methodName].apply(this, args);
|
2016-11-09 15:44:11 -05:00
|
|
|
} else {
|
|
|
|
this.queuedData = this.queuedData || [];
|
|
|
|
this.queuedData.push(args);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_addData: function(trigger, data) {
|
2016-12-02 16:02:54 -05:00
|
|
|
this._processData(trigger, data, 'addData');
|
|
|
|
},
|
|
|
|
|
|
|
|
_setData: function(trigger, data) {
|
|
|
|
this._processData(trigger, data, 'setData');
|
|
|
|
},
|
|
|
|
|
|
|
|
_processData: function(trigger, data, methodName) {
|
2016-12-13 22:36:54 -05:00
|
|
|
for(var i = 0; i < this.hooks.length; i++) {
|
|
|
|
var hook = this.hooks[i];
|
2016-11-09 15:44:11 -05:00
|
|
|
if(hook.trigger.dataset.hasOwnProperty('id')) {
|
|
|
|
if(hook.trigger.dataset.id === trigger) {
|
2016-12-02 16:02:54 -05:00
|
|
|
hook.list[methodName](data);
|
2016-11-09 15:44:11 -05:00
|
|
|
}
|
|
|
|
}
|
2016-12-13 22:36:54 -05:00
|
|
|
}
|
2016-11-09 15:44:11 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
addEvents: function() {
|
|
|
|
var self = this;
|
2016-12-08 16:36:54 -05:00
|
|
|
this.windowClickedWrapper = function(e){
|
2016-11-09 15:44:11 -05:00
|
|
|
var thisTag = e.target;
|
2016-12-09 13:11:29 -05:00
|
|
|
if(thisTag.tagName !== 'UL'){
|
2016-11-09 15:44:11 -05:00
|
|
|
// climb up the tree to find the UL
|
|
|
|
thisTag = utils.closest(thisTag, 'UL');
|
|
|
|
}
|
|
|
|
if(utils.isDropDownParts(thisTag)){ return }
|
|
|
|
if(utils.isDropDownParts(e.target)){ return }
|
2016-12-13 22:36:54 -05:00
|
|
|
for(var i = 0; i < self.hooks.length; i++) {
|
|
|
|
self.hooks[i].list.hide();
|
|
|
|
}
|
2016-12-08 16:36:54 -05:00
|
|
|
}.bind(this);
|
2017-01-20 14:00:34 -05:00
|
|
|
document.addEventListener('click', this.windowClickedWrapper);
|
2016-12-08 16:36:54 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
removeEvents: function(){
|
|
|
|
w.removeEventListener('click', this.windowClickedWrapper);
|
|
|
|
w.removeEventListener('load', this.loadWrapper);
|
2016-11-09 15:44:11 -05:00
|
|
|
},
|
|
|
|
|
2016-12-08 16:36:54 -05:00
|
|
|
changeHookList: function(trigger, list, plugins, config) {
|
2016-12-02 16:02:54 -05:00
|
|
|
trigger = document.querySelector('[data-id="'+trigger+'"]');
|
2016-12-09 12:44:09 -05:00
|
|
|
// list = document.querySelector(list);
|
2016-12-02 16:02:54 -05:00
|
|
|
this.hooks.every(function(hook, i) {
|
|
|
|
if(hook.trigger === trigger) {
|
2016-12-08 16:36:54 -05:00
|
|
|
hook.destroy();
|
2016-12-02 16:02:54 -05:00
|
|
|
this.hooks.splice(i, 1);
|
2016-12-08 16:36:54 -05:00
|
|
|
this.addHook(trigger, list, plugins, config);
|
2016-12-02 16:02:54 -05:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}.bind(this));
|
|
|
|
},
|
|
|
|
|
2016-12-08 16:36:54 -05:00
|
|
|
addHook: function(hook, list, plugins, config) {
|
2016-11-09 15:44:11 -05:00
|
|
|
if(!(hook instanceof HTMLElement) && typeof hook === 'string'){
|
|
|
|
hook = document.querySelector(hook);
|
|
|
|
}
|
2016-12-02 16:02:54 -05:00
|
|
|
if(!list){
|
|
|
|
list = document.querySelector(hook.dataset[utils.toDataCamelCase(DATA_TRIGGER)]);
|
|
|
|
}
|
2017-01-20 14:00:34 -05:00
|
|
|
|
2016-12-02 16:02:54 -05:00
|
|
|
if(hook) {
|
|
|
|
if(hook.tagName === 'A' || hook.tagName === 'BUTTON') {
|
2016-12-08 16:36:54 -05:00
|
|
|
this.hooks.push(new HookButton(hook, list, plugins, config));
|
2016-12-02 16:02:54 -05:00
|
|
|
} else if(hook.tagName === 'INPUT') {
|
2016-12-08 16:36:54 -05:00
|
|
|
this.hooks.push(new HookInput(hook, list, plugins, config));
|
2016-12-02 16:02:54 -05:00
|
|
|
}
|
2016-11-09 15:44:11 -05:00
|
|
|
}
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2016-12-08 16:36:54 -05:00
|
|
|
addHooks: function(hooks, plugins, config) {
|
2016-12-13 22:36:54 -05:00
|
|
|
for(var i = 0; i < hooks.length; i++) {
|
|
|
|
var hook = hooks[i];
|
2016-12-08 16:36:54 -05:00
|
|
|
this.addHook(hook, null, plugins, config);
|
2016-12-13 22:36:54 -05:00
|
|
|
}
|
2016-11-09 15:44:11 -05:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
setConfig: function(obj){
|
|
|
|
this.config = obj;
|
|
|
|
},
|
|
|
|
|
|
|
|
init: function () {
|
2016-12-08 16:36:54 -05:00
|
|
|
this.addEvents();
|
2016-11-09 15:44:11 -05:00
|
|
|
var readyEvent = new CustomEvent('ready.dl', {
|
|
|
|
detail: {
|
|
|
|
dropdown: this,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
window.dispatchEvent(readyEvent);
|
|
|
|
this.ready = true;
|
2016-12-13 22:36:54 -05:00
|
|
|
for(var i = 0; i < this.queuedData.length; i++) {
|
|
|
|
this.addData.apply(this, this.queuedData[i]);
|
|
|
|
}
|
2016-11-09 15:44:11 -05:00
|
|
|
this.queuedData = [];
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
return DropLab;
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
},{"./constants":1,"./custom_event_polyfill":2,"./hook_button":6,"./hook_input":7,"./utils":10,"./window":11}],5:[function(require,module,exports){
|
|
|
|
var DropDown = require('./dropdown');
|
|
|
|
|
2016-12-08 16:36:54 -05:00
|
|
|
var Hook = function(trigger, list, plugins, config){
|
2016-11-09 15:44:11 -05:00
|
|
|
this.trigger = trigger;
|
|
|
|
this.list = new DropDown(list);
|
|
|
|
this.type = 'Hook';
|
|
|
|
this.event = 'click';
|
2016-12-08 16:36:54 -05:00
|
|
|
this.plugins = plugins || [];
|
|
|
|
this.config = config || {};
|
2016-11-09 15:44:11 -05:00
|
|
|
this.id = trigger.dataset.id;
|
|
|
|
};
|
|
|
|
|
|
|
|
Object.assign(Hook.prototype, {
|
2016-12-08 16:36:54 -05:00
|
|
|
|
2016-11-09 15:44:11 -05:00
|
|
|
addEvents: function(){},
|
|
|
|
|
|
|
|
constructor: Hook,
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = Hook;
|
|
|
|
|
|
|
|
},{"./dropdown":3}],6:[function(require,module,exports){
|
|
|
|
var CustomEvent = require('./custom_event_polyfill');
|
|
|
|
var Hook = require('./hook');
|
|
|
|
|
2016-12-08 16:36:54 -05:00
|
|
|
var HookButton = function(trigger, list, plugins, config) {
|
|
|
|
Hook.call(this, trigger, list, plugins, config);
|
2016-11-09 15:44:11 -05:00
|
|
|
this.type = 'button';
|
|
|
|
this.event = 'click';
|
|
|
|
this.addEvents();
|
2016-12-08 16:36:54 -05:00
|
|
|
this.addPlugins();
|
2016-11-09 15:44:11 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
HookButton.prototype = Object.create(Hook.prototype);
|
|
|
|
|
|
|
|
Object.assign(HookButton.prototype, {
|
2016-12-08 16:36:54 -05:00
|
|
|
addPlugins: function() {
|
2016-12-13 22:36:54 -05:00
|
|
|
for(var i = 0; i < this.plugins.length; i++) {
|
|
|
|
this.plugins[i].init(this);
|
|
|
|
}
|
2016-12-08 16:36:54 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
clicked: function(e){
|
|
|
|
var buttonEvent = new CustomEvent('click.dl', {
|
|
|
|
detail: {
|
|
|
|
hook: this,
|
|
|
|
},
|
|
|
|
bubbles: true,
|
|
|
|
cancelable: true
|
|
|
|
});
|
|
|
|
this.list.show();
|
|
|
|
e.target.dispatchEvent(buttonEvent);
|
|
|
|
},
|
|
|
|
|
2016-11-09 15:44:11 -05:00
|
|
|
addEvents: function(){
|
2016-12-08 16:36:54 -05:00
|
|
|
this.clickedWrapper = this.clicked.bind(this);
|
|
|
|
this.trigger.addEventListener('click', this.clickedWrapper);
|
|
|
|
},
|
|
|
|
|
|
|
|
removeEvents: function(){
|
|
|
|
this.trigger.removeEventListener('click', this.clickedWrapper);
|
|
|
|
},
|
|
|
|
|
|
|
|
restoreInitialState: function() {
|
|
|
|
this.list.list.innerHTML = this.list.initialState;
|
|
|
|
},
|
|
|
|
|
|
|
|
removePlugins: function() {
|
2016-12-13 22:36:54 -05:00
|
|
|
for(var i = 0; i < this.plugins.length; i++) {
|
|
|
|
this.plugins[i].destroy();
|
|
|
|
}
|
2016-11-09 15:44:11 -05:00
|
|
|
},
|
|
|
|
|
2016-12-08 16:36:54 -05:00
|
|
|
destroy: function() {
|
|
|
|
this.restoreInitialState();
|
|
|
|
this.removeEvents();
|
|
|
|
this.removePlugins();
|
|
|
|
},
|
|
|
|
|
|
|
|
|
2016-11-09 15:44:11 -05:00
|
|
|
constructor: HookButton,
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = HookButton;
|
|
|
|
|
|
|
|
},{"./custom_event_polyfill":2,"./hook":5}],7:[function(require,module,exports){
|
|
|
|
var CustomEvent = require('./custom_event_polyfill');
|
|
|
|
var Hook = require('./hook');
|
|
|
|
|
2016-12-08 16:36:54 -05:00
|
|
|
var HookInput = function(trigger, list, plugins, config) {
|
|
|
|
Hook.call(this, trigger, list, plugins, config);
|
2016-11-09 15:44:11 -05:00
|
|
|
this.type = 'input';
|
|
|
|
this.event = 'input';
|
2016-12-08 16:36:54 -05:00
|
|
|
this.addPlugins();
|
2016-11-09 15:44:11 -05:00
|
|
|
this.addEvents();
|
|
|
|
};
|
|
|
|
|
|
|
|
Object.assign(HookInput.prototype, {
|
2016-12-08 16:36:54 -05:00
|
|
|
addPlugins: function() {
|
|
|
|
var self = this;
|
2016-12-13 22:36:54 -05:00
|
|
|
for(var i = 0; i < this.plugins.length; i++) {
|
|
|
|
this.plugins[i].init(self);
|
|
|
|
}
|
2016-12-08 16:36:54 -05:00
|
|
|
},
|
|
|
|
|
2016-11-09 15:44:11 -05:00
|
|
|
addEvents: function(){
|
|
|
|
var self = this;
|
2016-12-02 16:02:54 -05:00
|
|
|
|
2016-12-08 16:36:54 -05:00
|
|
|
this.mousedown = function mousedown(e) {
|
2017-01-20 17:59:40 -05:00
|
|
|
if(self.hasRemovedEvents) return;
|
|
|
|
|
2016-11-09 15:44:11 -05:00
|
|
|
var mouseEvent = new CustomEvent('mousedown.dl', {
|
|
|
|
detail: {
|
|
|
|
hook: self,
|
|
|
|
text: e.target.value,
|
|
|
|
},
|
|
|
|
bubbles: true,
|
|
|
|
cancelable: true
|
|
|
|
});
|
|
|
|
e.target.dispatchEvent(mouseEvent);
|
2016-12-02 16:02:54 -05:00
|
|
|
}
|
2016-11-09 15:44:11 -05:00
|
|
|
|
2016-12-08 16:36:54 -05:00
|
|
|
this.input = function input(e) {
|
2017-01-20 17:59:40 -05:00
|
|
|
if(self.hasRemovedEvents) return;
|
|
|
|
|
2017-01-20 12:57:31 -05:00
|
|
|
self.list.show();
|
|
|
|
|
2016-11-09 15:44:11 -05:00
|
|
|
var inputEvent = new CustomEvent('input.dl', {
|
|
|
|
detail: {
|
|
|
|
hook: self,
|
|
|
|
text: e.target.value,
|
|
|
|
},
|
|
|
|
bubbles: true,
|
|
|
|
cancelable: true
|
|
|
|
});
|
|
|
|
e.target.dispatchEvent(inputEvent);
|
2016-12-02 16:02:54 -05:00
|
|
|
}
|
2016-11-09 15:44:11 -05:00
|
|
|
|
2016-12-08 16:36:54 -05:00
|
|
|
this.keyup = function keyup(e) {
|
2017-01-20 17:59:40 -05:00
|
|
|
if(self.hasRemovedEvents) return;
|
|
|
|
|
2016-11-09 15:44:11 -05:00
|
|
|
keyEvent(e, 'keyup.dl');
|
2016-12-02 16:02:54 -05:00
|
|
|
}
|
2016-11-09 15:44:11 -05:00
|
|
|
|
2016-12-08 16:36:54 -05:00
|
|
|
this.keydown = function keydown(e) {
|
2017-01-20 17:59:40 -05:00
|
|
|
if(self.hasRemovedEvents) return;
|
|
|
|
|
2016-11-09 15:44:11 -05:00
|
|
|
keyEvent(e, 'keydown.dl');
|
2016-12-02 16:02:54 -05:00
|
|
|
}
|
2016-11-09 15:44:11 -05:00
|
|
|
|
|
|
|
function keyEvent(e, keyEventName){
|
2017-01-20 12:57:31 -05:00
|
|
|
self.list.show();
|
|
|
|
|
2016-11-09 15:44:11 -05:00
|
|
|
var keyEvent = new CustomEvent(keyEventName, {
|
|
|
|
detail: {
|
|
|
|
hook: self,
|
|
|
|
text: e.target.value,
|
|
|
|
which: e.which,
|
|
|
|
key: e.key,
|
|
|
|
},
|
|
|
|
bubbles: true,
|
|
|
|
cancelable: true
|
|
|
|
});
|
|
|
|
e.target.dispatchEvent(keyEvent);
|
|
|
|
}
|
2016-12-02 16:02:54 -05:00
|
|
|
|
|
|
|
this.events = this.events || {};
|
2016-12-08 16:36:54 -05:00
|
|
|
this.events.mousedown = this.mousedown;
|
|
|
|
this.events.input = this.input;
|
|
|
|
this.events.keyup = this.keyup;
|
|
|
|
this.events.keydown = this.keydown;
|
|
|
|
this.trigger.addEventListener('mousedown', this.mousedown);
|
|
|
|
this.trigger.addEventListener('input', this.input);
|
|
|
|
this.trigger.addEventListener('keyup', this.keyup);
|
|
|
|
this.trigger.addEventListener('keydown', this.keydown);
|
2016-11-09 15:44:11 -05:00
|
|
|
},
|
2016-12-08 16:36:54 -05:00
|
|
|
|
2017-01-20 17:59:40 -05:00
|
|
|
removeEvents: function() {
|
|
|
|
this.hasRemovedEvents = true;
|
2016-12-08 16:36:54 -05:00
|
|
|
this.trigger.removeEventListener('mousedown', this.mousedown);
|
|
|
|
this.trigger.removeEventListener('input', this.input);
|
|
|
|
this.trigger.removeEventListener('keyup', this.keyup);
|
|
|
|
this.trigger.removeEventListener('keydown', this.keydown);
|
|
|
|
},
|
|
|
|
|
|
|
|
restoreInitialState: function() {
|
|
|
|
this.list.list.innerHTML = this.list.initialState;
|
|
|
|
},
|
|
|
|
|
|
|
|
removePlugins: function() {
|
2016-12-13 22:36:54 -05:00
|
|
|
for(var i = 0; i < this.plugins.length; i++) {
|
|
|
|
this.plugins[i].destroy();
|
|
|
|
}
|
2016-12-08 16:36:54 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
destroy: function() {
|
|
|
|
this.restoreInitialState();
|
|
|
|
this.removeEvents();
|
|
|
|
this.removePlugins();
|
2016-12-09 12:44:09 -05:00
|
|
|
this.list.destroy();
|
2016-12-08 16:36:54 -05:00
|
|
|
}
|
2016-11-09 15:44:11 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = HookInput;
|
|
|
|
|
|
|
|
},{"./custom_event_polyfill":2,"./hook":5}],8:[function(require,module,exports){
|
|
|
|
var DropLab = require('./droplab')();
|
|
|
|
var DATA_TRIGGER = require('./constants').DATA_TRIGGER;
|
|
|
|
var keyboard = require('./keyboard')();
|
|
|
|
var setup = function() {
|
2016-12-08 16:36:54 -05:00
|
|
|
window.DropLab = DropLab;
|
2016-11-09 15:44:11 -05:00
|
|
|
};
|
|
|
|
|
2016-12-08 16:36:54 -05:00
|
|
|
|
2016-11-09 15:44:11 -05:00
|
|
|
module.exports = setup();
|
|
|
|
|
2016-12-08 16:36:54 -05:00
|
|
|
},{"./constants":1,"./droplab":4,"./keyboard":9}],9:[function(require,module,exports){
|
2016-11-09 15:44:11 -05:00
|
|
|
require('./window')(function(w){
|
|
|
|
module.exports = function(){
|
|
|
|
var currentKey;
|
|
|
|
var currentFocus;
|
|
|
|
var isUpArrow = false;
|
|
|
|
var isDownArrow = false;
|
|
|
|
var removeHighlight = function removeHighlight(list) {
|
2017-01-20 12:57:31 -05:00
|
|
|
var listItems = Array.prototype.slice.call(list.list.querySelectorAll('li:not(.divider)'), 0);
|
|
|
|
var listItemsTmp = [];
|
2016-12-13 22:36:54 -05:00
|
|
|
for(var i = 0; i < listItems.length; i++) {
|
2017-01-20 12:57:31 -05:00
|
|
|
var listItem = listItems[i];
|
|
|
|
listItem.classList.remove('dropdown-active');
|
|
|
|
|
|
|
|
if (listItem.style.display !== 'none') {
|
|
|
|
listItemsTmp.push(listItem);
|
|
|
|
}
|
2016-12-13 22:36:54 -05:00
|
|
|
}
|
2017-01-20 12:57:31 -05:00
|
|
|
return listItemsTmp;
|
2016-11-09 15:44:11 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
var setMenuForArrows = function setMenuForArrows(list) {
|
|
|
|
var listItems = removeHighlight(list);
|
2017-01-20 12:57:31 -05:00
|
|
|
if(list.currentIndex>0){
|
|
|
|
if(!listItems[list.currentIndex-1]){
|
|
|
|
list.currentIndex = list.currentIndex-1;
|
2016-11-09 15:44:11 -05:00
|
|
|
}
|
2017-01-20 09:20:29 -05:00
|
|
|
|
2017-01-20 12:57:31 -05:00
|
|
|
if (listItems[list.currentIndex-1]) {
|
|
|
|
var el = listItems[list.currentIndex-1];
|
|
|
|
var filterDropdownEl = el.closest('.filter-dropdown');
|
|
|
|
el.classList.add('dropdown-active');
|
|
|
|
|
|
|
|
if (filterDropdownEl) {
|
|
|
|
var filterDropdownBottom = filterDropdownEl.offsetHeight;
|
|
|
|
var elOffsetTop = el.offsetTop - 30;
|
|
|
|
|
|
|
|
if (elOffsetTop > filterDropdownBottom) {
|
|
|
|
filterDropdownEl.scrollTop = elOffsetTop - filterDropdownBottom;
|
|
|
|
}
|
|
|
|
}
|
2017-01-20 09:20:29 -05:00
|
|
|
}
|
2016-11-09 15:44:11 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
var mousedown = function mousedown(e) {
|
|
|
|
var list = e.detail.hook.list;
|
|
|
|
removeHighlight(list);
|
|
|
|
list.show();
|
2017-01-20 12:57:31 -05:00
|
|
|
list.currentIndex = 0;
|
2016-11-09 15:44:11 -05:00
|
|
|
isUpArrow = false;
|
|
|
|
isDownArrow = false;
|
|
|
|
};
|
|
|
|
var selectItem = function selectItem(list) {
|
|
|
|
var listItems = removeHighlight(list);
|
2017-01-20 12:57:31 -05:00
|
|
|
var currentItem = listItems[list.currentIndex-1];
|
2016-11-09 15:44:11 -05:00
|
|
|
var listEvent = new CustomEvent('click.dl', {
|
|
|
|
detail: {
|
|
|
|
list: list,
|
|
|
|
selected: currentItem,
|
|
|
|
data: currentItem.dataset,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
list.list.dispatchEvent(listEvent);
|
|
|
|
list.hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
var keydown = function keydown(e){
|
|
|
|
var typedOn = e.target;
|
2017-01-20 12:57:31 -05:00
|
|
|
var list = e.detail.hook.list;
|
|
|
|
var currentIndex = list.currentIndex;
|
2016-11-09 15:44:11 -05:00
|
|
|
isUpArrow = false;
|
|
|
|
isDownArrow = false;
|
|
|
|
|
|
|
|
if(e.detail.which){
|
|
|
|
currentKey = e.detail.which;
|
|
|
|
if(currentKey === 13){
|
|
|
|
selectItem(e.detail.hook.list);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(currentKey === 38) {
|
|
|
|
isUpArrow = true;
|
|
|
|
}
|
|
|
|
if(currentKey === 40) {
|
|
|
|
isDownArrow = true;
|
|
|
|
}
|
|
|
|
} else if(e.detail.key) {
|
|
|
|
currentKey = e.detail.key;
|
|
|
|
if(currentKey === 'Enter'){
|
|
|
|
selectItem(e.detail.hook.list);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(currentKey === 'ArrowUp') {
|
2017-01-20 14:00:34 -05:00
|
|
|
isUpArrow = true;
|
2016-11-09 15:44:11 -05:00
|
|
|
}
|
|
|
|
if(currentKey === 'ArrowDown') {
|
|
|
|
isDownArrow = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(isUpArrow){ currentIndex--; }
|
|
|
|
if(isDownArrow){ currentIndex++; }
|
|
|
|
if(currentIndex < 0){ currentIndex = 0; }
|
2017-01-20 12:57:31 -05:00
|
|
|
list.currentIndex = currentIndex;
|
2016-11-09 15:44:11 -05:00
|
|
|
setMenuForArrows(e.detail.hook.list);
|
|
|
|
};
|
|
|
|
|
|
|
|
w.addEventListener('mousedown.dl', mousedown);
|
|
|
|
w.addEventListener('keydown.dl', keydown);
|
|
|
|
};
|
|
|
|
});
|
|
|
|
},{"./window":11}],10:[function(require,module,exports){
|
|
|
|
var DATA_TRIGGER = require('./constants').DATA_TRIGGER;
|
|
|
|
var DATA_DROPDOWN = require('./constants').DATA_DROPDOWN;
|
|
|
|
|
|
|
|
var toDataCamelCase = function(attr){
|
|
|
|
return this.camelize(attr.split('-').slice(1).join(' '));
|
|
|
|
};
|
|
|
|
|
|
|
|
// the tiniest damn templating I can do
|
|
|
|
var t = function(s,d){
|
|
|
|
for(var p in d)
|
|
|
|
s=s.replace(new RegExp('{{'+p+'}}','g'), d[p]);
|
|
|
|
return s;
|
|
|
|
};
|
|
|
|
|
|
|
|
var camelize = function(str) {
|
|
|
|
return str.replace(/(?:^\w|[A-Z]|\b\w)/g, function(letter, index) {
|
|
|
|
return index == 0 ? letter.toLowerCase() : letter.toUpperCase();
|
|
|
|
}).replace(/\s+/g, '');
|
|
|
|
};
|
|
|
|
|
|
|
|
var closest = function(thisTag, stopTag) {
|
2017-01-20 17:59:40 -05:00
|
|
|
while(thisTag && thisTag.tagName !== stopTag && thisTag.tagName !== 'HTML'){
|
2016-11-09 15:44:11 -05:00
|
|
|
thisTag = thisTag.parentNode;
|
|
|
|
}
|
|
|
|
return thisTag;
|
|
|
|
};
|
|
|
|
|
|
|
|
var isDropDownParts = function(target) {
|
2017-01-20 17:59:40 -05:00
|
|
|
if(!target || target.tagName === 'HTML') { return false; }
|
2016-11-09 15:44:11 -05:00
|
|
|
return (
|
2017-01-20 14:00:34 -05:00
|
|
|
target.hasAttribute(DATA_TRIGGER) ||
|
2016-11-09 15:44:11 -05:00
|
|
|
target.hasAttribute(DATA_DROPDOWN)
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
toDataCamelCase: toDataCamelCase,
|
|
|
|
t: t,
|
|
|
|
camelize: camelize,
|
|
|
|
closest: closest,
|
|
|
|
isDropDownParts: isDropDownParts,
|
|
|
|
};
|
|
|
|
|
|
|
|
},{"./constants":1}],11:[function(require,module,exports){
|
|
|
|
module.exports = function(callback) {
|
|
|
|
return (function() {
|
|
|
|
callback(this);
|
|
|
|
}).call(null);
|
|
|
|
};
|
|
|
|
|
|
|
|
},{}]},{},[8])(8)
|
|
|
|
});
|