Skip to content

Commit

Permalink
Add config to allow subdomain cookies
Browse files Browse the repository at this point in the history
  • Loading branch information
Rendez committed May 13, 2014
1 parent 3667454 commit 0d3498c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
11 changes: 9 additions & 2 deletions build/ouibounce.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ return function ouibounce(el, config) {
timer = setDefault(config.timer, 1000),
callback = config.callback || function() {},
cookieExpire = setDefaultCookieExpire(config.cookieExpire) || '',
cookieDomain = config.cookieDomain ? ';domain=' + config.cookieDomain : '',
sitewide = config.sitewide === true ? ';path=/' : '',
_html = document.getElementsByTagName('html')[0];

Expand Down Expand Up @@ -93,8 +94,14 @@ return function ouibounce(el, config) {
sitewide = ';path=/';
}

document.cookie = 'viewedOuibounceModal=true' + cookieExpire + sitewide;

// you can pass a domain string, for example when the cookie should be
// read subdomain-wise, e.g.: .example.com
if (typeof options.cookieDomain !== 'undefined') {
cookieDomain = options.cookieDomain;
}

document.cookie = 'viewedOuibounceModal=true' + cookieExpire + ookieDomain + sitewide;

// remove listeners
_html.removeEventListener('mouseout', handleMouseout);
_html.removeEventListener('keydown', handleKeydown);
Expand Down
2 changes: 1 addition & 1 deletion build/ouibounce.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions source/ouibounce.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ function ouibounce(el, config) {
timer = setDefault(config.timer, 1000),
callback = config.callback || function() {},
cookieExpire = setDefaultCookieExpire(config.cookieExpire) || '',
cookieDomain = config.cookieDomain ? ';domain=' + config.cookieDomain : '',
sitewide = config.sitewide === true ? ';path=/' : '',
_html = document.getElementsByTagName('html')[0];

Expand Down Expand Up @@ -81,8 +82,14 @@ function ouibounce(el, config) {
sitewide = ';path=/';
}

document.cookie = 'viewedOuibounceModal=true' + cookieExpire + sitewide;

// you can pass a domain string, for example when the cookie should be
// read subdomain-wise, e.g.: .example.com
if (typeof options.cookieDomain !== 'undefined') {
cookieDomain = options.cookieDomain;
}

document.cookie = 'viewedOuibounceModal=true' + cookieExpire + ookieDomain + sitewide;

// remove listeners
_html.removeEventListener('mouseout', handleMouseout);
_html.removeEventListener('keydown', handleKeydown);
Expand Down
1 change: 0 additions & 1 deletion test/ouibounce.min.css

This file was deleted.

0 comments on commit 0d3498c

Please sign in to comment.