2014-11-28 20:49:41 -05:00
RootView = require ' views/core/RootView '
2014-11-29 15:46:04 -05:00
template = require ' templates/home-view '
2014-01-03 13:32:13 -05:00
2014-07-17 20:16:32 -04:00
module.exports = class HomeView extends RootView
2014-01-03 13:32:13 -05:00
id: ' home-view '
template: template
2014-03-21 20:42:13 -04:00
2014-06-19 16:42:25 -04:00
events:
2015-10-21 17:18:13 -04:00
' click # play-button ' : ' onClickPlayButton '
2014-01-03 13:32:13 -05:00
2014-10-21 19:49:25 -04:00
constructor: ->
super ( )
2015-02-27 19:07:41 -05:00
window . tracker ? . trackEvent ' Homepage Loaded ' , category: ' Homepage '
2014-11-27 12:44:08 -05:00
if not me . get ( ' hourOfCode ' ) and @ getQueryVariable ' hour_of_code '
@ setUpHourOfCode ( )
elapsed = ( new Date ( ) - new Date ( me . get ( ' dateCreated ' ) ) )
if me . get ( ' hourOfCode ' ) and elapsed < 86400 * 1000 and me . get ( ' preferredLanguage ' , true ) is ' en-US '
# Show the Hour of Code footer explanation in English until it's been more than a day
@explainsHourOfCode = true
2014-10-21 19:49:25 -04:00
2015-10-21 17:18:13 -04:00
onClickPlayButton: (e) ->
2014-11-26 09:58:23 -05:00
@ playSound ' menu-button-click '
2014-09-25 18:32:33 -04:00
e . preventDefault ( )
e . stopImmediatePropagation ( )
2014-11-28 15:05:34 -05:00
window . tracker ? . trackEvent ' Click Play ' , category: ' Homepage '
2014-11-10 18:24:05 -05:00
window . open ' /play ' , ' _blank '
afterInsert: ->
super ( arguments . . . )
2014-11-27 12:44:08 -05:00
@ $el . addClass ' hour-of-code ' if @ explainsHourOfCode
2015-10-21 20:00:46 -04:00
isOldBrowser: ->
if $ . browser
majorVersion = $ . browser . versionNumber
return true if $ . browser . mozilla && majorVersion < 25
return true if $ . browser . chrome && majorVersion < 31 # Noticed Gems in the Deep not loading with 30
return true if $ . browser . safari && majorVersion < 6 # 6 might have problems with Aether, or maybe just old minors of 6: https://errorception.com/projects/51a79585ee207206390002a2/errors/547a202e1ead63ba4e4ac9fd
else
console . warn ' no more jquery browser version... '
return false
2014-11-27 12:44:08 -05:00
setUpHourOfCode: ->
2015-10-13 11:11:55 -04:00
# All this HoC stuff is for the 2014-2015 year. 2015-2016 year lands at /hoc instead (the courses view).
# TODO: get rid of all this sometime in November 2015 when code.org/learn updates to the new version for Hour of Code tutorials.
2014-11-27 12:44:08 -05:00
elapsed = ( new Date ( ) - new Date ( me . get ( ' dateCreated ' ) ) )
if elapsed < 5 * 60 * 1000
me . set ' hourOfCode ' , true
me . patch ( )
2014-12-28 16:25:20 -05:00
# We may also insert the tracking pixel for everyone on the CampaignView so as to count directly-linked visitors.
2015-04-18 19:02:18 -04:00
$ ( ' body ' ) . append ( $ ( ' <img src= " https://code.org/api/hour/begin_codecombat.png " style= " visibility: hidden; " > ' ) )
2015-02-27 19:07:41 -05:00
application . tracker ? . trackEvent ' Hour of Code Begin '