feat(nav): remove sidecar
This commit is contained in:
130
client/main.js
130
client/main.js
@@ -2,136 +2,6 @@ var main = window.main || {};
|
||||
|
||||
main.ga = window.ga || function() {};
|
||||
|
||||
main = (function(main, global) {
|
||||
const { Mousetrap } = global;
|
||||
|
||||
// should be set before gitter script loads
|
||||
((window.gitter = {}).chat = {}).options = {
|
||||
disableDefaultChat: true
|
||||
};
|
||||
// wait for sidecar to load
|
||||
|
||||
main.chat = {};
|
||||
main.chat.isOpen = false;
|
||||
main.chat.createHelpChat = function createHelpChat() {
|
||||
throw new Error('Sidecar chat has not initialized');
|
||||
};
|
||||
|
||||
document.addEventListener('gitter-sidecar-ready', function(e) {
|
||||
main.chat.GitterChat = e.detail.Chat;
|
||||
|
||||
main.chat.createHelpChat = function(room, helpChatBtnClass, roomTitle) {
|
||||
// room is always in PascalCase
|
||||
roomTitle = room
|
||||
.replace(/([A-Z])/g, ' $1')
|
||||
.replace('Java Script', 'JavaScript');
|
||||
|
||||
$('body').append(
|
||||
'<aside id="chat-embed-help" class="gitter-chat-embed is-collapsed" />'
|
||||
);
|
||||
|
||||
main.chat.helpChat = new main.chat.GitterChat({
|
||||
room: `freecodecamp/${room}`,
|
||||
activationElement: false,
|
||||
targetElement: $('#chat-embed-help')
|
||||
});
|
||||
|
||||
$(helpChatBtnClass).on('click', function() {
|
||||
// is button already pressed?
|
||||
// no? open chat
|
||||
// yes? close chat
|
||||
var shouldChatBeOpen = !$(this).hasClass('active');
|
||||
main.chat.helpChat.toggleChat(shouldChatBeOpen);
|
||||
if (shouldChatBeOpen) {
|
||||
$(helpChatBtnClass).addClass('active');
|
||||
}
|
||||
});
|
||||
|
||||
var helpTitleAdd = false;
|
||||
$('#chat-embed-help').on('gitter-chat-toggle', function(e) {
|
||||
var shouldButtonBePressed = !!e.originalEvent.detail.state;
|
||||
|
||||
if (!helpTitleAdd) {
|
||||
helpTitleAdd = true;
|
||||
$('#chat-embed-help > .gitter-chat-embed-action-bar').prepend(
|
||||
'<div class="chat-embed-main-title">' +
|
||||
'<span>' +
|
||||
roomTitle +
|
||||
'</span>' +
|
||||
'</div>'
|
||||
);
|
||||
}
|
||||
|
||||
if (shouldButtonBePressed) {
|
||||
return $(helpChatBtnClass).addClass('active');
|
||||
}
|
||||
return $(helpChatBtnClass).removeClass('active');
|
||||
});
|
||||
};
|
||||
|
||||
$('body').append(
|
||||
'<aside id="chat-embed-main" class="gitter-chat-embed is-collapsed" />'
|
||||
);
|
||||
|
||||
main.chat.mainChat = new main.chat.GitterChat({
|
||||
room: 'freecodecamp/freecodecamp',
|
||||
activationElement: false,
|
||||
targetElement: $('#chat-embed-main')
|
||||
});
|
||||
|
||||
var mainChatTitleAdded = false;
|
||||
$('#chat-embed-main').on('gitter-chat-toggle', function() {
|
||||
if (mainChatTitleAdded) {
|
||||
return null;
|
||||
}
|
||||
mainChatTitleAdded = true;
|
||||
if ($('body').hasClass('night')) {
|
||||
$('#chat-embed-main').addClass('night');
|
||||
}
|
||||
$('#chat-embed-main > .gitter-chat-embed-action-bar').prepend(
|
||||
'<div class="chat-embed-main-title">' +
|
||||
'<span>Free Code Camp\'s Main Chat</span>' +
|
||||
'</div>'
|
||||
);
|
||||
return null;
|
||||
});
|
||||
|
||||
|
||||
$('#nav-chat-btn').on('click', function(event) {
|
||||
if (!(event.ctrlKey || event.metaKey)) {
|
||||
toggleMainChat();
|
||||
}
|
||||
window.ga('send', 'event', 'Nav', 'clicked', 'Nav chat opened');
|
||||
});
|
||||
|
||||
function showMainChat() {
|
||||
if (!main.chat.isOpen) {
|
||||
main.chat.mainChat.toggleChat(true);
|
||||
}
|
||||
}
|
||||
|
||||
function collapseMainChat() {
|
||||
$('#chat-embed-main').addClass('is-collapsed');
|
||||
document.activeElement.blur();
|
||||
}
|
||||
|
||||
function toggleMainChat() {
|
||||
var isCollapsed = $('#chat-embed-main').hasClass('is-collapsed');
|
||||
|
||||
if (isCollapsed) {
|
||||
showMainChat();
|
||||
} else {
|
||||
collapseMainChat();
|
||||
}
|
||||
}
|
||||
|
||||
// keyboard shortcuts: open main chat
|
||||
Mousetrap.bind('g c', toggleMainChat);
|
||||
});
|
||||
|
||||
return main;
|
||||
}(main, window));
|
||||
|
||||
$(document).ready(function() {
|
||||
|
||||
const { Observable } = window.Rx;
|
||||
|
||||
Reference in New Issue
Block a user