2016-07-15 01:43:25 -04:00
|
|
|
template = require 'templates/play/level/tome/spell-top-bar-view'
|
2014-11-08 11:38:25 -05:00
|
|
|
ReloadLevelModal = require 'views/play/level/modal/ReloadLevelModal'
|
2016-07-15 01:43:25 -04:00
|
|
|
CocoView = require 'views/core/CocoView'
|
2016-07-16 16:11:43 -04:00
|
|
|
ImageGalleryModal = require 'views/play/level/modal/ImageGalleryModal'
|
2014-01-03 13:32:13 -05:00
|
|
|
|
2016-07-15 01:43:25 -04:00
|
|
|
module.exports = class SpellTopBarView extends CocoView
|
2014-01-03 13:32:13 -05:00
|
|
|
template: template
|
2016-07-15 01:43:25 -04:00
|
|
|
id: 'spell-top-bar-view'
|
|
|
|
controlsEnabled: true
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
subscriptions:
|
2014-08-27 15:24:03 -04:00
|
|
|
'level:disable-controls': 'onDisableControls'
|
|
|
|
'level:enable-controls': 'onEnableControls'
|
2014-06-30 22:16:26 -04:00
|
|
|
'tome:spell-loaded': 'onSpellLoaded'
|
|
|
|
'tome:spell-changed': 'onSpellChanged'
|
2014-06-26 01:56:39 -04:00
|
|
|
'tome:spell-changed-language': 'onSpellChangedLanguage'
|
2014-08-27 21:43:17 -04:00
|
|
|
'tome:toggle-maximize': 'onToggleMaximize'
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
events:
|
|
|
|
'click .reload-code': 'onCodeReload'
|
2014-02-22 20:18:58 -05:00
|
|
|
'click .beautify-code': 'onBeautifyClick'
|
2014-08-27 21:43:17 -04:00
|
|
|
'click .fullscreen-code': 'onToggleMaximize'
|
2016-05-26 20:46:49 -04:00
|
|
|
'click .hints-button': 'onClickHintsButton'
|
2016-07-16 16:11:43 -04:00
|
|
|
'click .image-gallery-button': 'onClickImageGalleryButton'
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
constructor: (options) ->
|
2016-05-26 20:46:49 -04:00
|
|
|
@hintsState = options.hintsState
|
2016-07-15 01:43:25 -04:00
|
|
|
@spell = options.spell
|
2016-05-26 20:46:49 -04:00
|
|
|
super(options)
|
2014-01-03 13:32:13 -05:00
|
|
|
|
2014-02-11 17:58:45 -05:00
|
|
|
getRenderData: (context={}) ->
|
2014-01-03 13:32:13 -05:00
|
|
|
context = super context
|
2014-08-27 20:26:56 -04:00
|
|
|
ctrl = if @isMac() then 'Cmd' else 'Ctrl'
|
|
|
|
shift = $.i18n.t 'keyboard_shortcuts.shift'
|
|
|
|
context.beautifyShortcutVerbose = "#{ctrl}+#{shift}+B: #{$.i18n.t 'keyboard_shortcuts.beautify'}"
|
|
|
|
context.maximizeShortcutVerbose = "#{ctrl}+#{shift}+M: #{$.i18n.t 'keyboard_shortcuts.maximize_editor'}"
|
2014-09-24 19:29:28 -04:00
|
|
|
context.codeLanguage = @options.codeLanguage
|
2014-01-03 13:32:13 -05:00
|
|
|
context
|
|
|
|
|
|
|
|
afterRender: ->
|
|
|
|
super()
|
2016-07-29 14:21:57 -04:00
|
|
|
@$el.addClass 'spell-tab'
|
2014-07-23 09:50:47 -04:00
|
|
|
@attachTransitionEventListener()
|
2014-01-03 13:32:13 -05:00
|
|
|
|
2014-07-23 08:38:12 -04:00
|
|
|
onDisableControls: (e) -> @toggleControls e, false
|
|
|
|
onEnableControls: (e) -> @toggleControls e, true
|
2014-01-03 13:32:13 -05:00
|
|
|
|
2016-07-16 16:11:43 -04:00
|
|
|
onClickImageGalleryButton: (e) ->
|
|
|
|
@openModalView new ImageGalleryModal()
|
|
|
|
|
2016-05-26 20:46:49 -04:00
|
|
|
onClickHintsButton: ->
|
|
|
|
return unless @hintsState?
|
|
|
|
@hintsState.set('hidden', not @hintsState.get('hidden'))
|
|
|
|
window.tracker?.trackEvent 'Hints Clicked', category: 'Students', levelSlug: @options.level.get('slug'), hintCount: @hintsState.get('hints')?.length ? 0, ['Mixpanel']
|
|
|
|
|
2014-08-27 20:26:56 -04:00
|
|
|
onCodeReload: (e) ->
|
2016-07-15 01:43:25 -04:00
|
|
|
@openModalView new ReloadLevelModal()
|
2014-11-08 11:38:25 -05:00
|
|
|
|
2014-08-27 20:26:56 -04:00
|
|
|
onBeautifyClick: (e) ->
|
2014-02-24 14:21:51 -05:00
|
|
|
return unless @controlsEnabled
|
2014-08-27 15:24:03 -04:00
|
|
|
Backbone.Mediator.publish 'tome:spell-beautify', spell: @spell
|
2014-02-22 20:18:58 -05:00
|
|
|
|
2014-08-27 21:43:17 -04:00
|
|
|
onToggleMaximize: (e) ->
|
2014-08-14 16:29:57 -04:00
|
|
|
$codearea = $('html')
|
|
|
|
$('#code-area').css 'z-index', 20 unless $codearea.hasClass 'fullscreen-editor'
|
|
|
|
$('html').toggleClass 'fullscreen-editor'
|
2014-07-23 08:38:12 -04:00
|
|
|
$('.fullscreen-code').toggleClass 'maximized'
|
2014-08-27 21:43:17 -04:00
|
|
|
Backbone.Mediator.publish 'tome:maximize-toggled', {}
|
2014-07-09 16:41:42 -04:00
|
|
|
|
2014-01-03 13:32:13 -05:00
|
|
|
updateReloadButton: ->
|
|
|
|
changed = @spell.hasChanged null, @spell.getSource()
|
|
|
|
@$el.find('.reload-code').css('display', if changed then 'inline-block' else 'none')
|
|
|
|
|
|
|
|
onSpellLoaded: (e) ->
|
|
|
|
return unless e.spell is @spell
|
|
|
|
@updateReloadButton()
|
|
|
|
|
|
|
|
onSpellChanged: (e) ->
|
|
|
|
return unless e.spell is @spell
|
|
|
|
@updateReloadButton()
|
|
|
|
|
2014-06-26 01:56:39 -04:00
|
|
|
onSpellChangedLanguage: (e) ->
|
|
|
|
return unless e.spell is @spell
|
2014-09-24 19:29:28 -04:00
|
|
|
@options.codeLanguage = e.language
|
2014-06-26 01:56:39 -04:00
|
|
|
@render()
|
2014-09-24 19:29:28 -04:00
|
|
|
@updateReloadButton()
|
2014-06-26 01:56:39 -04:00
|
|
|
|
2014-01-03 13:32:13 -05:00
|
|
|
toggleControls: (e, enabled) ->
|
|
|
|
return if e.controls and not ('editor' in e.controls)
|
|
|
|
return if enabled is @controlsEnabled
|
|
|
|
@controlsEnabled = enabled
|
|
|
|
@$el.toggleClass 'read-only', not enabled
|
2014-02-11 15:02:49 -05:00
|
|
|
|
2014-07-23 09:50:47 -04:00
|
|
|
attachTransitionEventListener: =>
|
|
|
|
transitionListener = ''
|
|
|
|
testEl = document.createElement 'fakeelement'
|
2014-08-27 15:24:03 -04:00
|
|
|
transitions =
|
2014-07-23 09:50:47 -04:00
|
|
|
'transition':'transitionend'
|
|
|
|
'OTransition':'oTransitionEnd'
|
|
|
|
'MozTransition':'transitionend'
|
|
|
|
'WebkitTransition':'webkitTransitionEnd'
|
|
|
|
for transition, transitionEvent of transitions
|
|
|
|
unless testEl.style[transition] is undefined
|
|
|
|
transitionListener = transitionEvent
|
|
|
|
break
|
|
|
|
$codearea = $('#code-area')
|
|
|
|
$codearea.on transitionListener, =>
|
2015-04-07 11:55:33 -04:00
|
|
|
$codearea.css 'z-index', 2 unless $('html').hasClass 'fullscreen-editor'
|
2014-07-23 09:50:47 -04:00
|
|
|
|
2014-02-11 15:02:49 -05:00
|
|
|
destroy: ->
|
2014-02-12 21:54:45 -05:00
|
|
|
super()
|