diff options
author | Luke "Jared" Bennett <lbennett@gitlab.com> | 2017-02-20 16:51:47 +0300 |
---|---|---|
committer | Luke "Jared" Bennett <lbennett@gitlab.com> | 2017-02-22 13:19:42 +0300 |
commit | 173e27d62a2fa880fa438ef6f07847bbd3e06fea (patch) | |
tree | 1c1dfca5adfc632eb2ed582bcb0fa5771b948332 /app/assets/javascripts/behaviors | |
parent | 479cdc2cac78241109d2cb9d8cfd22d36319d367 (diff) |
Finished up mattermost team creation
Diffstat (limited to 'app/assets/javascripts/behaviors')
-rw-r--r-- | app/assets/javascripts/behaviors/bind_in_out.js.es6 | 48 | ||||
-rw-r--r-- | app/assets/javascripts/behaviors/toggler_behavior.js | 1 |
2 files changed, 48 insertions, 1 deletions
diff --git a/app/assets/javascripts/behaviors/bind_in_out.js.es6 b/app/assets/javascripts/behaviors/bind_in_out.js.es6 new file mode 100644 index 00000000000..3cb892451e3 --- /dev/null +++ b/app/assets/javascripts/behaviors/bind_in_out.js.es6 @@ -0,0 +1,48 @@ +class BindInOut { + constructor(bindIn, bindOut) { + this.in = bindIn; + this.out = bindOut; + + this.eventWrapper = {}; + this.eventType = /(INPUT|TEXTAREA)/.test(bindIn.tagName) ? 'keyup' : 'change'; + } + + addEvents() { + this.eventWrapper.updateOut = this.updateOut.bind(this); + + this.in.addEventListener(this.eventType, this.eventWrapper.updateOut); + + return this; + } + + updateOut() { + this.out.textContent = this.in.value; + + return this; + } + + removeEvents() { + this.in.removeEventListener(this.eventType, this.eventWrapper.updateOut); + + return this; + } + + static initAll() { + const ins = document.querySelectorAll('*[data-bind-in]'); + + return [].map.call(ins, anIn => BindInOut.init(anIn)); + } + + static init(anIn, anOut) { + const out = anOut || document.querySelector(`*[data-bind-out="${anIn.dataset.bindIn}"]`); + const bindInOut = new BindInOut(anIn, out); + + return bindInOut.addEvents().updateOut(); + } +} + +const global = window.gl || (window.gl = {}); + +global.BindInOut = BindInOut; + +module.exports = BindInOut; diff --git a/app/assets/javascripts/behaviors/toggler_behavior.js b/app/assets/javascripts/behaviors/toggler_behavior.js index a7181904ac9..2d98fc5a545 100644 --- a/app/assets/javascripts/behaviors/toggler_behavior.js +++ b/app/assets/javascripts/behaviors/toggler_behavior.js @@ -22,7 +22,6 @@ // %div.js-toggle-content // $('body').on('click', '.js-toggle-button', function(e) { - e.preventDefault(); toggleContainer($(this).closest('.js-toggle-container')); }); |