add onBlur and onFocus events for the window

This allows us to simulate those events and test for them easier
This commit is contained in:
Justin Palmer
2013-02-05 10:53:35 -08:00
parent 9011d62351
commit 22770bd663
2 changed files with 15 additions and 3 deletions

View File

@@ -15,10 +15,11 @@ describe "Window", ->
describe "window is loaded", ->
it "doesn't have .is-blurred on the body tag", ->
$(window).trigger 'window:focus'
expect($("body").hasClass("is-blurred")).toBe false
it "does have .is-blurred on the window blur event", ->
$(window).blur()
$(window).trigger 'window:blur'
expect($("body").hasClass("is-blurred")).toBe true
describe ".close()", ->

View File

@@ -28,8 +28,12 @@ windowAdditions =
$(window).on 'core:close', => @close()
$(window).command 'window:close', => @close()
$(window).on 'focus', -> $("body").removeClass('is-blurred')
$(window).on 'blur', -> $("body").addClass('is-blurred')
$(window).on 'window:focus', onFocus
$(window).on 'window:blur', onBlur
$(window).on 'focus', -> $(@).trigger 'window:focus'
$(window).on 'blur', -> $(@).trigger 'window:blur'
# This method is intended only to be run when starting a normal application
# Note: RootView assigns itself on window on initialization so that
@@ -102,6 +106,13 @@ windowAdditions =
onerror: ->
atom.showDevTools()
onFocus: (event) =>
console.log 'focused'
$('body').removeClass 'is-blurred'
onBlur: (event) =>
$('body').addClass 'is-blurred'
measure: (description, fn) ->
start = new Date().getTime()
value = fn()