Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var dictionary = {};
- dictionary.currency = [{
- text: "USD",
- id: "USD"
- }, {
- text: "AUD",
- id: "AUD"
- }, {
- text: "BRL",
- id: "BRL"
- }, {
- text: "CAD",
- id: "CAD"
- }, {
- text: "CHF",
- id: "CHF"
- }, {
- text: "CLP",
- id: "CLP"
- }, {
- text: "CNY",
- id: "CNY"
- }, {
- text: "CZK",
- id: "CZK"
- }, {
- text: "DKK",
- id: "DKK"
- }, {
- text: "EUR",
- id: "EUR"
- }, {
- text: "GBP",
- id: "GBP"
- }, {
- text: "HKD",
- id: "HKD"
- }, {
- text: "HUF",
- id: "HUF"
- }, {
- text: "IDR",
- id: "IDR"
- }, {
- text: "ILS",
- id: "ILS"
- }, {
- text: "INR",
- id: "INR"
- }, {
- text: "JPY",
- id: "JPY"
- }, {
- text: "KRW",
- id: "KRW"
- }, {
- text: "MXN",
- id: "MXN"
- }, {
- text: "MYR",
- id: "MYR"
- }, {
- text: "NOK",
- id: "NOK"
- }, {
- text: "NZD",
- id: "NZD"
- }, {
- text: "PHP",
- id: "PHP"
- }, {
- text: "PKR",
- id: "PKR"
- }, {
- text: "PLN",
- id: "PLN"
- }, {
- text: "RUB",
- id: "RUB"
- }, {
- text: "SEK",
- id: "SEK"
- }, {
- text: "SGD",
- id: "SGD"
- }, {
- text: "THB",
- id: "THB"
- }, {
- text: "TRY",
- id: "TRY"
- }, {
- text: "TWD",
- id: "TWD"
- }, {
- text: "ZAR",
- id: "ZAR"
- }];
- dictionary.coinUrl = "https://min-api.cryptocompare.com/data/";
- dictionary.cryptocompareUrl = "https://www.cryptocompare.com";
- dictionary.pluginName = "/wp-content/plugins/cryptocurrency-rocket-tools";
- String.prototype.replaceAll = function(a, b) {
- var c = this;
- return c.replace(new RegExp(a, "g"), b)
- };
- isEmpty = function(a) {
- return a == null || a == ""
- };
- SToA = function(b) {
- if (!b) {
- return null
- }
- var a = b.split(",");
- jQuery.each(a, function(c, d) {
- a[c] = d.replace(" ", "")
- });
- return a
- };
- renderArray = function(a, c, b) {
- if (!c.html()) {
- if (a.length > 1) {
- jQuery.each(a, function(d, e) {
- c.append(b.replaceAll("{{name}}", e))
- })
- }
- }
- };
- waitAjax = function(a) {
- jQuery(document).ajaxStop(function() {
- jQuery("#" + a + "_processing").hide()
- })
- };
- sortCoins = function(b) {
- var a = [];
- jQuery.each(b, function(c, d) {
- a.push(d)
- });
- a = a.sort(function(d, c) {
- return parseInt(d.SortOrder) - parseInt(c.SortOrder)
- });
- return a
- };
- function priceMultiRequests(b, a, d) {
- var e = [],
- c = "";
- jQuery.each(b ? b : dictionary.coinsList, function(f, g) {
- c += (b ? g : f) + ",";
- if (c.length > 100) {
- c = c.substring(0, c.length - 1);
- e.push(jQuery.get(dictionary.coinUrl + "pricemultifull?fsyms=" + c + "&tsyms=" + a, function(h) {
- d.DISPLAY = jQuery.extend(true, d.DISPLAY, h.DISPLAY);
- d.RAW = jQuery.extend(true, d.RAW, h.RAW)
- }));
- c = ""
- }
- });
- if (c !== "") {
- e.push(jQuery.get(dictionary.coinUrl + "pricemultifull?fsyms=" + c + "&tsyms=" + a, function(f) {
- d.DISPLAY = jQuery.extend(true, d.DISPLAY, f.DISPLAY);
- d.RAW = jQuery.extend(true, d.RAW, f.RAW)
- }))
- }
- return e
- }
- var crtools = crtools || {};
- var types = ["from", "to", "other"];
- crtools.converter = {
- addSelect: function(d, a, b, e) {
- var h = jQuery('<select class="input-group-addon-ct"></select>'),
- g = jQuery('<div><label></label><div class="input-group-ct ' + (e == "other" ? "cr-other to" : "") + '" ><input type="number" class="form-control-ct"></div></div>');
- g.find("input").on({
- keyup: function(f) {
- crtools.converter.initData(f)
- },
- change: function(f) {
- crtools.converter.initData(f)
- }
- });
- g.find("label").text(d[a + "Name"]);
- h.on("change", function(l) {
- var f = jQuery(l.currentTarget);
- crtools.converter.initData({
- currentTarget: f.closest(".calc").find(".from input")
- })
- });
- h.addClass(a);
- g.find("div.input-group-ct").addClass(a);
- b.append(g);
- if (d[a] && d[a] !== "") {
- var k = d[a].split(",");
- if (k.length > 0) {
- if (k.length === 1) {
- var c = b.find("div." + a);
- if (!e) {
- var i = jQuery('<span class="input-group-addon-ct">' + k[0].replaceAll(" ", "") + " </span>");
- i.addClass(a);
- c.append(i)
- }
- } else {
- crtools.converter.addOptions(h, k);
- b.find("div." + a).append(h)
- }
- } else {
- crtools.converter.addOptions(h, dictionary.currency);
- b.find("div." + a).append(h)
- }
- } else {
- var j = null;
- if (e == "other") {
- j = jQuery.map(dictionary.currency, function(m, f) {
- var l = {
- text: m.text,
- id: m.id
- };
- if (m.text == a) {
- l.selected = true
- }
- return l
- })
- }
- crtools.converter.addOptions(h, j == null ? dictionary.currency : j);
- b.find("div." + a).append(h)
- }
- },
- init: function(a) {
- var d = this;
- var c = {
- from: crtoolsVars.converter_from,
- to: crtoolsVars.converter_to
- };
- a.toolID = a.toolID.indexOf("#") == 0 ? a.toolID : "#" + a.toolID;
- var b = jQuery('<div class="calc"></div>');
- jQuery.each(types, function(e, f) {
- if (!a.fromName) {
- a.fromName = c.from
- }
- if (!a.toName) {
- a.toName = c.to
- }
- if (f == "other") {
- if (a[f]) {
- var g = a[f].split(",");
- a[f] = "";
- jQuery.each(g, function(h, i) {
- d.addSelect(a, i, b, "other")
- })
- }
- } else {
- d.addSelect(a, f, b)
- }
- });
- if (jQuery(a.toolID + " .calc").length == 0) {
- jQuery(a.toolID).html(b)
- }
- },
- render: function() {},
- addOptions: function(b, a) {
- b.html("");
- jQuery.each(a, function(c, d) {
- var f = d.id ? d.id : d.replace(" ", "");
- var e = d.text ? d.text : d.replace(" ", "");
- b.append("<option value='" + f + "' " + (d.selected ? "selected='true'" : "") + "'>" + e + "</option>")
- })
- },
- calculate: function(b, d, a, c) {
- if (!c.hasClass("current")) {
- jQuery.get(dictionary.coinUrl + "price?fsym=" + b + "&tsyms=" + d, function(f) {
- var e;
- if (c.closest("div").hasClass("to")) {
- e = (f[d] * parseFloat(a)).toFixed(2)
- } else {
- e = (parseFloat(a) / f[d]).toFixed(10)
- }
- c.val(e);
- if (c.closest(".input-group-ct").hasClass("from")) {
- c.trigger("keyup", {
- currentTarget: c
- })
- }
- })
- }
- },
- initData: function(d) {
- var c = jQuery(d.currentTarget);
- var i = this;
- var h = "current";
- if (c.closest(".input-group-ct").hasClass("to")) {
- c.closest(".calc").find("." + h).removeClass(h);
- c.addClass(h);
- var b = {
- from: c.closest(".calc").find(".from"),
- to: c.closest(".input-group-ct")
- };
- this.initFrom(b)
- } else {
- var a = {
- from: c.closest(".calc").find(".from span"),
- to: c.closest(".calc").find(".to span")
- };
- var f = c.val(),
- g = a.from.length != 0 ? a.from.html().replaceAll(" ", "") : c.closest(".calc").find(".from select").val();
- if (f && f != "") {
- c.closest(".calc").find(".to").each(function(e, j) {
- var l = i.getCurrency(jQuery(j)),
- k = jQuery(j).find("input");
- crtools.converter.calculate(g, l, f, k)
- })
- }
- c.closest(".calc").find("." + h).removeClass(h)
- }
- },
- initFrom: function(a) {
- var c = {
- value: a.from.find("input").val(),
- curruncy: this.getCurrency(a.from)
- },
- b = {
- value: a.to.find("input").val(),
- curruncy: this.getCurrency(a.to)
- };
- crtools.converter.calculate(c.curruncy, b.curruncy, b.value, a.from.find("input"))
- },
- getCurrency: function(b) {
- var a = b.find("span, select");
- if (a.prop("tagName") == "SELECT") {
- return a.val().trim()
- } else {
- if (a.prop("tagName") == "SPAN") {
- return a.text().trim()
- }
- }
- return ""
- },
- removeCurrentClass: function() {}
- };
- var crtools = crtools || {};
- var currencyIcons = {
- USD: {
- Name: "US Dollar",
- ISOSymbol: "$"
- },
- EUR: {
- Name: "Euro",
- ISOSymbol: "€"
- },
- GBP: {
- Name: "British Pound",
- ISOSymbol: "£"
- },
- BTC: {
- Name: "Bitcoin",
- ISOSymbol: "Ƀ"
- },
- ETH: {
- Name: "Ether",
- ISOSymbol: "Ξ"
- },
- GOLD: {
- Name: "Gold",
- ISOSymbol: "Gold g"
- },
- AUD: {
- Name: "Australian Dollar",
- ISOSymbol: "AUD"
- },
- BRL: {
- Name: "Brazilian Real",
- ISOSymbol: " R$"
- },
- CAD: {
- Name: "Canadian Dollar",
- ISOSymbol: "CAD"
- },
- CHF: {
- Name: "Swiss Franc",
- ISOSymbol: "CHF"
- },
- CNY: {
- Name: "Chinese Yuan",
- ISOSymbol: "¥"
- },
- HKD: {
- Name: "Hong Kong Dollar",
- ISOSymbol: "HKD"
- },
- HUF: {
- Name: "Hungarian Forint ",
- ISOSymbol: "HUF"
- },
- INR: {
- Name: "Indian Rupee",
- ISOSymbol: "₹"
- },
- JPY: {
- Name: "Japanese Yen",
- ISOSymbol: "¥"
- },
- KRW: {
- Name: "South Korean Won",
- ISOSymbol: "₩"
- },
- MXN: {
- Name: "Mexican Peso",
- ISOSymbol: "MXN"
- },
- NZD: {
- Name: "New Zealand Dollar",
- ISOSymbol: "NZD"
- },
- PHP: {
- Name: "Philippines Peso",
- ISOSymbol: "₱"
- },
- PLN: {
- Name: "Polish Zloty",
- ISOSymbol: "zł"
- },
- RON: {
- Name: "Romanian New Leu",
- ISOSymbol: "lei"
- },
- RUB: {
- Name: "Russian Ruble",
- ISOSymbol: "₽"
- },
- SGD: {
- Name: "Singapore Dollar",
- ISOSymbol: "SGD"
- },
- VEF: {
- Name: "Venezuelan Bolivar",
- ISOSymbol: "Bs"
- }
- };
- var localArgs = {};
- crtools.graph = {
- init: function(a) {
- this.initLocale();
- var c = this;
- a.toolID = a.toolID.indexOf("#") == 0 ? a.toolID : "#" + a.toolID;
- localArgs[a.toolID] = a;
- var b = jQuery('<div class="single-chart-block"><div class="sg-fiats"></div><div class="sg-buttons"></div><div class="chart-div" style="width : 100%; height : 500px;"></div></div>');
- b.find(".chart-div").attr("id", a.toolID + "-chart-div");
- if (jQuery(a.toolID + " .single-chart-block").length == 0) {
- jQuery(a.toolID).html(b)
- }
- this.render(a);
- jQuery(".period-button").on("click", function(g) {
- var d = jQuery(g.currentTarget);
- jQuery(a.toolID + " .period-button").removeClass("active");
- d.addClass("active");
- var f = d.closest(".single-chart-block").find(".chart-div").attr("id").replace("-chart-div", "");
- localArgs[f].currentPeriod = d.text();
- c.render(a)
- });
- jQuery(".fiat-button").on("click", function(g) {
- var d = jQuery(g.currentTarget);
- jQuery(a.toolID + " .fiat-button").removeClass("active");
- d.addClass("active");
- var f = d.closest(".single-chart-block").find(".chart-div").attr("id").replace("-chart-div", "");
- localArgs[f].currentFiat = d.text();
- c.render(a)
- })
- },
- initLocale: function() {
- AmCharts.dayNames = crtoolsVars.graph_dayNames;
- AmCharts.shortDayNames = crtoolsVars.graph_shortDayNames;
- AmCharts.monthNames = crtoolsVars.graph_monthNames;
- AmCharts.shortMonthNames = crtoolsVars.graph_shortMonthNames
- },
- renderGraph: function(e, h, a, d, f, b) {
- var g = this;
- var c = AmCharts.makeChart(h, {
- type: "stock",
- theme: "light",
- categoryAxesSettings: {
- minPeriod: d,
- groupToPeriods: [d]
- },
- dataSets: [{
- fieldMappings: [{
- fromField: "value",
- toField: "value"
- }, {
- fromField: "volume",
- toField: "volume"
- }],
- dataProvider: e,
- title: "",
- categoryField: "date"
- }],
- panels: [{
- title: crtoolsVars.graph_valuesName + " " + f,
- percentHeight: 70,
- stockGraphs: [{
- type: "line",
- id: "g1",
- valueField: "value",
- lineThickness: 2,
- fillAlphas: 0.3,
- useDataSetColors: false,
- balloonText: a + " [[value]]",
- title: "",
- lineColor: b.line
- }],
- chartCursor: {
- valueBalloonsEnabled: true,
- valueLineEnabled: true,
- valueLineBalloonEnabled: true,
- cursorColor: b.cursor,
- fullWidth: true,
- cursorAlpha: 0.1
- },
- stockLegend: {
- valueTextRegular: a + " [[value]]",
- valueText: a + " [[value]]"
- }
- }, {
- title: crtoolsVars.graph_valuesName + " " + f,
- percentHeight: 30,
- columnWidth: 0.8,
- stockGraphs: [{
- type: "column",
- id: "g2",
- valueField: "volume",
- fillAlphas: 0.8,
- useDataSetColors: false,
- balloonText: a + " [[volume]]",
- title: "",
- lineColor: b.line
- }],
- chartCursor: {
- valueBalloonsEnabled: true,
- valueLineEnabled: true,
- valueLineBalloonEnabled: true,
- cursorColor: b.cursor,
- fullWidth: true,
- cursorAlpha: 0.1
- },
- stockLegend: {
- valueTextRegular: a + " [[value]]",
- valueText: " [[value]]"
- }
- }],
- chartScrollbarSettings: {
- graph: "g1",
- backgroundAlpha: 0.25,
- backgroundColor: "#b0b0b0",
- selectedBackgroundAlpha: 0.8,
- selectedBackgroundColor: "#b0b0b0"
- },
- responsive: {
- enabled: true
- }
- });
- c.addListener("dataUpdated", function() {
- g.zoomChart(c, e)
- })
- },
- zoomChart: function(a, b) {
- if (a.zoomToIndexes) {
- a.zoomToIndexes(0, b.length)
- }
- },
- render: function(h) {
- var k = h.coin,
- f = h.fiat,
- i = h.period,
- b = h.toolID,
- a = {
- line: h.graphColor ? h.graphColor : "#5db75c",
- cursor: h.cursorColor ? h.cursorColor : "#c90000"
- };
- var g = this;
- if (isEmpty(f)) {
- f = ["USD", "EUR"]
- } else {
- f = SToA(f)
- }
- if (isEmpty(k)) {
- k = "BTC"
- }
- if (isEmpty(i)) {
- i = ["12H", "1D", "1W", "1M", "6M", "1Y", "ALL"]
- } else {
- i = SToA(i)
- }
- if (!h.currentPeriod) {
- h.currentPeriod = jQuery.inArray("1D", i) != -1 ? "1D" : i[0]
- }
- if (!h.currentFiat) {
- h.currentFiat = f[0]
- }
- renderArray(i, jQuery(h.toolID).find(".sg-buttons"), '<button type="button" class="period-button" value={{name}}>{{name}}</button>');
- renderArray(f, jQuery(h.toolID).find(".sg-fiats"), '<button type="button" class="fiat-button" value={{name}}>{{name}}</button>');
- jQuery(h.toolID).find(".sg-buttons [type=button][value=" + h.currentPeriod + "]").addClass("active");
- jQuery(h.toolID).find(".sg-fiats [type=button][value=" + h.currentFiat + "]").addClass("active");
- var c, e, d, j;
- switch (h.currentPeriod) {
- case "12H":
- c = "1";
- e = "720";
- d = "histominute";
- j = c + "mm";
- break;
- case "1D":
- c = "5";
- e = "288";
- d = "histominute";
- j = c + "mm";
- break;
- case "1W":
- c = "1";
- e = "168";
- d = "histohour";
- j = c + "hh";
- break;
- case "1M":
- c = "1";
- e = "720";
- d = "histohour";
- j = c + "hh";
- break;
- case "6M":
- c = "1";
- e = "182";
- d = "histoday";
- j = c + "DD";
- break;
- case "1Y":
- c = "1";
- e = "364";
- d = "histoday";
- j = c + "DD";
- break;
- case "ALL":
- jQuery.get(ajaxurl + "?action=get_start_date&coin=" + k, function(l) {
- l = JSON.parse(l);
- if (l.Response == "Success") {
- var o = new Date(l.Date);
- var n = new Date();
- var p = Math.abs(n.getTime() - o.getTime());
- var m = Math.ceil(p / (1000 * 3600 * 24));
- console.log(Math.ceil(m / 1000));
- c = Math.ceil(m / 1000).toString();
- e = "1000";
- d = "histoday";
- j = c + "DD";
- g.getDataFromService(b, k, h.currentFiat, c, e, d, j, a)
- } else {
- alert(l.Message)
- }
- });
- return
- }
- this.getDataFromService(b, k, h.currentFiat, c, e, d, j, a)
- },
- getDataFromService: function(b, j, g, c, e, d, i, a) {
- var f = [];
- var h = this;
- jQuery.get(dictionary.coinUrl + d + "?fsym=" + j + "&tsym=" + g + "&aggregate=" + c + "&limit=" + e, function(l) {
- if (l.Data != null && l.Data.length > 0) {
- jQuery.each(l.Data, function(o, p) {
- f.push({
- date: new Date(p.time * 1000),
- value: p.close,
- volume: p.volumeto
- })
- })
- }
- var m = jQuery(b).find(".chart-div");
- var k = currencyIcons[g] == null ? g : currencyIcons[g].ISOSymbol;
- var n = currencyIcons[g] == null ? g : currencyIcons[g].Name;
- h.renderGraph(f, m.attr("id"), k, i, n, a)
- })
- }
- };
- var crtools = crtools || {};
- crtools.pricelist = {
- templates: {
- tabs: '<div class="crtools-pricelist"><div class="tab-div"></div></div>',
- tab: '<a class="tab">{{name}}</a>',
- row: '<div class="crtools-row">\n<div class="row-left"><img class="crtools-logo" src="{{logo}}"><span class="crtools-symbol">{{symbol}}</span></div>\n<div class="row-right"><div class="{{color}}" style="{{styleColor}}"><span class="crtools-price">{{price}}</span> <span class="crtools-change">({{change}}) <img src="{{arrow}}"></span></div></div>\n</div>'
- },
- init: function(b) {
- var a = this.getFiats(b.fiat),
- c = this.getCols(b.cols);
- this.initCoins(b.coin, b.limit, a, c, b.toolID, b.redColor, b.greenColor)
- },
- initCoins: function(d, b, a, e, c, f, h) {
- var g = this;
- jQuery.get(dictionary.coinUrl + "all/coinlist", function(j) {
- crtools.pricelist.sortedCoins = sortCoins(j.Data);
- crtools.pricelist.notSortedCoins = j.Data;
- var i = g.getCoinsList(d, b);
- g.getPrices(i, a, e, c, f, h)
- })
- },
- getCoinsList: function(b, a) {
- if (a && a !== "" && a !== "0") {
- return this.getTopCoins(a)
- } else {
- if (a === "0") {
- return this.getTopCoins(0)
- } else {
- if (b && b !== "") {
- return SToA(b)
- } else {
- return this.getTopCoins(10)
- }
- }
- }
- },
- getTopCoins: function(b) {
- var a = [];
- jQuery.each(crtools.pricelist.sortedCoins, function(c, d) {
- if (b === 0 || c < b) {
- a.push(d.Symbol)
- } else {
- return false
- }
- });
- return a
- },
- getPrices: function(e, g, h, d, c, b) {
- var f = this;
- var i = {
- DISPLAY: {},
- RAW: {}
- };
- var a = priceMultiRequests(e, g.join(","), i);
- jQuery.when.apply(jQuery, a).done(function() {
- crtools.pricelist[d] = {
- coins: i,
- fiats: g,
- cols: h,
- redColor: c,
- greenColor: b
- };
- jQuery("#" + d).html(f.getHtml(d))
- })
- },
- getFiats: function(a) {
- return a && a !== "" ? SToA(a) : ["USD"]
- },
- getCols: function(a) {
- return a && a !== "" ? SToA(a) : null
- },
- getHtml: function(c) {
- var e = this;
- var b = jQuery(crtools.pricelist.templates.tabs);
- var d = crtools.pricelist[c].fiats[0];
- var a = jQuery(this.getTabsHtml(crtools.pricelist[c].fiats));
- b.find(".tab-div").append(a);
- a.on("click", function(j) {
- var g = jQuery(j.currentTarget);
- var h = g.closest(".crtools-pricelist"),
- f = g.text();
- var i = h.parent().attr("id");
- e.renderTab(i, f, h)
- });
- this.renderTab(c, d, b);
- return b
- },
- renderTab: function(c, a, b) {
- b.find(".crtools-row").remove();
- this.activateTab(a, b);
- b.append(this.getRowsHtml(crtools.pricelist[c].coins, a, crtools.pricelist[c].cols, crtools.pricelist[c].redColor, crtools.pricelist[c].greenColor))
- },
- activateTab: function(a, c) {
- var b = c.find(".tab");
- b.removeClass("active");
- b.each(function(d, f) {
- var e = jQuery(f);
- if (e.text() === a) {
- e.addClass("active")
- }
- })
- },
- getTabsHtml: function(a) {
- var c = this;
- var b = "";
- jQuery.each(a, function(d, e) {
- b += c.getTabHtml(e)
- });
- return b
- },
- getTabHtml: function(a) {
- return crtools.pricelist.templates.tab.replace("{{name}}", a)
- },
- getRowsHtml: function(b, a, d, e, g) {
- var f = this;
- var c = "";
- jQuery.each(b.DISPLAY, function(h, i) {
- c += f.getRowHtml(h, i[a], d, e, g)
- });
- return c
- },
- getRowHtml: function(c, e, h, b, a) {
- var d, i, g = "";
- var j = dictionary.cryptocompareUrl + crtools.pricelist.notSortedCoins[c].ImageUrl;
- if (e.CHANGEPCT24HOUR && e.CHANGEPCT24HOUR.substr(0, 1) === "-") {
- i = dictionary.pluginName + "/assets/images/crtools_down.svg";
- if (b && b !== "") {
- g = "color:" + b;
- d = ""
- } else {
- d = "red"
- }
- } else {
- i = dictionary.pluginName + "/assets/images/crtools_up.svg";
- if (a && a !== "") {
- g = "color:" + a;
- d = ""
- } else {
- d = "green"
- }
- }
- var f = crtools.pricelist.templates.row;
- f = f.replace("{{logo}}", j);
- f = f.replace("{{symbol}}", c);
- f = f.replace("{{price}}", e.PRICE.split(" ")[1]);
- f = f.replace("{{change}}", e.CHANGEPCT24HOUR + "%");
- f = f.replace("{{arrow}}", i);
- f = f.replace("{{color}}", d);
- f = f.replace("{{styleColor}}", g);
- var k = jQuery(f);
- if (h) {
- if (h.indexOf("logo") === -1) {
- k.find(".crtools-logo").remove()
- }
- if (h.indexOf("symbol") === -1) {
- k.find(".crtools-symbol").remove()
- }
- if (h.indexOf("price") === -1) {
- k.find(".crtools-price").remove()
- }
- if (h.indexOf("change") === -1) {
- k.find(".crtools-change").remove()
- }
- }
- return k[0].outerHTML
- }
- };
- var crtools = crtools || {};
- var dt = {},
- dataSet = {};
- crtools.table = {
- init: function(a) {
- jQuery.get(dictionary.coinUrl + "all/coinlist", function(b) {
- dictionary.coinsList = b.Data;
- crtools.table.initData(a)
- })
- },
- initData: function(j) {
- var g = ["USD", "EUR"];
- if (j.fiat != null) {
- g = j.fiat.split(",")
- }
- var h = this;
- var b = j.coin,
- f = g,
- e = j.cols,
- o = j.search,
- d = j.pagination;
- var n = {
- base: j.baseLink && j.baseLink !== "" ? j.baseLink : null,
- coins: j.pageLinks && j.pageLinks.length !== 0 ? j.pageLinks : null,
- isGraph: j.graphLink
- };
- if (!e || e == "") {
- e = ["price", "cap", "supply", "volume", "change", "graph"]
- } else {
- e = e.split(",")
- }
- j.toolID = (j.toolID.indexOf("#") == 0 ? "" : "#") + j.toolID;
- if (b && b != "") {
- b = b.split(",");
- jQuery.each(b, function(p, q) {
- q = q.replaceAll(" ", "").toUpperCase()
- })
- }
- if (d && d != "") {
- d = jQuery.map(d.split(","), function(p) {
- return parseInt(p)
- })
- } else {
- d = [10, 25]
- }
- var c = {
- fiat: g.length == 1,
- search: o == "no" || o === false,
- length: d.length == 1
- };
- var l = jQuery(".currency select").val();
- if (!l) {
- l = f && f[0] ? f[0] : "USD"
- }
- if (f) {
- dictionary.currency = [];
- jQuery.each(f, function(p, q) {
- dictionary.currency.push({
- id: q,
- text: q
- })
- })
- }
- dataSet[j.toolID] = [];
- pricemulti = {
- DISPLAY: {},
- RAW: {}
- };
- var a = priceMultiRequests(b, l, pricemulti);
- jQuery.when.apply(jQuery, a).done(function() {
- jQuery.each(b ? b : dictionary.coinsList, function(s, t) {
- if (b) {
- s = t;
- t = dictionary.coinsList[t]
- }
- if (pricemulti.DISPLAY[s]) {
- dataSet[j.toolID].push(m(e, pricemulti, s, l, t))
- }
- });
- if (dt[j.toolID] == null) {
- columnsDT = i(e, n);
- var q = {
- lengthMenu: d,
- processing: true,
- serverSide: true,
- responsive: true,
- aoColumns: columnsDT.aoColumns,
- dom: (c.fiat ? "" : '<"currency">') + (c.search ? "" : "f") + "rtp" + (c.length ? "" : "l"),
- columns: columnsDT.names,
- order: [
- [0, "asc"]
- ],
- columnDefs: columnsDT.columnDefs,
- language: {
- lengthMenu: crtoolsVars.table_lengthName,
- search: crtoolsVars.table_search,
- processing: crtoolsVars.table_processing,
- paginate: {
- first: crtoolsVars.table_paginate_first,
- last: crtoolsVars.table_paginate_last,
- next: crtoolsVars.table_paginate_next,
- previous: crtoolsVars.table_paginate_previous
- }
- },
- drawCallback: function(t) {
- var s = jQuery(this).closest(".dataTables_wrapper").find(".dataTables_paginate");
- s.toggle(this.api().page.info().pages > 1)
- },
- ajax: function(x, E) {
- var s = this.dataTable().api().settings()[0].sTableId;
- jQuery("#" + s + "_processing").show();
- x.start = parseInt(x.start);
- x.length = parseInt(x.length);
- var F = x.search.value;
- var u = 0;
- var C = x.order[0].column;
- var y = dataSet[j.toolID][0][C];
- if (y.fullName) {
- y = y.fullName
- }
- var z, B, t = x.order[0].dir;
- if (y.indexOf(" ") >= 0) {
- var w = y.indexOf("%") != -1 ? 0 : 1;
- var A = y.split(" ")[w];
- if (isNaN(parseFloat(A))) {
- z = "string"
- } else {
- z = "float";
- B = w
- }
- } else {
- if (isNaN(y)) {
- z = "string"
- } else {
- B = 0;
- z = "float"
- }
- }
- dataSet[j.toolID].sort(function(H, G) {
- var I;
- if (H.fullName) {
- I = true
- }
- if (z == "float") {
- if (t == "asc") {
- return parseFloat(H[C].split(" ")[B].replaceAll(",", "")) - parseFloat(G[C].split(" ")[B].replaceAll(",", ""))
- } else {
- return parseFloat(G[C].split(" ")[B].replaceAll(",", "")) - parseFloat(H[C].split(" ")[B].replaceAll(",", ""))
- }
- } else {
- if (t == "asc") {
- return (G[C].fullName ? G[C].fullName : G[C]) < (H[C].fullName ? H[C].fullName : H[C]) ? 1 : -1
- } else {
- return (G[C].fullName ? G[C].fullName : G[C]) > (H[C].fullName ? H[C].fullName : H[C]) ? 1 : -1
- }
- }
- });
- var v = {
- aaData: []
- };
- var D = 0;
- jQuery.each(dataSet[j.toolID], function(G, H) {
- if (F !== "") {
- if (H[1].fullName.toLowerCase().indexOf(F.toLowerCase()) >= 0) {
- if (G - u >= parseInt(x.start) && G - u < parseInt(x.start) + parseInt(x.length)) {
- v.aaData.push(H)
- }
- D++
- } else {
- u++
- }
- } else {
- if (G >= parseInt(x.start) && G < parseInt(x.start) + parseInt(x.length)) {
- v.aaData.push(H)
- }
- }
- });
- v.recordsTotal = v.out_cunt = v.recordsFiltered = F !== "" ? D : dataSet[j.toolID].length;
- this.rowsCount = v.aaData.length;
- E(v)
- }
- };
- if (k(j.toolID)) {
- q.fixedColumns = true;
- q.scrollY = true;
- q.scrollX = true;
- q.scrollCollapse = true;
- q.fixedColumns = {
- leftColumns: 2
- }
- }
- dt[j.toolID] = jQuery(j.toolID).DataTable(q);
- var p = jQuery(".currency");
- if (p.find("select").length == 0) {
- var r = "";
- jQuery.each(dictionary.currency, function(s, t) {
- r += '<option value="' + t.id + '">' + t.text + "</option>\r\n"
- });
- p.append("<span>" + crtoolsVars.table_currency + ': </span><select class="form-control input-sm">' + r + "</select>");
- p.find("select").on("change", function() {
- h.initData(j)
- })
- }
- } else {
- dt[j.toolID].rows().invalidate("data").draw(false)
- }
- });
- function k(p) {
- if (jQuery(p).width() < 1050) {
- return true
- }
- return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)
- }
- function m(s, u, r, q, t) {
- var p = [t.SortOrder, {
- fullName: t.FullName,
- name: t.Name,
- img: dictionary.cryptocompareUrl + t.ImageUrl
- }];
- jQuery.each(s, function(v, x) {
- x = x.replaceAll(" ", "");
- switch (x) {
- case "price":
- p.push(u.DISPLAY[r][q].PRICE);
- break;
- case "cap":
- var w = u.DISPLAY[r][q].MKTCAP;
- var z = "";
- switch (w.substring(w.length - 1, w.length)) {
- case "B":
- z = ",000,000,000";
- break;
- case "M":
- z = ",000,000";
- break;
- case "K":
- z = ",000";
- break
- }
- var y = w.indexOf(".");
- if (v != -1) {
- w = w.substring(0, y)
- }
- w += z;
- if (w == "") {
- w = u.DISPLAY[r][q].TOSYMBOL + " 0"
- }
- p.push(w);
- break;
- case "supply":
- p.push(u.DISPLAY[r][q].SUPPLY);
- break;
- case "volume":
- p.push(u.DISPLAY[r][q].VOLUME24HOURTO);
- break;
- case "change":
- p.push(u.DISPLAY[r][q].CHANGEPCT24HOUR + " %");
- break;
- case "graph":
- p.push("");
- break
- }
- });
- return p
- }
- function i(r, q) {
- var p = {
- names: [{
- title: crtoolsVars.table_number
- }, {
- title: crtoolsVars.table_name
- }],
- aoColumns: [{
- bSortable: true,
- sTitle: crtoolsVars.table_number
- }, {
- bSortable: true,
- sTitle: crtoolsVars.table_name
- }],
- columnDefs: [{
- createdCell: function(y, s, x, v) {
- var u = '<div class="table-cell coin-ico"><img src="' + s.img + '" alt="' + s.fullName + '" style="width:25px;max-width: inherit;"></div><div class="table-cell coin-name"><span>' + s.fullName + "</span></div>";
- var w = s.fullName.substring(s.fullName.indexOf("(") + 1, s.fullName.indexOf(")"));
- if (q.base && (!q.coins || q.coins.indexOf(w) !== -1)) {
- jQuery(y).html('<a href="/' + (q.base == "/" ? "" : q.base + "/") + w.toLowerCase() + '/">' + u + "</a>")
- } else {
- jQuery(y).html(u)
- }
- jQuery(y).addClass("left-side");
- if (this.rowsCount - 1 == v) {
- var t = this.dataTable().api().settings()[0].sTableId;
- waitAjax(t)
- }
- },
- targets: 1
- }]
- };
- jQuery.each(r, function(s, t) {
- t = t.replaceAll(" ", "");
- if (t === "price") {
- p.names.push({
- title: crtoolsVars.table_price
- });
- p.aoColumns.push({
- bSortable: true,
- sTitle: crtoolsVars.table_price
- })
- } else {
- if (t === "cap") {
- p.names.push({
- title: crtoolsVars.table_cap,
- width: 150
- });
- p.aoColumns.push({
- bSortable: true,
- sTitle: crtoolsVars.table_cap
- })
- } else {
- if (t === "supply") {
- p.names.push({
- title: crtoolsVars.table_supply,
- width: 150
- });
- p.aoColumns.push({
- bSortable: true,
- sTitle: crtoolsVars.table_supply
- })
- } else {
- if (t === "volume") {
- p.names.push({
- title: crtoolsVars.table_volume,
- width: 200
- });
- p.aoColumns.push({
- bSortable: true,
- sTitle: crtoolsVars.table_volume
- });
- p.columnDefs.push({
- render: function(v) {
- if (v) {
- var u = v.indexOf("-") >= 0 ? "red-text" : "green-text";
- return '<span class="' + u + '">' + v + "</span>"
- } else {
- return ""
- }
- },
- targets: s + 2
- })
- } else {
- if (t === "change") {
- p.names.push({
- title: crtoolsVars.table_change,
- width: 200
- });
- p.aoColumns.push({
- bSortable: true,
- sTitle: crtoolsVars.table_change
- });
- p.columnDefs.push({
- render: function(v) {
- if (v) {
- var u = v.indexOf("-") >= 0 ? "red-text" : "green-text";
- return '<span class="' + u + '">' + v + "</span>"
- } else {
- return ""
- }
- },
- targets: s + 2
- })
- } else {
- if (t === "graph") {
- p.names.push({
- title: crtoolsVars.table_graph,
- width: 250
- });
- p.aoColumns.push({
- bSortable: false,
- sTitle: crtoolsVars.table_graph,
- sWidth: "250px"
- });
- p.columnDefs.push({
- createdCell: function(y, u, x, v) {
- var w = x[1].name;
- jQuery.ajax({
- url: dictionary.coinUrl + "histohour?fsym=" + w + "&tsym=" + l + "&limit=168&aggregate=1",
- success: function(C) {
- var F = [],
- D = [];
- var E, B;
- if (C.Data[0] == null) {
- jQuery(y).html("");
- return
- }
- if (C.Data[0].close < C.Data[C.Data.length - 1].close) {
- E = "#1e8b3b";
- B = "#a8d1b2"
- } else {
- E = "#a11b09";
- B = "#daa5a1"
- }
- jQuery.each(C.Data, function(I, H) {
- var G = new Date(H.time * 1000);
- F.push(G);
- D.push(H.close)
- });
- var z = '<canvas class="myChart" height="50px" width="200px"></canvas>';
- if (q.base && q.isGraph && (!q.coins || q.coins.indexOf(w) !== -1)) {
- jQuery(y).html('<a href="/' + (q.base == "/" ? "" : q.base + "/") + w.toLowerCase() + '/">' + z + "</a>")
- } else {
- jQuery(y).html(z)
- }
- var A = new Chart(jQuery(y).find(".myChart"), {
- type: "line",
- data: {
- labels: F,
- datasets: [{
- data: D
- }]
- },
- options: {
- elements: {
- point: {
- radius: 0
- },
- line: {
- borderColor: E,
- backgroundColor: B
- }
- },
- scales: {
- xAxes: [{
- display: false
- }],
- yAxes: [{
- display: false
- }]
- },
- legend: {
- display: false
- },
- responsive: false,
- display: false,
- tooltips: {
- enabled: false
- }
- }
- });
- jQuery(window).trigger("resize")
- },
- error: function() {
- jQuery(y).html("")
- }
- })
- },
- targets: s + 2
- })
- }
- }
- }
- }
- }
- }
- });
- return p
- }
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment