| 
									
										
										
										
											2015-11-21 19:48:24 -08:00
										 |  |  | window.common = (function(global) { | 
					
						
							|  |  |  |   const { | 
					
						
							|  |  |  |     $, | 
					
						
							|  |  |  |     Rx: { Observable }, | 
					
						
							| 
									
										
										
										
											2016-04-22 17:31:16 +08:00
										 |  |  |     common = { init: [] }, | 
					
						
							|  |  |  |     Mousetrap | 
					
						
							| 
									
										
										
										
											2015-11-21 19:48:24 -08:00
										 |  |  |   } = global; | 
					
						
							| 
									
										
										
										
											2015-11-17 21:25:16 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   common.ctrlEnterClickHandler = function ctrlEnterClickHandler(e) { | 
					
						
							|  |  |  |     // ctrl + enter or cmd + enter
 | 
					
						
							|  |  |  |     if ( | 
					
						
							| 
									
										
										
										
											2015-11-21 19:48:24 -08:00
										 |  |  |       e.keyCode === 13 && | 
					
						
							| 
									
										
										
										
											2015-11-23 17:50:09 -08:00
										 |  |  |       (e.metaKey || e.ctrlKey) | 
					
						
							| 
									
										
										
										
											2015-11-17 21:25:16 -08:00
										 |  |  |     ) { | 
					
						
							|  |  |  |       $('#complete-courseware-dialog').off('keydown', ctrlEnterClickHandler); | 
					
						
							|  |  |  |       if ($('#submit-challenge').length > 0) { | 
					
						
							|  |  |  |         $('#submit-challenge').click(); | 
					
						
							|  |  |  |       } else { | 
					
						
							|  |  |  |         window.location = '/challenges/next-challenge?id=' + common.challengeId; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   common.init.push(function($) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     var $marginFix = $('.innerMarginFix'); | 
					
						
							|  |  |  |     $marginFix.css('min-height', $marginFix.height()); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-21 19:48:24 -08:00
										 |  |  |     common.submitBtn$ = Observable.fromEvent($('#submitButton'), 'click'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     common.resetBtn$ = Observable.fromEvent($('#reset-button'), 'click'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-17 21:25:16 -08:00
										 |  |  |     // init modal keybindings on open
 | 
					
						
							|  |  |  |     $('#complete-courseware-dialog').on('shown.bs.modal', function() { | 
					
						
							|  |  |  |       $('#complete-courseware-dialog').keydown(common.ctrlEnterClickHandler); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // remove modal keybinds on close
 | 
					
						
							|  |  |  |     $('#complete-courseware-dialog').on('hidden.bs.modal', function() { | 
					
						
							|  |  |  |       $('#complete-courseware-dialog').off( | 
					
						
							|  |  |  |         'keydown', | 
					
						
							|  |  |  |         common.ctrlEnterClickHandler | 
					
						
							|  |  |  |       ); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-22 17:31:16 +08:00
										 |  |  |     // set focus keybind
 | 
					
						
							|  |  |  |     Mousetrap.bind(['command+shift+e', 'ctrl+shift+e'], () => { | 
					
						
							|  |  |  |         common.editor.focus(); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-17 21:25:16 -08:00
										 |  |  |     // video checklist binding
 | 
					
						
							|  |  |  |     $('.challenge-list-checkbox').on('change', function() { | 
					
						
							|  |  |  |       var checkboxId = $(this).parent().parent().attr('id'); | 
					
						
							|  |  |  |       if ($(this).is(':checked')) { | 
					
						
							|  |  |  |         $(this).parent().siblings().children().addClass('faded'); | 
					
						
							|  |  |  |         if (!localStorage || !localStorage[checkboxId]) { | 
					
						
							|  |  |  |           localStorage[checkboxId] = true; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if (!$(this).is(':checked')) { | 
					
						
							|  |  |  |         $(this).parent().siblings().children().removeClass('faded'); | 
					
						
							|  |  |  |         if (localStorage[checkboxId]) { | 
					
						
							|  |  |  |           localStorage.removeItem(checkboxId); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $('.checklist-element').each(function() { | 
					
						
							|  |  |  |       var checklistElementId = $(this).attr('id'); | 
					
						
							|  |  |  |       if (localStorage[checklistElementId]) { | 
					
						
							|  |  |  |         $(this).children().children('li').addClass('faded'); | 
					
						
							|  |  |  |         $(this).children().children('input').trigger('click'); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // video challenge submit
 | 
					
						
							|  |  |  |     $('#next-courseware-button').on('click', function() { | 
					
						
							|  |  |  |       $('#next-courseware-button').unbind('click'); | 
					
						
							|  |  |  |       if ($('.signup-btn-nav').length < 1) { | 
					
						
							|  |  |  |         var data; | 
					
						
							| 
									
										
										
										
											2016-01-19 22:30:01 -08:00
										 |  |  |         var solution = $('#public-url').val() || null; | 
					
						
							|  |  |  |         var githubLink = $('#github-url').val() || null; | 
					
						
							| 
									
										
										
										
											2015-11-17 21:25:16 -08:00
										 |  |  |         switch (common.challengeType) { | 
					
						
							|  |  |  |           case common.challengeTypes.VIDEO: | 
					
						
							|  |  |  |             data = { | 
					
						
							| 
									
										
										
										
											2015-12-08 13:52:03 -08:00
										 |  |  |               id: common.challengeId, | 
					
						
							| 
									
										
										
										
											2016-01-19 22:30:01 -08:00
										 |  |  |               name: common.challengeName, | 
					
						
							| 
									
										
										
										
											2016-02-10 22:10:06 -08:00
										 |  |  |               challengeType: +common.challengeType | 
					
						
							| 
									
										
										
										
											2015-11-17 21:25:16 -08:00
										 |  |  |             }; | 
					
						
							| 
									
										
										
										
											2016-02-10 22:10:06 -08:00
										 |  |  |             $.ajax({ | 
					
						
							|  |  |  |               url: '/completed-challenge/', | 
					
						
							|  |  |  |               type: 'POST', | 
					
						
							|  |  |  |               data: JSON.stringify(data), | 
					
						
							|  |  |  |               contentType: 'application/json', | 
					
						
							|  |  |  |               dataType: 'json' | 
					
						
							|  |  |  |             }) | 
					
						
							| 
									
										
										
										
											2015-11-17 21:25:16 -08:00
										 |  |  |               .success(function(res) { | 
					
						
							|  |  |  |                 if (!res) { | 
					
						
							|  |  |  |                   return; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 window.location.href = '/challenges/next-challenge?id=' + | 
					
						
							|  |  |  |                   common.challengeId; | 
					
						
							|  |  |  |               }) | 
					
						
							|  |  |  |               .fail(function() { | 
					
						
							| 
									
										
										
										
											2016-02-10 22:10:06 -08:00
										 |  |  |                 window.location.replace(window.location.href); | 
					
						
							| 
									
										
										
										
											2015-11-17 21:25:16 -08:00
										 |  |  |               }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |           case common.challengeTypes.BASEJUMP: | 
					
						
							|  |  |  |           case common.challengeTypes.ZIPLINE: | 
					
						
							|  |  |  |             data = { | 
					
						
							| 
									
										
										
										
											2016-01-19 22:30:01 -08:00
										 |  |  |               id: common.challengeId, | 
					
						
							|  |  |  |               name: common.challengeName, | 
					
						
							|  |  |  |               challengeType: +common.challengeType, | 
					
						
							|  |  |  |               solution, | 
					
						
							|  |  |  |               githubLink | 
					
						
							| 
									
										
										
										
											2015-11-17 21:25:16 -08:00
										 |  |  |             }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-10 22:10:06 -08:00
										 |  |  |             $.ajax({ | 
					
						
							|  |  |  |               url: '/completed-zipline-or-basejump/', | 
					
						
							|  |  |  |               type: 'POST', | 
					
						
							|  |  |  |               data: JSON.stringify(data), | 
					
						
							|  |  |  |               contentType: 'application/json', | 
					
						
							|  |  |  |               dataType: 'json' | 
					
						
							|  |  |  |             }) | 
					
						
							| 
									
										
										
										
											2015-11-17 21:25:16 -08:00
										 |  |  |               .success(function() { | 
					
						
							|  |  |  |                 window.location.href = '/challenges/next-challenge?id=' + | 
					
						
							|  |  |  |                   common.challengeId; | 
					
						
							|  |  |  |               }) | 
					
						
							|  |  |  |               .fail(function() { | 
					
						
							|  |  |  |                 window.location.replace(window.location.href); | 
					
						
							|  |  |  |               }); | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           case common.challengeTypes.BONFIRE: | 
					
						
							|  |  |  |             window.location.href = '/challenges/next-challenge?id=' + | 
					
						
							|  |  |  |               common.challengeId; | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           default: | 
					
						
							|  |  |  |             console.log('Happy Coding!'); | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (common.challengeName) { | 
					
						
							| 
									
										
										
										
											2016-01-30 00:13:41 -08:00
										 |  |  |       window.ga('send', 'event', 'Challenge', 'load', common.gaName); | 
					
						
							| 
									
										
										
										
											2015-11-17 21:25:16 -08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-30 23:11:07 -05:00
										 |  |  |     $('.modal').on('show.bs.modal', function() { | 
					
						
							|  |  |  |       $('.gitter-chat-embed, .wiki-aside, .map-aside') | 
					
						
							|  |  |  |         .addClass('is-collapsed'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-17 21:25:16 -08:00
										 |  |  |     $('#complete-courseware-dialog').on('hidden.bs.modal', function() { | 
					
						
							| 
									
										
										
										
											2015-11-19 21:51:38 -08:00
										 |  |  |       if (common.editor.focus) { | 
					
						
							|  |  |  |         common.editor.focus(); | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2015-11-17 21:25:16 -08:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $('#trigger-issue-modal').on('click', function() { | 
					
						
							|  |  |  |       $('#issue-modal').modal('show'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $('#trigger-help-modal').on('click', function() { | 
					
						
							|  |  |  |       $('#help-modal').modal('show'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $('#trigger-reset-modal').on('click', function() { | 
					
						
							|  |  |  |       $('#reset-modal').modal('show'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $('#trigger-pair-modal').on('click', function() { | 
					
						
							|  |  |  |       $('#pair-modal').modal('show'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $('#completed-courseware').on('click', function() { | 
					
						
							|  |  |  |       $('#complete-courseware-dialog').modal('show'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-30 23:11:07 -05:00
										 |  |  |     $('#show-solution').on('click', function() { | 
					
						
							|  |  |  |       $('#complete-courseware-dialog').modal('hide'); | 
					
						
							|  |  |  |       $('#nav-wiki-btn').click(); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $('#challenge-help-btn').on('click', function() { | 
					
						
							|  |  |  |       $('.wiki-aside, .map-aside, #chat-embed-main').addClass('is-collapsed'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-17 21:25:16 -08:00
										 |  |  |     $('#help-ive-found-a-bug-wiki-article').on('click', function() { | 
					
						
							|  |  |  |       window.open( | 
					
						
							|  |  |  |         'https://github.com/FreeCodeCamp/FreeCodeCamp/wiki/' + | 
					
						
							| 
									
										
										
										
											2016-05-17 01:36:52 -04:00
										 |  |  |           'FreeCodeCamp-Report-Bugs', | 
					
						
							| 
									
										
										
										
											2015-11-17 21:25:16 -08:00
										 |  |  |         '_blank' | 
					
						
							|  |  |  |       ); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $('#search-issue').on('click', function() { | 
					
						
							| 
									
										
										
										
											2015-12-06 13:17:19 +04:00
										 |  |  |       var queryIssue = window.location.href | 
					
						
							|  |  |  |         .toString() | 
					
						
							|  |  |  |         .split('?')[0] | 
					
						
							|  |  |  |         .replace(/(#*)$/, ''); | 
					
						
							| 
									
										
										
										
											2015-11-17 21:25:16 -08:00
										 |  |  |       window.open( | 
					
						
							|  |  |  |         'https://github.com/FreeCodeCamp/FreeCodeCamp/issues?q=' + | 
					
						
							|  |  |  |         'is:issue is:all ' + | 
					
						
							|  |  |  |         (common.challengeName) + | 
					
						
							|  |  |  |         ' OR ' + | 
					
						
							|  |  |  |         queryIssue | 
					
						
							|  |  |  |           .substr(queryIssue.lastIndexOf('challenges/') + 11) | 
					
						
							|  |  |  |           .replace('/', ''), '_blank'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return common; | 
					
						
							|  |  |  | }(window)); |