2014-10-18 02:23:53 +00:00
$ ( document ) . ready ( function ( ) {
2015-03-29 11:39:41 +00:00
var challengeName = typeof challengeName !== undefined ? challengeName : 'Untitled' ;
if ( challengeName ) {
ga ( 'send' , 'event' , 'Challenge' , 'load' , challengeName ) ;
}
var CSRF _HEADER = 'X-CSRF-Token' ;
var setCSRFToken = function ( securityToken ) {
jQuery . ajaxPrefilter ( function ( options , _ , xhr ) {
if ( ! xhr . crossDomain ) {
xhr . setRequestHeader ( CSRF _HEADER , securityToken ) ;
2015-03-11 15:03:56 +00:00
}
} ) ;
2015-03-29 11:39:41 +00:00
} ;
setCSRFToken ( $ ( 'meta[name="csrf-token"]' ) . attr ( 'content' ) ) ;
2015-05-23 07:53:41 +00:00
$ ( '#i-want-help' ) . on ( 'click' , function ( ) {
2015-05-28 21:29:45 +00:00
$ ( '#help-modal' ) . modal ( 'hide' ) ;
2015-05-23 06:26:29 +00:00
var editorValue = editor . getValue ( ) ;
2015-05-23 07:53:41 +00:00
var currentLocation = window . location . href ;
2015-05-23 06:26:29 +00:00
$ . post (
'/get-help' ,
{
payload : {
code : editorValue ,
2015-05-24 07:53:01 +00:00
challenge : currentLocation
2015-05-23 06:26:29 +00:00
}
} ,
function ( res ) {
if ( res ) {
2015-06-23 18:42:27 +00:00
window . open ( 'https://gitter.im/FreeCodeCamp/Help' , '_blank' )
2015-05-23 06:26:29 +00:00
}
}
) ;
2015-05-23 07:53:41 +00:00
} ) ;
2015-05-23 06:26:29 +00:00
2015-05-24 07:53:01 +00:00
$ ( '#i-want-help-editorless' ) . on ( 'click' , function ( ) {
2015-05-28 23:18:04 +00:00
$ ( '#help-editorless-modal' ) . modal ( 'hide' ) ;
2015-05-24 07:53:01 +00:00
var currentLocation = window . location . href ;
$ . post (
'/get-help' ,
{
payload : {
challenge : currentLocation
}
} ,
function ( res ) {
if ( res ) {
2015-06-23 18:42:27 +00:00
window . open ( 'https://gitter.im/FreeCodeCamp/Help' , '_blank' )
2015-05-24 07:53:01 +00:00
}
}
) ;
} ) ;
$ ( '#report-issue' ) . on ( 'click' , function ( ) {
2015-05-28 21:29:45 +00:00
$ ( '#issue-modal' ) . modal ( 'hide' ) ;
2015-06-30 02:28:43 +00:00
window . open ( 'https://github.com/freecodecamp/freecodecamp/issues/new?&body=Challenge ' + window . location . href + ' has an issue. Please describe how to reproduce it, and include links to screenshots if possible.' , '_blank' )
2015-05-24 07:53:01 +00:00
} ) ;
2015-05-23 07:53:41 +00:00
$ ( '#i-want-to-pair' ) . on ( 'click' , function ( ) {
2015-05-28 21:29:45 +00:00
$ ( '#pair-modal' ) . modal ( 'hide' ) ;
2015-05-23 07:53:41 +00:00
var currentLocation = window . location . href ;
$ . post (
'/get-pair' ,
{
payload : {
challenge : currentLocation
}
} ,
function ( res ) {
if ( res ) {
2015-06-23 18:42:27 +00:00
window . open ( 'https://gitter.im/FreeCodeCamp/LetsPair' , '_blank' )
2015-05-23 07:53:41 +00:00
}
}
) ;
2015-05-23 06:26:29 +00:00
} ) ;
2015-04-18 06:51:57 +00:00
$ ( '.checklist-element' ) . each ( function ( ) {
2015-04-18 08:29:10 +00:00
var checklistElementId = $ ( this ) . attr ( 'id' ) ;
if ( ! ! localStorage [ checklistElementId ] ) {
2015-04-19 04:09:24 +00:00
$ ( this ) . children ( ) . children ( 'li' ) . addClass ( 'faded' ) ;
2015-04-18 08:29:10 +00:00
$ ( this ) . children ( ) . children ( 'input' ) . trigger ( 'click' ) ;
2015-04-18 06:51:57 +00:00
}
} ) ;
2015-03-29 11:39:41 +00:00
$ ( '.start-challenge' ) . on ( 'click' , function ( ) {
$ ( this ) . parent ( ) . remove ( ) ;
$ ( '.challenge-content' )
. removeClass ( 'hidden-element' )
. addClass ( 'animated fadeInDown' ) ;
} ) ;
2015-04-13 06:41:42 +00:00
$ ( '.challenge-list-checkbox' ) . on ( 'change' , function ( ) {
2015-04-18 06:51:57 +00:00
var checkboxId = $ ( this ) . parent ( ) . parent ( ) . attr ( 'id' ) ;
2015-04-13 06:41:42 +00:00
if ( $ ( this ) . is ( ":checked" ) ) {
2015-04-18 22:00:31 +00:00
$ ( this ) . parent ( ) . siblings ( ) . children ( ) . addClass ( 'faded' ) ;
2015-04-18 06:51:57 +00:00
if ( ! localStorage || ! localStorage [ checkboxId ] ) {
2015-04-18 08:29:10 +00:00
localStorage [ checkboxId ] = true ;
2015-04-18 06:51:57 +00:00
}
2015-04-13 06:41:42 +00:00
}
if ( ! $ ( this ) . is ( ":checked" ) ) {
2015-04-18 22:00:31 +00:00
$ ( this ) . parent ( ) . siblings ( ) . children ( ) . removeClass ( 'faded' ) ;
2015-04-18 06:51:57 +00:00
if ( localStorage [ checkboxId ] ) {
2015-04-18 08:29:10 +00:00
localStorage . removeItem ( checkboxId ) ;
2015-04-18 06:51:57 +00:00
}
2015-04-13 06:41:42 +00:00
}
} ) ;
2015-04-09 00:18:51 +00:00
function completedFieldGuide ( fieldGuideId ) {
2015-04-05 23:44:07 +00:00
if ( $ ( '.signup-btn-nav' ) . length < 1 ) {
$ . post (
2015-04-09 00:18:51 +00:00
'/completed-field-guide' ,
2015-04-05 23:44:07 +00:00
{
2015-04-09 00:18:51 +00:00
fieldGuideInfo : {
fieldGuideId : fieldGuideId
2015-04-05 23:44:07 +00:00
}
} ,
function ( res ) {
if ( res ) {
2015-04-09 00:18:51 +00:00
window . location . href = '/field-guide'
2015-04-05 23:44:07 +00:00
}
} ) ;
}
}
2015-04-09 00:18:51 +00:00
$ ( '.next-field-guide-button' ) . on ( 'click' , function ( ) {
var fieldGuideId = $ ( '#fieldGuideId' ) . text ( ) ;
completedFieldGuide ( fieldGuideId ) ;
2015-04-05 23:44:07 +00:00
} ) ;
2015-04-02 20:42:15 +00:00
$ ( "img" ) . error ( function ( ) {
$ ( this ) . unbind ( "error" ) . attr ( "src" , "https://s3.amazonaws.com/freecodecamp/camper-image-placeholder.png" ) ;
} ) ;
2015-05-28 23:18:04 +00:00
$ ( '#completed-courseware' ) . on ( 'click' , function ( ) {
$ ( '#complete-courseware-dialog' ) . modal ( 'show' ) ;
} ) ;
$ ( '#completed-courseware-editorless' ) . on ( 'click' , function ( ) {
$ ( '#complete-courseware-editorless-dialog' ) . modal ( 'show' ) ;
} ) ;
2015-05-28 21:29:45 +00:00
$ ( '#trigger-pair-modal' ) . on ( 'click' , function ( ) {
$ ( '#pair-modal' ) . modal ( 'show' ) ;
} ) ;
$ ( '#trigger-help-modal' ) . on ( 'click' , function ( ) {
$ ( '#help-modal' ) . modal ( 'show' ) ;
} ) ;
$ ( '#trigger-issue-modal' ) . on ( 'click' , function ( ) {
$ ( '#issue-modal' ) . modal ( 'show' ) ;
2015-03-29 11:39:41 +00:00
} ) ;
2015-01-24 08:11:01 +00:00
2015-03-29 11:39:41 +00:00
$ ( '#completed-zipline-or-basejump' ) . on ( 'click' , function ( ) {
$ ( '#complete-zipline-or-basejump-dialog' ) . modal ( 'show' ) ;
} ) ;
2015-01-28 07:22:12 +00:00
2015-03-29 11:39:41 +00:00
$ ( '#complete-courseware-dialog' ) . on ( 'hidden.bs.modal' , function ( ) {
editor . focus ( ) ;
} ) ;
2015-05-28 23:18:04 +00:00
$ ( '#complete-challenge-dialog' ) . on ( 'hidden.bs.modal' , function ( ) {
editor . focus ( ) ;
} ) ;
2015-05-21 01:50:31 +00:00
var challengeTypes = {
2015-06-04 20:28:35 +00:00
'HTML_CSS_JQ' : '0' ,
'JAVASCRIPT' : '1' ,
'VIDEO' : '2' ,
'ZIPLINE' : '3' ,
'BASEJUMP' : '4' ,
'BONFIRE' : '5'
2015-05-21 01:50:31 +00:00
} ;
2015-03-29 11:39:41 +00:00
$ ( '#next-courseware-button' ) . on ( 'click' , function ( ) {
2015-05-26 16:32:50 +00:00
$ ( '#next-courseware-button' ) . unbind ( 'click' ) ;
2015-03-29 11:39:41 +00:00
if ( $ ( '.signup-btn-nav' ) . length < 1 ) {
switch ( challengeType ) {
2015-05-21 01:50:31 +00:00
case challengeTypes . HTML _CSS _JQ :
case challengeTypes . JAVASCRIPT :
case challengeTypes . VIDEO :
2015-03-29 11:39:41 +00:00
$ . post (
2015-05-20 02:31:01 +00:00
'/completed-challenge/' ,
2015-03-29 11:39:41 +00:00
{
2015-05-20 02:31:01 +00:00
challengeInfo : {
2015-05-21 01:50:31 +00:00
challengeId : challenge _Id ,
challengeName : challenge _Name
2015-03-29 11:39:41 +00:00
}
} ) . success (
function ( res ) {
if ( res ) {
2015-05-20 02:31:01 +00:00
window . location . href = '/challenges/next-challenge' ;
2015-03-29 11:39:41 +00:00
}
2015-05-26 16:32:50 +00:00
} ) . fail (
function ( ) {
window . location . href = "/challenges" ;
2015-01-24 05:44:08 +00:00
}
2015-03-29 11:39:41 +00:00
) ;
break ;
2015-05-21 01:50:31 +00:00
case challengeTypes . ZIPLINE :
2015-03-29 11:39:41 +00:00
var didCompleteWith = $ ( '#completed-with' ) . val ( ) || null ;
var publicURL = $ ( '#public-url' ) . val ( ) || null ;
$ . post (
'/completed-zipline-or-basejump/' ,
2015-03-05 10:21:26 +00:00
{
2015-05-20 02:31:01 +00:00
challengeInfo : {
2015-05-21 01:50:31 +00:00
challengeId : challenge _Id ,
challengeName : challenge _Name ,
2015-03-29 11:39:41 +00:00
completedWith : didCompleteWith ,
publicURL : publicURL ,
2015-04-02 21:07:00 +00:00
challengeType : challengeType
2015-03-29 11:39:41 +00:00
}
} ) . success (
function ( ) {
2015-05-20 02:31:01 +00:00
window . location . href = '/challenges/next-challenge' ;
2015-03-29 11:39:41 +00:00
} ) . fail (
function ( ) {
window . location . href = '/challenges' ;
2015-03-05 10:21:26 +00:00
} ) ;
2015-03-29 11:39:41 +00:00
break ;
2015-05-21 01:50:31 +00:00
case challengeTypes . BASEJUMP :
2015-03-29 11:39:41 +00:00
var didCompleteWith = $ ( '#completed-with' ) . val ( ) || null ;
var publicURL = $ ( '#public-url' ) . val ( ) || null ;
var githubURL = $ ( '#github-url' ) . val ( ) || null ;
$ . post (
'/completed-zipline-or-basejump/' ,
{
2015-05-20 02:31:01 +00:00
challengeInfo : {
2015-05-21 01:50:31 +00:00
challengeId : challenge _Id ,
challengeName : challenge _Name ,
2015-03-29 11:39:41 +00:00
completedWith : didCompleteWith ,
2015-03-29 12:15:18 +00:00
publicURL : publicURL ,
2015-03-29 11:39:41 +00:00
githubURL : githubURL ,
2015-04-02 20:42:15 +00:00
challengeType : challengeType ,
verified : false
2015-03-29 11:39:41 +00:00
}
} ) . success ( function ( ) {
2015-05-20 02:31:01 +00:00
window . location . href = '/challenges/next-challenge' ;
2015-03-29 11:39:41 +00:00
} ) . fail ( function ( ) {
window . location . replace ( window . location . href ) ;
} ) ;
break ;
2015-05-21 01:50:31 +00:00
case challengeTypes . BONFIRE :
2015-05-25 21:27:27 +00:00
window . location . href = '/challenges/next-challenge' ;
2015-03-29 11:39:41 +00:00
default :
break ;
2015-03-11 15:03:56 +00:00
}
2015-03-29 11:39:41 +00:00
}
} ) ;
$ ( '.next-challenge-button' ) . on ( 'click' , function ( ) {
l = location . pathname . split ( '/' ) ;
window . location = '/challenges/' + ( parseInt ( l [ l . length - 1 ] ) + 1 ) ;
} ) ;
2015-04-24 06:46:58 +00:00
// Bonfire instructions functions
2015-03-29 11:39:41 +00:00
$ ( '#more-info' ) . on ( 'click' , function ( ) {
ga ( 'send' , 'event' , 'Challenge' , 'more-info' , challengeName ) ;
$ ( '#brief-instructions' ) . hide ( ) ;
$ ( '#long-instructions' ) . show ( ) . removeClass ( 'hide' ) ;
} ) ;
$ ( '#less-info' ) . on ( 'click' , function ( ) {
$ ( '#brief-instructions' ) . show ( ) ;
$ ( '#long-instructions' ) . hide ( ) ;
} ) ;
var upvoteHandler = function ( ) {
2015-06-04 20:20:42 +00:00
var id = storyId ;
2015-03-29 11:39:41 +00:00
$ ( '#upvote' ) . unbind ( 'click' ) ;
var alreadyUpvoted = false ;
for ( var i = 0 ; i < upVotes . length ; i ++ ) {
2015-04-19 07:36:54 +00:00
if ( upVotes [ i ] . upVotedBy === B3BA669EC5C1DD70FB478221E067A7E1B686929C569F5E73561B69C8F42129B ) {
2015-03-29 11:39:41 +00:00
alreadyUpvoted = true ;
break ;
}
}
if ( ! alreadyUpvoted ) {
$ . post ( '/stories/upvote' ,
{
data : {
2015-06-04 20:20:42 +00:00
id : id
2015-03-29 11:39:41 +00:00
}
} )
. fail ( function ( xhr , textStatus , errorThrown ) {
$ ( '#upvote' ) . bind ( 'click' , upvoteHandler ) ;
} )
. done ( function ( data , textStatus , xhr ) {
$ ( '#upvote' ) . text ( 'Upvoted!' ) . addClass ( 'disabled' ) ;
$ ( '#storyRank' ) . text ( data . rank + " points" ) ;
} ) ;
}
} ;
$ ( '#upvote' ) . on ( 'click' , upvoteHandler ) ;
2015-01-28 07:22:12 +00:00
2015-03-29 11:39:41 +00:00
var storySubmitButtonHandler = function storySubmitButtonHandler ( ) {
2015-03-03 13:03:33 +00:00
2015-03-29 11:39:41 +00:00
var link = $ ( '#story-url' ) . val ( ) ;
var headline = $ ( '#story-title' ) . val ( ) ;
var description = $ ( '#description-box' ) . val ( ) ;
2015-04-19 07:36:54 +00:00
2015-03-29 11:39:41 +00:00
$ ( '#story-submit' ) . unbind ( 'click' ) ;
$ . post ( '/stories/' ,
{
data : {
link : link ,
headline : headline ,
timePosted : Date . now ( ) ,
description : description ,
storyMetaDescription : storyMetaDescription ,
rank : 1 ,
comments : [ ] ,
image : storyImage
2015-03-03 22:15:00 +00:00
}
2015-03-29 11:39:41 +00:00
} )
. fail ( function ( xhr , textStatus , errorThrown ) {
$ ( '#story-submit' ) . bind ( 'click' , storySubmitButtonHandler ) ;
} )
2015-06-25 22:03:46 +00:00
. done ( function ( data , textStatus , xhr ) {
window . location = '/stories/' + data . storyLink ;
2015-03-29 11:39:41 +00:00
} ) ;
} ;
$ ( '#story-submit' ) . on ( 'click' , storySubmitButtonHandler ) ;
var commentSubmitButtonHandler = function commentSubmitButtonHandler ( ) {
2015-04-26 01:59:15 +00:00
$ ( '#comment-button' ) . unbind ( 'click' ) ;
2015-03-29 11:39:41 +00:00
var data = $ ( '#comment-box' ) . val ( ) ;
$ ( '#comment-button' ) . attr ( 'disabled' , 'disabled' ) ;
$ . post ( '/stories/comment/' ,
{
data : {
associatedPost : storyId ,
2015-04-25 14:05:36 +00:00
originalStoryLink : originalStoryLink ,
originalStoryAuthorEmail : originalStoryAuthorEmail ,
2015-04-19 07:36:54 +00:00
body : data
2015-03-03 22:15:00 +00:00
}
2015-03-29 11:39:41 +00:00
} )
. fail ( function ( xhr , textStatus , errorThrown ) {
$ ( '#comment-button' ) . attr ( 'disabled' , false ) ;
2015-04-26 01:59:15 +00:00
$ ( '#comment-button' ) . bind ( 'click' , commentSubmitButtonHandler ) ;
2015-03-29 11:39:41 +00:00
} )
. done ( function ( data , textStatus , xhr ) {
window . location . reload ( ) ;
} ) ;
} ;
2015-03-05 21:08:40 +00:00
2015-07-02 20:27:16 +00:00
//fakeiphone positioning hotfix
if ( $ ( '.iphone-position' ) . html ( ) !== undefined || $ ( '.iphone' ) . html ( ) !== undefined ) {
var startIphonePosition = parseInt ( $ ( '.iphone-position' ) . css ( 'top' ) . replace ( 'px' , '' ) ) ;
var startIphone = parseInt ( $ ( '.iphone' ) . css ( 'top' ) . replace ( 'px' , '' ) ) ;
$ ( window ) . on ( 'scroll' , function ( ) {
if ( ( ( $ ( '.courseware-height' ) . height ( ) + $ ( '.courseware-height' ) . offset ( ) . top ) - $ ( window ) . scrollTop ( ) - $ ( '.iphone-position' ) . height ( ) ) <= 0 ) {
$ ( '.iphone-position' ) . css ( 'top' , startIphonePosition + ( ( $ ( '.courseware-height' ) . height ( ) + $ ( '.courseware-height' ) . offset ( ) . top ) - $ ( window ) . scrollTop ( ) - $ ( '.iphone-position' ) . height ( ) ) ) ;
$ ( '.iphone' ) . css ( 'top' , startIphonePosition + ( ( $ ( '.courseware-height' ) . height ( ) + $ ( '.courseware-height' ) . offset ( ) . top ) - $ ( window ) . scrollTop ( ) - $ ( '.iphone-position' ) . height ( ) ) + 120 ) ;
}
else {
$ ( '.iphone-position' ) . css ( 'top' , startIphonePosition ) ;
$ ( '.iphone' ) . css ( 'top' , startIphone ) ;
}
} ) ;
}
2015-07-30 19:45:51 +00:00
if ( $ ( '.scroll-locker' ) . html ( ) != undefined ) {
2015-07-02 20:27:16 +00:00
function lockTop ( initOff ) {
$ ( window ) . scroll ( function ( ) {
if ( $ ( window ) . width ( ) >= 992 ) {
if ( ( ( $ ( '.scroll-locker' ) . offset ( ) . top - $ ( window ) . scrollTop ( ) ) + $ ( '.scroll-locker' ) . height ( ) ) >= ( $ ( '.fcc-footer' ) . offset ( ) . top - $ ( window ) . scrollTop ( ) ) ) {
$ ( '.scroll-locker' ) . css ( 'position' , 'fixed' ) . css ( 'top' , initOff ) . css ( 'width' , $ ( $ ( '.scroll-locker' ) . parent ( ) ) . width ( ) ) . css ( 'max-height' , '75%' ) . css ( 'overflow-y' , 'auto' ) . css ( 'overflow-x' , 'hidden' ) ;
$ ( '.well' ) . css ( 'margin-right' , '6px' ) ;
}
else {
$ ( '.scroll-locker' ) . css ( 'position' , 'fixed' ) . css ( 'bottom' , $ ( '.fcc-footer' ) - ( ( $ ( '.scroll-locker' ) . offset ( ) . top - $ ( window ) . scrollTop ( ) ) + $ ( '.scroll-locker' ) . height ( ) ) - ( $ ( '.fcc-footer' ) . offset ( ) . top - $ ( window ) . scrollTop ( ) ) ) . css ( 'width' , $ ( $ ( '.scroll-locker' ) . parent ( ) ) . width ( ) ) . css ( 'max-height' , '75%' ) . css ( 'overflow-y' , 'auto' ) . css ( 'overflow-x' , 'hidden' ) ;
$ ( '.well' ) . css ( 'margin-right' , '6px' ) ;
}
}
else {
$ ( '.scroll-locker' ) . css ( 'position' , 'inherit' ) . css ( 'top' , 'inherit' ) . css ( 'width' , '100%' ) . css ( 'max-height' , '' ) . css ( 'overflow-y' , 'auto' ) . css ( 'overflow-x' , 'hidden' ) ;
$ ( '.well' ) . css ( 'margin-right' , '' ) ;
}
} ) ;
}
2015-07-04 15:31:26 +00:00
var $scrollLocker = $ ( '.scroll-locker' ) ;
if ( $scrollLocker . offset ( ) ) {
var initOff = $scrollLocker . offset ( ) . top - $ ( window ) . scrollTop ( ) ;
lockTop ( initOff ) ;
$ ( window ) . on ( 'resize' , function ( ) {
lockTop ( initOff ) ;
} ) ;
}
2015-07-02 20:27:16 +00:00
}
2015-03-29 11:39:41 +00:00
$ ( '#comment-button' ) . on ( 'click' , commentSubmitButtonHandler ) ;
2014-11-07 01:38:47 +00:00
} ) ;
2015-04-19 07:36:54 +00:00
var profileValidation = angular . module ( 'profileValidation' ,
2015-04-20 02:22:11 +00:00
[ 'ui.bootstrap' ] ) ;
2015-01-06 04:09:23 +00:00
profileValidation . controller ( 'profileValidationController' , [ '$scope' , '$http' ,
2015-03-29 11:39:41 +00:00
function ( $scope , $http ) {
$http . get ( '/account/api' ) . success ( function ( data ) {
$scope . user = data . user ;
2015-06-04 19:54:41 +00:00
$scope . user . username = $scope . user . username ? $scope . user . username . toLowerCase ( ) : undefined ;
$scope . storedUsername = data . user . username ;
2015-03-29 11:39:41 +00:00
$scope . storedEmail = data . user . email ;
$scope . user . email = $scope . user . email ? $scope . user . email . toLowerCase ( ) : undefined ;
2015-06-04 19:54:41 +00:00
$scope . user . twitterHandle = $scope . user . twitterHandle ? $scope . user . twitterHandle . toLowerCase ( ) : undefined ;
2015-03-29 11:39:41 +00:00
$scope . asyncComplete = true ;
} ) ;
}
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' ,
2015-03-29 11:39:41 +00:00
function ( $scope ) {
$scope . existingUser = null ;
}
2015-01-24 09:14:41 +00:00
] ) ;
2015-01-10 01:52:19 +00:00
profileValidation . controller ( 'emailSignUpController' , [ '$scope' ,
2015-03-29 11:39:41 +00:00
function ( $scope ) {
2015-01-10 01:52:19 +00:00
2015-03-29 11:39:41 +00:00
}
2015-01-10 01:52:19 +00:00
] ) ;
2015-01-10 02:09:49 +00:00
profileValidation . controller ( 'emailSignInController' , [ '$scope' ,
2015-03-29 11:39:41 +00:00
function ( $scope ) {
2015-01-10 02:09:49 +00:00
2015-03-29 11:39:41 +00:00
}
2015-01-10 02:09:49 +00:00
] ) ;
2015-03-08 02:53:03 +00:00
profileValidation . controller ( 'URLSubmitController' , [ '$scope' ,
2015-03-29 11:39:41 +00:00
function ( $scope ) {
2015-03-08 02:53:03 +00:00
2015-03-29 11:39:41 +00:00
}
2015-03-08 02:53:03 +00:00
] ) ;
2015-01-13 20:50:00 +00:00
profileValidation . controller ( 'nonprofitFormController' , [ '$scope' ,
2015-03-29 11:39:41 +00:00
function ( $scope ) {
2015-01-13 20:50:00 +00:00
2015-03-29 11:39:41 +00:00
}
2015-01-13 20:50:00 +00:00
] ) ;
2015-01-14 21:28:20 +00:00
profileValidation . controller ( 'doneWithFirst100HoursFormController' , [ '$scope' ,
2015-03-29 11:39:41 +00:00
function ( $scope ) {
2015-01-14 21:28:20 +00:00
2015-03-29 11:39:41 +00:00
}
2015-01-14 21:28:20 +00:00
] ) ;
2015-03-18 07:40:18 +00:00
profileValidation . controller ( 'submitStoryController' , [ '$scope' ,
2015-03-29 11:39:41 +00:00
function ( $scope ) {
2015-03-18 07:40:18 +00:00
2015-03-29 11:39:41 +00:00
}
2015-03-18 07:40:18 +00:00
] ) ;
2015-04-19 07:36:54 +00:00
profileValidation . directive ( 'uniqueUsername' , [ '$http' , function ( $http ) {
2015-03-29 11:39:41 +00:00
return {
restrict : 'A' ,
require : 'ngModel' ,
link : function ( scope , element , attrs , ngModel ) {
element . bind ( "keyup" , function ( event ) {
ngModel . $setValidity ( 'unique' , true ) ;
2015-06-09 23:43:08 +00:00
var username = element . val ( ) ;
if ( username ) {
var config = { params : { username : username } } ;
$http
. get ( '/api/users/exists' , config )
2015-06-11 00:21:57 +00:00
. success ( function ( result ) {
2015-06-09 23:43:08 +00:00
if ( username === scope . storedUsername ) {
ngModel . $setValidity ( 'unique' , true ) ;
2015-06-11 00:21:57 +00:00
} else if ( result . exists ) {
2015-06-09 23:43:08 +00:00
ngModel . $setValidity ( 'unique' , false ) ;
}
} ) ;
2015-01-10 01:52:19 +00:00
}
2015-03-29 11:39:41 +00:00
} ) ;
2015-01-10 04:03:24 +00:00
}
2015-04-19 07:36:54 +00:00
} ;
2015-02-15 03:35:16 +00:00
} ] ) ;
2015-02-03 01:39:05 +00:00
2015-04-19 07:36:54 +00:00
profileValidation . directive ( 'existingUsername' ,
2015-04-20 02:22:11 +00:00
[ '$http' , function ( $http ) {
2015-05-23 06:26:29 +00:00
return {
restrict : 'A' ,
require : 'ngModel' ,
link : function ( scope , element , attrs , ngModel ) {
element . bind ( 'keyup' , function ( event ) {
if ( element . val ( ) . length > 0 ) {
ngModel . $setValidity ( 'exists' , false ) ;
} else {
element . removeClass ( 'ng-dirty' ) ;
ngModel . $setPristine ( ) ;
}
2015-06-09 23:43:08 +00:00
var username = element . val ( ) ;
if ( username ) {
var config = { params : { username : username } } ;
2015-05-23 06:26:29 +00:00
$http
2015-06-09 23:43:08 +00:00
. get ( '/api/users/exists' , config )
2015-06-11 00:21:57 +00:00
. success ( function ( result ) {
ngModel . $setValidity ( 'exists' , result . exists ) ;
2015-05-23 06:26:29 +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-03-29 11:39:41 +00:00
return {
restrict : 'A' ,
require : 'ngModel' ,
link : function getUnique ( scope , element , attrs , ngModel ) {
element . bind ( "keyup" , function ( event ) {
ngModel . $setValidity ( 'unique' , true ) ;
2015-06-09 23:43:08 +00:00
var email = element . val ( ) ;
2015-06-11 00:11:32 +00:00
if ( email ) {
2015-06-09 23:43:08 +00:00
var config = { params : { email : email } } ;
$http
. get ( '/api/users/exists' , config )
2015-06-11 00:21:57 +00:00
. success ( function ( result ) {
2015-06-09 23:43:08 +00:00
if ( email === scope . storedEmail ) {
ngModel . $setValidity ( 'unique' , true ) ;
2015-06-11 00:21:57 +00:00
} else if ( result . exists ) {
2015-06-09 23:43:08 +00:00
ngModel . $setValidity ( 'unique' , false ) ;
}
} ) ;
2015-03-29 11:39:41 +00:00
} ;
} ) ;
2015-01-10 04:03:24 +00:00
}
2015-03-29 11:39:41 +00:00
}
2015-03-09 09:49:03 +00:00
} ] ) ;