1 2 3( function ( root, factory ) { 4 if ( typeof define === 'function' && define.amd ) { 5 define( factory ); 6 } else if ( typeof exports === 'object' ) { 7 module.exports = factory( require, exports, module ); 8 } else { 9 root.ouibounce = factory(); 10 } 11}( this, function ( require, exports, module ) { 12 13 return function ouibounce( el, config ) { 14 var config = config || { }, 15 aggressive = config.aggressive || false, 16 sensitivity = setDefault( config.sensitivity, 20 ), 17 timer = setDefault( config.timer, 1000 ), 18 delay = setDefault( config.delay, 0 ), 19 callback = config.callback || function () {}, 20 cookieExpire = setDefaultCookieExpire( config.cookieExpire ) || '', 21 cookieDomain = config.cookieDomain ? ';domain=' + config.cookieDomain : '', 22 cookieName = config.cookieName ? config.cookieName : 'viewedOuibounceModal', 23 sitewide = config.sitewide === true ? ';path=/' : '', 24 _delayTimer = null, 25 _html = document.documentElement; 26 27 function setDefault( _property, _default ) { 28 return typeof _property === 'undefined' ? _default : _property; 29 } 30 31 function setDefaultCookieExpire( days ) { 32 // transform days to milliseconds 33 var ms = days * 24 * 60 * 60 * 1000; 34 35 var date = new Date(); 36 date.setTime( date.getTime() + ms ); 37 38 return "; expires=" + date.toUTCString(); 39 } 40 41 setTimeout( attachOuiBounce, timer ); 42 function attachOuiBounce() { 43 _html.addEventListener( 'mouseleave', handleMouseleave ); 44 _html.addEventListener( 'mouseenter', handleMouseenter ); 45 _html.addEventListener( 'keydown', handleKeydown ); 46 } 47 48 function handleMouseleave( e ) { 49 if ( e.clientY > sensitivity || ( checkCookieValue( cookieName, 'true' ) && !aggressive ) ) 50 return; 51 52 _delayTimer = setTimeout( _fireAndCallback, delay ); 53 } 54 55 function handleMouseenter( e ) { 56 if ( _delayTimer ) { 57 clearTimeout( _delayTimer ); 58 _delayTimer = null; 59 } 60 } 61 62 var disableKeydown = false; 63 function handleKeydown( e ) { 64 if ( disableKeydown || checkCookieValue( cookieName, 'true' ) && !aggressive ) 65 return; 66 else if ( !e.metaKey || e.keyCode !== 76 ) 67 return; 68 69 disableKeydown = true; 70 _delayTimer = setTimeout( _fireAndCallback, delay ); 71 } 72 73 function checkCookieValue( cookieName, value ) { 74 return parseCookies()[cookieName] === value; 75 } 76 77 function parseCookies() { 78 // cookies are separated by '; ' 79 var cookies = document.cookie.split( '; ' ); 80 81 var ret = { }; 82 for ( var i = cookies.length - 1; i >= 0; i-- ) { 83 var el = cookies[i].split( '=' ); 84 ret[el[0]] = el[1]; 85 } 86 return ret; 87 } 88 89 function _fireAndCallback() { 90 fire(); 91 callback(); 92 } 93 94 function fire() { 95 // You can use ouibounce without passing an element 96 // https://github.com/carlsednaoui/ouibounce/issues/30 97 if ( el ) 98 el.style.display = 'block'; 99 if ( typeof ( CMregisterPopupFlyinWatchers ) === "function" ) { 100 CMregisterPopupFlyinWatchers(); 101 } 102 callback(); 103 disable(); 104 } 105 106 function disable( options ) { 107 var options = options || { }; 108 109 // you can pass a specific cookie expiration when using the OuiBounce API 110 // ex: _ouiBounce.disable({ cookieExpire: 5 }); 111 if ( typeof options.cookieExpire !== 'undefined' ) { 112 cookieExpire = setDefaultCookieExpire( options.cookieExpire ); 113 } 114 115 // you can pass use sitewide cookies too 116 // ex: _ouiBounce.disable({ cookieExpire: 5, sitewide: true }); 117 if ( options.sitewide === true ) { 118 sitewide = ';path=/'; 119 } 120 121 // you can pass a domain string when the cookie should be read subdomain-wise 122 // ex: _ouiBounce.disable({ cookieDomain: '.example.com' }); 123 if ( typeof options.cookieDomain !== 'undefined' ) { 124 cookieDomain = ';domain=' + options.cookieDomain; 125 } 126 127 if ( typeof options.cookieName !== 'undefined' ) { 128 cookieName = options.cookieName; 129 } 130 131 document.cookie = cookieName + '=true' + cookieExpire + cookieDomain + sitewide; 132 133 // remove listeners 134 _html.removeEventListener( 'mouseleave', handleMouseleave ); 135 _html.removeEventListener( 'mouseenter', handleMouseenter ); 136 _html.removeEventListener( 'keydown', handleKeydown ); 137 } 138 function close() { 139 //if (el) el.style.display = 'none'; 140 //jQuery( el ).hide(); 141 jQuery( el ).remove(); 142 disable(); 143 if ( typeof ( CMpopupClosed ) == "function" ) { 144 CMpopupClosed(); 145 } 146 } 147 return { 148 fire: fire, 149 disable: disable, 150 close: close 151 }; 152 } 153 ; 154 155} ) );
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.