Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Попытка ухода с сайта
- window.carrotExit = {
- cookieManager: {
- create: function(name, value, days) {
- var expires = "";
- if(days) {
- var date = new Date();
- date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
- expires = "; expires=" + date.toGMTString();
- }
- document.cookie = name + "=" + value + expires + "; path=/";
- },
- 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;
- },
- erase: function(name) {
- this.create(name, "", -1);
- }
- },
- track: function() {
- carrotquest.track('Попытка ухода с сайта');
- },
- scalePopup: function() {
- var margins = { width: 40, height: 40 };
- var popupSize = { width: carrotExit.popupEl.offsetWidth, height: carrotExit.popupEl.offsetHeight };
- var windowSize = { width: window.innerWidth, height: window.innerHeight };
- var newSize = { width: 0, height: 0 };
- var aspectRatio = popupSize.width / popupSize.height;
- if(popupSize.width > (windowSize.width - margins.width)) {
- newSize.width = windowSize.width - margins.width;
- newSize.height = newSize.width / aspectRatio;
- if(newSize.height > (windowSize.height - margins.height)) {
- newSize.height = windowSize.height - margins.height;
- newSize.width = newSize.height * aspectRatio;
- }
- }
- if(newSize.height === 0) {
- if(popupSize.height > (windowSize.height - margins.height)) {
- newSize.height = windowSize.height - margins.height;
- newSize.width = newSize.height * aspectRatio;
- }
- }
- var scaleTo = newSize.width / popupSize.width;
- if(scaleTo <= 0 || scaleTo > 1) scaleTo = 1;
- if(this.transformDefault === "")
- this.transformDefault = window.getComputedStyle(this.popupEl, null).getPropertyValue("transform");
- this.popupEl.style.transform = this.transformDefault + " scale(" + scaleTo + ")";
- },
- addEvent: function (obj, event, callback) {
- if(obj.addEventListener)
- obj.addEventListener(event, callback, false);
- else if(obj.attachEvent)
- obj.attachEvent("on" + event, callback);
- },
- loadEvents: function() {
- this.addEvent(document, "mouseout", function(e) {
- e = e ? e : window.event;
- var from = e.relatedTarget || e.toElement;
- if(!from)
- carrotExit.track();
- });
- },
- domReady: function(callback) {
- (document.readyState === "interactive" || document.readyState === "complete") ? callback() : this.addEvent(document, "DOMContentLoaded", callback);
- },
- init: function(opts) {
- this.domReady(function() {
- setTimeout(function() { carrotExit.loadEvents() }, 6000);
- });
- }
- }
- carrotExit.init({});
Add Comment
Please, Sign In to add comment