diff --git a/README.md b/README.md index d239fe1..b148ce0 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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. @@ -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!'); } }); diff --git a/build/ouibounce.js b/build/ouibounce.js index 5d72ab0..5326d99 100644 --- a/build/ouibounce.js +++ b/build/ouibounce.js @@ -100,7 +100,7 @@ return function ouibounce(el, config) { cookieDomain = options.cookieDomain; } - document.cookie = 'viewedOuibounceModal=true' + cookieExpire + ookieDomain + sitewide; + document.cookie = 'viewedOuibounceModal=true' + cookieExpire + cookieDomain + sitewide; // remove listeners _html.removeEventListener('mouseout', handleMouseout); @@ -112,6 +112,7 @@ return function ouibounce(el, config) { disable: disable }; } + ; })); diff --git a/build/ouibounce.min.js b/build/ouibounce.min.js index f0c89ea..b126916 100644 --- a/build/ouibounce.min.js +++ b/build/ouibounce.min.js @@ -1 +1 @@ -!function(e,o){"function"==typeof define&&define.amd?define(o):"object"==typeof exports?module.exports=o(require,exports,module):e.ouibounce=o()}(this,function(){return function(e,o){function i(e,o){return"undefined"==typeof e?o:e}function n(e){var o=24*e*60*60*1e3,i=new Date;return i.setTime(i.getTime()+o),"; expires="+i.toGMTString()}function t(){y.addEventListener("mouseout",u),y.addEventListener("keydown",r)}function u(e){e.clientY>s||c("viewedOuibounceModal","true")&&!f||(d(),p())}function r(e){b||c("viewedOuibounceModal","true")&&!f||e.metaKey&&76==e.keyCode&&(b=!0,d(),p())}function c(e,o){var i=document.cookie.split("; ").reduce(function(e,o){var i=o.split("=");return e[i[0]]=i[1],e},{});return i[e]===o}function d(){e&&(e.style.display="block"),a()}function a(e){var e=e||{};"undefined"!=typeof e.cookieExpire&&(v=n(e.cookieExpire)),"undefined"!=typeof e.sitewide&&(k=";path=/"),"undefined"!=typeof e.cookieDomain&&(l=e.cookieDomain),document.cookie="viewedOuibounceModal=true"+v+ookieDomain+k,y.removeEventListener("mouseout",u),y.removeEventListener("keydown",r)}var o=o||{},f=o.aggressive||!1,s=i(o.sensitivity,20),m=i(o.timer,1e3),p=o.callback||function(){},v=n(o.cookieExpire)||"",l=o.cookieDomain?";domain="+o.cookieDomain:"",k=o.sitewide===!0?";path=/":"",y=document.getElementsByTagName("html")[0];setTimeout(t,m);var b=!1;return{fire:d,disable:a}}}); \ No newline at end of file +!function(e,n){"function"==typeof define&&define.amd?define(n):"object"==typeof exports?module.exports=n(require,exports,module):e.ouibounce=n()}(this,function(){return function(e,n){function o(e,n){return"undefined"==typeof e?n:e}function i(e){var n=24*e*60*60*1e3,o=new Date;return o.setTime(o.getTime()+n),"; expires="+o.toGMTString()}function t(){y.addEventListener("mouseout",u),y.addEventListener("keydown",r)}function u(e){e.clientY>s||c("viewedOuibounceModal","true")&&!f||(d(),p())}function r(e){b||c("viewedOuibounceModal","true")&&!f||e.metaKey&&76==e.keyCode&&(b=!0,d(),p())}function c(e,n){var o=document.cookie.split("; ").reduce(function(e,n){var o=n.split("=");return e[o[0]]=o[1],e},{});return o[e]===n}function d(){e&&(e.style.display="block"),a()}function a(e){var e=e||{};"undefined"!=typeof e.cookieExpire&&(v=i(e.cookieExpire)),"undefined"!=typeof e.sitewide&&(k=";path=/"),"undefined"!=typeof e.cookieDomain&&(l=e.cookieDomain),document.cookie="viewedOuibounceModal=true"+v+l+k,y.removeEventListener("mouseout",u),y.removeEventListener("keydown",r)}var n=n||{},f=n.aggressive||!1,s=o(n.sensitivity,20),m=o(n.timer,1e3),p=n.callback||function(){},v=i(n.cookieExpire)||"",l=n.cookieDomain?";domain="+n.cookieDomain:"",k=n.sitewide===!0?";path=/":"",y=document.getElementsByTagName("html")[0];setTimeout(t,m);var b=!1;return{fire:d,disable:a}}}); \ No newline at end of file diff --git a/source/ouibounce.js b/source/ouibounce.js index ffa168c..d1e3d09 100644 --- a/source/ouibounce.js +++ b/source/ouibounce.js @@ -88,7 +88,7 @@ function ouibounce(el, config) { cookieDomain = options.cookieDomain; } - document.cookie = 'viewedOuibounceModal=true' + cookieExpire + ookieDomain + sitewide; + document.cookie = 'viewedOuibounceModal=true' + cookieExpire + cookieDomain + sitewide; // remove listeners _html.removeEventListener('mouseout', handleMouseout); @@ -100,3 +100,4 @@ function ouibounce(el, config) { disable: disable }; } +