The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Rocket.Chat/packages/rocketchat-ui/client/lib/menu.js

80 lines
2.0 KiB

9 years ago
/* globals isRtl */
const sideNavW = 280;
9 years ago
this.menu = new class {
constructor() {
this._onOpen = [];
this._open = false;
this._onClose = [];
9 years ago
this.updateUnreadBars = _.throttle(() => {
if (this.list == null) {
return;
}
const listOffset = this.list.offset();
const listHeight = this.list.height();
let showTop = false;
let showBottom = false;
$('li.has-alert').each(function() {
if ($(this).offset().top < listOffset.top - $(this).height()) {
showTop = true;
}
if ($(this).offset().top > listOffset.top + listHeight) {
return showBottom = true;
}
});
if (showTop === true) {
$('.top-unread-rooms').removeClass('hidden');
} else {
$('.top-unread-rooms').addClass('hidden');
}
if (showBottom === true) {
return $('.bottom-unread-rooms').removeClass('hidden');
} else {
return $('.bottom-unread-rooms').addClass('hidden');
}
}, 200);
this.sideNavW = sideNavW;
9 years ago
}
init() {
this.mainContent = $('.main-content');
9 years ago
this.list = $('.rooms-list');
this._open = false;
Session.set('isMenuOpen', this._open);
this.mainContent[0].addEventListener('click', _.debounce(() => {
this._open && this.close();
}, 300));
9 years ago
}
isOpen() {
return Session.get('isMenuOpen');
}
onOpen(fn) {
if (typeof fn === 'function') {
this._onOpen.push(fn);
}
}
onClose(fn) {
if (typeof fn === 'function') {
this._onClose.push(fn);
}
}
9 years ago
open() {
this._open = true;
Session.set('isMenuOpen', this._open);
this.mainContent && this.mainContent.css('transform', `translateX(${ isRtl(localStorage.getItem('userLanguage'))?'-':'' }${ this.sideNavW }px)`);
setTimeout(() => this._onOpen.forEach(fn => fn.apply(this)), 10);
9 years ago
}
close() {
this._open = false;
Session.set('isMenuOpen', this._open);
9 years ago
this.mainContent && this.mainContent .css('transform', 'translateX(0)');
setTimeout(() => this._onClose.forEach(fn => fn.apply(this)), 10);
9 years ago
}
toggle() {
return this.isOpen() ? this.close() : this.open();
}
};