diff --git a/js/bioep.js b/js/bioep.js index be9dbf5..6241207 100644 --- a/js/bioep.js +++ b/js/bioep.js @@ -6,10 +6,6 @@ window.bioEp = { shown: false, overflowDefault: "visible", transformDefault: "", - mouse: { - curY: 0, - lastY: 0 - }, // Popup options width: 400, @@ -224,36 +220,32 @@ window.bioEp = { // Load event listeners for the popup loadEvents: function() { - // Track mouse movement. - this.addEvent(document, "mousemove", function(e) { - e = e ? e : window.event; - this.mouse.curY = e.pageY; - }.bind(this)); - - // Store the last Y position of the mouse every 350 ms. - window.setInterval(function() { - this.mouse.lastY = this.mouse.curY; - }.bind(this), 350); - // Track mouseout event on document this.addEvent(document, "mouseout", function(e) { e = e ? e : window.event; // If this is an autocomplete element. if(e.target.tagName.toLowerCase() == "input") - return - - // If the current mouse Y position is less than the last - // mouse Y position, show the pop up. - // - // This should be enough to signify exit intent. - if(this.mouse.curY < this.mouse.lastY) { - // Reliable, works on mouse exiting window and - // user switching active program - var from = e.relatedTarget || e.toElement; - if(!from) - bioEp.showPopup(); - } + return; + + // Get the current viewport width. + var vpWidth = Math.max(document.documentElement.clientWidth, window.innerWidth || 0); + + // If the current mouse X position is within 50px of the right edge + // of the viewport, return. + if(e.clientX >= (vpWidth - 50)) + return; + + // If the current mouse Y position is not within 50px of the top + // edge of the viewport, return. + if(e.clientY >= 50) + return; + + // Reliable, works on mouse exiting window and + // user switching active program + var from = e.relatedTarget || e.toElement; + if(!from) + bioEp.showPopup(); }.bind(this)); // Handle the popup close button diff --git a/js/bioep.min.js b/js/bioep.min.js index d3a2c8c..e40d023 100644 --- a/js/bioep.min.js +++ b/js/bioep.min.js @@ -1,10 +1,10 @@ -window.bioEp={bgEl:{},popupEl:{},closeBtnEl:{},shown:!1,overflowDefault:"visible",transformDefault:"",mouse:{curY:0,lastY:0},width:400,height:220,html:"",css:"",fonts:[],delay:5,showOnDelay:!1,cookieExp:30,showOncePerSession:!1,onPopup:null,cookieManager:{create:function(a,b,d,c){var e="";c?e="; expires=0":d&&(c=new Date,c.setTime(c.getTime()+864E5*d),e="; expires="+c.toGMTString());document.cookie=a+"="+b+e+"; path=/"},get:function(a){a+="=";for(var b=document.cookie.split(";"),d=0;d=this.cookieExp){if(this.showOncePerSession&&"true"==this.cookieManager.get("bioep_shown_session"))return!0;this.cookieManager.erase("bioep_shown");return!1}return"true"==this.cookieManager.get("bioep_shown")?!0:!1},addCSS:function(){for(var a=0;a=this.cookieExp){if(this.showOncePerSession&&"true"==this.cookieManager.get("bioep_shown_session"))return!0;this.cookieManager.erase("bioep_shown");return!1}return"true"==this.cookieManager.get("bioep_shown")?!0:!1},addCSS:function(){for(var a=0;ad-40&&(e=d-40,f=e/g,f>c-40&&(f=c-40,e=f*g));0===f&&b>c-40&&(e=(c-40)*g);a=e/a;if(0>=a|| -1=Math.max(document.documentElement.clientWidth,window.innerWidth|| +0)-50||50<=a.clientY||a.relatedTarget||a.toElement||bioEp.showPopup())}.bind(this));this.addEvent(this.closeBtnEl,"click",function(){bioEp.hidePopup()});this.addEvent(window,"resize",function(){bioEp.scalePopup()})},setOptions:function(a){this.width="undefined"===typeof a.width?this.width:a.width;this.height="undefined"===typeof a.height?this.height:a.height;this.html="undefined"===typeof a.html?this.html:a.html;this.css="undefined"===typeof a.css?this.css:a.css;this.fonts="undefined"===typeof a.fonts? +this.fonts:a.fonts;this.delay="undefined"===typeof a.delay?this.delay:a.delay;this.showOnDelay="undefined"===typeof a.showOnDelay?this.showOnDelay:a.showOnDelay;this.cookieExp="undefined"===typeof a.cookieExp?this.cookieExp:a.cookieExp;this.showOncePerSession="undefined"===typeof a.showOncePerSession?this.showOncePerSession:a.showOncePerSession;this.onPopup="undefined"===typeof a.onPopup?this.onPopup:a.onPopup},domReady:function(a){"interactive"===document.readyState||"complete"===document.readyState? +a():this.addEvent(document,"DOMContentLoaded",a)},init:function(a){"undefined"!==typeof a&&this.setOptions(a);this.addCSS();this.domReady(function(){bioEp.checkCookie()||(bioEp.addPopup(),setTimeout(function(){bioEp.loadEvents();bioEp.showOnDelay&&bioEp.showPopup()},1E3*bioEp.delay))})}}; \ No newline at end of file