Fix lint issues with gist saving

This commit is contained in:
Berkeley Martinez
2015-11-06 17:48:17 -08:00
parent 13a505cf23
commit 328e75812a
2 changed files with 41 additions and 28 deletions

View File

@ -300,34 +300,49 @@ $(document).ready(function() {
} }
var request = createCORSRequest('post', 'https://api.github.com/gists'); var request = createCORSRequest('post', 'https://api.github.com/gists');
if (request) { if (!request) {
request.onload = function() { return null;
if (request.readyState === 4 && }
request.status === 201 &&
request.statusText === 'Created') { request.onload = function() {
gistWindow.location.href = JSON.parse(request.responseText)['html_url']; if (
} request.readyState === 4 &&
}; request.status === 201 &&
var data = { request.statusText === 'Created'
description: (username ? 'http://www.freecodecamp.com/' + username + ) {
' \'s s' : 'S') + 'olution for ' + (challenge_Name || challengeName), gistWindow.location.href =
public: true, JSON.parse(request.responseText)['html_url'];
files: {} }
}, };
queryIssue = window.location.href.toString().split('#?')[0],
filename = queryIssue var description = common.username ?
'http://www.freecodecamp.com/' + common.username + ' \'s s' :
'S';
var data = {
description: description + 'olution for ' + common.challengeName,
public: true,
files: {}
};
var queryIssue = window.location.href.toString().split('#?')[0];
var filename = queryIssue
.substr(queryIssue.lastIndexOf('challenges/') + 11) .substr(queryIssue.lastIndexOf('challenges/') + 11)
.replace('/', '') + '.js'; .replace('/', '') + '.js';
data['files'][filename] = {
content: '// ' + (challenge_Name || challengeName) + '\n' +
(username ? '// Author: @' + username + '\n' : '') +
'// Challenge: ' + queryIssue + '\n' +
'// Learn to Code at Free Code Camp (www.freecodecamp.com)' +
'\n\n' + editor.getValue().trim()
};
request.send(JSON.stringify(data)); data.files[filename] = {
} content: '// ' +
common.challengeName +
'\n' +
(common.username ? '// Author: @' + common.username + '\n' : '') +
'// Challenge: ' +
queryIssue +
'\n' +
'// Learn to Code at Free Code Camp (www.freecodecamp.com)' +
'\n\n' +
window.editor.getValue().trim()
};
request.send(JSON.stringify(data));
}); });
$('#help-ive-found-a-bug-wiki-article').unbind('click'); $('#help-ive-found-a-bug-wiki-article').unbind('click');

View File

@ -125,9 +125,7 @@ block content
common.dashedName = !{JSON.stringify(dashedName)}; common.dashedName = !{JSON.stringify(dashedName)};
common.started = Math.floor(Date.now()); common.started = Math.floor(Date.now());
if (user) { common.username = !{JSON.stringify(user && user.username || '')};
common.username = !{JSON.stringify(user.username)};
}
include ../partials/challenge-footer include ../partials/challenge-footer
script. script.