Refactor HomeView to use view in template

This commit is contained in:
Scott Erickson 2015-10-21 17:00:46 -07:00
parent 625babd4a0
commit 9a29c26cc8
2 changed files with 13 additions and 19 deletions

View file

@ -26,10 +26,10 @@ block outer_content
.alert.alert-danger.lt-ie9
strong(data-i18n="home.no_ie") CodeCombat does not run in Internet Explorer 8 or older. Sorry!
if isIPadBrowser || isMobile
if view.isIPadBrowser() || view.isMobile()
.alert.alert-danger.mobile
strong(data-i18n="home.no_mobile") CodeCombat wasn't designed for mobile devices and may not work!
else if isOldBrowser
else if view.isOldBrowser()
.alert.alert-danger.old-browser
strong(data-i18n="home.old_browser") Uh oh, your browser is too old to run CodeCombat. Sorry!
br
@ -37,7 +37,7 @@ block outer_content
block extra_footer_content
if explainsHourOfCode
if view.explainsHourOfCode
// Does not show up unless lang is en-US.
div.hour-of-code-explanation
| The 'Hour of Code' is a nationwide initiative by

View file

@ -18,22 +18,6 @@ module.exports = class HomeView extends RootView
# Show the Hour of Code footer explanation in English until it's been more than a day
@explainsHourOfCode = true
getRenderData: ->
c = super()
if $.browser
majorVersion = $.browser.versionNumber
c.isOldBrowser = true if $.browser.mozilla && majorVersion < 25
c.isOldBrowser = true if $.browser.chrome && majorVersion < 31 # Noticed Gems in the Deep not loading with 30
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
else
console.warn 'no more jquery browser version...'
c.isEnglish = _.string.startsWith (me.get('preferredLanguage') or 'en'), 'en'
c.languageName = me.get('preferredLanguage')
c.explainsHourOfCode = @explainsHourOfCode
c.isMobile = @isMobile()
c.isIPadBrowser = @isIPadBrowser()
c
onClickPlayButton: (e) ->
@playSound 'menu-button-click'
e.preventDefault()
@ -45,6 +29,16 @@ module.exports = class HomeView extends RootView
super(arguments...)
@$el.addClass 'hour-of-code' if @explainsHourOfCode
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
setUpHourOfCode: ->
# 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.