fix window blur and focus events

This commit is contained in:
Justin Palmer & Nathan Sobo
2013-02-05 12:03:56 -08:00
parent 44df146034
commit 65927ea0cf
3 changed files with 21 additions and 16 deletions

1
.pairs
View File

@@ -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

View File

@@ -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", ->

View File

@@ -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()