Skip to content

Commit

Permalink
Add main chat window on nav bar chat click
Browse files Browse the repository at this point in the history
  • Loading branch information
Berkeley Martinez authored and Berkeley Martinez committed Oct 16, 2015
1 parent a018295 commit 35219cd
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 44 deletions.
8 changes: 0 additions & 8 deletions client/commonFramework.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,6 @@ var common = (function() {
});
};

// this will overwrite if gitter object is already present
common.createGitterOptions = function createGitterOptions(room) {
((window.gitter = {}).chat = {}).options = {
room: room,
activationElement: document.createElement('div')
};
};

return common;
})();

Expand Down
47 changes: 46 additions & 1 deletion client/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,50 @@ main.mapShareKey = 'map-shares';

main.ga = window.ga || function() {};

main = (function(main) {

((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) {
main.chat.helpChat = new main.chat.GitterChat({
room: room,
activationElement: document.createElement('div')
});

$(helpChatBtnClass).on('click', function() {
main.chat.helpChat.toggleChat(true);
});
};

main.chat.mainChat = new main.chat.GitterChat({
room: 'freecodecamp/freecodecamp',
activationElement: document.createElement('div')
});

$('#nav-chat-btn').on('click', function() {
console.log('Create');
if (!main.chat.isOpen) {

main.chat.mainChat.toggleChat(true);
}
});
});

return main;
}(main));

var lastCompleted = typeof lastCompleted !== 'undefined' ?
lastCompleted :
'';
Expand Down Expand Up @@ -38,9 +82,10 @@ function setMapShare(id) {

$(document).ready(function() {


var challengeName = typeof challengeName !== 'undefined' ?
challengeName :
'Untitled';
'';

if (challengeName) {
ga('send', 'event', 'Challenge', 'load', challengeName);
Expand Down
13 changes: 7 additions & 6 deletions server/views/coursewares/showBonfire.jade
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ block content
label.btn.btn-success#trigger-reset-modal
i.fa.fa-refresh
|   Reset
label.btn.btn-success.js-gitter-toggle-chat-button
label.btn.btn-success#challenge-help-btn
i.fa.fa-medkit
|   Help
label.btn.btn-success#trigger-issue-modal
Expand Down Expand Up @@ -122,13 +122,14 @@ block content
a.btn.btn-lg.btn-primary.btn-block(href='#', data-dismiss='modal', aria-hidden='true') Cancel
include ../partials/challenge-modals
script.
// requires common framework
if (window.common) {
window.common.createGitterOptions('freecodecamp/helpbonfires', 'challenge-help-chat-btn');
}

document.addEventListener('gitter-sidecar-ready', function(e) {
if (window.main) {
window.main.chat.createHelpChat('freecodecamp/helpbonfires', '#challenge-help-btn');
}
});

var MDNlinks = !{JSON.stringify(MDNlinks)};
if (!MDNlinks.length) {
$('#MDN-links').addClass('collapse');
}
script(src="https://sidecar.gitter.im/dist/sidecar.v1.js" async defer)
12 changes: 6 additions & 6 deletions server/views/coursewares/showHTML.jade
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ block content
label.btn.btn-success#trigger-reset-modal
i.fa.fa-refresh
|   Reset
label.btn.btn-success.js-gitter-toggle-chat-button
label.btn.btn-success#challenge-help-btn
i.fa.fa-medkit
|   Help
label.btn.btn-success#trigger-issue-modal
Expand Down Expand Up @@ -96,8 +96,8 @@ block content
a.btn.btn-lg.btn-primary.btn-block(href='/challenges/next-challenge?id=' + challengeId) Go to my next challenge
include ../partials/challenge-modals
script.
// requires common framework
if (window.common) {
window.common.createGitterOptions('freecodecamp/help');
}
script(src="https://sidecar.gitter.im/dist/sidecar.v1.js" async defer)
document.addEventListener('gitter-sidecar-ready', function(e) {
if (window.main) {
window.main.chat.createHelpChat('freecodecamp/help', '#challenge-help-btn');
}
});
12 changes: 6 additions & 6 deletions server/views/coursewares/showJS.jade
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ block content
label.btn.btn-success#trigger-reset-modal
i.fa.fa-refresh
|   Reset
label.btn.btn-success.js-gitter-toggle-chat-button
label.btn.btn-success#challenge-help-btn
i.fa.fa-medkit
|   Help
label.btn.btn-success#trigger-issue-modal
Expand Down Expand Up @@ -98,12 +98,12 @@ block content
a.animated.fadeIn.btn.btn-lg.btn-primary.btn-block(href='/challenges/next-challenge?id=' + challengeId) Go to my next challenge
include ../partials/challenge-modals
script.
// requires common framework
if (window.common) {
window.common.createGitterOptions('freecodecamp/help');
}
var MDNlinks = !{JSON.stringify(MDNlinks)};
if (!MDNlinks.length) {
$('#MDN-links').addClass('collapse');
}
script(src="https://sidecar.gitter.im/dist/sidecar.v1.js" async defer)
document.addEventListener('gitter-sidecar-ready', function(e) {
if (window.main) {
window.main.chat.createHelpChat('freecodecamp/help', '#challenge-help-btn');
}
});
2 changes: 0 additions & 2 deletions server/views/coursewares/showStep.jade
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ block content
script(src=rev('/js', 'commonFramework.js'))
script.
var common = window.common || { init: [] };
common.createGitterOptions('freecodecamp/help');
common.challengeId = !{JSON.stringify(challengeId)};
common.challengeName = !{JSON.stringify(name)};
common.challengeType = 7;
Expand All @@ -41,4 +40,3 @@ block content
common.isFrontEndCert = !{JSON.stringify(isFrontEndCert || false)};
common.isFullStackCert = !{JSON.stringify(isFullStackCert || false)};
common.challengeSeed = !{JSON.stringify(challengeSeed || [])};
script(src="https://sidecar.gitter.im/dist/sidecar.v1.js" async defer)
12 changes: 7 additions & 5 deletions server/views/coursewares/showVideo.jade
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ block content
var userLoggedIn = true;
.button-spacer
.btn-group.input-group.btn-group-justified
.btn.btn-success.btn-big.js-gitter-toggle-chat-button
.btn.btn-success.btn-big#challenge-help-btn
i.fa.fa-medkit
|   Get help
.btn.btn-success.btn-big#trigger-issue-modal
Expand Down Expand Up @@ -78,8 +78,10 @@ block content
var challenge_Name = !{JSON.stringify(name)};
var challengeType = !{JSON.stringify(challengeType)};
var dashedName = !{JSON.stringify(dashedName)};
if (window.common) {
window.common.createGitterOptions('freecodecamp/help');
}
document.addEventListener('gitter-sidecar-ready', function(e) {
if (window.main) {
window.main.chat.createHelpChat('freecodecamp/help', '#challenge-help-btn');
}
});
include ../partials/challenge-modals
script(src="https://sidecar.gitter.im/dist/sidecar.v1.js" async defer)

20 changes: 11 additions & 9 deletions server/views/coursewares/showZiplineOrBasejump.jade
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ block content
a.btn.btn-big.btn-primary.btn-block(href='/challenges/next-challenge?id=' + challengeId) Go to my next challenge (ctrl + enter)
.button-spacer
.btn-group.input-group.btn-group-justified
.btn.btn-success.btn-big.js-gitter-toggle-chat-button
.btn.btn-success.btn-big#challenge-help-btn
i.fa.fa-medkit
|   Help
.btn.btn-success.btn-big#trigger-issue-modal
Expand Down Expand Up @@ -97,11 +97,13 @@ block content
$('body').on('keypress', controlEnterHandler);
include ../partials/challenge-modals
script.
if (window.common) {
window.common.createGitterOptions(
!{JSON.stringify(challengeType)} === 3 ?
'freecodecamp/helpZiplines' :
'freecodecamp/helpBonfires'
);
}
script(src="https://sidecar.gitter.im/dist/sidecar.v1.js" async defer)
document.addEventListener('gitter-sidecar-ready', function(e) {
if (window.main) {
window.main.chat.createHelpChat(
!{JSON.stringify(challengeType)} === 3 ?
'freecodecamp/helpZiplines' :
'freecodecamp/helpBonfires',
'#challenge-help-btn'
);
}
});
3 changes: 3 additions & 0 deletions server/views/partials/footer.jade
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@
span.sr-only Free Code Camp on Twitter
a.ion-locked(href="//github.com/FreeCodeCamp/freecodecamp/wiki/Free-Code-Camp's-Privacy-Policy")
span.sr-only Free Code Camp's Privacy Policy

// scripts should be moved here
script(src="https://sidecar.gitter.im/dist/sidecar.v1.js" async defer)
2 changes: 1 addition & 1 deletion server/views/partials/navbar.jade
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ nav.navbar.navbar-default.navbar-fixed-top.nav-height
li
a(href='/map') Map
li
a(href='//gitter.im/FreeCodeCamp/FreeCodeCamp', target='_blank') Chat
a#nav-chat-btn(href='#' onclick="return false") Chat
li
a(href='/news', target='_blank') News
li
Expand Down

0 comments on commit 35219cd

Please sign in to comment.