Created
February 13, 2013 22:55
-
-
Save gmac/4949156 to your computer and use it in GitHub Desktop.
Click-off dismissal behavior for a component that should close upon any mouse click, touch, or resize.
This file contains 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 characters
require("nixable", [ | |
"jquery", | |
"underscore" | |
], function( $, _ ) { | |
return { | |
nixable: function( closeTest, closeCall, context ) { | |
var self = this; | |
// Clear any outstanding nix call: | |
if ( this._nix ) { | |
this._nix(); | |
} | |
// Store new nix call: | |
this._nix = _.bind( closeCall, context ); | |
// Nixable events: | |
var events = "mousedown.nix touchstart.nix resize.nix"; | |
// Configure nixable behavior: | |
var doc = $( document ) | |
.off( events ) | |
.on( events, function( evt ) { | |
if ( closeTest.call( context, evt ) ) { | |
doc.off( events ); | |
self._nix(); | |
self._nix = null; | |
} | |
}); | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment