Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add config to allow subdomain cookies #36

Merged
merged 2 commits into from
May 14, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ OuiBounce offers a few options, such as:
- [Timer](#set-a-min-time-before-ouibounce-fires)
- [Callback](#callback)
- [Cookie expiration](#cookie-expiration)
- [Cookie domain](#cookie-domain)
- [Sitewide cookie](#sitewide-cookie)
- [Chaining options](#chaining-options)

Expand Down Expand Up @@ -109,6 +110,21 @@ _Example:_
ouibounce(document.getElementById('ouibounce-modal'), { cookieExpire: 10 });
```

##### Cookie domain
Ouibounce sets a cookie by default to prevent the modal from appearing
more than once per user. You can add a cookie domain using
`cookieDomain` to specify the domain under which the cookie should work.
By default, no extra domain information will be added. If you need a
cookie to work also in your subdomain (like blog.example.com and
example.com), then set a cookieDomain such as .example.com (notice the
dot in front).

_Example:_
```js
ouibounce(document.getElementById('ouibounce-modal'), { cookieDomain:
'.example.com' });
```

##### Sitewide cookie
You can drop sitewide cookies by using this option.

Expand All @@ -125,6 +141,7 @@ _Example:_
ouibounce(document.getElementById('ouibounce-modal'), {
aggressive: true,
sitewide: true,
cookieDomain: '.example.com',
timer: 0,
callback: function() { console.log('ouibounce fired!'); }
});
Expand Down
12 changes: 10 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 + cookieDomain + sitewide;

// remove listeners
_html.removeEventListener('mouseout', handleMouseout);
_html.removeEventListener('keydown', handleKeydown);
Expand All @@ -105,6 +112,7 @@ return function ouibounce(el, config) {
disable: disable
};
}

;

}));
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.

12 changes: 10 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 + cookieDomain + sitewide;

// remove listeners
_html.removeEventListener('mouseout', handleMouseout);
_html.removeEventListener('keydown', handleKeydown);
Expand All @@ -93,3 +100,4 @@ function ouibounce(el, config) {
disable: disable
};
}

1 change: 0 additions & 1 deletion test/ouibounce.min.css

This file was deleted.