freeCodeCamp/public/js/main.js

125 lines
4.0 KiB
JavaScript
Raw Normal View History

2014-10-18 02:23:53 +00:00
$(document).ready(function() {
var CSRF_HEADER = 'X-CSRF-Token';
var setCSRFToken = function(securityToken) {
jQuery.ajaxPrefilter(function(options, _, xhr) {
if (!xhr.crossDomain) {
xhr.setRequestHeader(CSRF_HEADER, securityToken);
}
2014-11-07 01:38:47 +00:00
});
};
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-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/'
});
}
});
$('.all-challenges').on('click', function() {
$('#all-challenges-dialog').modal('show');
});
$('.next-button').on('click', function() {
l = location.pathname.split('/');
window.location = '/challenges/' + (parseInt(l[l.length - 1]) + 1);
});
2014-11-07 01:38:47 +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;
$scope.user.profile.username = $scope.user.profile.username ? $scope.user.profile.username.toLowerCase() : undefined;
$scope.storedUsername = data.user.profile.username;
$scope.storedEmail = data.user.email;
$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;
$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-10 01:52:19 +00:00
profileValidation.controller('emailSignUpController', ['$scope',
function($scope) {
}
]);
profileValidation.controller('emailSignInController', ['$scope',
function($scope) {
}
]);
2015-01-13 20:50:00 +00:00
profileValidation.controller('nonprofitFormController', ['$scope',
function($scope) {
}
]);
profileValidation.controller('doneWithFirst100HoursFormController', ['$scope',
function($scope) {
}
]);
2015-01-10 01:52:19 +00:00
profileValidation.directive('uniqueUsername', function($http) {
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) {
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 01:52:19 +00:00
});
profileValidation.directive('uniqueEmail', function($http) {
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/checkUniqueEmail/" + encodeURIComponent(element.val())).success(function (data) {
if (element.val() == scope.storedEmail) {
ngModel.$setValidity('unique', true);
} else if (data) {
ngModel.$setValidity('unique', false);
}
});
};
});
}
}
});