From 0d3498c2ba714377b15e4aa2079e61d08e9ae74c Mon Sep 17 00:00:00 2001 From: Luis Merino Date: Tue, 13 May 2014 19:11:19 +0200 Subject: [PATCH] Add config to allow subdomain cookies --- build/ouibounce.js | 11 +++++++++-- build/ouibounce.min.js | 2 +- source/ouibounce.js | 11 +++++++++-- test/ouibounce.min.css | 1 - 4 files changed, 19 insertions(+), 6 deletions(-) delete mode 100644 test/ouibounce.min.css diff --git a/build/ouibounce.js b/build/ouibounce.js index 12ef79f..5d72ab0 100644 --- a/build/ouibounce.js +++ b/build/ouibounce.js @@ -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]; @@ -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); diff --git a/build/ouibounce.min.js b/build/ouibounce.min.js index 6c3f4bd..f0c89ea 100644 --- a/build/ouibounce.min.js +++ b/build/ouibounce.min.js @@ -1 +1 @@ -!function(e,t){"function"==typeof define&&define.amd?define(t):"object"==typeof exports?module.exports=t(require,exports,module):e.ouibounce=t()}(this,function(){return function(e,t){function n(e,t){return"undefined"==typeof e?t:e}function i(e){var t=24*e*60*60*1e3,n=new Date;return n.setTime(n.getTime()+t),"; expires="+n.toGMTString()}function o(){y.addEventListener("mouseout",u),y.addEventListener("keydown",r)}function u(e){e.clientY>a||d("viewedOuibounceModal","true")&&!s||(c(),p())}function r(e){k||d("viewedOuibounceModal","true")&&!s||e.metaKey&&76==e.keyCode&&(k=!0,c(),p())}function d(e,t){var n=document.cookie.split("; ").reduce(function(e,t){var n=t.split("=");return e[n[0]]=n[1],e},{});return n[e]===t}function c(){e&&(e.style.display="block"),f()}function f(e){var e=e||{};"undefined"!=typeof e.cookieExpire&&(v=i(e.cookieExpire)),"undefined"!=typeof e.sitewide&&(l=";path=/"),document.cookie="viewedOuibounceModal=true"+v+l,y.removeEventListener("mouseout",u),y.removeEventListener("keydown",r)}var t=t||{},s=t.aggressive||!1,a=n(t.sensitivity,20),m=n(t.timer,1e3),p=t.callback||function(){},v=i(t.cookieExpire)||"",l=t.sitewide===!0?";path=/":"",y=document.getElementsByTagName("html")[0];setTimeout(o,m);var k=!1;return{fire:c,disable:f}}}); \ No newline at end of file +!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 diff --git a/source/ouibounce.js b/source/ouibounce.js index b4f1a2e..ffa168c 100644 --- a/source/ouibounce.js +++ b/source/ouibounce.js @@ -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]; @@ -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); diff --git a/test/ouibounce.min.css b/test/ouibounce.min.css deleted file mode 100644 index 041565f..0000000 --- a/test/ouibounce.min.css +++ /dev/null @@ -1 +0,0 @@ -#ouibounce-modal{font-family:'Open Sans',sans-serif;display:none;position:fixed;top:0;left:0;width:100%;height:100%}#ouibounce-modal .underlay{width:100%;height:100%;position:absolute;top:0;left:0;background-color:rgba(0,0,0,.5);cursor:pointer;-webkit-animation:fadein .5s;animation:fadein .5s}#ouibounce-modal .modal{width:600px;height:400px;background-color:#f0f1f2;z-index:1;position:absolute;margin:auto;top:0;right:0;bottom:0;left:0;border-radius:4px;-webkit-animation:popin .3s;animation:popin .3s}#ouibounce-modal .modal-title{font-size:18px;background-color:#252525;color:#fff;padding:10px;margin:0;border-radius:4px 4px 0 0;text-align:center}#ouibounce-modal h3{color:#fff;font-size:1em;margin:.2em;text-transform:uppercase;font-weight:500}#ouibounce-modal .modal-body{padding:20px 35px;font-size:.9em}#ouibounce-modal p{color:#344a5f}#ouibounce-modal form{text-align:center;margin-top:35px}#ouibounce-modal form input[type=text]{padding:12px;font-size:1.2em;width:300px;border-radius:4px;border:1px solid #ccc;-webkit-font-smoothing:antialiased}#ouibounce-modal form input[type=submit]{text-transform:uppercase;font-weight:700;padding:12px;font-size:1.1em;border-radius:4px;color:#fff;background-color:#4ab471;border:0;cursor:pointer;-webkit-font-smoothing:antialiased}#ouibounce-modal form p{text-align:left;margin-left:35px;opacity:.8;margin-top:1px;padding-top:1px;font-size:.9em}#ouibounce-modal .modal-footer{position:absolute;bottom:20px;text-align:center;width:100%}#ouibounce-modal .modal-footer p{text-transform:capitalize;cursor:pointer;display:inline;border-bottom:1px solid #344a5f}@-webkit-keyframes fadein{0%{opacity:0}100%{opacity:1}}@-ms-keyframes fadein{0%{opacity:0}100%{opacity:1}}@keyframes fadein{0%{opacity:0}100%{opacity:1}}@-webkit-keyframes popin{0%{-webkit-transform:scale(0);transform:scale(0);opacity:0}85%{-webkit-transform:scale(1.05);transform:scale(1.05);opacity:1}100%{-webkit-transform:scale(1);transform:scale(1);opacity:1}}@-ms-keyframes popin{0%{-ms-transform:scale(0);transform:scale(0);opacity:0}85%{-ms-transform:scale(1.05);transform:scale(1.05);opacity:1}100%{-ms-transform:scale(1);transform:scale(1);opacity:1}}@keyframes popin{0%{-webkit-transform:scale(0);-ms-transform:scale(0);transform:scale(0);opacity:0}85%{-webkit-transform:scale(1.05);-ms-transform:scale(1.05);transform:scale(1.05);opacity:1}100%{-webkit-transform:scale(1);-ms-transform:scale(1);transform:scale(1);opacity:1}} \ No newline at end of file