-
-
Save koriroys/74a6b9eb117ed7dbe2af to your computer and use it in GitHub Desktop.
Revisions
-
alexspeller revised this gist
Apr 10, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,7 +6,7 @@ App.ClickElsewhereMixin = Ember.Mixin.create #bound version of our instance method clickHandler: Em.computed -> Em.run.bind @, 'onClickElsewhere' #logic for determining of a click has landed anywhere but our view elsewhereHandler: (e) -> -
alexspeller revised this gist
Apr 7, 2015 . 1 changed file with 5 additions and 9 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,14 +1,12 @@ #original attribution https://gist.github.com/alexspeller/6251054 & https://gist.github.com/stevekane/6356006 App.ClickElsewhereMixin = Ember.Mixin.create #use this method hook to define your desired behavior onClickElsewhere: Ember.K #bound version of our instance method clickHandler: Em.computed -> @onClickElsewhere.bind(@) #logic for determining of a click has landed anywhere but our view elsewhereHandler: (e) -> @@ -18,11 +16,9 @@ App.ClickElsewhereMixin = Ember.Mixin.create unless thisIsElement then @onClickElsewhere event #attach event listener to window when view in DOM setupClickEvent: Em.on 'didInsertElement', -> $(window).on "click", @get "clickHandler" #remove window event listener when view removed from DOM teardownClickEvent: Em.on 'willDestroyElement', -> $(window).off "click", @get "clickHandler" -
stevekane created this gist
Aug 27, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,28 @@ #original attribution https://gist.github.com/alexspeller/6251054 bound = (fnName) -> Ember.computed fnName -> @get(fnName).bind(@) App.ClickElsewhereMixin = Ember.Mixin.create #use this method hook to define your desired behavior onClickElsewhere: Ember.K #bound version of our instance method clickHandler: bound "elsewhereHandler" #logic for determining of a click has landed anywhere but our view elsewhereHandler: (e) -> element = @get "element" $target = $ e.target thisIsElement = $target.closest(element).length is 1 unless thisIsElement then @onClickElsewhere event #attach event listener to window when view in DOM didInsertElement: -> @_super.apply(@, arguments) $(window).on "click", @get "clickHandler" #remove window event listener when view removed from DOM willDestroyElement: -> $(window).off "click", @get "clickHandler" @_super.apply(@, arguments)