Guest User

Untitled

a guest
Dec 5th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1. //Попытка ухода с сайта
  2. window.carrotExit = {
  3. cookieManager: {
  4. create: function(name, value, days) {
  5. var expires = "";
  6. if(days) {
  7. var date = new Date();
  8. date.setTime(date.getTime() + (days * 24 * 60 * 60 * 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. carrotquest.track('Попытка ухода с сайта');
  31. },
  32. scalePopup: function() {
  33. var margins = { width: 40, height: 40 };
  34. var popupSize = { width: carrotExit.popupEl.offsetWidth, height: carrotExit.popupEl.offsetHeight };
  35. var windowSize = { width: window.innerWidth, height: window.innerHeight };
  36. var newSize = { width: 0, height: 0 };
  37. var aspectRatio = popupSize.width / popupSize.height;
  38.  
  39. if(popupSize.width > (windowSize.width - margins.width)) {
  40. newSize.width = windowSize.width - margins.width;
  41. newSize.height = newSize.width / aspectRatio;
  42.  
  43. if(newSize.height > (windowSize.height - margins.height)) {
  44. newSize.height = windowSize.height - margins.height;
  45. newSize.width = newSize.height * aspectRatio;
  46. }
  47. }
  48.  
  49. if(newSize.height === 0) {
  50. if(popupSize.height > (windowSize.height - margins.height)) {
  51. newSize.height = windowSize.height - margins.height;
  52. newSize.width = newSize.height * aspectRatio;
  53. }
  54. }
  55. var scaleTo = newSize.width / popupSize.width;
  56. if(scaleTo <= 0 || scaleTo > 1) scaleTo = 1;
  57.  
  58. if(this.transformDefault === "")
  59. this.transformDefault = window.getComputedStyle(this.popupEl, null).getPropertyValue("transform");
  60.  
  61. this.popupEl.style.transform = this.transformDefault + " scale(" + scaleTo + ")";
  62. },
  63.  
  64. addEvent: function (obj, event, callback) {
  65. if(obj.addEventListener)
  66. obj.addEventListener(event, callback, false);
  67. else if(obj.attachEvent)
  68. obj.attachEvent("on" + event, callback);
  69. },
  70. loadEvents: function() {
  71. this.addEvent(document, "mouseout", function(e) {
  72. e = e ? e : window.event;
  73. var from = e.relatedTarget || e.toElement;
  74. if(!from)
  75. carrotExit.track();
  76. });
  77.  
  78. },
  79. domReady: function(callback) {
  80. (document.readyState === "interactive" || document.readyState === "complete") ? callback() : this.addEvent(document, "DOMContentLoaded", callback);
  81. },
  82.  
  83. init: function(opts) {
  84. this.domReady(function() {
  85. setTimeout(function() { carrotExit.loadEvents() }, 6000);
  86. });
  87. }
  88. }
  89. carrotExit.init({});
Add Comment
Please, Sign In to add comment