Skip to content
Snippets Groups Projects

Resolve "Customize branch name when using create branch in an issue"

Compare and Show latest version
8 files
+ 193
36
Compare changes
  • Side-by-side
  • Inline
Files
8
import utils from './utils';
import utils from './utils';
import { SELECTED_CLASS, IGNORE_CLASS } from './constants';
import { SELECTED_CLASS, IGNORE_CLASS, IGNORE_HIDING_CLASS } from './constants';
class DropDown {
class DropDown {
constructor(list) {
constructor(list, config = {}) {
this.currentIndex = 0;
this.currentIndex = 0;
this.hidden = true;
this.hidden = true;
this.list = typeof list === 'string' ? document.querySelector(list) : list;
this.list = typeof list === 'string' ? document.querySelector(list) : list;
this.items = [];
this.items = [];
this.eventWrapper = {};
this.eventWrapper = {};
 
if (config.addActiveClassToDropdownButton) {
 
this.dropdownToggle = this.list.parentNode.querySelector('.js-dropdown-toggle');
 
}
 
this.getItems();
this.getItems();
this.initTemplateString();
this.initTemplateString();
this.addEvents();
this.addEvents();
@@ -42,7 +45,7 @@ class DropDown {
@@ -42,7 +45,7 @@ class DropDown {
this.addSelectedClass(selected);
this.addSelectedClass(selected);
e.preventDefault();
e.preventDefault();
this.hide();
if (!e.target.classList.contains(IGNORE_HIDING_CLASS)) this.hide();
const listEvent = new CustomEvent('click.dl', {
const listEvent = new CustomEvent('click.dl', {
detail: {
detail: {
@@ -67,7 +70,20 @@ class DropDown {
@@ -67,7 +70,20 @@ class DropDown {
addEvents() {
addEvents() {
this.eventWrapper.clickEvent = this.clickEvent.bind(this);
this.eventWrapper.clickEvent = this.clickEvent.bind(this);
 
this.eventWrapper.closeDropdown = this.closeDropdown.bind(this);
 
this.list.addEventListener('click', this.eventWrapper.clickEvent);
this.list.addEventListener('click', this.eventWrapper.clickEvent);
 
this.list.addEventListener('keyup', this.eventWrapper.closeDropdown);
 
}
 
 
closeDropdown(event) {
 
// `ESC` key closes the dropdown.
 
if (event.keyCode === 27) {
 
event.preventDefault();
 
return this.toggle();
 
}
 
 
return true;
}
}
setData(data) {
setData(data) {
@@ -110,6 +126,8 @@ class DropDown {
@@ -110,6 +126,8 @@ class DropDown {
this.list.style.display = 'block';
this.list.style.display = 'block';
this.currentIndex = 0;
this.currentIndex = 0;
this.hidden = false;
this.hidden = false;
 
 
if (this.dropdownToggle) this.dropdownToggle.classList.add('active');
}
}
hide() {
hide() {
@@ -117,6 +135,8 @@ class DropDown {
@@ -117,6 +135,8 @@ class DropDown {
this.list.style.display = 'none';
this.list.style.display = 'none';
this.currentIndex = 0;
this.currentIndex = 0;
this.hidden = true;
this.hidden = true;
 
 
if (this.dropdownToggle) this.dropdownToggle.classList.remove('active');
}
}
toggle() {
toggle() {
@@ -128,6 +148,7 @@ class DropDown {
@@ -128,6 +148,7 @@ class DropDown {
destroy() {
destroy() {
this.hide();
this.hide();
this.list.removeEventListener('click', this.eventWrapper.clickEvent);
this.list.removeEventListener('click', this.eventWrapper.clickEvent);
 
this.list.removeEventListener('keyup', this.eventWrapper.closeDropdown);
}
}
static setImagesSrc(template) {
static setImagesSrc(template) {
Loading