Skip to content

Commit

Permalink
Add handleKeydown
Browse files Browse the repository at this point in the history
  • Loading branch information
schonfeld authored and carlsednaoui committed May 2, 2014
1 parent e4ad4a5 commit 1f8896e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion source/ouibounce.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function ouiBounce(el, config) {
callback = config.callback || function() {},
cookieExpire = setDefaultCookieExpire(config.cookieExpire) || '',
_html = document.getElementsByTagName('html')[0];

function setDefault(_property, _default) {
return typeof _property === 'undefined' ? _default : _property;
}
Expand All @@ -24,6 +24,7 @@ function ouiBounce(el, config) {
setTimeout(attachOuiBounce, timer);
function attachOuiBounce() {
_html.addEventListener('mouseout', handleMouseout);
_html.addEventListener('keydown', handleKeydown);
}

function handleMouseout(e) {
Expand All @@ -32,6 +33,14 @@ function ouiBounce(el, config) {
callback();
}

function handleKeydown(e) {
if(checkCookieValue('viewedOuibounceModal', 'true') && !aggressive) return;
else if(!e.metaKey || e.keyCode != 76) return;

fire();
callback();
}

function checkCookieValue(cookieName, value) {
// cookies are separated by '; '
var cookies = document.cookie.split('; ').reduce(function(prev, curr) {
Expand Down
2 changes: 1 addition & 1 deletion test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>

<!-- Add OuiBounce JS -->
<script src="../build/ouibounce.js"></script>
<script src="../source/ouibounce.js"></script>
</head>

<body>
Expand Down

0 comments on commit 1f8896e

Please sign in to comment.