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