| 
									
										
										
										
											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-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-08-18 19:21:34 +01:00
										 |  |  |   function reBindModals(){ | 
					
						
							| 
									
										
										
										
											2015-05-28 14:29:45 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-22 12:10:08 -07:00
										 |  |  |       $('.close-modal').unbind('click'); | 
					
						
							|  |  |  |       $('.close-modal').on('click', function(){ | 
					
						
							|  |  |  |         setTimeout(function() { | 
					
						
							| 
									
										
										
										
											2015-08-22 23:18:10 +01:00
										 |  |  |             $('.close-modal').parent().parent().parent().parent().modal('hide'); | 
					
						
							| 
									
										
										
										
											2015-08-22 22:51:48 +01:00
										 |  |  |         }, 200); | 
					
						
							| 
									
										
										
										
											2015-08-18 19:21:34 +01:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-01 07:18:44 +04:00
										 |  |  |       $('#search-issue').unbind('click'); | 
					
						
							|  |  |  |       $('#search-issue').on('click', function() { | 
					
						
							|  |  |  |           var queryIssue = window.location.href.toString(); | 
					
						
							|  |  |  |           window.open('https://github.com/FreeCodeCamp/FreeCodeCamp/issues?q=is:issue is:all '+ queryIssue.substr(queryIssue.lastIndexOf('challenges/') + 11).replace('/', ''), '_blank'); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-07 08:18:44 -07:00
										 |  |  |       $('#help-ive-found-a-bug-wiki-article').unbind('click'); | 
					
						
							|  |  |  |       $('#help-ive-found-a-bug-wiki-article').on('click', function() { | 
					
						
							|  |  |  |         var queryIssue = window.location.href.toString(); | 
					
						
							|  |  |  |         window.open("https://github.com/FreeCodeCamp/FreeCodeCamp/wiki/Help-I've-Found-a-Bug", '_blank'); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-18 19:21:34 +01:00
										 |  |  |       $('#report-issue').unbind('click'); | 
					
						
							|  |  |  |       $('#report-issue').on('click', function() { | 
					
						
							| 
									
										
										
										
											2015-09-07 07:54:29 -07:00
										 |  |  |           var textMessage = 'https://github.com/freecodecamp/freecodecamp/issues/new?&body=Challenge ' + window.location.href + ' has an issue.'; | 
					
						
							|  |  |  |           textMessage += ' User Agent is: <code>' + navigator.userAgent + '</code>.'; | 
					
						
							|  |  |  |           textMessage += ' Please describe how to reproduce this issue, and include links to screenshots if possible.%0A%0A'; | 
					
						
							| 
									
										
										
										
											2015-09-06 11:40:06 +04:00
										 |  |  |           textMessage = textMessage.replace(';', ','); //GitHub cuts User Agent text because of ';' symbol so I just replace it with ','
 | 
					
						
							| 
									
										
										
										
											2015-08-18 19:21:34 +01:00
										 |  |  |           $('#issue-modal').modal('hide'); | 
					
						
							| 
									
										
										
										
											2015-09-01 07:18:44 +04:00
										 |  |  |           window.open(textMessage, '_blank'); | 
					
						
							| 
									
										
										
										
											2015-08-18 19:21:34 +01:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       $('#completed-courseware').unbind('click'); | 
					
						
							|  |  |  |       $('#completed-courseware').on('click', function() { | 
					
						
							|  |  |  |           $('#complete-courseware-dialog').modal('show'); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       $('#completed-courseware-editorless').unbind('click'); | 
					
						
							|  |  |  |       $('#completed-courseware-editorless').on('click', function() { | 
					
						
							|  |  |  |           $('#complete-courseware-editorless-dialog').modal('show'); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       $('#trigger-pair-modal').unbind('click'); | 
					
						
							|  |  |  |       $('#trigger-pair-modal').on('click', function() { | 
					
						
							|  |  |  |           $('#pair-modal').modal('show'); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       $('#trigger-reset-modal').unbind('click'); | 
					
						
							|  |  |  |       $('#trigger-reset-modal').on('click', function() { | 
					
						
							|  |  |  |           $('#reset-modal').modal('show'); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       $('#trigger-help-modal').unbind('click'); | 
					
						
							|  |  |  |       $('#trigger-help-modal').on('click', function() { | 
					
						
							|  |  |  |           $('#help-modal').modal('show'); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       $('#trigger-issue-modal').unbind('click'); | 
					
						
							|  |  |  |       $('#trigger-issue-modal').on('click', function() { | 
					
						
							|  |  |  |           $('#issue-modal').modal('show'); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       $('#completed-zipline-or-basejump').unbind('click'); | 
					
						
							|  |  |  |       $('#completed-zipline-or-basejump').on('click', function() { | 
					
						
							|  |  |  |           $('#complete-zipline-or-basejump-dialog').modal('show'); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-19 18:11:43 -07:00
										 |  |  |       $('#next-courseware-button').unbind('click'); | 
					
						
							|  |  |  |       $('#next-courseware-button').on('click', function() { | 
					
						
							|  |  |  |           $('#next-courseware-button').unbind('click'); | 
					
						
							|  |  |  |           if ($('.signup-btn-nav').length < 1) { | 
					
						
							|  |  |  |               switch (challengeType) { | 
					
						
							|  |  |  |                   case challengeTypes.HTML_CSS_JQ: | 
					
						
							|  |  |  |                   case challengeTypes.JAVASCRIPT: | 
					
						
							|  |  |  |                   case challengeTypes.VIDEO: | 
					
						
							|  |  |  |                       $.post( | 
					
						
							|  |  |  |                           '/completed-challenge/', | 
					
						
							|  |  |  |                           { | 
					
						
							|  |  |  |                               challengeInfo: { | 
					
						
							|  |  |  |                                   challengeId: challenge_Id, | 
					
						
							|  |  |  |                                   challengeName: challenge_Name | 
					
						
							|  |  |  |                               } | 
					
						
							|  |  |  |                           }).success( | 
					
						
							|  |  |  |                           function(res) { | 
					
						
							|  |  |  |                               if (res) { | 
					
						
							| 
									
										
										
										
											2015-09-08 21:45:53 -07:00
										 |  |  |                                   window.location.href = '/challenges/next-challenge?id=' + challenge_Id; | 
					
						
							| 
									
										
										
										
											2015-08-19 18:11:43 -07:00
										 |  |  |                               } | 
					
						
							|  |  |  |                           }).fail( | 
					
						
							|  |  |  |                           function() { | 
					
						
							|  |  |  |                               window.location.href="/challenges"; | 
					
						
							|  |  |  |                           } | 
					
						
							|  |  |  |                       ); | 
					
						
							|  |  |  |                       break; | 
					
						
							|  |  |  |                   case challengeTypes.ZIPLINE: | 
					
						
							|  |  |  |                       var didCompleteWith = $('#completed-with').val() || null; | 
					
						
							|  |  |  |                       var publicURL = $('#public-url').val() || null; | 
					
						
							|  |  |  |                       $.post( | 
					
						
							|  |  |  |                           '/completed-zipline-or-basejump/', | 
					
						
							|  |  |  |                           { | 
					
						
							|  |  |  |                               challengeInfo: { | 
					
						
							|  |  |  |                                   challengeId: challenge_Id, | 
					
						
							|  |  |  |                                   challengeName: challenge_Name, | 
					
						
							|  |  |  |                                   completedWith: didCompleteWith, | 
					
						
							|  |  |  |                                   publicURL: publicURL, | 
					
						
							|  |  |  |                                   challengeType: challengeType | 
					
						
							|  |  |  |                               } | 
					
						
							|  |  |  |                           }).success( | 
					
						
							|  |  |  |                           function() { | 
					
						
							| 
									
										
										
										
											2015-09-08 21:45:53 -07:00
										 |  |  |                               window.location.href = '/challenges/next-challenge?id=' + challenge_Id; | 
					
						
							| 
									
										
										
										
											2015-08-19 18:11:43 -07:00
										 |  |  |                           }).fail( | 
					
						
							|  |  |  |                           function() { | 
					
						
							|  |  |  |                               window.location.href = '/challenges'; | 
					
						
							|  |  |  |                           }); | 
					
						
							|  |  |  |                       break; | 
					
						
							|  |  |  |                   case challengeTypes.BASEJUMP: | 
					
						
							|  |  |  |                       var didCompleteWith = $('#completed-with').val() || null; | 
					
						
							|  |  |  |                       var publicURL = $('#public-url').val() || null; | 
					
						
							|  |  |  |                       var githubURL = $('#github-url').val() || null; | 
					
						
							|  |  |  |                       $.post( | 
					
						
							|  |  |  |                           '/completed-zipline-or-basejump/', | 
					
						
							|  |  |  |                           { | 
					
						
							|  |  |  |                               challengeInfo: { | 
					
						
							|  |  |  |                                   challengeId: challenge_Id, | 
					
						
							|  |  |  |                                   challengeName: challenge_Name, | 
					
						
							|  |  |  |                                   completedWith: didCompleteWith, | 
					
						
							|  |  |  |                                   publicURL: publicURL, | 
					
						
							|  |  |  |                                   githubURL: githubURL, | 
					
						
							|  |  |  |                                   challengeType: challengeType, | 
					
						
							|  |  |  |                                   verified: false | 
					
						
							|  |  |  |                               } | 
					
						
							|  |  |  |                           }).success(function() { | 
					
						
							| 
									
										
										
										
											2015-09-08 21:45:53 -07:00
										 |  |  |                               window.location.href = '/challenges/next-challenge?id=' + challenge_Id; | 
					
						
							| 
									
										
										
										
											2015-08-19 18:11:43 -07:00
										 |  |  |                           }).fail(function() { | 
					
						
							|  |  |  |                               window.location.replace(window.location.href); | 
					
						
							|  |  |  |                           }); | 
					
						
							|  |  |  |                       break; | 
					
						
							|  |  |  |                   case challengeTypes.BONFIRE: | 
					
						
							| 
									
										
										
										
											2015-09-08 21:45:53 -07:00
										 |  |  |                       window.location.href = '/challenges/next-challenge?id=' + challenge_Id; | 
					
						
							| 
									
										
										
										
											2015-08-19 18:11:43 -07:00
										 |  |  |                   default: | 
					
						
							|  |  |  |                       break; | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       $('.next-challenge-button').unbind('click'); | 
					
						
							|  |  |  |       $('.next-challenge-button').on('click', function() { | 
					
						
							|  |  |  |           l = location.pathname.split('/'); | 
					
						
							|  |  |  |           window.location = '/challenges/' + (parseInt(l[l.length - 1]) + 1); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-18 19:21:34 +01:00
										 |  |  |       $('#complete-courseware-dialog').on('hidden.bs.modal', function() { | 
					
						
							|  |  |  |           editor.focus(); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       $('#complete-zipline-or-basejump').on('hidden.bs.modal', function() { | 
					
						
							|  |  |  |           editor.focus(); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |   }; | 
					
						
							| 
									
										
										
										
											2015-05-28 14:29:45 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-24 03:11:01 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-28 02:22:12 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-18 19:21:34 +01:00
										 |  |  |     $(window).resize(function(){ | 
					
						
							|  |  |  |         reBindModals(); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2015-05-28 16:18:04 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-18 19:21:34 +01:00
										 |  |  |     reBindModals(); | 
					
						
							| 
									
										
										
										
											2015-05-28 16:18:04 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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-08-13 01:20:12 +01:00
										 |  |  |         function lockTop(){ | 
					
						
							|  |  |  |             if ($(window).width() >= 990) { | 
					
						
							|  |  |  |                 if($('.editorScrollDiv').html() !== 'undefined'){ | 
					
						
							|  |  |  |                     var magiVal = $(window).height()-($('.navbar').height()+$('.footer').height()); | 
					
						
							|  |  |  |                     if(magiVal < 0){ | 
					
						
							|  |  |  |                         magiVal = 0; | 
					
						
							| 
									
										
										
										
											2015-07-02 21:27:16 +01:00
										 |  |  |                     } | 
					
						
							| 
									
										
										
										
											2015-08-13 01:20:12 +01:00
										 |  |  |                     $('.editorScrollDiv').css("height", (magiVal-85) + "px"); | 
					
						
							| 
									
										
										
										
											2015-07-02 21:27:16 +01:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2015-08-13 01:20:12 +01:00
										 |  |  |                 magiVal = $(window).height()-($('.navbar').height()+$('.footer').height()); | 
					
						
							|  |  |  |                 if(magiVal < 0){ | 
					
						
							|  |  |  |                     magiVal = 0; | 
					
						
							| 
									
										
										
										
											2015-07-02 21:27:16 +01:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2015-08-14 21:45:25 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |                 $('.scroll-locker').css("min-height", $('.editorScrollDiv').height()).css("height",magiVal-185); | 
					
						
							| 
									
										
										
										
											2015-08-13 01:20:12 +01:00
										 |  |  |             } | 
					
						
							|  |  |  |             else { | 
					
						
							|  |  |  |                 $('.editorScrollDiv').css("max-height", 500 + "px"); | 
					
						
							| 
									
										
										
										
											2015-08-14 21:45:25 +01:00
										 |  |  |                 $('.scroll-locker').css('position', 'inherit').css('top', 'inherit').css('width', '100%').css('max-height', '85%'); | 
					
						
							| 
									
										
										
										
											2015-08-13 01:20:12 +01:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2015-07-02 21:27:16 +01:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-08-14 21:45:25 +01:00
										 |  |  |         if ($('.scroll-locker').html()){ | 
					
						
							| 
									
										
										
										
											2015-08-13 01:20:12 +01:00
										 |  |  |             lockTop(); | 
					
						
							|  |  |  |             $(window).on('resize', function(){ | 
					
						
							|  |  |  |               lockTop(); | 
					
						
							|  |  |  |             }); | 
					
						
							| 
									
										
										
										
											2015-08-14 21:45:25 +01:00
										 |  |  |             $(window).on('scroll', function() { | 
					
						
							| 
									
										
										
										
											2015-08-13 01:20:12 +01:00
										 |  |  |               lockTop(); | 
					
						
							|  |  |  |             }); | 
					
						
							| 
									
										
										
										
											2015-07-04 08:31:26 -07:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-08-20 16:48:46 +01:00
										 |  |  |        var execInProgress = false; | 
					
						
							|  |  |  |        document.getElementById('scroll-locker').addEventListener('previewUpdateSpy', function(e){ | 
					
						
							|  |  |  |            if (!execInProgress){ | 
					
						
							|  |  |  |                execInProgress = true; | 
					
						
							|  |  |  |                setTimeout(function(){ | 
					
						
							|  |  |  |                    if($($('.scroll-locker').children()[0]).height()-800 > e.detail){ | 
					
						
							|  |  |  |                        $('.scroll-locker').scrollTop(e.detail); | 
					
						
							|  |  |  |                    } | 
					
						
							|  |  |  |                    else { | 
					
						
							|  |  |  |                        $('.scroll-locker').animate({"scrollTop":$($('.scroll-locker').children()[0]).height()}, 175); | 
					
						
							|  |  |  |                    } | 
					
						
							|  |  |  |                    execInProgress = false; | 
					
						
							|  |  |  |                }, 750); | 
					
						
							|  |  |  |            } | 
					
						
							|  |  |  |        }, false); | 
					
						
							| 
									
										
										
										
											2015-07-31 19:51:21 -07:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2014-11-06 17:38:47 -08:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-14 23:57:43 +01:00
										 |  |  | function defCheck(a){ | 
					
						
							|  |  |  |     if(a !== 'undefined'){return(true);}else{return(false);} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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
										 |  |  | }]); |