From ea1b7b3984f0f2eebd5ae5ced1a54b97ba0083bd Mon Sep 17 00:00:00 2001 From: Tex Andersen Date: Fri, 3 Feb 2017 09:38:40 +1000 Subject: [PATCH 1/2] add inactive property and the ability to toggle it --- js/bioep.js | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/js/bioep.js b/js/bioep.js index 6241207..cef9612 100644 --- a/js/bioep.js +++ b/js/bioep.js @@ -4,9 +4,10 @@ window.bioEp = { popupEl: {}, closeBtnEl: {}, shown: false, + inactive: false, overflowDefault: "visible", transformDefault: "", - + // Popup options width: 400, height: 220, @@ -18,14 +19,14 @@ window.bioEp = { cookieExp: 30, showOncePerSession: false, onPopup: null, - + // Object for handling cookies, taken from QuirksMode // http://www.quirksmode.org/js/cookies.html cookieManager: { // Create a cookie create: function(name, value, days, sessionOnly) { var expires = ""; - + if(sessionOnly) expires = "; expires=0" else if(days) { @@ -33,30 +34,30 @@ window.bioEp = { date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); expires = "; expires=" + date.toGMTString(); } - + document.cookie = name + "=" + value + expires + "; path=/"; }, - + // Get the value of a cookie get: function(name) { var nameEQ = name + "="; var ca = document.cookie.split(";"); - + for(var i = 0; i < ca.length; i++) { var c = ca[i]; while (c.charAt(0) == " ") c = c.substring(1, c.length); if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length); } - + return null; }, - + // Delete a cookie erase: function(name) { this.create(name, "", -1); } }, - + // Handle the bioep_shown cookie // If present and true, return true // If not present or false, create and return false @@ -137,7 +138,7 @@ window.bioEp = { // Show the popup showPopup: function() { - if(this.shown) return; + if(this.shown || this.inactive) return; this.bgEl.style.display = "block"; this.popupEl.style.display = "block"; @@ -150,10 +151,10 @@ window.bioEp = { document.body.style.overflow = "hidden"; this.shown = true; - + this.cookieManager.create("bioep_shown", "true", this.cookieExp, false); this.cookieManager.create("bioep_shown_session", "true", 0, true); - + if(typeof this.onPopup === "function") { this.onPopup(); } @@ -210,6 +211,11 @@ window.bioEp = { this.popupEl.style.transform = this.transformDefault + " scale(" + scaleTo + ")"; }, + // Toggle whether or not the popup is active + toggleActive: function() { + this.inactive = !this.inactive; + }, + // Event listener initialisation for all browsers addEvent: function (obj, event, callback) { if(obj.addEventListener) From d5bdc3d9f6ae1d1b2baa0ef856c39708cf27f775 Mon Sep 17 00:00:00 2001 From: Tex Andersen Date: Fri, 3 Feb 2017 09:41:21 +1000 Subject: [PATCH 2/2] update README.md with functionality --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4bd2208..9eaa775 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ exit-intent-popup * Cookie support with optional expiry date. * Set a timed delay before the script starts tracking exit intent. * Display popup based on exit intent or timed delay. +* Popup can be enabled and disabled after initialization. * Scales to adjust to window size. # Usage @@ -36,7 +37,7 @@ You can also add HTML and CSS directly on the page. The popup element you wish // Options }); - +