ivan_carrotquest

Untitled

May 24th, 2017
580
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.93 KB | None | 0 0
  1. //Попытка ухода с сайта
  2. window.carrotExit = {
  3. cookieManager: {
  4. create: function(name, value, seconds) {
  5. var expires = "";
  6. if(seconds) {
  7. var date = new Date();
  8. date.setTime(date.getTime() + (seconds * 1000));
  9. expires = "; expires=" + date.toGMTString();
  10. }
  11. document.cookie = name + "=" + value + expires + "; path=/";
  12. },
  13. get: function(name) {
  14. var nameEQ = name + "=";
  15. var ca = document.cookie.split(";");
  16.  
  17. for(var i = 0; i < ca.length; i++) {
  18. var c = ca[i];
  19. while (c.charAt(0) == " ") c = c.substring(1, c.length);
  20. if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length);
  21. }
  22.  
  23. return null;
  24. },
  25. erase: function(name) {
  26. this.create(name, "", -1);
  27. }
  28. },
  29. track: function() {
  30. if (!this.cookieManager.get('carrotExit')) {
  31. carrotquest.track('Попытка ухода с сайта');
  32. this.cookieManager.create('carrotExit', 1, 1 * 30);
  33. }
  34. },
  35. scalePopup: function() {
  36. var margins = { width: 40, height: 40 };
  37. var popupSize = { width: carrotExit.popupEl.offsetWidth, height: carrotExit.popupEl.offsetHeight };
  38. var windowSize = { width: window.innerWidth, height: window.innerHeight };
  39. var newSize = { width: 0, height: 0 };
  40. var aspectRatio = popupSize.width / popupSize.height;
  41.  
  42. if(popupSize.width > (windowSize.width - margins.width)) {
  43. newSize.width = windowSize.width - margins.width;
  44. newSize.height = newSize.width / aspectRatio;
  45.  
  46. if(newSize.height > (windowSize.height - margins.height)) {
  47. newSize.height = windowSize.height - margins.height;
  48. newSize.width = newSize.height * aspectRatio;
  49. }
  50. }
  51.  
  52. if(newSize.height === 0) {
  53. if(popupSize.height > (windowSize.height - margins.height)) {
  54. newSize.height = windowSize.height - margins.height;
  55. newSize.width = newSize.height * aspectRatio;
  56. }
  57. }
  58. var scaleTo = newSize.width / popupSize.width;
  59. if(scaleTo <= 0 || scaleTo > 1) scaleTo = 1;
  60.  
  61. if(this.transformDefault === "")
  62. this.transformDefault = window.getComputedStyle(this.popupEl, null).getPropertyValue("transform");
  63.  
  64. this.popupEl.style.transform = this.transformDefault + " scale(" + scaleTo + ")";
  65. },
  66.  
  67. addEvent: function (obj, event, callback) {
  68. if(obj.addEventListener)
  69. obj.addEventListener(event, callback, false);
  70. else if(obj.attachEvent)
  71. obj.attachEvent("on" + event, callback);
  72. },
  73. loadEvents: function() {
  74. this.addEvent(document, "mouseout", function(e) {
  75. e = e ? e : window.event;
  76. var from = e.relatedTarget || e.toElement;
  77. if(!from)
  78. carrotExit.track();
  79. });
  80.  
  81. },
  82. domReady: function(callback) {
  83. (document.readyState === "interactive" || document.readyState === "complete") ? callback() : this.addEvent(document, "DOMContentLoaded", callback);
  84. },
  85.  
  86. init: function(opts) {
  87. this.domReady(function() {
  88. setTimeout(function() { carrotExit.loadEvents() }, 6000);
  89. });
  90. }
  91. }
  92. carrotExit.init({});
Advertisement
Add Comment
Please, Sign In to add comment