From 65927ea0cf0beb60e4c3104faf9404778896c9b8 Mon Sep 17 00:00:00 2001 From: Justin Palmer & Nathan Sobo Date: Tue, 5 Feb 2013 12:03:56 -0800 Subject: [PATCH] fix window blur and focus events --- .pairs | 1 + spec/app/window-spec.coffee | 22 ++++++++++++++++------ src/app/window.coffee | 14 ++++---------- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/.pairs b/.pairs index c939edd3c..ec4f2417c 100644 --- a/.pairs +++ b/.pairs @@ -5,6 +5,7 @@ pairs: ks: Kevin Sawicki; kevin jc: Jerry Cheung; jerry bl: Brian Lopez; brian + jp: Justin Palmer; justin email: domain: github.com #global: true diff --git a/spec/app/window-spec.coffee b/spec/app/window-spec.coffee index 2fbff2c40..25855e6de 100644 --- a/spec/app/window-spec.coffee +++ b/spec/app/window-spec.coffee @@ -13,14 +13,24 @@ describe "Window", -> atom.setRootViewStateForPath(rootView.project.getPath(), null) $(window).off 'beforeunload' - describe "window is loaded", -> + describe "when the window is loaded", -> it "doesn't have .is-blurred on the body tag", -> - $(window).trigger 'window:focus' - expect($("body").hasClass("is-blurred")).toBe false + expect($("body")).not.toHaveClass("is-blurred") - it "does have .is-blurred on the window blur event", -> - $(window).trigger 'window:blur' - expect($("body").hasClass("is-blurred")).toBe true + fdescribe "when the window is blurred", -> + beforeEach -> + $(window).trigger 'blur' + + afterEach -> + $('body').removeClass('is-blurred') + + it "adds the .is-blurred class on the body", -> + expect($("body")).toHaveClass("is-blurred") + + describe "when the window is focused again", -> + it "removes the .is-blurred class from the body", -> + $(window).trigger 'focus' + expect($("body")).not.toHaveClass("is-blurred") describe ".close()", -> it "is triggered by the 'core:close' event", -> diff --git a/src/app/window.coffee b/src/app/window.coffee index 1a707f905..cc465aa47 100644 --- a/src/app/window.coffee +++ b/src/app/window.coffee @@ -29,11 +29,11 @@ windowAdditions = $(window).on 'core:close', => @close() $(window).command 'window:close', => @close() - $(window).on 'window:focus', onFocus - $(window).on 'window:blur', onBlur + $(window).on 'focus', -> + $('body').removeClass 'is-blurred' - $(window).on 'focus', -> $(@).trigger 'window:focus' - $(window).on 'blur', -> $(@).trigger 'window:blur' + $(window).on 'blur', -> + $('body').addClass 'is-blurred' # This method is intended only to be run when starting a normal application # Note: RootView assigns itself on window on initialization so that @@ -106,12 +106,6 @@ windowAdditions = onerror: -> atom.showDevTools() - onFocus: (event) => - $('body').removeClass 'is-blurred' - - onBlur: (event) => - $('body').addClass 'is-blurred' - measure: (description, fn) -> start = new Date().getTime() value = fn()