freeCodeCamp/client/commonFramework/show-completion.js

68 lines
1.7 KiB
JavaScript
Raw Normal View History

2015-11-18 05:25:16 +00:00
window.common = (function(global) {
const {
$,
ga = (() => {}),
common = { init: [] }
} = global;
common.showCompletion = function showCompletion() {
2015-12-13 09:06:33 +00:00
var time = Math.floor(Date.now() - common.started);
2015-11-18 05:25:16 +00:00
ga(
'send',
'event',
'Challenge',
'solved',
common.challengeName + ', Time: ' + time + ', Attempts: ' + 0
);
var solution = common.editor.getValue();
2015-11-18 05:25:16 +00:00
var didCompleteWith = $('#completed-with').val() || null;
$('#complete-courseware-dialog').modal('show');
$('#complete-courseware-dialog .modal-header').click();
$('#submit-challenge').click(function(e) {
e.preventDefault();
$('#submit-challenge')
.attr('disabled', 'true')
.removeClass('btn-primary')
.addClass('btn-warning disabled');
var $checkmarkContainer = $('#checkmark-container');
$checkmarkContainer.css({ height: $checkmarkContainer.innerHeight() });
$('#challenge-checkmark')
.addClass('zoomOutUp')
// .removeClass('zoomInDown')
.delay(1000)
.queue(function(next) {
$(this).replaceWith(
'<div id="challenge-spinner" ' +
'class="animated zoomInUp inner-circles-loader">' +
'submitting...</div>'
);
next();
});
const data = {
id: common.challengeId,
name: common.challengeName,
completedWith: didCompleteWith,
challengeType: common.challengeType,
solution
};
$.post('/completed-challenge/', data, function(res) {
if (res) {
window.location =
'/challenges/next-challenge?id=' + common.challengeId;
2015-11-18 05:25:16 +00:00
}
});
2015-11-18 05:25:16 +00:00
});
};
return common;
}(window));