2014-10-17 19:23:53 -07:00
|
|
|
$(document).ready(function() {
|
2015-02-27 05:02:52 +09:00
|
|
|
challengeName = typeof challengeName !== undefined ? challengeName : 'Untitled';
|
2015-02-07 21:11:26 -08:00
|
|
|
if (challengeName) {
|
|
|
|
ga('send', 'event', 'Challenge', 'load', challengeName);
|
2015-02-03 01:57:35 -05:00
|
|
|
}
|
2014-11-06 22:47:35 -08:00
|
|
|
|
2015-01-24 00:44:08 -05:00
|
|
|
var CSRF_HEADER = 'X-CSRF-Token';
|
2014-11-06 22:47:35 -08:00
|
|
|
|
2015-01-24 00:44:08 -05: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 03:11:01 -05:00
|
|
|
function completedBonfire(didCompleteWith, bonfireSolution, thisBonfireHash) {
|
2015-01-24 00:44:08 -05: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 17:17:45 -05:00
|
|
|
|
|
|
|
$.post(
|
|
|
|
'/completed-bonfire',
|
|
|
|
{
|
2015-01-24 03:11:01 -05:00
|
|
|
bonfireInfo: {
|
|
|
|
completedWith : didCompleteWith,
|
|
|
|
solution: bonfireSolution,
|
|
|
|
bonfireHash: thisBonfireHash
|
|
|
|
}
|
|
|
|
},
|
2015-01-28 17:17:45 -05:00
|
|
|
function(res) {
|
|
|
|
if (res) {
|
2015-01-28 14:48:18 -08:00
|
|
|
window.location.href = '/bonfires'
|
2015-01-28 17:17:45 -05:00
|
|
|
}
|
|
|
|
})
|
2015-01-24 00:44:08 -05:00
|
|
|
}
|
2015-01-24 03:11:01 -05:00
|
|
|
}
|
2015-01-24 00:44:08 -05:00
|
|
|
|
2015-01-28 17:17:45 -05: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-13 20:55:49 -05:00
|
|
|
$('#completed-courseware').on('click', function() {
|
|
|
|
$('#complete-courseware-dialog').modal('show');
|
|
|
|
});
|
2015-01-28 17:17:45 -05:00
|
|
|
|
2015-02-06 16:55:48 -08:00
|
|
|
$('#complete-bonfire-dialog').on('hidden.bs.modal', function() {
|
|
|
|
editor.focus();
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#complete-courseware-dialog').on('hidden.bs.modal', function() {
|
|
|
|
editor.focus();
|
|
|
|
});
|
2015-02-12 16:48:35 -08:00
|
|
|
$('#next-courseware-button').on('click', function() {
|
2015-02-04 21:28:10 -05:00
|
|
|
if ($('.signup-btn-nav').length < 1) {
|
|
|
|
$.post(
|
|
|
|
'/completed-courseware',
|
|
|
|
{
|
|
|
|
coursewareInfo: {
|
|
|
|
coursewareHash: passedCoursewareHash
|
|
|
|
}
|
|
|
|
},
|
|
|
|
function(res) {
|
|
|
|
if (res) {
|
|
|
|
window.location.href = '/coursewares'
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2015-01-24 00:44:08 -05:00
|
|
|
$('.all-challenges').on('click', function() {
|
|
|
|
$('#all-challenges-dialog').modal('show');
|
|
|
|
});
|
|
|
|
|
|
|
|
$('.all-bonfires').on('click', function() {
|
|
|
|
$('#all-bonfires-dialog').modal('show');
|
|
|
|
});
|
|
|
|
|
2015-01-24 03:11:01 -05:00
|
|
|
$('.next-challenge-button').on('click', function() {
|
2015-01-24 00:44:08 -05:00
|
|
|
l = location.pathname.split('/');
|
|
|
|
window.location = '/challenges/' + (parseInt(l[l.length - 1]) + 1);
|
2014-11-06 17:38:47 -08:00
|
|
|
});
|
2015-01-24 03:11:01 -05:00
|
|
|
|
2015-01-24 20:49:59 -05:00
|
|
|
// Bonfire instructions functions
|
|
|
|
$('#more-info').on('click', function() {
|
2015-02-07 21:11:26 -08:00
|
|
|
ga('send', 'event', 'Challenge', 'more-info', challengeName);
|
2015-01-24 20:49:59 -05:00
|
|
|
$('#brief-instructions').hide();
|
|
|
|
$('#long-instructions').show().removeClass('hide');
|
|
|
|
|
|
|
|
});
|
|
|
|
$('#less-info').on('click', function() {
|
|
|
|
$('#brief-instructions').show();
|
|
|
|
$('#long-instructions').hide();
|
|
|
|
});
|
2015-03-03 22:03:33 +09:00
|
|
|
|
|
|
|
var upvoteHandler = function () {
|
|
|
|
var _id = storyId;
|
2015-03-04 07:15:00 +09: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 22:03:33 +09:00
|
|
|
}
|
2015-03-04 07:15:00 +09: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) {
|
|
|
|
$('#storyRank').text(data.rank);
|
|
|
|
});
|
|
|
|
}
|
2015-03-03 22:03:33 +09:00
|
|
|
};
|
|
|
|
$('#upvote').on('click', upvoteHandler);
|
2014-11-06 17:38:47 -08:00
|
|
|
});
|
|
|
|
|
2015-01-06 02:27:08 -05:00
|
|
|
var profileValidation = angular.module('profileValidation',['ui.bootstrap']);
|
2015-01-05 20:09:23 -08:00
|
|
|
profileValidation.controller('profileValidationController', ['$scope', '$http',
|
|
|
|
function($scope, $http) {
|
2015-01-06 00:52:30 -05:00
|
|
|
$http.get('/account/api').success(function(data) {
|
2015-01-05 20:09:23 -08:00
|
|
|
$scope.user = data.user;
|
2015-01-12 11:48:36 -08:00
|
|
|
$scope.user.profile.username = $scope.user.profile.username ? $scope.user.profile.username.toLowerCase() : undefined;
|
2015-01-09 20:03:24 -08:00
|
|
|
$scope.storedUsername = data.user.profile.username;
|
|
|
|
$scope.storedEmail = data.user.email;
|
2015-01-12 11:48:36 -08: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-11 22:19:56 -08:00
|
|
|
$scope.asyncComplete = true;
|
2015-01-05 20:09:23 -08:00
|
|
|
});
|
2015-01-05 19:01:58 -08:00
|
|
|
}
|
|
|
|
]);
|
2015-01-06 10:28:57 -05:00
|
|
|
|
2015-01-24 04:14:41 -05:00
|
|
|
profileValidation.controller('pairedWithController', ['$scope',
|
|
|
|
function($scope) {
|
2015-01-24 12:51:53 -05:00
|
|
|
$scope.existingUser = null;
|
2015-01-24 04:14:41 -05:00
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
2015-01-09 17:52:19 -08:00
|
|
|
profileValidation.controller('emailSignUpController', ['$scope',
|
|
|
|
function($scope) {
|
|
|
|
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
2015-01-09 18:09:49 -08:00
|
|
|
profileValidation.controller('emailSignInController', ['$scope',
|
|
|
|
function($scope) {
|
|
|
|
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
2015-01-13 12:50:00 -08:00
|
|
|
profileValidation.controller('nonprofitFormController', ['$scope',
|
|
|
|
function($scope) {
|
|
|
|
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
2015-01-14 13:28:20 -08:00
|
|
|
profileValidation.controller('doneWithFirst100HoursFormController', ['$scope',
|
|
|
|
function($scope) {
|
|
|
|
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
2015-02-14 22:52:44 -05:00
|
|
|
profileValidation.directive('uniqueUsername',['$http',function($http) {
|
2015-01-09 17:52:19 -08: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-09 20:03:24 -08:00
|
|
|
if (element.val() == scope.storedUsername) {
|
|
|
|
ngModel.$setValidity('unique', true);
|
|
|
|
} else if (data) {
|
2015-01-09 17:52:19 -08:00
|
|
|
ngModel.$setValidity('unique', false);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2015-01-09 20:03:24 -08:00
|
|
|
}
|
2015-02-14 22:35:16 -05:00
|
|
|
}]);
|
2015-02-02 20:39:05 -05:00
|
|
|
|
2015-02-14 22:35:16 -05:00
|
|
|
profileValidation.directive('existingUsername', ['$http', function($http) {
|
2015-01-24 04:14:41 -05:00
|
|
|
return {
|
|
|
|
restrict: 'A',
|
|
|
|
require: 'ngModel',
|
|
|
|
link: function (scope, element, attrs, ngModel) {
|
|
|
|
element.bind("keyup", function (event) {
|
2015-02-14 22:42:10 -05:00
|
|
|
if (element.val().length > 0) {
|
2015-01-24 19:16:28 -05:00
|
|
|
ngModel.$setValidity('exists', false);
|
|
|
|
} else {
|
2015-02-15 11:51:56 -05:00
|
|
|
element.removeClass('ng-dirty');
|
2015-01-24 19:16:28 -05:00
|
|
|
ngModel.$setPristine();
|
|
|
|
}
|
2015-02-14 22:42:10 -05:00
|
|
|
if (element.val()) {
|
2015-02-14 22:35:16 -05:00
|
|
|
$http
|
2015-02-14 22:42:10 -05:00
|
|
|
.get("/api/checkExistingUsername/" + element.val())
|
2015-02-14 22:35:16 -05:00
|
|
|
.success(function (data) {
|
2015-02-14 21:48:48 -05:00
|
|
|
ngModel.$setValidity('exists', data);
|
2015-01-24 04:14:41 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2015-02-14 22:35:16 -05:00
|
|
|
}]);
|
2015-01-09 17:52:19 -08:00
|
|
|
|
2015-02-14 22:35:16 -05:00
|
|
|
profileValidation.directive('uniqueEmail', ['$http', function($http) {
|
2015-01-09 18:09:49 -08:00
|
|
|
return {
|
|
|
|
restrict: 'A',
|
|
|
|
require: 'ngModel',
|
2015-02-14 22:35:16 -05:00
|
|
|
link: function getUnique (scope, element, attrs, ngModel) {
|
2015-01-09 18:09:49 -08: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-09 20:03:24 -08:00
|
|
|
if (element.val() == scope.storedEmail) {
|
|
|
|
ngModel.$setValidity('unique', true);
|
|
|
|
} else if (data) {
|
2015-01-09 18:09:49 -08:00
|
|
|
ngModel.$setValidity('unique', false);
|
|
|
|
}
|
|
|
|
});
|
2015-01-09 20:03:24 -08:00
|
|
|
};
|
2015-01-09 18:09:49 -08:00
|
|
|
});
|
|
|
|
}
|
2015-01-09 20:03:24 -08:00
|
|
|
}
|
2015-02-14 22:35:16 -05:00
|
|
|
}]);
|