diff --git a/client/commonFramework.js b/client/commonFramework.js index e717d4d012..42e2b2832c 100644 --- a/client/commonFramework.js +++ b/client/commonFramework.js @@ -1,733 +1,10 @@ -var common = window.common || { init: [] }; - - -var BDDregex = new RegExp( - '(expect(\\s+)?\\(.*\\;)|' + - '(assert(\\s+)?\\(.*\\;)|' + - '(assert\\.\\w.*\\;)|' + - '(.*\\.should\\..*\\;)/' -); - -var libraryIncludes = - "" + - "" + - "" + - ''; - -var iFrameScript = ""; - -function workerError(error) { - var display = $('.runTimeError'); - var housing = $('#testSuite'); - - if (display.html() === error) { - return null; - } - - display.remove(); - - housing.prepend(` -
- ${common.unScopeJQuery(error)}
-
- ',
- navigator.userAgent,
- '
.\n',
- 'Please describe how to reproduce this issue, and include ',
- 'links to screenshots if possible.\n\n'
- ].join('');
-
- if (
- window.editor &&
- typeof window.editor.getValue === 'function' &&
- window.editor.getValue().trim()
- ) {
- var type;
- switch (common.challengeType) {
- case main.challengeTypes.HTML_CSS_JQ:
- type = 'html';
- break;
- case main.challengeTypes.JAVASCRIPT:
- case main.challengeTypes.BONFIRE:
- type = 'javascript';
- break;
- default:
- type = '';
- }
-
- textMessage += [
- 'My code:\n```',
- type,
- '\n',
- window.editor.getValue(),
- '\n```\n\n'
- ].join('');
- }
-
- textMessage = encodeURIComponent(textMessage);
-
- $('#issue-modal').modal('hide');
- window.open(
- 'https://github.com/freecodecamp/freecodecamp/issues/new?&body=' +
- textMessage, '_blank'
- );
- });
-
- $('#completed-courseware').unbind('click');
- $('#completed-courseware').on('click', function() {
- $('#complete-courseware-dialog').modal('show');
- });
-
- $('#completed-courseware-editorless').unbind('click');
- $('#completed-courseware-editorless').on('click', function() {
- $('#complete-courseware-editorless-dialog').modal('show');
- });
-
- $('#trigger-pair-modal').unbind('click');
- $('#trigger-pair-modal').on('click', function() {
- $('#pair-modal').modal('show');
- });
-
- $('#trigger-reset-modal').unbind('click');
- $('#trigger-reset-modal').on('click', function() {
- $('#reset-modal').modal('show');
- });
-
- $('#trigger-help-modal').unbind('click');
- $('#trigger-help-modal').on('click', function() {
- $('#help-modal').modal('show');
- });
-
- $('#trigger-issue-modal').unbind('click');
- $('#trigger-issue-modal').on('click', function() {
- $('#issue-modal').modal('show');
- });
-
- $('#completed-zipline-or-basejump').unbind('click');
- $('#completed-zipline-or-basejump').on('click', function() {
- $('#complete-zipline-or-basejump-dialog').modal('show');
- });
-
- $('#next-courseware-button').unbind('click');
- $('#next-courseware-button').on('click', function() {
- $('#next-courseware-button').unbind('click');
- if ($('.signup-btn-nav').length < 1) {
- var data;
- var completedWith;
- var publicURL;
- switch (common.challengeType) {
- case main.challengeTypes.HTML_CSS_JQ:
- case main.challengeTypes.JAVASCRIPT:
- case main.challengeTypes.VIDEO:
- data = {
- challengeInfo: {
- challengeId: common.challengeId,
- challengeName: common.challengeName
- }
- };
- $.post('/completed-challenge/', data)
- .success(function(res) {
- if (!res) {
- return;
- }
- window.location.href = '/challenges/next-challenge?id=' +
- common.challengeId;
- })
- .fail(function() {
- window.location.href = '/challenges';
- });
-
- break;
- case main.challengeTypes.ZIPLINE:
- completedWith = $('#completed-with').val() || null;
- publicURL = $('#public-url').val() || null;
- data = {
- challengeInfo: {
- challengeId: common.challengeId,
- challengeName: common.challengeName,
- completedWith: completedWith,
- publicURL: publicURL,
- challengeType: common.challengeType
- }
- };
-
- $.post('/completed-zipline-or-basejump/', data)
- .success(function() {
- window.location.href = '/challenges/next-challenge?id=' +
- common.challengeId;
- })
- .fail(function() {
- window.location.href = '/challenges';
- });
- break;
-
- case main.challengeTypes.BASEJUMP:
- completedWith = $('#completed-with').val() || null;
- publicURL = $('#public-url').val() || null;
- var githubURL = $('#github-url').val() || null;
- data = {
- challengeInfo: {
- challengeId: common.challengeId,
- challengeName: common.challengeName,
- completedWith: completedWith,
- publicURL: publicURL,
- githubURL: githubURL,
- challengeType: common.challengeType,
- verified: false
- }
- };
- $.post('/completed-zipline-or-basejump/', data)
- .success(function() {
- window.location.href = '/challenges/next-challenge?id=' +
- common.challengeId;
- })
- .fail(function() {
- window.location.replace(window.location.href);
- });
- break;
-
- case main.challengeTypes.BONFIRE:
- window.location.href = '/challenges/next-challenge?id=' +
- common.challengeId;
- break;
-
- default:
- console.log('Happy Coding!');
- break;
- }
- }
- });
-
- $('#complete-courseware-dialog').on('hidden.bs.modal', function() {
- window.editor.focus();
- });
-
- $('#complete-zipline-or-basejump').on('hidden.bs.modal', function() {
- window.editor.focus();
- });
- }
-
- $(window).resize(function() {
- reBindModals();
- });
-
- reBindModals();
-
function upvoteHandler(e) {
e.preventDefault();
var upvoteBtn = this;
@@ -602,101 +217,9 @@ $(document).ready(function() {
$('#story-submit').on('click', storySubmitButtonHandler);
- // fakeiphone positioning hotfix
- if (
- $('.iphone-position').html() ||
- $('.iphone').html()
- ) {
- var startIphonePosition = parseInt(
- $('.iphone-position')
- .css('top')
- .replace('px', ''),
- 10
- );
-
- var startIphone = parseInt(
- $('.iphone')
- .css('top')
- .replace('px', ''),
- 10
- );
-
- $(window).on('scroll', function() {
- var courseHeight = $('.courseware-height').height();
- var courseTop = $('.courseware-height').offset().top;
- var windowScrollTop = $(window).scrollTop();
- var phoneHeight = $('.iphone-position').height();
-
- if (courseHeight + courseTop - windowScrollTop - phoneHeight <= 0) {
- $('.iphone-position').css(
- 'top',
- startIphonePosition +
- courseHeight +
- courseTop -
- windowScrollTop -
- phoneHeight
- );
-
- $('.iphone').css(
- 'top',
- startIphonePosition +
- courseHeight +
- courseTop -
- windowScrollTop -
- phoneHeight +
- 120
- );
- } else {
- $('.iphone-position').css('top', startIphonePosition);
- $('.iphone').css('top', startIphone);
- }
- });
- }
-
- if ($('.scroll-locker').html()) {
-
- if ($('.scroll-locker').html()) {
- main.lockTop();
- $(window).on('resize', function() {
- main.lockTop();
- });
- $(window).on('scroll', function() {
- main.lockTop();
- });
- }
-
- var execInProgress = false;
-
- // why is this not $???
- document
- .getElementById('scroll-locker')
- .addEventListener(
- 'previewUpdateSpy',
- function(e) {
- if (execInProgress) {
- return null;
- }
- execInProgress = true;
- setTimeout(function() {
- if (
- $($('.scroll-locker').children()[0]).height() - 800 > e.detail
- ) {
- $('.scroll-locker').scrollTop(e.detail);
- } else {
- var scrollTop = $($('.scroll-locker').children()[0]).height();
-
- $('.scroll-locker').animate({ scrollTop: scrollTop }, 175);
- }
- execInProgress = false;
- }, 750);
- },
- false
- );
- }
-
// map sharing
- var alreadyShared = getMapShares();
+ var alreadyShared = main.getMapShares();
if (lastCompleted && alreadyShared.indexOf(lastCompleted) === -1) {
$('div[id="' + lastCompleted + '"]')
@@ -724,8 +247,8 @@ $(document).ready(function() {
username +
'&redirect_uri=http%3A%2F%2Ffreecodecamp%2Ecom%2Fmap';
- setMapShare(challengeBlockName);
- main.ga('send', 'event', 'FB_LINK', 'SHARE', 'Facebook map share');
+ main.setMapShare(challengeBlockName);
+ window.ga('send', 'event', 'FB_LINK', 'SHARE', 'Facebook map share');
window.location.href = link;
});
});
diff --git a/client/plugin.js b/client/plugin.js
index 7724b08fbf..2cc3c54904 100644
--- a/client/plugin.js
+++ b/client/plugin.js
@@ -13,22 +13,18 @@ function importScript(url, error) {
function run(code, cb) {
var err = null;
- var result = {
- input: code,
- output: null,
- type: null
- };
+ var result = {};
try {
var codeExec = runHidden(code);
result.type = typeof codeExec;
result.output = stringify(codeExec);
} catch (e) {
- err = e;
+ err = e.mesage;
}
if (err) {
- cb(err.message, null);
+ cb(err, null);
} else {
cb(null, result);
}
@@ -40,7 +36,7 @@ function run(code, cb) {
// protects even the worker scope from being accessed
function runHidden(code) {
- /* eslint-disable */
+ /* eslint-disable no-unused-vars */
var indexedDB = null;
var location = null;
var navigator = null;
@@ -63,21 +59,15 @@ function runHidden(code) {
var dump = null;
var onoffline = null;
var ononline = null;
- /* eslint-enable */
+ /* eslint-enable no-unused-vars */
var error = null;
- error = importScript(
- error,
- 'https://cdnjs.cloudflare.com/ajax/libs/ramda/0.13.0/ramda.min.js'
- );
-
error = importScript(
'https://cdnjs.cloudflare.com/ajax/libs/chai/2.2.0/chai.min.js'
);
/* eslint-disable*/
- var expect = chai.expect;
var assert = chai.assert;
/* eslint-enable */
diff --git a/server/views/coursewares/showBonfire.jade b/server/views/coursewares/showBonfire.jade
index 137e247cca..3357573bee 100644
--- a/server/views/coursewares/showBonfire.jade
+++ b/server/views/coursewares/showBonfire.jade
@@ -102,7 +102,7 @@ block content
a.btn.btn-lg.btn-primary.btn-block(href='#', data-dismiss='modal', aria-hidden='true') Cancel
include ../partials/challenge-modals
script(type="text/javascript").
- var common = window.common = { init: [] };
+ var common = window.common = window.common || { init: [] };
common.tests = !{JSON.stringify(tests)};
common.head = !{JSON.stringify(head)};
diff --git a/server/views/coursewares/showVideo.jade b/server/views/coursewares/showVideo.jade
index 8f95c5c73b..ed06486f89 100644
--- a/server/views/coursewares/showVideo.jade
+++ b/server/views/coursewares/showVideo.jade
@@ -39,25 +39,6 @@ block content
script(type="text/javascript").
- var controlEnterHandler = function(e) {
- $('body').unbind('keydown');
- if (e.metaKey && e.keyCode === 13 ||
- e.ctrlKey && e.keyCode === 13) {
- $('#complete-courseware-editorless-dialog').modal('show');
- } else {
- $('body').bind('keydown', controlEnterHandler);
- }
- };
- var modalControlEnterHandler = function(e) {
- $('#complete-courseware-editorless-dialog').unbind('keydown');
- if (e.metaKey && e.keyCode === 13 ||
- e.ctrlKey && e.keyCode === 13) {
- $('#next-courseware-button').click();
- } else {
- $('#complete-courseware-editorless-dialog').bind('keydown', modalControlEnterHandler);
- }
- };
-
#complete-courseware-editorless-dialog.modal(tabindex='-1')
.modal-dialog.animated.fadeIn.fast-animation
.modal-content
@@ -69,21 +50,48 @@ block content
span.completion-icon.ion-checkmark-circled.text-primary
if (user)
a.btn.btn-lg.btn-primary.btn-block#next-courseware-button(name='_csrf', value=_csrf) I've completed this challenge (ctrl + enter)
- script.
- $('#complete-courseware-editorless-dialog').bind('keydown', modalControlEnterHandler);
else
a.animated.fadeIn.btn.btn-lg.btn-primary.btn-block(href='/challenges/next-challenge?id=' + challengeId) I've completed this challenge (ctrl + enter)
- script.
- $('body').bind('keydown', controlEnterHandler);
include ../partials/challenge-modals
script.
- var common = window.common = { init: [] };
+ var common = window.common || { init: [] };
common.challengeId = !{JSON.stringify(challengeId)};
common.challengeName = !{JSON.stringify(name)};
common.challengeType = !{JSON.stringify(challengeType)};
common.dashedName = !{JSON.stringify(dashedName)};
+ common.init.push(function($) {
+ function controlEnterHandler(e) {
+ if (
+ e.keyCode === 13 &&
+ e.ctrlKey ||
+ e.metaKey
+ ) {
+ $('body').unbind('keydown');
+ $('#complete-courseware-editorless-dialog').modal('show');
+ }
+ };
+
+ function modalControlEnterHandler(e) {
+ if (
+ e.keyCode === 13 &&
+ e.ctrlKey ||
+ e.metaKey
+ ) {
+ $('#complete-courseware-editorless-dialog').unbind('keydown');
+ $('#next-courseware-button').click();
+ }
+ };
+ if (!{JSON.stringify(user && user.username ? true : false)}) {
+ $('#complete-courseware-editorless-dialog').bind('keydown', modalControlEnterHandler);
+ }
+ $('body').bind('keydown', controlEnterHandler);
+
+ $('#completed-courseware-editorless').on('click', function() {
+ $('#complete-courseware-editorless-dialog').modal('show');
+ });
+ });
document.addEventListener('gitter-sidecar-ready', function(e) {
if (window.main) {
diff --git a/server/views/coursewares/showZiplineOrBasejump.jade b/server/views/coursewares/showZiplineOrBasejump.jade
index 9a2f3e0acc..54d67cb844 100644
--- a/server/views/coursewares/showZiplineOrBasejump.jade
+++ b/server/views/coursewares/showZiplineOrBasejump.jade
@@ -105,9 +105,14 @@ block content
if (!!{ JSON.stringify(user ? true : false)}) {
$('#complete-zipline-or-basejump-dialog').on('keydown', common.modalControlEnterHandler);
}
+
+ $('#completed-zipline-or-basejump').on('click', function() {
+ $('#complete-zipline-or-basejump-dialog').modal('show');
+ });
});
+
document.addEventListener('gitter-sidecar-ready', function(e) {
var room = 'freecodecamp/help';
var title;