Files
freeCodeCamp/client/commonFramework/end.js

74 lines
1.8 KiB
JavaScript
Raw Normal View History

2015-08-27 00:02:07 -07:00
$(document).ready(function() {
const common = window.common;
const { Observable } = window.Rx;
const { challengeName, challengeType, challengeTypes } = common;
2015-09-27 15:58:59 -07:00
common.init.forEach(function(init) {
init($);
});
common.resetBtn$
.doOnNext(() => {
common.editor.setValue(common.replaceSafeTags(common.seed));
})
.flatMap(() => {
return common.executeChallenge$();
})
.subscribe(
({ output, original }) => {
common.codeStorage.updateStorage(challengeName, original);
common.updateOutputDisplay('' + output);
},
({ err }) => {
common.updateOutputDisplay('' + err);
}
);
common.submitBtn$
.flatMap(() => {
return common.executeChallenge$();
})
.subscribe(
2015-11-21 14:44:33 -08:00
({ output, original, tests }) => {
common.updateOutputDisplay(output);
common.codeStorage.updateStorage(challengeName, original);
2015-11-21 14:44:33 -08:00
common.displayTestResults(tests);
}
);
2015-08-27 00:15:13 -07:00
var $preview = $('#preview');
if ($preview.html()) {
2015-08-27 00:15:13 -07:00
$preview.load(function() {
common.executeChallenge()
.subscribe(
({ output = '' }) => {
common.updateOutputDisplay(output);
},
({ err }) => {
common.updateOutputDisplay('' + err);
}
);
2015-08-27 00:15:13 -07:00
});
2015-11-08 20:04:43 -08:00
} else if (
challengeType !== '2' &&
challengeType !== '3' &&
challengeType !== '4' &&
challengeType !== '7'
2015-11-08 20:04:43 -08:00
) {
common.executeChallenge$()
.subscribe(
({ original }) => {
// common.updateOutputDisplay('' + output);
common.codeStorage.updateStorage(challengeName, original);
},
({ err }) => {
if (err.stack) {
console.error(err);
}
common.updateOutputDisplay('' + err);
}
);
2015-08-27 00:15:13 -07:00
}
});