diff --git a/.travis.yml b/.travis.yml
index 26804033f5..b6bd11e2c2 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,7 +1,7 @@
language: node_js
-services:
- - mongodb
-
node_js:
- - '0.10'
\ No newline at end of file
+ - 'node'
+ - '1.6.4'
+
+sudo: false
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index ba4e245107..6830f00dc5 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -1,2 +1,12 @@
We're getting a lot of duplicate issues and bug reports that just aren't reporting actual bugs.
So, before you submit your issue, please read the [Help I've Found a Bug](https://github.com/FreeCodeCamp/FreeCodeCamp/wiki/Help-I've-Found-a-Bug) wiki page.
+
+We welcome pull requests from Free Code Camp campers (our students) and seasoned JavaScript developers alike! Follow these steps to contribute:
+
+1. Check our [public Waffle Board](https://waffle.io/freecodecamp/freecodecamp).
+2. Pick an issue that nobody has claimed and start working on it. If your issue isn't on the board, open an issue. If you think you can fix it yourself, start working on it. Feel free to ask for help in our [Gitter](https://gitter.im/FreeCodeCamp/FreeCodeCamp).
+3. Fork the project ([Need help with forking a project?](https://help.github.com/articles/fork-a-repo/)). You'll do all of your work on your forked copy.
+4. Create a branch specific to the issue or feature you are working on. Push your work to that branch. ([Need help with branching?](https://github.com/Kunena/Kunena-Forum/wiki/Create-a-new-branch-with-git-and-manage-branches))
+5. Name the branch something like `fix/xxx` or `feature/xxx` where `xxx` is a short description of the changes or feature you are attempting to add. For example `fix/email-login` would be a branch where I fix something specific to email login.
+6. You should have [ESLint running in your editor](http://eslint.org/docs/user-guide/integrations.html), and it will highlight anything doesn't conform to [Free Code Camp's JavaScript Style Guide](https://github.com/FreeCodeCamp/FreeCodeCamp/wiki/Free-Code-Camp-JavaScript-Style-Guide) (you can find a summary of those rules [here](https://github.com/FreeCodeCamp/FreeCodeCamp/blob/staging/.eslintrc). Please do not ignore any linting errors, as they are meant to **help** you and to ensure a clean and simple code base. Make sure none of your JavaScript is longer than 80 characters per line.
+7. Once your code is ready, submit a [pull request](https://github.com/FreeCodeCamp/FreeCodeCamp/wiki/Pull-Request-Contribute) from your branch to Free Code Camp's `staging` branch. We'll do a quick code review and give you feedback, then iterate from there. It may also be helpful to read about git [rebasing](https://github.com/FreeCodeCamp/FreeCodeCamp/wiki/git-rebase).
diff --git a/README.md b/README.md
index dba5013540..9b0c87d631 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-
+
[](https://waffle.io/freecodecamp/freecodecamp/metrics)
@@ -7,7 +7,7 @@
Welcome to Free Code Camp's open source codebase!
=======================
-Free Code Camp is an open-source community of busy people who learn to code, then build projects for nonprofits.
+Free Code Camp is an open-source community of busy people who learn to code and build projects for nonprofits.
Our campers (students) start by working through our free, self-paced, browser-based curriculum. Next, they build several practice projects. Finally, we pair two campers together with a stakeholder from a nonprofit organization, and help them build the solution the nonprofit has requested.
@@ -24,7 +24,7 @@ This code is running live at [FreeCodeCamp.com](http://www.FreeCodeCamp.com). We
Wiki
------------
-We would love your help expanding our [wiki](https://github.com/freecodecamp/freecodecamp/wiki) with more information about learning to code and getting a coding job.
+We would love your help expanding our [wiki](https://github.com/freecodecamp/freecodecamp/wiki). Our goal is to become a great resource for people learning to code, building local coding communities, and applying for coding jobs.
Contributing
------------
@@ -35,10 +35,9 @@ We welcome pull requests from Free Code Camp campers (our students) and seasoned
2. Pick an issue that nobody has claimed and start working on it. If your issue isn't on the board, open an issue. If you think you can fix it yourself, start working on it. Feel free to ask for help in our [Gitter](https://gitter.im/FreeCodeCamp/FreeCodeCamp).
3. Fork the project ([Need help with forking a project?](https://help.github.com/articles/fork-a-repo/)). You'll do all of your work on your forked copy.
4. Create a branch specific to the issue or feature you are working on. Push your work to that branch. ([Need help with branching?](https://github.com/Kunena/Kunena-Forum/wiki/Create-a-new-branch-with-git-and-manage-branches))
-5. Name the branch something like `user-xxx` where user is your username and xxx is the issue number you are addressing.
-6. You should have [ESLint running in your editor](http://eslint.org/docs/user-guide/integrations.html), and it will highlight anything doesn't conform to [AirBnB's JavaScript Style Guide](https://github.com/airbnb/javascript). Please do not ignore any linting errors, as they are meant to **help** you. Make sure none of your JavaScript is longer than 80 characters per line.
-7. Once your code is ready, submit a pull request from your branch to Free Code Camp's `staging` branch. We'll do a quick code review and give you feedback, then iterate from there.
-8. Once we accept one of your pull requests, one of the project owners (currently @quincylarson, @terakilobyte, and @berkeleytrue) will add you to our camper contributor group.
+5. Name the branch something like `fix/xxx` or `feature/xxx` where `xxx` is a short description of the changes or feature you are attempting to add. For example `fix/email-login` would be a branch where I fix something specific to email login.
+6. You should have [ESLint running in your editor](http://eslint.org/docs/user-guide/integrations.html), and it will highlight anything doesn't conform to [Free Code Camp's JavaScript Style Guide](https://github.com/FreeCodeCamp/FreeCodeCamp/wiki/Free-Code-Camp-JavaScript-Style-Guide) (you can find a summary of those rules [here](https://github.com/FreeCodeCamp/FreeCodeCamp/blob/staging/.eslintrc). Please do not ignore any linting errors, as they are meant to **help** you and to ensure a clean and simple code base. Make sure none of your JavaScript is longer than 80 characters per line.
+7. Once your code is ready, submit a [pull request](https://github.com/FreeCodeCamp/FreeCodeCamp/wiki/Pull-Request-Contribute) from your branch to Free Code Camp's `staging` branch. We'll do a quick code review and give you feedback, then iterate from there. It may also be helpful to read about git [rebasing](https://github.com/FreeCodeCamp/FreeCodeCamp/wiki/git-rebase).
Prerequisites
-------------
@@ -70,10 +69,9 @@ touch .env
npm install -g gulp
```
-Edit your .env file with the following API keys accordingly (if you only use email login, only the MONGOHQ_URL, SESSION_SECRET, MANDRILL_USER and MANDRILL_PASSWORD fields are necessary. Keep in mind if you want to use more services you'll have to get your own API keys for those services.
+Edit your `.env` file with the following API keys accordingly (if you only use email login, only the `MONGOHQ_URL`, `SESSION_SECRET`, `MANDRILL_USER` and `MANDRILL_PASSWORD` fields are necessary. Keep in mind if you want to use more services you'll have to get your own API keys for those services.
```
-
MONGOHQ_URL='mongodb://localhost:27017/freecodecamp'
FACEBOOK_ID=stuff
@@ -106,16 +104,14 @@ COOKIE_SECRET='this is a secret'
PEER=stuff
DEBUG=true
-
```
```bash
-
# Start the mongo server
mongod
-# Create your mongo database.
-# Type "mongo" in your terminal to access the mongo shell
+# Create your mongo database.
+# Type "mongo" in your terminal to access the mongo shell
use freecodecamp
# Exit the mongo shell with control + d
@@ -124,7 +120,6 @@ node seed/
# start the application
gulp
-
```
License
diff --git a/bower.json b/bower.json
index cd8cfd5cf3..1f833167fc 100644
--- a/bower.json
+++ b/bower.json
@@ -26,6 +26,7 @@
"moment": "~2.10.2",
"angular-bootstrap": "~0.13.0",
"ramda": "~0.13.0",
- "jshint": "~2.7.0"
+ "jshint": "~2.7.0",
+ "lightbox2": "~2.8.1"
}
}
diff --git a/client/commonFramework.js b/client/commonFramework.js
index dd91756e06..8abcb6a9dc 100644
--- a/client/commonFramework.js
+++ b/client/commonFramework.js
@@ -1,6 +1,107 @@
-/* globals jailed, CodeMirror, challenge_Id, challenge_Name, challengeType */
+// common namespace
+// all classes should be stored here
+var common = common || {
+ // init is an array of functions that are
+ // called at the beginning of dom ready
+ init: []
+};
+
+common.challengeName = common.challengeName || window.challenge_Name ?
+ window.challenge_Name :
+ '';
+
+common.challengeType = common.challengeType || window.challengeType ?
+ window.challengeType :
+ 0;
+
+common.challengeId = common.challengeId || window.challenge_Id;
+
+common.challengeSeed = common.challengeSeed || window.challengeSeed ?
+ window.challengeSeed :
+ [];
+
+common.seed = common.challengeSeed.reduce(function(seed, line) {
+ return seed + line + '\n';
+}, '');
+
+// store code in the URL
+common.codeUri = (function(common, encode, decode, location, history) {
+ var codeUri = {
+ encode: function(code) {
+ return encode(code);
+ },
+ decode: function(code) {
+ try {
+ return decode(code);
+ } catch (ignore) {
+ return null;
+ }
+ },
+ isInQuery: function(query) {
+ var decoded = codeUri.decode(query);
+ if (!decoded || typeof decoded.split !== 'function') {
+ return false;
+ }
+ return decoded
+ .split('?')
+ .splice(1)
+ .reduce(function(found, param) {
+ var key = param.split('=')[0];
+ if (key === 'solution') {
+ return true;
+ }
+ return found;
+ }, false);
+ },
+ isAlive: function() {
+ return codeUri.isInQuery(location.search) ||
+ codeUri.isInQuery(location.hash);
+ },
+ parse: function() {
+ var query;
+ if (location.search && codeUri.isInQuery(location.search)) {
+ query = location.search.replace(/^\?/, '');
+ if (history && typeof history.replaceState === 'function') {
+ history.replaceState(
+ history.state,
+ null,
+ location.href.split('?')[0]
+ );
+ location.hash = '#?' + query;
+ }
+ } else {
+ query = location.hash.replace(/^\#\?/, '');
+ }
+ if (!query) {
+ return null;
+ }
+
+ return query
+ .split('&')
+ .reduce(function(solution, param) {
+ var key = param.split('=')[0];
+ var value = param.split('=')[1];
+ if (key === 'solution') {
+ return codeUri.decode(value);
+ }
+ return solution;
+ }, null);
+ },
+ querify: function(solution) {
+ location.hash = '?solution=' + codeUri.encode(solution);
+ return solution;
+ }
+ };
+
+ common.init.push(function() {
+ codeUri.parse();
+ });
+
+ return codeUri;
+}(common, encodeURIComponent, decodeURIComponent, location, history));
+
// codeStorage
-var codeStorageFactory = (function($, localStorage) {
+common.codeStorageFactory = (function($, localStorage, codeUri) {
var CodeStorageProps = {
version: 0.01,
@@ -41,7 +142,10 @@ var codeStorageFactory = (function($, localStorage) {
updateStorage: function() {
if (typeof localStorage !== 'undefined') {
var value = this.editor.getValue();
+ // store in localStorage
localStorage.setItem(this.keyValue, value);
+ // also store code in URL
+ codeUri.querify(value);
} else {
console.log('no web storage');
}
@@ -66,10 +170,47 @@ var codeStorageFactory = (function($, localStorage) {
}
return codeStorageFactory;
-}($, localStorage));
+}($, localStorage, common.codeUri));
-var sandBox = (function() {
+common.codeOutput = (function(CodeMirror, document, challengeType) {
+ if (!CodeMirror) {
+ return {};
+ }
+ if (
+ challengeType === '0' ||
+ challengeType === '7'
+ ) {
+ return {};
+ }
+ var codeOutput = CodeMirror.fromTextArea(
+ document.getElementById('codeOutput'),
+ {
+ lineNumbers: false,
+ mode: 'text',
+ theme: 'monokai',
+ readOnly: 'nocursor',
+ lineWrapping: true
+ }
+ );
+ codeOutput.setValue(
+ '/**\n' +
+ ' * Your output will go here.\n' +
+ ' * Console.log() -type statements\n' +
+ ' * will appear in your browser\'s\n' +
+ ' * DevTools JavaScript console.\n' +
+ ' */'
+ );
+
+ codeOutput.setSize('100%', '100%');
+
+ return codeOutput;
+}(window.CodeMirror, window.document, common.challengeType || 0));
+
+var sandBox = (function(jailed, codeOutput) {
+ if (!jailed) {
+ return {};
+ }
var plugin = null;
var sandBox = {
@@ -150,7 +291,7 @@ var sandBox = (function() {
endLoading();
console.log('resetting on fatal plugin error');
- if (challengeType === 0) {
+ if (common.challengeType === 0) {
codeOutput.setValue(
'Sorry, your code is either too slow, has a fatal error, ' +
'or contains an infinite loop.'
@@ -163,7 +304,7 @@ var sandBox = (function() {
reset();
sandBox.submit = submit;
return sandBox;
-}());
+}(window.jailed, common.codeOutput));
function replaceSafeTags(value) {
return value
@@ -180,66 +321,110 @@ var BDDregex = new RegExp(
var isInitRun = false;
var initPreview = true;
-var editor;
-editor = CodeMirror.fromTextArea(document.getElementById('codeEditor'), {
- lineNumbers: true,
- mode: 'text',
- theme: 'monokai',
- runnable: true,
- matchBrackets: true,
- autoCloseBrackets: true,
- scrollbarStyle: 'null',
- lineWrapping: true,
- gutters: ['CodeMirror-lint-markers']
-});
-
-var codeStorage = codeStorageFactory(editor, challenge_Name);
-var myCodeMirror = editor;
-
-editor.on('keyup', function() {
- clearTimeout(codeStorage.updateTimeoutId);
- codeStorage.updateTimeoutId = setTimeout(
- codeStorage.updateStorage,
- codeStorage.updateWait
- );
-});
-
-var editorValue;
-var challengeSeed = challengeSeed || null;
-var tests = tests || [];
-var allSeeds = '';
-
-(function() {
- challengeSeed.forEach(function(elem) {
- allSeeds += elem + '\n';
- });
-})();
-
-editor.setOption('extraKeys', {
- Tab: function(cm) {
- if (cm.somethingSelected()) {
- cm.indentSelection('add');
- } else {
- var spaces = Array(cm.getOption('indentUnit') + 1).join(' ');
- cm.replaceSelection(spaces);
- }
- },
- 'Shift-Tab': function(cm) {
- if (cm.somethingSelected()) {
- cm.indentSelection('subtract');
- } else {
- var spaces = Array(cm.getOption('indentUnit') + 1).join(' ');
- cm.replaceSelection(spaces);
- }
- },
- 'Ctrl-Enter': function() {
- bonfireExecute(true);
- return false;
+var editor = (function(CodeMirror, emmetCodeMirror, common) {
+ var codeStorageFactory = common.codeStorageFactory;
+ if (!CodeMirror) {
+ return {};
}
-});
-editor.setSize('100%', 'auto');
+ var editor = CodeMirror.fromTextArea(document.getElementById('codeEditor'), {
+ lineNumbers: true,
+ mode: 'text',
+ theme: 'monokai',
+ runnable: true,
+ matchBrackets: true,
+ autoCloseBrackets: true,
+ scrollbarStyle: 'null',
+ lineWrapping: true,
+ gutters: ['CodeMirror-lint-markers']
+ });
+
+ editor.setSize('100%', 'auto');
+
+ var codeStorage = common.codeStorage =
+ codeStorageFactory(editor, common.challengeName);
+
+ editor.on('keyup', function() {
+ clearTimeout(codeStorage.updateTimeoutId);
+ codeStorage.updateTimeoutId = setTimeout(
+ codeStorage.updateStorage.bind(codeStorage),
+ codeStorage.updateWait
+ );
+ });
+
+ // Initialize CodeMirror editor with a nice html5 canvas demo.
+ editor.on('keyup', function() {
+ clearTimeout(delay);
+ delay = setTimeout(updatePreview, 300);
+ });
+
+ editor.setOption('extraKeys', {
+ Tab: function(cm) {
+ if (cm.somethingSelected()) {
+ cm.indentSelection('add');
+ } else {
+ var spaces = Array(cm.getOption('indentUnit') + 1).join(' ');
+ cm.replaceSelection(spaces);
+ }
+ },
+ 'Shift-Tab': function(cm) {
+ if (cm.somethingSelected()) {
+ cm.indentSelection('subtract');
+ } else {
+ var spaces = Array(cm.getOption('indentUnit') + 1).join(' ');
+ cm.replaceSelection(spaces);
+ }
+ },
+ 'Ctrl-Enter': function() {
+ isInitRun = false;
+ bonfireExecute(true);
+ return false;
+ }
+ });
+
+
+ var info = editor.getScrollInfo();
+
+ var after = editor.charCoords({
+ line: editor.getCursor().line + 1,
+ ch: 0
+ }, 'local').top;
+
+ if (info.top + info.clientHeight < after) {
+ editor.scrollTo(null, after - info.clientHeight + 3);
+ }
+
+ if (emmetCodeMirror) {
+ emmetCodeMirror(
+ editor,
+ {
+ 'Cmd-E': 'emmet.expand_abbreviation',
+ Tab: 'emmet.expand_abbreviation_with_tab',
+ Enter: 'emmet.insert_formatted_line_break_only'
+ }
+ );
+ }
+ common.init.push(function() {
+ var editorValue;
+ if (common.codeUri.isAlive()) {
+ console.log('in query');
+ editorValue = common.codeUri.parse();
+ } else {
+ editorValue = codeStorage.isAlive() ?
+ codeStorage.getStoredValue() :
+ common.seed;
+ }
+
+ editor.setValue(replaceSafeTags(editorValue));
+ editor.refresh();
+ });
+
+ return editor;
+}(window.CodeMirror, window.emmetCodeMirror, common));
+
+
+var tests = tests || [];
var libraryIncludes = "" +
"" +
@@ -283,7 +468,8 @@ function scopejQuery(str) {
}
function safeHTMLRun(test) {
- if (challengeType === '0') {
+ var codeStorage = common.codeStorage;
+ if (common.challengeType === '0') {
var previewFrame = document.getElementById('preview');
var preview = previewFrame.contentDocument || previewFrame.contentWindow.document;
if (editor.getValue().match(/\