This commit is contained in:
Scott Erickson 2014-06-13 13:35:57 -07:00
parent 8f4e1b4bf0
commit a1dd9a714e
4 changed files with 29 additions and 4 deletions

View file

@ -4,6 +4,7 @@ CocoClass = require 'lib/CocoClass'
loadingScreenTemplate = require 'templates/loading' loadingScreenTemplate = require 'templates/loading'
loadingErrorTemplate = require 'templates/loading_error' loadingErrorTemplate = require 'templates/loading_error'
lastToggleModalCall = 0
visibleModal = null visibleModal = null
waitingModal = null waitingModal = null
classCount = 0 classCount = 0
@ -15,9 +16,6 @@ module.exports = class CocoView extends Backbone.View
template: -> '' template: -> ''
events: events:
'click a': 'toggleModal'
'click button': 'toggleModal'
'click li': 'toggleModal'
'click .retry-loading-resource': 'onRetryResource' 'click .retry-loading-resource': 'onRetryResource'
'click .retry-loading-request': 'onRetryRequest' 'click .retry-loading-request': 'onRetryRequest'
@ -46,7 +44,6 @@ module.exports = class CocoView extends Backbone.View
@subviews = {} @subviews = {}
@listenToShortcuts() @listenToShortcuts()
@updateProgressBar = _.debounce @updateProgressBar, 100 @updateProgressBar = _.debounce @updateProgressBar, 100
@toggleModal = _.debounce @toggleModal, 100
# Backbone.Mediator handles subscription setup/teardown automatically # Backbone.Mediator handles subscription setup/teardown automatically
@listenTo(@supermodel, 'loaded-all', @onLoaded) @listenTo(@supermodel, 'loaded-all', @onLoaded)
@ -149,8 +146,16 @@ module.exports = class CocoView extends Backbone.View
$(e.target).closest('.loading-error-alert').remove() $(e.target).closest('.loading-error-alert').remove()
# Modals # Modals
@lastToggleModalCall = 0
toggleModal: (e) -> toggleModal: (e) ->
if new Date().getTime() - CocoView.lastToggleModalCall < 5
# Defensive move. This function has had a history of messing things up.
console.error 'toggleModal is getting called too often!'
return
CocoView.lastToggleModalCall = new Date().getTime()
if $(e.currentTarget).prop('target') is '_blank' if $(e.currentTarget).prop('target') is '_blank'
return true return true
# special handler for opening modals that are dynamically loaded, rather than static in the page. It works (or should work) like Bootstrap's modals, except use coco-modal for the data-toggle value. # special handler for opening modals that are dynamically loaded, rather than static in the page. It works (or should work) like Bootstrap's modals, except use coco-modal for the data-toggle value.

View file

@ -6,6 +6,11 @@ module.exports = class ModalView extends CocoView
closesOnClickOutside: true closesOnClickOutside: true
modalWidthPercent: null modalWidthPercent: null
plain: false plain: false
events:
'click a': 'toggleModal'
'click button': 'toggleModal'
'click li': 'toggleModal'
shortcuts: shortcuts:
'esc': 'hide' 'esc': 'hide'

View file

@ -22,6 +22,9 @@ module.exports = class RootView extends CocoView
'change .language-dropdown': 'onLanguageChanged' 'change .language-dropdown': 'onLanguageChanged'
'click .toggle-fullscreen': 'toggleFullscreen' 'click .toggle-fullscreen': 'toggleFullscreen'
'click .auth-button': 'onClickAuthbutton' 'click .auth-button': 'onClickAuthbutton'
'click a': 'toggleModal'
'click button': 'toggleModal'
'click li': 'toggleModal'
subscriptions: subscriptions:
'achievements:new': 'handleNewAchievements' 'achievements:new': 'handleNewAchievements'

View file

@ -0,0 +1,12 @@
AuthModalView = require 'views/modal/auth_modal'
RecoverModalView = require 'views/modal/recover_modal'
describe 'AuthModalView', ->
it 'opens the recover modal when you click the recover link', ->
m = new AuthModalView()
m.render()
spyOn(m, 'openModalView')
m.$el.find('#link-to-recover').click()
expect(m.openModalView.calls.count()).toEqual(1)
args = m.openModalView.calls.argsFor(0)
expect(args[0] instanceof RecoverModalView).toBeTruthy()