PageSourceSearch

https://www.meshnews.org/wp-content/plugins/cryptocurrency-widgets-pack/assets/public/js/common.js?ver=2.0.2

js meshnews.org collected 2026-09-26 10:25:02 UTC 14,213 bytes, 370 lines download raw bytes

1// Peity jQuery plugin version 3.3.0
2// (c) 2018 Ben Pickles
3//
4// http://benpickles.github.io/peity
5//
6// Released under MIT license.
7!function(t,i,e,n){var a=t.fn.peity=function(i,e){return l&&this.each(function(){var n=t(this),h=n.data("_peity");h?(i&&(h.type=i),t.extend(h.opts,e)):(h=new r(n,i,t.extend({},a.defaults[i],n.data("peity"),e)),n.change(function(){h.draw()}).data("_peity",h)),h.draw()}),this},r=function(t,i,e){this.$el=t,this.type=i,this.opts=e},h=r.prototype,s=h.svgElement=function(e,n){return t(i.createElementNS("http://www.w3.org/2000/svg",e)).attr(n)},l="createElementNS"in i&&s("svg",{})[0].createSVGRect;h.draw=function(){var t=this.opts;a.graphers[this.type].call(this,t),t.after&&t.after.call(this,t)},h.fill=function(){var i=this.opts.fill;return t.isFunction(i)?i:function(t,e){return i[e%i.length]}},h.prepare=function(t,i){return this.$svg||this.$el.hide().after(this.$svg=s("svg",{class:"peity"})),this.$svg.empty().data("_peity",this).attr({height:i,width:t})},h.values=function(){return t.map(this.$el.text().split(this.opts.delimiter),function(t){return parseFloat(t)})},a.defaults={},a.graphers={},a.register=function(t,i,e){this.defaults[t]=i,this.graphers[t]=e},a.register("pie",{fill:["#ff9900","#fff4dd","#ffc66e"],radius:8},function(i){if(!i.delimiter){var n=this.$el.text().match(/[^0-9\.]/);i.delimiter=n?n[0]:","}var a=t.map(this.values(),function(t){return t>0?t:0});if("/"==i.delimiter){var r=a[0],h=a[1];a=[r,e.max(0,h-r)]}for(var l=0,p=a.length,o=0;l<p;l++)o+=a[l];o||(p=2,o=1,a=[0,1]);var f=2*i.radius,c=this.prepare(i.width||f,i.height||f),u=c.width()/2,d=c.height()/2,g=e.min(u,d),v=i.innerRadius;"donut"!=this.type||v||(v=.5*g);var m=e.PI,y=this.fill(),w=this.scale=function(t,i){var n=t/o*m*2-m/2;return[i*e.cos(n)+u,i*e.sin(n)+d]},x=0;for(l=0;l<p;l++){var k,$=a[l],j=$/o;if(0!=j){if(1==j)if(v){var A=u-.01,E=d-g,F=d-v;k=s("path",{d:["M",u,E,"A",g,g,0,1,1,A,E,"L",A,F,"A",v,v,0,1,0,u,F].join(" "),"data-value":$})}else k=s("circle",{cx:u,cy:d,"data-value":$,r:g});else{var M=x+$,S=["M"].concat(w(x,g),"A",g,g,0,j>.5?1:0,1,w(M,g),"L");v?S=S.concat(w(M,v),"A",v,v,0,j>.5?1:0,0,w(x,v)):S.push(u,d),x+=$,k=s("path",{d:S.join(" "),"data-value":$})}k.attr("fill",y.call(this,$,l,a)),c.append(k)}}}),a.register("donut",t.extend(!0,{},a.defaults.pie),function(t){a.graphers.pie.call(this,t)}),a.register("line",{delimiter:",",fill:"#c6d9fd",height:16,min:0,stroke:"#4d89f9",strokeWidth:1,width:32},function(t){var i=this.values();1==i.length&&i.push(i[0]);for(var a=e.max.apply(e,t.max==n?i:i.concat(t.max)),r=e.min.apply(e,t.min==n?i:i.concat(t.min)),h=this.prepare(t.width,t.height),l=t.strokeWidth,p=h.width(),o=h.height()-l,f=a-r,c=this.x=function(t){return t*(p/(i.length-1))},u=this.y=function(t){var i=o;return f&&(i-=(t-r)/f*o),i+l/2},d=u(e.max(r,0)),g=[0,d],v=0;v<i.length;v++)g.push(c(v),u(i[v]));g.push(p,d),t.fill&&h.append(s("polygon",{fill:t.fill,points:g.join(" ")})),l&&h.append(s("polyline",{fill:"none",points:g.slice(2,g.length-2).join(" "),stroke:t.stroke,"stroke-width":l,"stroke-linecap":"square"}))}),a.register("bar",{delimiter:",",fill:["#4D89F9"],height:16,min:0,padding:.1,width:32},function(t){for(var i=this.values(),a=e.max.apply(e,t.max==n?i:i.concat(t.max)),r=e.min.apply(e,t.min==n?i:i.concat(t.min)),h=this.prepare(t.width,t.height),l=h.width(),p=h.height(),o=a-r,f=t.padding,c=this.fill(),u=this.x=function(t){return t*l/i.length},d=this.y=function(t){return p-(o?(t-r)/o*p:1)},g=0;g<i.length;g++){var v,m=u(g+f),y=u(g+1-f)-m,w=i[g],x=d(w),k=x,$=x;o?w<0?k=d(e.min(a,0)):$=d(e.max(r,0)):v=1,0==(v=$-k)&&(v=1,a>0&&o&&k--),h.append(s("rect",{"data-value":w,fill:c.call(this,w,g,i),x:m,y:k,width:y,height:v}))}})}(jQuery,document,Math);
8
9(function($) {
10	
11	function addCommas(nStr){
12		nStr += '';
13		var x = nStr.split('.');
14		var x1 = x[0];
15		var x2 = x.length > 1 ? '.' + x[1] : '';
16		var rgx = /(\d+)(\d{3})/;
17		while (rgx.test(x1)) {
18			x1 = x1.replace(rgx, '$1' + ',' + '$2');
19		}
20		return x1 + x2;
21    }
22	
23	function commarize(data){
24		
25		formats = [' Trillion',' Billion',' Million',' Thousand'];
26
27		return (Math.abs(Number(data).toFixed(2)) >= 1.0e+15)
28		? (Math.abs(Number(data)) / 1.0e+12).toFixed(2) + formats[0]
29		: Math.abs(Number(data)) >= 1.0e+9
30		? (Math.abs(Number(data)) / 1.0e+9).toFixed(2) + formats[1]
31		: Math.abs(Number(data)) >= 1.0e+6
32		? (Math.abs(Number(data)) / 1.0e+6).toFixed(2) + formats[2]
33		: Math.abs(Number(data)) >= 1.0e+3
34		? (Math.abs(Number(data)) / 1.0e+3).toFixed(2) + formats[3]
35		: addCommas(Math.abs(Number(data)));
36	}
37
38	function hex2rgb(hex, opac) {
39
40		hex = hex.replace('#','');
41	
42		if (hex.length === 3) {
43			hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2];
44		}
45	
46		var r = parseInt(hex.substring(0,2), 16);
47		var g = parseInt(hex.substring(2,4), 16);
48		var b = parseInt(hex.substring(4,6), 16);
49	
50		if (isNaN(r) || isNaN(g) || isNaN(b)) {
51			return new Error('Invalid Hex');
52		} else if (opac !== undefined) {
53			r = Math.round(((1 - opac) * 255) + (opac * r));
54			g = Math.round(((1 - opac) * 255) + (opac * g));
55			b = Math.round(((1 - opac) * 255) + (opac * b));
56			return 'rgb('+r+','+g+','+b+')';
57		} else {
58			return 'rgb('+r+','+g+','+b+')';
59		}
60	}
61	
62	function isBrightness($that){
63		var c = rgb2hex($that.css('background-color'));
64		var rgb = parseInt(c.substring(1), 16);
65		var r = (rgb >> 16) & 0xff;
66		var g = (rgb >>  8) & 0xff;
67		var b = (rgb >>  0) & 0xff;
68
69		var luma = 0.2126 * r + 0.7152 * g + 0.0722 * b;
70
71		if (luma < 40) {
72			$that.addClass('invert-act');
73		}
74	}
75
76	function rgb2hex(rgb){
77		rgb = rgb.match(/^rgba?[\s+]?\([\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?/i);
78		return (rgb && rgb.length === 4) ? "#" +
79		("0" + parseInt(rgb[1],10).toString(16)).slice(-2) +
80		("0" + parseInt(rgb[2],10).toString(16)).slice(-2) +
81		("0" + parseInt(rgb[3],10).toString(16)).slice(-2) : '';
82	}
83	
84	$.fn.multiply = function(numCopies) {
85		var newElements = this.clone();
86		for(var i = 1; i < numCopies; i++)
87		{
88			newElements = newElements.add(this.clone());
89		}
90		return newElements;
91	};
92
93	if($('.mcwp-crypto').length > 0){
94		
95		$.fn.extend({
96			animateCss: function(animationName, callback) {
97				var animationEnd = (function(el) {
98				var animations = {
99					animation: 'animationend',
100					OAnimation: 'oAnimationEnd',
101					MozAnimation: 'mozAnimationEnd',
102					WebkitAnimation: 'webkitAnimationEnd',
103				};
104
105				for (var t in animations) {
106					if (el.style[t] !== undefined) {
107					return animations[t];
108					}
109				}
110				})(document.createElement('div'));
111
112				this.addClass('mcwp-animated ' + animationName).one(animationEnd, function() {
113				$(this).removeClass('mcwp-animated ' + animationName);
114
115				if (typeof callback === 'function') callback();
116				});
117
118				return this;
119			},
120		});
121		
122		$.fn.mcwpTable = function(options) {
123
124			var opts = $.extend({
125				length: this.data('length'),
126				theme: this.data('theme'),
127				color: (this.data('color') == '') ? '#222' : this.data('color'),
128				bgColor: (this.data('bgcolor') == '') ? '#dd3333' : this.data('bgcolor')
129			}, options);
130
131			this.addClass(opts.theme);
132			this.addClass('no-wrap');
133			
134			this.find('thead th').css('color', opts.color);
135
136			if (opts.theme == 'custom') {
137				this.find('th').css('background-color', opts.bgColor);
138                this.css('background-color', hex2rgb(opts.bgColor, 0.1));
139			}
140
141			var coins = {};
142
143			var table = $(this).DataTable({
144				responsive: true,
145				searching: false,
146				paging: true,
147				lengthChange: false,
148				pagingType: 'simple',
149				pageLength: parseInt(opts.length),
150				processing: true,
151				serverSide: true,
152				autoWidth: false,
153				"ajax": {
154					url: mcwpajax.ajax_url,
155					"data": {
156						action : "mcwp_table",
157						mcwp_id : $(this).closest('.mcwp-crypto').attr('id').split('-')[1]
158					}
159				},
160				drawCallback: function(data) {
161
162					coins = {};
163
164					for (var i = 0; i < data.json.data.length; i++) {
165						var row = data.json.data[i];
166						coins[row.symbol] = row;
167						coins[row.symbol]['rowId'] = i;
168					}
169					$.fn.peity.defaults.line = {
170						delimiter: ",",
171						fill: "#c6d9fd",
172						height: '30',
173						max: null,
174						min: null,
175						stroke: "transparent",
176						strokeWidth: 1,
177						width: '150'
178					};
179					$(".mcwp-line").peity("line");
180
181				},
182				responsive: true,
183				columnDefs: [
184					{
185						targets: 0,
186						data: 'rank',
187						name: 'rank',
188						render: function(data, type, row, meta) {
189							return data;
190						}
191					},
192					{
193						targets: 1,
194						data: 'name',
195						name: 'name',
196						render: function(data, type, row, meta) {
197							var tabletd;
198							tabletd	= '<div class="mcwp-card-head"><div><img src="' + row.imgpath + '" class="mcwp-coinimage"><p>';
199							if(typeof row.link != 'undefined' && row.link === true) {
200								tabletd	= tabletd + '<a rel="nofollow" href="https://coingecko.com/coins/'+row.cid+'" target="_blank">' + data + '</a>';
201							} else {
202								tabletd	= tabletd + data;
203							}
204							tabletd	= tabletd + '</p></div></div>';
205							return tabletd;
206						}
207					},
208					{
209						targets: 2,
210						data: 'price',
211						name: 'price_usd',
212						render: function(data, type, row, meta) {
213							var num = parseFloat(data).toFixed(10);
214
215							if((num >= 1) || (num == 0)){
216								num = parseFloat(num).toFixed(2);
217							} else if (num > 0) {
218								zerocount = num.toString().length - Number(num.toString().split('.')[1]).toString().length - 2;
219								count = zerocount > 5 ? 8 : 6;
220								num = parseFloat(num).toFixed(count);
221							}
222							return '$ '+addCommas(num);
223						}
224					},
225					{
226						targets: 3,
227						data: 'mcap',
228						name: 'market_cap_usd',
229						render: function(data, type, row, meta) {
230							var num = data;
231							return '$ '+commarize(num);
232						}
233					},
234					{
235						targets: 4,
236						data: 'change',
237						name: 'percent_change_24h',
238						render: function(data, type, row, meta) {
239							var up = (data > 0) ? 'up mcwp-green' : 'down mcwp-red';
240							return '<small class="micon-arrow-'+up+'"> ' + Math.abs(data) + '%</small>';
241						}
242					},
243					{
244						targets: 5,
245						data: 'weekly',
246						orderable: false,
247						render: function(data, type, row, meta) {
248
249							var spcls = (row.change > 0) ? 'green' : 'red';
250							return '<span class="mcwp-line sp-'+spcls+'" style="display: none">'+data.join(',')+'</span>';
251						}
252					}
253				],
254				language: {
255					processing: '',
256					paginate: {
257						next: 'Next <span class="micon-arrow-circle-o-right"></span>',
258						previous: '<span class="micon-arrow-circle-o-left"></span> Back'  
259					}
260				}
261			});
262			
263			table.on('processing.dt', function ( e, settings, processing ) {
264				if (processing) {
265					$(this).addClass('table-processing');
266				} else {
267						$(this).removeClass('table-processing');
268						$('.dataTables_processing').css('top', '-45px');
269				}
270			});
271
272			table.on('responsive-display', function(e) {
273				$.fn.peity.defaults.line = {
274					delimiter: ",",
275					fill: "#c6d9fd",
276					height: '30',
277					max: null,
278					min: null,
279					stroke: "transparent",
280					strokeWidth: 1,
281					width: '100%'
282				};
283				$(".mcwp-line").peity("line");
284			});
285			
286			$(table.table().container()).addClass('mcwp-table');
287		}
288	}
289	
290	$('.cc-ticker,.mcwp-card,.mcwp-label').each(function(){
291		isBrightness($(this));
292		
293		var invertList = ['ripple','iota','eos','0x','bancor','dentacoin','bibox-token','medishares','santiment','quantstamp','raiden-network-token','pillar','republic-protocol','metal','eidoo','credo','blackmoon','covesting','shivom','suncontract','numeraire','daostack','bitdegree','matryx','faceter','internxt','cryptoping','invacio','chainium','creativecoin','trezarcoin','elcoin-el','jesus-coin','mojocoin','gapcoin','prime-xi','speedcash','veltor','loopring-neo','francs'];
294		
295		$(this).find('img').each(function(){
296			if(invertList.join('-').toLowerCase().indexOf($(this).attr('alt').toLowerCase()) > -1) {
297				$(this).addClass('invertable');
298			}
299			
300		});
301	});
302	
303	
304	$(window).load(function(){
305		
306		$('.cc-stats').each(function(){
307			var listWidth = 0,
308			$that = $(this);
309			
310			$(this).find('li').each(function() {
311				listWidth += $(this).innerWidth();
312			});
313			
314			clonedElem = $(this).find('li');
315			var mult = $(this).innerWidth()/listWidth;
316			$(this).append('<div class="cc-dup"></div>');
317			
318			if(mult > 0.5){
319				$(this).find('.cc-dup').append(clonedElem.multiply(Math.ceil(mult)));
320			} else {
321				$(this).find('.cc-dup').append(clonedElem.multiply(1));
322			}
323			$(this).css('width',listWidth);
324			
325			var itemcount = $(this).find('li').length;
326			var itemsize = listWidth / itemcount;
327			
328			var speed = $(this).closest('.mcwp-ticker').data('speed');
329			var duration = itemsize * 10;
330
331			if (speed === 200) {
332				duration = 10;
333			} else if (speed == 0) {
334				duration = 0;
335			} else if (speed > 100) {
336				speed = speed - 100;
337				speed = (speed / 10) * itemsize;
338				duration = duration - speed;
339			} else if (speed < 100) {
340				speed = 100 - speed;
341				speed = (speed / 10) * (itemsize * 8);
342				duration = duration + speed;
343			}
344			
345			var speed = (itemcount * duration) / 1000;
346			$(this).css('animation-duration',  speed + 's');
347			
348			$(this).closest('.mcwp-ticker').slideDown().css('opacity','1');
349		});
350	
351		if ($('.mcwp-ticker').length > 0) {
352			if($('.mcwp-ticker').hasClass('mcwp-header')){
353				
354				// var bodyHeight = parseInt($('body').css('margin-top')) + parseInt($('body').css('padding-top'));
355				// var htmlHeight = parseInt($('html').css('margin-top')) + parseInt($('html').css('padding-top'));
356				// var fixHeight = $('.mcwp-ticker').height() - bodyHeight - htmlHeight;
357				var fixHeight = $('.mcwp-ticker').height();
358
359				if(fixHeight > 0) {
360					$('body').css('padding-top',fixHeight);
361					$('#wpadminbar').css('margin-top',fixHeight);
362				}
363			}
364		}
365	});
366	
367    $('.mcwp-datatable').each(function(){
368		$(this).mcwpTable();
369	});
370}(jQuery));

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.