Set options + fire event listeners

This commit is contained in:
Josh Johnson 2016-03-16 09:03:59 +00:00
parent 41efa76a5b
commit 60a1bfc0a7
2 changed files with 11 additions and 2 deletions

View file

@ -1 +1 @@
!function(e){function n(o){if(t[o])return t[o].exports;var i=t[o]={exports:{},id:o,loaded:!1};return e[o].call(i.exports,i,i.exports,n),i.loaded=!0,i.exports}var t={};return n.m=e,n.c=t,n.p="/assets/scripts/dist/",n(0)}([function(e,n,t){e.exports=t(1)},function(e,n,t){function o(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}var i,u=function(){function e(e,n){for(var t=0;t<n.length;t++){var o=n[t];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(n,t,o){return t&&e(n.prototype,t),o&&e(n,o),n}}();"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};!function(o,u){i=function(){return u(o)}.call(n,t,n,e),!(void 0!==i&&(e.exports=i))}(void 0,function(e){"use strict";var n=function(){function e(){o(this,e);this.onClick=this.onClick.bind(this),this.onKeyDown=this.onKeyDown.bind(this),this.onChange=this.onChange.bind(this),this.onFocus=this.onFocus.bind(this),this.onBlur=this.onChange.bind(this),this.render()}return u(e,[{key:"isOpen",value:function(){}},{key:"isDisabled",value:function(){}},{key:"isEmpty",value:function(){}},{key:"onKeyDown",value:function(){console.log("Key down")}},{key:"onFocus",value:function(){console.log("Focus")}},{key:"onClick",value:function(){console.log("Click")}},{key:"onChange",value:function(){console.log("Change")}},{key:"addEventListeners",value:function(){document.addEventListener("click",this.onClick),document.addEventListener("keydown",this.onKeyDown),document.addEventListener("change",this.onChange),document.addEventListener("focus",this.onFocus),document.addEventListener("blur",this.onBlur)}},{key:"removeEventListeners",value:function(){document.removeEventListener("click",this.onClick),document.removeEventListener("keydown",this.onKeyDown),document.removeEventListener("change",this.onChange),document.removeEventListener("focus",this.onFocus),document.removeEventListener("blur",this.onBlur)}},{key:"setPlaceholder",value:function(){}},{key:"setValue",value:function(){}},{key:"getValue",value:function(){}},{key:"getPlaceholder",value:function(){}},{key:"search",value:function(){}},{key:"addItem",value:function(){}},{key:"removeItem",value:function(){}},{key:"removeAllItems",value:function(){}},{key:"createItemList",value:function(){}},{key:"render",value:function(){console.log("Render")}},{key:"destroy",value:function(){}}]),e}();new n})}]);
!function(e){function n(o){if(t[o])return t[o].exports;var i=t[o]={exports:{},id:o,loaded:!1};return e[o].call(i.exports,i,i.exports,n),i.loaded=!0,i.exports}var t={};return n.m=e,n.c=t,n.p="/assets/scripts/dist/",n(0)}([function(e,n,t){e.exports=t(1)},function(e,n,t){function o(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}var i,c=function(){function e(e,n){for(var t=0;t<n.length;t++){var o=n[t];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(n,t,o){return t&&e(n.prototype,t),o&&e(n,o),n}}();"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};!function(o,c){i=function(){return c(o)}.call(n,t,n,e),!(void 0!==i&&(e.exports=i))}(void 0,function(e){"use strict";var n=function(){function e(){o(this,e);var n={element:"[data-choice]",disabled:!1,maxItems:0,debug:!1,callbackOnInit:function(){},callbackOnRender:function(){},callbackOnKeyUp:function(){},callbackOnKeyDown:function(){},callbackOnEntry:function(){},callbackOnRemove:function(){}};this.options=n,this.elements=document.querySelectorAll(this.options.element),this.onClick=this.onClick.bind(this),this.onKeyDown=this.onKeyDown.bind(this),this.onChange=this.onChange.bind(this),this.onFocus=this.onFocus.bind(this),this.onBlur=this.onChange.bind(this),this.addEventListeners(),this.render()}return c(e,[{key:"isOpen",value:function(){}},{key:"isDisabled",value:function(){}},{key:"isEmpty",value:function(){}},{key:"onKeyDown",value:function(){console.log("Key down")}},{key:"onFocus",value:function(){console.log("Focus")}},{key:"onClick",value:function(){console.log("Click")}},{key:"onChange",value:function(){console.log("Change")}},{key:"addEventListeners",value:function(){document.addEventListener("click",this.onClick),document.addEventListener("keydown",this.onKeyDown),document.addEventListener("change",this.onChange),document.addEventListener("focus",this.onFocus),document.addEventListener("blur",this.onBlur)}},{key:"removeEventListeners",value:function(){document.removeEventListener("click",this.onClick),document.removeEventListener("keydown",this.onKeyDown),document.removeEventListener("change",this.onChange),document.removeEventListener("focus",this.onFocus),document.removeEventListener("blur",this.onBlur)}},{key:"setPlaceholder",value:function(){}},{key:"setValue",value:function(){}},{key:"getValue",value:function(){}},{key:"getPlaceholder",value:function(){}},{key:"search",value:function(){}},{key:"addItem",value:function(){}},{key:"removeItem",value:function(){}},{key:"removeAllItems",value:function(){}},{key:"createItemList",value:function(){}},{key:"render",value:function(){console.log("Render")}},{key:"destroy",value:function(){}}]),e}();new n})}]);

View file

@ -14,7 +14,7 @@
class Choices {
constructor() {
const DEFAULT_CONFIG = {
const DEFAULT_OPTIONS = {
element: '[data-choice]',
disabled: false,
maxItems: 0,
@ -27,12 +27,21 @@
callbackOnRemove: function(){}
};
// Merge options with user options
this.options = DEFAULT_OPTIONS;
// Retrieve elements
this.elements = document.querySelectorAll(this.options.element);
// Bind methods
this.onClick = this.onClick.bind(this);
this.onKeyDown = this.onKeyDown.bind(this);
this.onChange = this.onChange.bind(this);
this.onFocus = this.onFocus.bind(this);
this.onBlur = this.onChange.bind(this);
// Init
this.addEventListeners();
this.render();
}