From a1dd9a714e3af2854aaead7ff032141d5af1ec93 Mon Sep 17 00:00:00 2001 From: Scott Erickson Date: Fri, 13 Jun 2014 13:35:57 -0700 Subject: [PATCH] Fixed #1153. --- app/views/kinds/CocoView.coffee | 13 +++++++++---- app/views/kinds/ModalView.coffee | 5 +++++ app/views/kinds/RootView.coffee | 3 +++ test/app/views/modal/AuthModalView.spec.coffee | 12 ++++++++++++ 4 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 test/app/views/modal/AuthModalView.spec.coffee diff --git a/app/views/kinds/CocoView.coffee b/app/views/kinds/CocoView.coffee index 468176927..616fd7847 100644 --- a/app/views/kinds/CocoView.coffee +++ b/app/views/kinds/CocoView.coffee @@ -4,6 +4,7 @@ CocoClass = require 'lib/CocoClass' loadingScreenTemplate = require 'templates/loading' loadingErrorTemplate = require 'templates/loading_error' +lastToggleModalCall = 0 visibleModal = null waitingModal = null classCount = 0 @@ -15,9 +16,6 @@ module.exports = class CocoView extends Backbone.View template: -> '' events: - 'click a': 'toggleModal' - 'click button': 'toggleModal' - 'click li': 'toggleModal' 'click .retry-loading-resource': 'onRetryResource' 'click .retry-loading-request': 'onRetryRequest' @@ -46,7 +44,6 @@ module.exports = class CocoView extends Backbone.View @subviews = {} @listenToShortcuts() @updateProgressBar = _.debounce @updateProgressBar, 100 - @toggleModal = _.debounce @toggleModal, 100 # Backbone.Mediator handles subscription setup/teardown automatically @listenTo(@supermodel, 'loaded-all', @onLoaded) @@ -149,8 +146,16 @@ module.exports = class CocoView extends Backbone.View $(e.target).closest('.loading-error-alert').remove() # Modals + + @lastToggleModalCall = 0 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' 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. diff --git a/app/views/kinds/ModalView.coffee b/app/views/kinds/ModalView.coffee index 26a32081a..a5e3e49ed 100644 --- a/app/views/kinds/ModalView.coffee +++ b/app/views/kinds/ModalView.coffee @@ -6,6 +6,11 @@ module.exports = class ModalView extends CocoView closesOnClickOutside: true modalWidthPercent: null plain: false + + events: + 'click a': 'toggleModal' + 'click button': 'toggleModal' + 'click li': 'toggleModal' shortcuts: 'esc': 'hide' diff --git a/app/views/kinds/RootView.coffee b/app/views/kinds/RootView.coffee index 2ef78f7f7..899c0aaa7 100644 --- a/app/views/kinds/RootView.coffee +++ b/app/views/kinds/RootView.coffee @@ -22,6 +22,9 @@ module.exports = class RootView extends CocoView 'change .language-dropdown': 'onLanguageChanged' 'click .toggle-fullscreen': 'toggleFullscreen' 'click .auth-button': 'onClickAuthbutton' + 'click a': 'toggleModal' + 'click button': 'toggleModal' + 'click li': 'toggleModal' subscriptions: 'achievements:new': 'handleNewAchievements' diff --git a/test/app/views/modal/AuthModalView.spec.coffee b/test/app/views/modal/AuthModalView.spec.coffee new file mode 100644 index 000000000..4cddd2a9e --- /dev/null +++ b/test/app/views/modal/AuthModalView.spec.coffee @@ -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() \ No newline at end of file