2014-07-17 20:16:32 -04:00
|
|
|
RootView = require 'views/kinds/RootView'
|
2014-01-03 13:32:13 -05:00
|
|
|
template = require 'templates/home'
|
|
|
|
WizardSprite = require 'lib/surface/WizardSprite'
|
|
|
|
ThangType = require 'models/ThangType'
|
2014-02-14 18:50:42 -05:00
|
|
|
Simulator = require 'lib/simulator/Simulator'
|
2014-03-16 19:59:48 -04:00
|
|
|
{me} = require '/lib/auth'
|
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:
|
|
|
|
'click .code-language': 'onCodeLanguageSelected'
|
|
|
|
|
2014-03-03 13:42:11 -05:00
|
|
|
constructor: ->
|
|
|
|
super(arguments...)
|
|
|
|
ThangType.loadUniversalWizard()
|
2014-08-30 02:09:38 -04:00
|
|
|
@getCodeLanguageCounts()
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
getRenderData: ->
|
|
|
|
c = super()
|
|
|
|
if $.browser
|
2014-04-13 23:31:23 -04:00
|
|
|
majorVersion = $.browser.versionNumber
|
2014-01-03 13:32:13 -05:00
|
|
|
c.isOldBrowser = true if $.browser.mozilla && majorVersion < 21
|
|
|
|
c.isOldBrowser = true if $.browser.chrome && majorVersion < 17
|
2014-04-14 19:34:11 -04:00
|
|
|
c.isOldBrowser = true if $.browser.safari && majorVersion < 6
|
2014-01-03 13:32:13 -05:00
|
|
|
else
|
|
|
|
console.warn 'no more jquery browser version...'
|
2014-03-16 19:59:48 -04:00
|
|
|
c.isEnglish = (me.get('preferredLanguage') or 'en').startsWith 'en'
|
2014-04-09 01:50:13 -04:00
|
|
|
c.languageName = me.get('preferredLanguage')
|
2014-06-19 16:42:25 -04:00
|
|
|
c.codeLanguage = (me.get('aceConfig') ? {}).language or 'javascript'
|
2014-08-30 02:09:38 -04:00
|
|
|
c.codeLanguageCountMap = @codeLanguageCountMap
|
2014-01-03 13:32:13 -05:00
|
|
|
c
|
|
|
|
|
|
|
|
afterRender: ->
|
|
|
|
super()
|
2014-01-30 19:36:36 -05:00
|
|
|
@$el.find('.modal').on 'shown.bs.modal', ->
|
2014-01-03 13:32:13 -05:00
|
|
|
$('input:visible:first', @).focus()
|
|
|
|
|
2014-06-30 22:16:26 -04:00
|
|
|
# Try to find latest level and set 'Play' link to go to that level
|
|
|
|
lastLevel = me.get('lastLevel')
|
|
|
|
lastLevel ?= localStorage?['lastLevel'] # Temp, until it's migrated to user property
|
2014-03-21 20:42:13 -04:00
|
|
|
if lastLevel
|
2014-06-30 22:16:26 -04:00
|
|
|
playLink = @$el.find('#beginner-campaign')
|
2014-03-21 19:49:30 -04:00
|
|
|
if playLink[0]?
|
2014-06-30 22:16:26 -04:00
|
|
|
href = playLink.attr('href').split('/')
|
2014-03-21 19:49:30 -04:00
|
|
|
href[href.length-1] = lastLevel if href.length isnt 0
|
2014-06-30 22:16:26 -04:00
|
|
|
href = href.join('/')
|
|
|
|
playLink.attr('href', href)
|
2014-06-19 16:42:25 -04:00
|
|
|
|
|
|
|
codeLanguage = (me.get('aceConfig') ? {}).language or 'javascript'
|
|
|
|
@$el.find(".code-language[data-code-language=#{codeLanguage}]").addClass 'selected-language'
|
2014-06-19 17:55:16 -04:00
|
|
|
@updateLanguageLogos codeLanguage
|
|
|
|
|
|
|
|
updateLanguageLogos: (codeLanguage) ->
|
2014-07-18 23:14:41 -04:00
|
|
|
@$el.find('.game-mode-wrapper .code-language-logo').css('background-image', "url(/images/common/code_languages/#{codeLanguage}_small.png)")
|
2014-06-19 16:42:25 -04:00
|
|
|
|
|
|
|
onCodeLanguageSelected: (e) ->
|
|
|
|
target = $(e.target).closest('.code-language')
|
|
|
|
codeLanguage = target.data('code-language')
|
|
|
|
@$el.find('.code-language').removeClass 'selected-language'
|
|
|
|
target.addClass 'selected-language'
|
|
|
|
aceConfig = me.get('aceConfig') ? {}
|
|
|
|
return if (aceConfig.language or 'javascript') is codeLanguage
|
|
|
|
aceConfig.language = codeLanguage
|
|
|
|
me.set 'aceConfig', aceConfig
|
|
|
|
me.save() # me.patch() doesn't work if aceConfig previously existed and we switched just once
|
2014-06-19 17:55:16 -04:00
|
|
|
|
|
|
|
firstButton = @$el.find('#beginner-campaign .game-mode-wrapper').delay(500).addClass('hovered', 500).delay(500).removeClass('hovered', 500)
|
|
|
|
lastButton = @$el.find('#multiplayer .game-mode-wrapper').delay(1000).addClass('hovered', 500).delay(500).removeClass('hovered', 500)
|
|
|
|
$('#page-container').animate {scrollTop: firstButton.offset().top - 100, easing: 'easeInOutCubic'}, 500
|
|
|
|
@updateLanguageLogos codeLanguage
|
2014-08-30 02:09:38 -04:00
|
|
|
|
|
|
|
getCodeLanguageCounts: ->
|
|
|
|
@codeLanguageCountMap = {}
|
|
|
|
success = (codeLanguageCounts) =>
|
|
|
|
return if @destroyed
|
|
|
|
for codeLanguage in codeLanguageCounts
|
|
|
|
@codeLanguageCountMap[codeLanguage._id] = codeLanguage.sessions
|
|
|
|
@codeLanguageCountMap.javascript += @codeLanguageCountMap[null]
|
|
|
|
@render() if @supermodel.finished()
|
|
|
|
|
|
|
|
codeLanguageCountsRequest = @supermodel.addRequestResource 'play_counts', {
|
|
|
|
url: '/db/level.session/-/code_language_counts'
|
|
|
|
method: 'POST'
|
|
|
|
success: success
|
|
|
|
}, 0
|
|
|
|
codeLanguageCountsRequest.load()
|