2014-10-18 02:23:53 +00:00
|
|
|
$(document).ready(function() {
|
2015-03-09 09:49:03 +00:00
|
|
|
var challengeName = typeof challengeName !== undefined ? challengeName : 'Untitled';
|
2015-02-08 05:11:26 +00:00
|
|
|
if (challengeName) {
|
|
|
|
ga('send', 'event', 'Challenge', 'load', challengeName);
|
2015-02-03 06:57:35 +00:00
|
|
|
}
|
2014-11-07 06:47:35 +00:00
|
|
|
|
2015-01-24 05:44:08 +00:00
|
|
|
var CSRF_HEADER = 'X-CSRF-Token';
|
2014-11-07 06:47:35 +00:00
|
|
|
|
2015-01-24 05:44:08 +00:00
|
|
|
var setCSRFToken = function(securityToken) {
|
|
|
|
jQuery.ajaxPrefilter(function(options, _, xhr) {
|
|
|
|
if (!xhr.crossDomain) {
|
|
|
|
xhr.setRequestHeader(CSRF_HEADER, securityToken);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
setCSRFToken($('meta[name="csrf-token"]').attr('content'));
|
|
|
|
|
|
|
|
$('.start-challenge').on('click', function() {
|
|
|
|
$(this).parent().remove();
|
|
|
|
$('.challenge-content')
|
|
|
|
.removeClass('hidden-element')
|
|
|
|
.addClass('animated fadeInDown');
|
|
|
|
});
|
|
|
|
|
|
|
|
$('.completed-challenge').on('click', function() {
|
|
|
|
$('#complete-challenge-dialog').modal('show');
|
|
|
|
// Only post to server if there is an authenticated user
|
|
|
|
if ($('.signup-btn-nav').length < 1) {
|
|
|
|
l = location.pathname.split('/');
|
|
|
|
cn = l[l.length - 1];
|
|
|
|
$.ajax({
|
|
|
|
type: 'POST',
|
|
|
|
data: {challengeNumber: cn},
|
|
|
|
url: '/completed-challenge/'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-01-24 08:11:01 +00:00
|
|
|
function completedBonfire(didCompleteWith, bonfireSolution, thisBonfireHash) {
|
2015-01-24 05:44:08 +00:00
|
|
|
$('#complete-bonfire-dialog').modal('show');
|
|
|
|
// Only post to server if there is an authenticated user
|
|
|
|
if ($('.signup-btn-nav').length < 1) {
|
2015-01-28 22:17:45 +00:00
|
|
|
|
|
|
|
$.post(
|
|
|
|
'/completed-bonfire',
|
|
|
|
{
|
2015-01-24 08:11:01 +00:00
|
|
|
bonfireInfo: {
|
|
|
|
completedWith : didCompleteWith,
|
|
|
|
solution: bonfireSolution,
|
|
|
|
bonfireHash: thisBonfireHash
|
|
|
|
}
|
|
|
|
},
|
2015-01-28 22:17:45 +00:00
|
|
|
function(res) {
|
|
|
|
if (res) {
|
2015-01-28 22:48:18 +00:00
|
|
|
window.location.href = '/bonfires'
|
2015-01-28 22:17:45 +00:00
|
|
|
}
|
2015-03-05 10:21:26 +00:00
|
|
|
});
|
2015-01-24 05:44:08 +00:00
|
|
|
}
|
2015-01-24 08:11:01 +00:00
|
|
|
}
|
2015-01-24 05:44:08 +00:00
|
|
|
|
2015-01-28 22:17:45 +00:00
|
|
|
$('.next-bonfire-button').on('click', function() {
|
|
|
|
var bonfireSolution = myCodeMirror.getValue();
|
|
|
|
var thisBonfireHash = passedBonfireHash || null;
|
|
|
|
var didCompleteWith = $('#completed-with').val() || null;
|
|
|
|
completedBonfire(didCompleteWith, bonfireSolution, thisBonfireHash);
|
|
|
|
|
|
|
|
});
|
2015-02-14 01:55:49 +00:00
|
|
|
$('#completed-courseware').on('click', function() {
|
|
|
|
$('#complete-courseware-dialog').modal('show');
|
|
|
|
});
|
2015-01-28 22:17:45 +00:00
|
|
|
|
2015-03-11 15:03:56 +00:00
|
|
|
$('#complete-courseware-dialog').on('keypress', function(e) {
|
|
|
|
if (e.which === 13 || e === 13) {
|
|
|
|
$('#next-courseware-button').click();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-02-07 00:55:48 +00:00
|
|
|
$('#complete-bonfire-dialog').on('hidden.bs.modal', function() {
|
|
|
|
editor.focus();
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#complete-courseware-dialog').on('hidden.bs.modal', function() {
|
|
|
|
editor.focus();
|
|
|
|
});
|
2015-02-13 00:48:35 +00:00
|
|
|
$('#next-courseware-button').on('click', function() {
|
2015-02-05 02:28:10 +00:00
|
|
|
if ($('.signup-btn-nav').length < 1) {
|
|
|
|
$.post(
|
|
|
|
'/completed-courseware',
|
|
|
|
{
|
|
|
|
coursewareInfo: {
|
|
|
|
coursewareHash: passedCoursewareHash
|
|
|
|
}
|
|
|
|
},
|
|
|
|
function(res) {
|
|
|
|
if (res) {
|
|
|
|
window.location.href = '/coursewares'
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2015-01-24 05:44:08 +00:00
|
|
|
$('.all-challenges').on('click', function() {
|
|
|
|
$('#all-challenges-dialog').modal('show');
|
|
|
|
});
|
|
|
|
|
|
|
|
$('.all-bonfires').on('click', function() {
|
|
|
|
$('#all-bonfires-dialog').modal('show');
|
|
|
|
});
|
|
|
|
|
2015-01-24 08:11:01 +00:00
|
|
|
$('.next-challenge-button').on('click', function() {
|
2015-01-24 05:44:08 +00:00
|
|
|
l = location.pathname.split('/');
|
|
|
|
window.location = '/challenges/' + (parseInt(l[l.length - 1]) + 1);
|
2014-11-07 01:38:47 +00:00
|
|
|
});
|
2015-01-24 08:11:01 +00:00
|
|
|
|
2015-03-18 00:57:50 +00:00
|
|
|
|
2015-01-25 01:49:59 +00:00
|
|
|
// Bonfire instructions functions
|
|
|
|
$('#more-info').on('click', function() {
|
2015-02-08 05:11:26 +00:00
|
|
|
ga('send', 'event', 'Challenge', 'more-info', challengeName);
|
2015-01-25 01:49:59 +00:00
|
|
|
$('#brief-instructions').hide();
|
|
|
|
$('#long-instructions').show().removeClass('hide');
|
|
|
|
|
|
|
|
});
|
|
|
|
$('#less-info').on('click', function() {
|
|
|
|
$('#brief-instructions').show();
|
|
|
|
$('#long-instructions').hide();
|
|
|
|
});
|
2015-03-03 13:03:33 +00:00
|
|
|
|
2015-03-18 07:40:18 +00:00
|
|
|
var upvoteHandler = function () {
|
2015-03-03 13:03:33 +00:00
|
|
|
var _id = storyId;
|
2015-03-03 22:15:00 +00:00
|
|
|
$('#upvote').unbind('click');
|
|
|
|
var alreadyUpvoted = false;
|
|
|
|
for (var i = 0; i < upVotes.length; i++) {
|
|
|
|
if (upVotes[i].upVotedBy === user._id) {
|
|
|
|
alreadyUpvoted = true;
|
|
|
|
break;
|
2015-03-03 13:03:33 +00:00
|
|
|
}
|
2015-03-03 22:15:00 +00:00
|
|
|
}
|
|
|
|
if (!alreadyUpvoted) {
|
|
|
|
$.post('/stories/upvote',
|
|
|
|
{
|
|
|
|
data: {
|
|
|
|
id: _id,
|
|
|
|
upVoter: user
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.fail(function (xhr, textStatus, errorThrown) {
|
|
|
|
$('#upvote').bind('click', upvoteHandler);
|
|
|
|
})
|
|
|
|
.done(function (data, textStatus, xhr) {
|
2015-03-18 07:40:18 +00:00
|
|
|
$('#upvote').text('Upvoted!').addClass('disabled');
|
|
|
|
|
|
|
|
$('#storyRank').text(data.rank + " points");
|
2015-03-03 22:15:00 +00:00
|
|
|
});
|
|
|
|
}
|
2015-03-03 13:03:33 +00:00
|
|
|
};
|
2015-03-18 07:40:18 +00:00
|
|
|
$('#upvote').on('click', upvoteHandler);
|
|
|
|
|
2015-03-05 10:21:26 +00:00
|
|
|
|
|
|
|
var storySubmitButtonHandler = function storySubmitButtonHandler() {
|
2015-03-07 09:26:49 +00:00
|
|
|
|
|
|
|
var link = $('#story-url').val();
|
|
|
|
var headline = $('#story-title').val();
|
|
|
|
var description = $('#description-box').val();
|
2015-03-06 00:20:30 +00:00
|
|
|
var userDataForUpvote = {
|
|
|
|
upVotedBy: user._id,
|
|
|
|
upVotedByUsername: user.profile.username
|
|
|
|
};
|
2015-03-05 10:21:26 +00:00
|
|
|
$('#story-submit').unbind('click');
|
2015-03-06 16:57:09 +00:00
|
|
|
$.post('/stories/',
|
2015-03-05 10:21:26 +00:00
|
|
|
{
|
|
|
|
data: {
|
|
|
|
link: link,
|
|
|
|
headline: headline,
|
|
|
|
timePosted: Date.now(),
|
2015-03-07 09:26:49 +00:00
|
|
|
description: description,
|
2015-03-09 09:38:05 +00:00
|
|
|
storyMetaDescription: storyMetaDescription,
|
2015-03-06 00:20:30 +00:00
|
|
|
rank: 1,
|
|
|
|
upVotes: [userDataForUpvote],
|
2015-03-05 10:21:26 +00:00
|
|
|
author: {
|
|
|
|
picture: user.profile.picture,
|
|
|
|
userId: user._id,
|
|
|
|
username: user.profile.username
|
|
|
|
},
|
|
|
|
comments: [],
|
2015-03-09 04:55:13 +00:00
|
|
|
image: storyImage
|
2015-03-05 10:21:26 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.fail(function (xhr, textStatus, errorThrown) {
|
|
|
|
$('#story-submit').bind('click', storySubmitButtonHandler);
|
|
|
|
})
|
|
|
|
.done(function (data, textStatus, xhr) {
|
2015-03-05 10:40:44 +00:00
|
|
|
window.location = '/stories/' + JSON.parse(data).storyLink;
|
2015-03-05 10:21:26 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
$('#story-submit').on('click', storySubmitButtonHandler);
|
2015-03-05 21:08:40 +00:00
|
|
|
|
|
|
|
var commentSubmitButtonHandler = function commentSubmitButtonHandler() {
|
2015-03-07 11:51:20 +00:00
|
|
|
$('comment-button').unbind('click');
|
2015-03-05 21:08:40 +00:00
|
|
|
var data = $('#comment-box').val();
|
|
|
|
|
2015-03-07 11:51:20 +00:00
|
|
|
$('#comment-button').attr('disabled', 'disabled');
|
2015-03-06 16:57:09 +00:00
|
|
|
$.post('/stories/comment/',
|
2015-03-05 21:08:40 +00:00
|
|
|
{
|
|
|
|
data: {
|
|
|
|
associatedPost: storyId,
|
|
|
|
body: data,
|
|
|
|
author: {
|
|
|
|
picture: user.profile.picture,
|
|
|
|
userId: user._id,
|
|
|
|
username: user.profile.username
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.fail(function (xhr, textStatus, errorThrown) {
|
2015-03-07 11:51:20 +00:00
|
|
|
$('#comment-button').attr('disabled', false);
|
2015-03-05 21:08:40 +00:00
|
|
|
})
|
|
|
|
.done(function (data, textStatus, xhr) {
|
2015-03-06 17:24:28 +00:00
|
|
|
window.location.reload();
|
2015-03-05 21:08:40 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
$('#comment-button').on('click', commentSubmitButtonHandler);
|
2014-11-07 01:38:47 +00:00
|
|
|
});
|
|
|
|
|
2015-01-06 07:27:08 +00:00
|
|
|
var profileValidation = angular.module('profileValidation',['ui.bootstrap']);
|
2015-01-06 04:09:23 +00:00
|
|
|
profileValidation.controller('profileValidationController', ['$scope', '$http',
|
|
|
|
function($scope, $http) {
|
2015-01-06 05:52:30 +00:00
|
|
|
$http.get('/account/api').success(function(data) {
|
2015-01-06 04:09:23 +00:00
|
|
|
$scope.user = data.user;
|
2015-01-12 19:48:36 +00:00
|
|
|
$scope.user.profile.username = $scope.user.profile.username ? $scope.user.profile.username.toLowerCase() : undefined;
|
2015-01-10 04:03:24 +00:00
|
|
|
$scope.storedUsername = data.user.profile.username;
|
|
|
|
$scope.storedEmail = data.user.email;
|
2015-01-12 19:48:36 +00:00
|
|
|
$scope.user.email = $scope.user.email ? $scope.user.email.toLowerCase() : undefined;
|
|
|
|
$scope.user.profile.twitterHandle = $scope.user.profile.twitterHandle ? $scope.user.profile.twitterHandle.toLowerCase() : undefined;
|
2015-01-12 06:19:56 +00:00
|
|
|
$scope.asyncComplete = true;
|
2015-01-06 04:09:23 +00:00
|
|
|
});
|
2015-01-06 03:01:58 +00:00
|
|
|
}
|
|
|
|
]);
|
2015-01-06 15:28:57 +00:00
|
|
|
|
2015-01-24 09:14:41 +00:00
|
|
|
profileValidation.controller('pairedWithController', ['$scope',
|
|
|
|
function($scope) {
|
2015-01-24 17:51:53 +00:00
|
|
|
$scope.existingUser = null;
|
2015-01-24 09:14:41 +00:00
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
2015-01-10 01:52:19 +00:00
|
|
|
profileValidation.controller('emailSignUpController', ['$scope',
|
|
|
|
function($scope) {
|
|
|
|
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
2015-01-10 02:09:49 +00:00
|
|
|
profileValidation.controller('emailSignInController', ['$scope',
|
|
|
|
function($scope) {
|
|
|
|
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
2015-03-08 02:53:03 +00:00
|
|
|
profileValidation.controller('URLSubmitController', ['$scope',
|
|
|
|
function($scope) {
|
|
|
|
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
2015-01-13 20:50:00 +00:00
|
|
|
profileValidation.controller('nonprofitFormController', ['$scope',
|
|
|
|
function($scope) {
|
|
|
|
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
2015-01-14 21:28:20 +00:00
|
|
|
profileValidation.controller('doneWithFirst100HoursFormController', ['$scope',
|
|
|
|
function($scope) {
|
|
|
|
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
2015-03-18 07:40:18 +00:00
|
|
|
profileValidation.controller('submitStoryController', ['$scope',
|
|
|
|
function($scope) {
|
|
|
|
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
2015-02-15 03:52:44 +00:00
|
|
|
profileValidation.directive('uniqueUsername',['$http',function($http) {
|
2015-01-10 01:52:19 +00:00
|
|
|
return {
|
|
|
|
restrict: 'A',
|
|
|
|
require: 'ngModel',
|
|
|
|
link: function (scope, element, attrs, ngModel) {
|
|
|
|
element.bind("keyup", function (event) {
|
|
|
|
ngModel.$setValidity('unique', true);
|
|
|
|
if (element.val()) {
|
|
|
|
$http.get("/api/checkUniqueUsername/" + element.val()).success(function (data) {
|
2015-01-10 04:03:24 +00:00
|
|
|
if (element.val() == scope.storedUsername) {
|
|
|
|
ngModel.$setValidity('unique', true);
|
|
|
|
} else if (data) {
|
2015-01-10 01:52:19 +00:00
|
|
|
ngModel.$setValidity('unique', false);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2015-01-10 04:03:24 +00:00
|
|
|
}
|
2015-02-15 03:35:16 +00:00
|
|
|
}]);
|
2015-02-03 01:39:05 +00:00
|
|
|
|
2015-02-15 03:35:16 +00:00
|
|
|
profileValidation.directive('existingUsername', ['$http', function($http) {
|
2015-01-24 09:14:41 +00:00
|
|
|
return {
|
|
|
|
restrict: 'A',
|
|
|
|
require: 'ngModel',
|
|
|
|
link: function (scope, element, attrs, ngModel) {
|
|
|
|
element.bind("keyup", function (event) {
|
2015-02-15 03:42:10 +00:00
|
|
|
if (element.val().length > 0) {
|
2015-01-25 00:16:28 +00:00
|
|
|
ngModel.$setValidity('exists', false);
|
|
|
|
} else {
|
2015-02-15 16:51:56 +00:00
|
|
|
element.removeClass('ng-dirty');
|
2015-01-25 00:16:28 +00:00
|
|
|
ngModel.$setPristine();
|
|
|
|
}
|
2015-02-15 03:42:10 +00:00
|
|
|
if (element.val()) {
|
2015-02-15 03:35:16 +00:00
|
|
|
$http
|
2015-02-15 03:42:10 +00:00
|
|
|
.get("/api/checkExistingUsername/" + element.val())
|
2015-02-15 03:35:16 +00:00
|
|
|
.success(function (data) {
|
2015-02-15 02:48:48 +00:00
|
|
|
ngModel.$setValidity('exists', data);
|
2015-01-24 09:14:41 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2015-02-15 03:35:16 +00:00
|
|
|
}]);
|
2015-01-10 01:52:19 +00:00
|
|
|
|
2015-02-15 03:35:16 +00:00
|
|
|
profileValidation.directive('uniqueEmail', ['$http', function($http) {
|
2015-01-10 02:09:49 +00:00
|
|
|
return {
|
|
|
|
restrict: 'A',
|
|
|
|
require: 'ngModel',
|
2015-02-15 03:35:16 +00:00
|
|
|
link: function getUnique (scope, element, attrs, ngModel) {
|
2015-01-10 02:09:49 +00:00
|
|
|
element.bind("keyup", function (event) {
|
|
|
|
ngModel.$setValidity('unique', true);
|
|
|
|
if (element.val()) {
|
|
|
|
$http.get("/api/checkUniqueEmail/" + encodeURIComponent(element.val())).success(function (data) {
|
2015-01-10 04:03:24 +00:00
|
|
|
if (element.val() == scope.storedEmail) {
|
|
|
|
ngModel.$setValidity('unique', true);
|
|
|
|
} else if (data) {
|
2015-01-10 02:09:49 +00:00
|
|
|
ngModel.$setValidity('unique', false);
|
|
|
|
}
|
|
|
|
});
|
2015-01-10 04:03:24 +00:00
|
|
|
};
|
2015-01-10 02:09:49 +00:00
|
|
|
});
|
|
|
|
}
|
2015-01-10 04:03:24 +00:00
|
|
|
}
|
2015-03-09 09:49:03 +00:00
|
|
|
}]);
|