2014-10-17 19:23:53 -07:00
|
|
|
$(document).ready(function() {
|
2015-03-09 04:49:03 -05:00
|
|
|
var 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-03-05 19:21:26 +09: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-03-12 00:03:56 +09:00
|
|
|
$('#complete-courseware-dialog').on('keypress', function(e) {
|
|
|
|
if (e.which === 13 || e === 13) {
|
|
|
|
$('#next-courseware-button').click();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
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-03-17 17:57:50 -07: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
|
|
|
|
2015-03-17 17:57:50 -07:00
|
|
|
$('#upvote').on('click', upvoteHandler);
|
|
|
|
|
|
|
|
var upvoteHandler = function (event) {
|
|
|
|
event.preventDefault();
|
|
|
|
var $this = $(this);
|
|
|
|
$this.addClass('disabled');
|
|
|
|
$this.text('Upvoted!');
|
2015-03-03 22:03:33 +09:00
|
|
|
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
|
|
|
};
|
2015-03-05 19:21:26 +09:00
|
|
|
|
|
|
|
var storySubmitButtonHandler = function storySubmitButtonHandler() {
|
2015-03-07 18:26:49 +09:00
|
|
|
|
|
|
|
var link = $('#story-url').val();
|
|
|
|
var headline = $('#story-title').val();
|
|
|
|
var description = $('#description-box').val();
|
2015-03-06 09:20:30 +09:00
|
|
|
var userDataForUpvote = {
|
|
|
|
upVotedBy: user._id,
|
|
|
|
upVotedByUsername: user.profile.username
|
|
|
|
};
|
2015-03-05 19:21:26 +09:00
|
|
|
$('#story-submit').unbind('click');
|
2015-03-07 01:57:09 +09:00
|
|
|
$.post('/stories/',
|
2015-03-05 19:21:26 +09:00
|
|
|
{
|
|
|
|
data: {
|
|
|
|
link: link,
|
|
|
|
headline: headline,
|
|
|
|
timePosted: Date.now(),
|
2015-03-07 18:26:49 +09:00
|
|
|
description: description,
|
2015-03-09 18:38:05 +09:00
|
|
|
storyMetaDescription: storyMetaDescription,
|
2015-03-06 09:20:30 +09:00
|
|
|
rank: 1,
|
|
|
|
upVotes: [userDataForUpvote],
|
2015-03-05 19:21:26 +09:00
|
|
|
author: {
|
|
|
|
picture: user.profile.picture,
|
|
|
|
userId: user._id,
|
|
|
|
username: user.profile.username
|
|
|
|
},
|
|
|
|
comments: [],
|
2015-03-09 13:55:13 +09:00
|
|
|
image: storyImage
|
2015-03-05 19:21:26 +09:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.fail(function (xhr, textStatus, errorThrown) {
|
|
|
|
$('#story-submit').bind('click', storySubmitButtonHandler);
|
|
|
|
})
|
|
|
|
.done(function (data, textStatus, xhr) {
|
2015-03-05 19:40:44 +09:00
|
|
|
window.location = '/stories/' + JSON.parse(data).storyLink;
|
2015-03-05 19:21:26 +09:00
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
$('#story-submit').on('click', storySubmitButtonHandler);
|
2015-03-06 06:08:40 +09:00
|
|
|
|
|
|
|
var commentSubmitButtonHandler = function commentSubmitButtonHandler() {
|
2015-03-07 20:51:20 +09:00
|
|
|
$('comment-button').unbind('click');
|
2015-03-06 06:08:40 +09:00
|
|
|
var data = $('#comment-box').val();
|
|
|
|
|
2015-03-07 20:51:20 +09:00
|
|
|
$('#comment-button').attr('disabled', 'disabled');
|
2015-03-07 01:57:09 +09:00
|
|
|
$.post('/stories/comment/',
|
2015-03-06 06:08:40 +09: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 20:51:20 +09:00
|
|
|
$('#comment-button').attr('disabled', false);
|
2015-03-06 06:08:40 +09:00
|
|
|
})
|
|
|
|
.done(function (data, textStatus, xhr) {
|
2015-03-07 02:24:28 +09:00
|
|
|
window.location.reload();
|
2015-03-06 06:08:40 +09:00
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
$('#comment-button').on('click', commentSubmitButtonHandler);
|
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-03-08 11:53:03 +09:00
|
|
|
profileValidation.controller('URLSubmitController', ['$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-03-09 04:49:03 -05:00
|
|
|
}]);
|