Skip to content

Commit

Permalink
Merge branch 'proudsugar-feature-cookie-domain'
Browse files Browse the repository at this point in the history
  • Loading branch information
carlsednaoui committed May 14, 2014
2 parents 39a69d6 + 07513dd commit a630f1a
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 5 deletions.
23 changes: 23 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 passing `sitewide: true`.

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 All @@ -142,6 +159,12 @@ modal.disable() // disable ouibounce, it will not fire on page exit
modal.disable({ cookieExpire: 50, sitewide: true }) // disable ouibounce sitewide for 50 days.
```

##### Disable options
The `disable` function accepts a few options:
- [Cookie expiration](#cookie-expiration)
- [Cookie domain](#cookie-domain)
- [Sitewide cookie](#sitewide-cookie)

### Using Ouibounce with other libraries
If you want to use this library with other plugins — such as [Vex](http://github.hubspot.com/vex/docs/welcome/) — you can call ouibounce with `false`. See [#30](https://github.com/carlsednaoui/ouibounce/issues/30) for discussion.

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 when the cookie should be read subdomain-wise
// ex: _ouiBounce.disable({ cookieDomain: '.example.com' });
if (typeof options.cookieDomain !== 'undefined') {
cookieDomain = ';domain=' + 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.

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 when the cookie should be read subdomain-wise
// ex: _ouiBounce.disable({ cookieDomain: '.example.com' });
if (typeof options.cookieDomain !== 'undefined') {
cookieDomain = ';domain=' + options.cookieDomain;
}

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

// remove listeners
_html.removeEventListener('mouseout', handleMouseout);
_html.removeEventListener('keydown', handleKeydown);
Expand Down

0 comments on commit a630f1a

Please sign in to comment.