2017-06-30 12:52:11 -04:00
|
|
|
import Cookies from 'js-cookie';
|
2017-03-18 08:01:00 -04:00
|
|
|
import _ from 'underscore';
|
2017-02-28 21:59:55 -05:00
|
|
|
|
|
|
|
export default class GroupName {
|
|
|
|
constructor() {
|
2017-06-30 12:52:11 -04:00
|
|
|
this.titleContainer = document.querySelector('.js-title-container');
|
|
|
|
this.title = this.titleContainer.querySelector('.title');
|
2017-07-06 12:24:03 -04:00
|
|
|
|
|
|
|
if (this.title) {
|
|
|
|
this.titleWidth = this.title.offsetWidth;
|
|
|
|
this.groupTitle = this.titleContainer.querySelector('.group-title');
|
|
|
|
this.groups = this.titleContainer.querySelectorAll('.group-path');
|
|
|
|
this.toggle = null;
|
|
|
|
this.isHidden = false;
|
|
|
|
this.init();
|
|
|
|
}
|
2017-02-28 21:59:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
init() {
|
2017-03-18 08:01:00 -04:00
|
|
|
if (this.groups.length > 0) {
|
2017-02-28 21:59:55 -05:00
|
|
|
this.groups[this.groups.length - 1].classList.remove('hidable');
|
2017-03-18 08:01:00 -04:00
|
|
|
this.toggleHandler();
|
|
|
|
window.addEventListener('resize', _.debounce(this.toggleHandler.bind(this), 100));
|
2017-02-28 21:59:55 -05:00
|
|
|
}
|
|
|
|
this.render();
|
|
|
|
}
|
|
|
|
|
2017-03-18 08:01:00 -04:00
|
|
|
toggleHandler() {
|
|
|
|
if (this.titleWidth > this.titleContainer.offsetWidth) {
|
|
|
|
if (!this.toggle) this.createToggle();
|
|
|
|
this.showToggle();
|
|
|
|
} else if (this.toggle) {
|
|
|
|
this.hideToggle();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
createToggle() {
|
2017-02-28 21:59:55 -05:00
|
|
|
this.toggle = document.createElement('button');
|
2017-06-30 12:52:11 -04:00
|
|
|
this.toggle.setAttribute('type', 'button');
|
2017-02-28 21:59:55 -05:00
|
|
|
this.toggle.className = 'text-expander group-name-toggle';
|
|
|
|
this.toggle.setAttribute('aria-label', 'Toggle full path');
|
2017-06-30 12:52:11 -04:00
|
|
|
if (Cookies.get('new_nav') === 'true') {
|
|
|
|
this.toggle.innerHTML = '<i class="fa fa-ellipsis-h" aria-hidden="true"></i>';
|
|
|
|
} else {
|
|
|
|
this.toggle.innerHTML = '...';
|
|
|
|
}
|
2017-02-28 21:59:55 -05:00
|
|
|
this.toggle.addEventListener('click', this.toggleGroups.bind(this));
|
2017-06-30 12:52:11 -04:00
|
|
|
if (Cookies.get('new_nav') === 'true') {
|
|
|
|
this.title.insertBefore(this.toggle, this.groupTitle);
|
|
|
|
} else {
|
|
|
|
this.titleContainer.insertBefore(this.toggle, this.title);
|
|
|
|
}
|
2017-02-28 21:59:55 -05:00
|
|
|
this.toggleGroups();
|
|
|
|
}
|
|
|
|
|
2017-03-18 08:01:00 -04:00
|
|
|
showToggle() {
|
|
|
|
this.title.classList.add('wrap');
|
|
|
|
this.toggle.classList.remove('hidden');
|
2017-05-22 22:25:54 -04:00
|
|
|
if (this.isHidden) this.groupTitle.classList.add('hidden');
|
2017-03-18 08:01:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
hideToggle() {
|
|
|
|
this.title.classList.remove('wrap');
|
|
|
|
this.toggle.classList.add('hidden');
|
2017-05-22 22:25:54 -04:00
|
|
|
if (this.isHidden) this.groupTitle.classList.remove('hidden');
|
2017-03-18 08:01:00 -04:00
|
|
|
}
|
|
|
|
|
2017-02-28 21:59:55 -05:00
|
|
|
toggleGroups() {
|
|
|
|
this.isHidden = !this.isHidden;
|
2017-05-22 22:25:54 -04:00
|
|
|
this.groupTitle.classList.toggle('hidden');
|
2017-02-28 21:59:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2017-03-18 08:01:00 -04:00
|
|
|
this.title.classList.remove('initializing');
|
2017-02-28 21:59:55 -05:00
|
|
|
}
|
|
|
|
}
|