codecombat/app/views/HomeView.coffee

56 lines
2.2 KiB
CoffeeScript
Raw Normal View History

RootView = require 'views/core/RootView'
template = require 'templates/home-view'
2014-01-03 13:32:13 -05:00
module.exports = class HomeView extends RootView
2014-01-03 13:32:13 -05:00
id: 'home-view'
template: template
events:
'click #play-button': 'onClickBeginnerCampaign'
2014-01-03 13:32:13 -05:00
constructor: ->
super()
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-01-03 13:32:13 -05:00
getRenderData: ->
c = super()
if $.browser
majorVersion = $.browser.versionNumber
c.isOldBrowser = true if $.browser.mozilla && majorVersion < 25
c.isOldBrowser = true if $.browser.chrome && majorVersion < 25
c.isOldBrowser = 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
2014-01-03 13:32:13 -05:00
else
console.warn 'no more jquery browser version...'
c.isEnglish = _.string.startsWith (me.get('preferredLanguage') or 'en'), 'en'
2014-04-09 01:50:13 -04:00
c.languageName = me.get('preferredLanguage')
2014-11-27 12:44:08 -05:00
c.explainsHourOfCode = @explainsHourOfCode
c.isMobile = @isMobile()
c.isIPadBrowser = @isIPadBrowser()
2014-01-03 13:32:13 -05:00
c
onClickBeginnerCampaign: (e) ->
@playSound 'menu-button-click'
e.preventDefault()
e.stopImmediatePropagation()
window.tracker?.trackEvent 'Click Play', category: 'Homepage'
window.open '/play', '_blank'
afterInsert: ->
super(arguments...)
2014-11-27 12:44:08 -05:00
@$el.addClass 'hour-of-code' if @explainsHourOfCode
setUpHourOfCode: ->
elapsed = (new Date() - new Date(me.get('dateCreated')))
if elapsed < 5 * 60 * 1000
me.set 'hourOfCode', true
me.patch()
# We may also insert the tracking pixel for everyone on the CampaignView so as to count directly-linked visitors.
$('body').append($('<img src="https://code.org/api/hour/begin_codecombat.png" style="visibility: hidden;">'))
application.tracker?.trackEvent 'Hour of Code Begin'