PageSourceSearch

https://www.pinglighting.com/modules/ets_abandonedcart/views/js/favico.js

js pinglighting.com collected 2026-10-06 18:27:07 UTC 19,130 bytes, 763 lines download raw bytes

1/**
2 * 2007-2021 ETS-Soft
3 *
4 * NOTICE OF LICENSE
5 *
6 * This file is not open source! Each license that you purchased is only available for 1 wesite only.
7 * If you want to use this file on more websites (or projects), you need to purchase additional licenses.
8 * You are not allowed to redistribute, resell, lease, license, sub-license or offer our resources to any third party.
9 *
10 * DISCLAIMER
11 *
12 * Do not edit or add to this file if you wish to upgrade PrestaShop to newer
13 * versions in the future. If you wish to customize PrestaShop for your
14 * needs please contact us for extra customization service at an affordable price
15 *
16 *  @author ETS-Soft <[email protected]>
17 *  @copyright  2007-2021 ETS-Soft
18 *  @license    Valid for 1 website (or project) for each purchase of license
19 *  International Registered Trademark & Property of ETS-Soft
20 */
21
22(function () {
23
24	var ETSFavico = (function (opt) {
25		'use strict';
26		opt = (opt) ? opt : {};
27		var _def = {
28			bgColor: '#d00',
29			textColor: '#fff',
30			fontFamily: 'sans-serif', //Arial,Verdana,Times New Roman,serif,sans-serif,...
31			fontStyle: 'bold', //normal,italic,oblique,bold,bolder,lighter,100,200,300,400,500,600,700,800,900
32			type: 'circle',
33			position: 'down', // down, up, left, leftup (upleft)
34			animation: 'slide',
35			elementId: false,
36			element: null,
37			dataUrl: false,
38			win: window
39		};
40		var _opt, _orig, _h, _w, _canvas, _context, _img, _ready, _lastBadge, _running, _readyCb, _stop, _browser, _animTimeout, _drawTimeout, _doc;
41
42		_browser = {};
43		_browser.ff = typeof InstallTrigger != 'undefined';
44		_browser.chrome = !!window.chrome;
45		_browser.opera = !!window.opera || navigator.userAgent.indexOf('Opera') >= 0;
46		_browser.ie = /*@cc_on!@*/false;
47		_browser.safari = Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0;
48		_browser.supported = (_browser.chrome || _browser.ff || _browser.opera);
49
50		var _queue = [];
51		_readyCb = function () {
52		};
53		_ready = _stop = false;
54		/**
55		 * Initialize favico
56		 */
57		var init = function () {
58			//merge initial options
59			_opt = merge(_def, opt);
60			_opt.bgColor = hexToRgb(_opt.bgColor);
61			_opt.textColor = hexToRgb(_opt.textColor);
62			_opt.position = _opt.position.toLowerCase();
63			_opt.animation = (animation.types['' + _opt.animation]) ? _opt.animation : _def.animation;
64
65			_doc = _opt.win.document;
66
67			var isUp = _opt.position.indexOf('up') > -1;
68			var isLeft = _opt.position.indexOf('left') > -1;
69
70			//transform the animations
71			if (isUp || isLeft) {
72				for (var a in animation.types) {
73					for (var i = 0; i < animation.types[a].length; i++) {
74						var step = animation.types[a][i];
75
76						if (isUp) {
77							if (step.y < 0.6) {
78								step.y = step.y - 0.4;
79							} else {
80								step.y = step.y - 2 * step.y + (1 - step.w);
81							}
82						}
83
84						if (isLeft) {
85							if (step.x < 0.6) {
86								step.x = step.x - 0.4;
87							} else {
88								step.x = step.x - 2 * step.x + (1 - step.h);
89							}
90						}
91
92						animation.types[a][i] = step;
93					}
94				}
95			}
96			_opt.type = (type['' + _opt.type]) ? _opt.type : _def.type;
97
98			_orig = link. getIcons();
99			//create temp canvas
100			_canvas = document.createElement('canvas');
101			//create temp image
102			_img = document.createElement('img');
103			var lastIcon = _orig[_orig.length - 1];
104			if (lastIcon.hasAttribute('href')) {
105				_img.setAttribute('crossOrigin', 'anonymous');
106				//get width/height
107				_img.onload = function () {
108					_h = (_img.height > 0) ? _img.height : 32;
109					_w = (_img.width > 0) ? _img.width : 32;
110					_canvas.height = _h;
111					_canvas.width = _w;
112					_context = _canvas.getContext('2d');
113					icon.ready();
114				};
115				_img.setAttribute('src', lastIcon.getAttribute('href'));
116			} else {
117				_h = 32;
118				_w = 32;
119				_img.height = _h;
120				_img.width = _w;
121				_canvas.height = _h;
122				_canvas.width = _w;
123				_context = _canvas.getContext('2d');
124				icon.ready();
125			}
126
127		};
128		/**
129		 * Icon namespace
130		 */
131		var icon = {};
132		/**
133		 * Icon is ready (reset icon) and start animation (if ther is any)
134		 */
135		icon.ready = function () {
136			_ready = true;
137			icon.reset();
138			_readyCb();
139		};
140		/**
141		 * Reset icon to default state
142		 */
143		icon.reset = function () {
144			//reset
145			if (!_ready) {
146				return;
147			}
148			_queue = [];
149			_lastBadge = false;
150			_running = false;
151			_context.clearRect(0, 0, _w, _h);
152			_context.drawImage(_img, 0, 0, _w, _h);
153			//_stop=true;
154			link.setIcon(_canvas);
155			//webcam('stop');
156			//video('stop');
157			window.clearTimeout(_animTimeout);
158			window.clearTimeout(_drawTimeout);
159		};
160		/**
161		 * Start animation
162		 */
163		icon.start = function () {
164			if (!_ready || _running) {
165				return;
166			}
167			var finished = function () {
168				_lastBadge = _queue[0];
169				_running = false;
170				if (_queue.length > 0) {
171					_queue.shift();
172					icon.start();
173				} else {
174
175				}
176			};
177			if (_queue.length > 0) {
178				_running = true;
179				var run = function () {
180					// apply options for this animation
181					['type', 'animation', 'bgColor', 'textColor', 'fontFamily', 'fontStyle'].forEach(function (a) {
182						if (a in _queue[0].options) {
183							_opt[a] = _queue[0].options[a];
184						}
185					});
vendor: 4,919 bytes, lines 186-320
186					animation.run(_queue[0].options, function () {
187						finished();
188					}, false);
189				};
190				if (_lastBadge) {
191					animation.run(_lastBadge.options, function () {
192						run();
193					}, true);
194				} else {
195					run();
196				}
197			}
198		};
199
200		/**
201		 * Badge types
202		 */
203		var type = {};
204		var options = function (opt) {
205			opt.n = ((typeof opt.n) === 'number') ? Math.abs(opt.n | 0) : opt.n;
206			opt.x = _w * opt.x;
207			opt.y = _h * opt.y;
208			opt.w = _w * opt.w;
209			opt.h = _h * opt.h;
210			opt.len = ("" + opt.n).length;
211			return opt;
212		};
213		/**
214		 * Generate circle
215		 * @param {Object} opt Badge options
216		 */
217		type.circle = function (opt) {
218			opt = options(opt);
219			var more = false;
220			if (opt.len === 2) {
221				opt.x = opt.x - opt.w * 0.4;
222				opt.w = opt.w * 1.4;
223				more = true;
224			} else if (opt.len >= 3) {
225				opt.x = opt.x - opt.w * 0.65;
226				opt.w = opt.w * 1.65;
227				more = true;
228			}
229			_context.clearRect(0, 0, _w, _h);
230			_context.drawImage(_img, 0, 0, _w, _h);
231			_context.beginPath();
232			_context.font = _opt.fontStyle + " " + Math.floor(opt.h * (opt.n > 99 ? 0.85 : 1)) + "px " + _opt.fontFamily;
233			_context.textAlign = 'center';
234			if (more) {
235				_context.moveTo(opt.x + opt.w / 2, opt.y);
236				_context.lineTo(opt.x + opt.w - opt.h / 2, opt.y);
237				_context.quadraticCurveTo(opt.x + opt.w, opt.y, opt.x + opt.w, opt.y + opt.h / 2);
238				_context.lineTo(opt.x + opt.w, opt.y + opt.h - opt.h / 2);
239				_context.quadraticCurveTo(opt.x + opt.w, opt.y + opt.h, opt.x + opt.w - opt.h / 2, opt.y + opt.h);
240				_context.lineTo(opt.x + opt.h / 2, opt.y + opt.h);
241				_context.quadraticCurveTo(opt.x, opt.y + opt.h, opt.x, opt.y + opt.h - opt.h / 2);
242				_context.lineTo(opt.x, opt.y + opt.h / 2);
243				_context.quadraticCurveTo(opt.x, opt.y, opt.x + opt.h / 2, opt.y);
244			} else {
245				_context.arc(opt.x + opt.w / 2, opt.y + opt.h / 2, opt.h / 2, 0, 2 * Math.PI);
246			}
247			_context.fillStyle = 'rgba(' + _opt.bgColor.r + ',' + _opt.bgColor.g + ',' + _opt.bgColor.b + ',' + opt.o + ')';
248			_context.fill();
249			_context.closePath();
250			_context.beginPath();
251			_context.stroke();
252			_context.fillStyle = 'rgba(' + _opt.textColor.r + ',' + _opt.textColor.g + ',' + _opt.textColor.b + ',' + opt.o + ')';
253			//_context.fillText((more) ? '9+' : opt.n, Math.floor(opt.x + opt.w / 2), Math.floor(opt.y + opt.h - opt.h * 0.15));
254			if ((typeof opt.n) === 'number' && opt.n > 999) {
255				_context.fillText(((opt.n > 9999) ? 9 : Math.floor(opt.n / 1000)) + 'k+', Math.floor(opt.x + opt.w / 2), Math.floor(opt.y + opt.h - opt.h * 0.2));
256			} else {
257				_context.fillText(opt.n, Math.floor(opt.x + opt.w / 2), Math.floor(opt.y + opt.h - opt.h * 0.15));
258			}
259			_context.closePath();
260		};
261		/**
262		 * Generate rectangle
263		 * @param {Object} opt Badge options
264		 */
265		type.rectangle = function (opt) {
266			opt = options(opt);
267			var more = false;
268			if (opt.len === 2) {
269				opt.x = opt.x - opt.w * 0.4;
270				opt.w = opt.w * 1.4;
271				more = true;
272			} else if (opt.len >= 3) {
273				opt.x = opt.x - opt.w * 0.65;
274				opt.w = opt.w * 1.65;
275				more = true;
276			}
277			_context.clearRect(0, 0, _w, _h);
278			_context.drawImage(_img, 0, 0, _w, _h);
279			_context.beginPath();
280			_context.font = _opt.fontStyle + " " + Math.floor(opt.h * (opt.n > 99 ? 0.9 : 1)) + "px " + _opt.fontFamily;
281			_context.textAlign = 'center';
282			_context.fillStyle = 'rgba(' + _opt.bgColor.r + ',' + _opt.bgColor.g + ',' + _opt.bgColor.b + ',' + opt.o + ')';
283			_context.fillRect(opt.x, opt.y, opt.w, opt.h);
284			_context.fillStyle = 'rgba(' + _opt.textColor.r + ',' + _opt.textColor.g + ',' + _opt.textColor.b + ',' + opt.o + ')';
285			//_context.fillText((more) ? '9+' : opt.n, Math.floor(opt.x + opt.w / 2), Math.floor(opt.y + opt.h - opt.h * 0.15));
286			if ((typeof opt.n) === 'number' && opt.n > 999) {
287				_context.fillText(((opt.n > 9999) ? 9 : Math.floor(opt.n / 1000)) + 'k+', Math.floor(opt.x + opt.w / 2), Math.floor(opt.y + opt.h - opt.h * 0.2));
288			} else {
289				_context.fillText(opt.n, Math.floor(opt.x + opt.w / 2), Math.floor(opt.y + opt.h - opt.h * 0.15));
290			}
291			_context.closePath();
292		};
293
294		/**
295		 * Set badge
296		 */
297		var badge = function (number, opts) {
298			opts = ((typeof opts) === 'string' ? {
299				animation: opts
300			} : opts) || {};
301			_readyCb = function () {
302				try {
303					if (typeof (number) === 'number' ? (number > 0) : (number !== '')) {
304						var q = {
305							type: 'badge',
306							options: {
307								n: number
308							}
309						};
310						if ('animation' in opts && animation.types['' + opts.animation]) {
311							q.options.animation = '' + opts.animation;
312						}
313						if ('type' in opts && type['' + opts.type]) {
314							q.options.type = '' + opts.type;
315						}
316						['bgColor', 'textColor'].forEach(function (o) {
317							if (o in opts) {
318								q.options[o] = hexToRgb(opts[o]);
319							}
320						});
321						['fontStyle', 'fontFamily'].forEach(function (o) {
322							if (o in opts) {
323								q.options[o] = opts[o];
324							}
325						});
326						_queue.push(q);
327						if (_queue.length > 100) {
328							throw new Error('Too many badges requests in queue.');
329						}
330						icon.start();
331					} else {
332						icon.reset();
333					}
334				} catch (e) {
335					throw new Error('Error setting badge. Message: ' + e.message);
336				}
337			};
338			if (_ready) {
339				_readyCb();
340			}
341		};
342
343		var setOpt = function (key, value) {
344			var opts = key;
345			if (!(value == null && Object.prototype.toString.call(key) == '[object Object]')) {
346				opts = {};
347				opts[key] = value;
348			}
349
350			var keys = Object.keys(opts);
351			for (var i = 0; i < keys.length; i++) {
352				if (keys[i] == 'bgColor' || keys[i] == 'textColor') {
353					_opt[keys[i]] = hexToRgb(opts[keys[i]]);
354				} else {
355					_opt[keys[i]] = opts[keys[i]];
356				}
357			}
358
359			_queue.push(_lastBadge);
360			icon.start();
361		};
362
363		var link = {};
364		/**
365		 * Get icons from HEAD tag or create a new <link> element
366		 */
367		link.getIcons = function () {
368			var elms = [];
369			//get link element
370			var getLinks = function () {
371				var icons = [];
372				var links = _doc.getElementsByTagName('head')[0].getElementsByTagName('link');
373				for (var i = 0; i < links.length; i++) {
374					if ((/(^|\s)icon(\s|$)/i).test(links[i].getAttribute('rel'))) {
375						icons.push(links[i]);
376					}
377				}
378				return icons;
379			};
380			if (_opt.element) {
381				elms = [_opt.element];
382			} else if (_opt.elementId) {
383				//if img element identified by elementId
384				elms = [_doc.getElementById(_opt.elementId)];
385				elms[0].setAttribute('href', elms[0].getAttribute('src'));
386			} else {
387				//if link element
388				elms = getLinks();
389				if (elms.length === 0) {
390					elms = [_doc.createElement('link')];
391					elms[0].setAttribute('rel', 'icon');
392					_doc.getElementsByTagName('head')[0].appendChild(elms[0]);
393				}
394			}
395			elms.forEach(function(item) {
396				item.setAttribute('type', 'image/png');
397			});
398			return elms;
399		};
400		link.setIcon = function (canvas) {
401			var url = canvas.toDataURL('image/png');
402			link.setIconSrc(url);
403		};
404		link.setIconSrc = function (url) {
405			if (_opt.dataUrl) {
406				//if using custom exporter
407				_opt.dataUrl(url);
408			}
409			if (_opt.element) {
410				_opt.element.setAttribute('href', url);
411				_opt.element.setAttribute('src', url);
412			} else if (_opt.elementId) {
413				//if is attached to element (image)
414				var elm = _doc.getElementById(_opt.elementId);
415				elm.setAttribute('href', url);
416				elm.setAttribute('src', url);
417			} else {
418				//if is attached to fav icon
419				if (_browser.ff || _browser.opera) {
420					//for FF we need to "recreate" element, atach to dom and remove old <link>
421					//var originalType = _orig.getAttribute('rel');
422					var old = _orig[_orig.length - 1];
423					var newIcon = _doc.createElement('link');
424					_orig = [newIcon];
425					//_orig.setAttribute('rel', originalType);
426					if (_browser.opera) {
427						newIcon.setAttribute('rel', 'icon');
428					}
429					newIcon.setAttribute('rel', 'icon');
430					newIcon.setAttribute('type', 'image/png');
431					_doc.getElementsByTagName('head')[0].appendChild(newIcon);
432					newIcon.setAttribute('href', url);
433					if (old.parentNode) {
434						old.parentNode.removeChild(old);
435					}
436				} else {
437					_orig.forEach(function(icon) {
438						icon.setAttribute('href', url);
439					});
440				}
441			}
442		};
443
444		//http://stackoverflow.com/questions/5623838/rgb-to-hex-and-hex-to-rgb#answer-5624139
445		//HEX to RGB convertor
446		function hexToRgb(hex) {
447			var shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
448			hex = hex.replace(shorthandRegex, function (m, r, g, b) {
449				return r + r + g + g + b + b;
450			});
451			var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
452			return result ? {
453				r: parseInt(result[1], 16),
454				g: parseInt(result[2], 16),
455				b: parseInt(result[3], 16)
456			} : false;
457		}
458
459		/**
460		 * Merge options
461		 */
462		function merge(def, opt) {
463			var mergedOpt = {};
464			var attrname;
465			for (attrname in def) {
466				mergedOpt[attrname] = def[attrname];
467			}
468			for (attrname in opt) {
469				mergedOpt[attrname] = opt[attrname];
470			}
471			return mergedOpt;
472		}
473
474		/**
475		 * Cross-browser page visibility shim
476		 * http://stackoverflow.com/questions/12536562/detect-whether-a-window-is-visible
477		 */
478		function isPageHidden() {
479			return _doc.hidden || _doc.msHidden || _doc.webkitHidden || _doc.mozHidden;
480		}
481
482		/**
483		 * @namespace animation
484		 */
485		var animation = {};
486		/**
487		 * Animation "frame" duration
488		 */
489		animation.duration = 40;
490		/**
491		 * Animation types (none,fade,pop,slide)
492		 */
493		animation.types = {};
494		animation.types.fade = [{
495			x: 0.4,
496			y: 0.4,
497			w: 0.6,
498			h: 0.6,
499			o: 0.0
500		}, {
501				x: 0.4,
502				y: 0.4,
503				w: 0.6,
504				h: 0.6,
505				o: 0.1
506			}, {
507				x: 0.4,
508				y: 0.4,
509				w: 0.6,
510				h: 0.6,
511				o: 0.2
512			}, {
513				x: 0.4,
514				y: 0.4,
515				w: 0.6,
516				h: 0.6,
517				o: 0.3
518			}, {
519				x: 0.4,
520				y: 0.4,
521				w: 0.6,
522				h: 0.6,
523				o: 0.4
524			}, {
525				x: 0.4,
526				y: 0.4,
527				w: 0.6,
528				h: 0.6,
529				o: 0.5
530			}, {
531				x: 0.4,
532				y: 0.4,
533				w: 0.6,
534				h: 0.6,
535				o: 0.6
536			}, {
537				x: 0.4,
538				y: 0.4,
539				w: 0.6,
540				h: 0.6,
541				o: 0.7
542			}, {
543				x: 0.4,
544				y: 0.4,
545				w: 0.6,
546				h: 0.6,
547				o: 0.8
548			}, {
549				x: 0.4,
550				y: 0.4,
551				w: 0.6,
552				h: 0.6,
553				o: 0.9
554			}, {
555				x: 0.4,
556				y: 0.4,
557				w: 0.6,
558				h: 0.6,
559				o: 1.0
560			}];
561		animation.types.none = [{
562			x: 0.4,
563			y: 0.4,
564			w: 0.6,
565			h: 0.6,
566			o: 1
567		}];
568		animation.types.pop = [{
569			x: 1,
570			y: 1,
571			w: 0,
572			h: 0,
573			o: 1
574		}, {
575				x: 0.9,
576				y: 0.9,
577				w: 0.1,
578				h: 0.1,
579				o: 1
580			}, {
581				x: 0.8,
582				y: 0.8,
583				w: 0.2,
584				h: 0.2,
585				o: 1
586			}, {
587				x: 0.7,
588				y: 0.7,
589				w: 0.3,
590				h: 0.3,
591				o: 1
592			}, {
593				x: 0.6,
594				y: 0.6,
595				w: 0.4,
596				h: 0.4,
597				o: 1
598			}, {
599				x: 0.5,
600				y: 0.5,
601				w: 0.5,
602				h: 0.5,
603				o: 1
604			}, {
605				x: 0.4,
606				y: 0.4,
607				w: 0.6,
608				h: 0.6,
609				o: 1
610			}];
611		animation.types.popFade = [{
612			x: 0.75,
613			y: 0.75,
614			w: 0,
615			h: 0,
616			o: 0
617		}, {
618				x: 0.65,
619				y: 0.65,
620				w: 0.1,
621				h: 0.1,
622				o: 0.2
623			}, {
624				x: 0.6,
625				y: 0.6,
626				w: 0.2,
627				h: 0.2,
628				o: 0.4
629			}, {
630				x: 0.55,
631				y: 0.55,
632				w: 0.3,
633				h: 0.3,
634				o: 0.6
635			}, {
636				x: 0.50,
637				y: 0.50,
638				w: 0.4,
639				h: 0.4,
640				o: 0.8
641			}, {
642				x: 0.45,
643				y: 0.45,
644				w: 0.5,
645				h: 0.5,
646				o: 0.9
647			}, {
648				x: 0.4,
649				y: 0.4,
650				w: 0.6,
651				h: 0.6,
652				o: 1
653			}];
654		animation.types.slide = [{
655			x: 0.4,
656			y: 1,
657			w: 0.6,
658			h: 0.6,
659			o: 1
660		}, {
661				x: 0.4,
662				y: 0.9,
663				w: 0.6,
664				h: 0.6,
665				o: 1
666			}, {
667				x: 0.4,
668				y: 0.9,
669				w: 0.6,
670				h: 0.6,
671				o: 1
672			}, {
673				x: 0.4,
674				y: 0.8,
675				w: 0.6,
676				h: 0.6,
677				o: 1
678			}, {
679				x: 0.4,
680				y: 0.7,
681				w: 0.6,
682				h: 0.6,
683				o: 1
684			}, {
685				x: 0.4,
686				y: 0.6,
687				w: 0.6,
688				h: 0.6,
689				o: 1
690			}, {
691				x: 0.4,
692				y: 0.5,
693				w: 0.6,
694				h: 0.6,
695				o: 1
696			}, {
697				x: 0.4,
698				y: 0.4,
699				w: 0.6,
700				h: 0.6,
701				o: 1
702			}];
703		/**
704		 * Run animation
705		 * @param {Object} opt Animation options
706		 * @param {Object} cb Callabak after all steps are done
707		 * @param {Object} revert Reverse order? true|false
708		 * @param {Object} step Optional step number (frame bumber)
709		 */
710		animation.run = function (opt, cb, revert, step) {
711			var animationType = animation.types[isPageHidden() ? 'none' : _opt.animation];
712			if (revert === true) {
713				step = (typeof step !== 'undefined') ? step : animationType.length - 1;
714			} else {
715				step = (typeof step !== 'undefined') ? step : 0;
716			}
717			cb = (cb) ? cb : function () {
718			};
719			if ((step < animationType.length) && (step >= 0)) {
720				type[_opt.type](merge(opt, animationType[step]));
721				_animTimeout = setTimeout(function () {
722					if (revert) {
723						step = step - 1;
724					} else {
725						step = step + 1;
726					}
727					animation.run(opt, cb, revert, step);
728				}, animation.duration);
729
730				link.setIcon(_canvas);
731			} else {
732				cb();
733				return;
734			}
735		};
736		//auto init
737		init();
738		return {
739			badge: badge,
740			setOpt: setOpt,
741			reset: icon.reset,
742			browser: {
743				supported: _browser.supported
744			}
745		};
746	});
747
748	// AMD / RequireJS
749	if (typeof define !== 'undefined' && define.amd) {
750		define([], function () {
751			return ETSFavico;
752		});
753	}
754	// CommonJS
755	else if (typeof module !== 'undefined' && module.exports) {
756		module.exports = ETSFavico;
757	}
758	// included directly via <script> tag
759	else {
760		this.ETSFavico = ETSFavico;
761	}
762
763})();

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.