Getting coin names from coinmarketcap

This commit is contained in:
Antonio Viggiano 2018-03-21 00:55:48 -03:00
parent a76db28a60
commit 55feb245c9
4 changed files with 331 additions and 327 deletions

View File

@ -78,7 +78,7 @@
<!-- Javascript -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<script src="js/main.min.js"></script>
<script src="js/main.js"></script>
</body>
</html>

View File

@ -8,6 +8,7 @@ $(document).ready(function() {
var variants = ["color", "black", "icon", "white"];
var iconDefault = "black";
var iconHover = "color";
var url = 'https://api.coinmarketcap.com/v1/ticker/?limit=0'
// ------------------------------
@ -26,40 +27,43 @@ $(document).ready(function() {
// ------------------------------
// Get list of icons in manifest
// ------------------------------
$.getJSON(dataJson, function(data) {
$.get(url, function(coins){
$.getJSON(dataJson, function(data) {
var icons = "";
var count = 0;
data.icons.forEach(function(icon) {
var coin = coins.find(function(coin){
return coin.symbol.toLowerCase() === icon
})
var name = coin ? coin.name.toLowerCase() : icon
// Construct icon
if (icons.indexOf("data-icon=\"" + icon + "\"") === -1) {
icons += "<div class=\"col-6 col-sm-4 col-lg-3 col-xl-2 text-left icon\">";
icons += "<a href=\"#" + icon + "\" class=\"bg-light text-muted text-uppercase d-block p-4\" data-toggle=\"modal\" data-target=\"#infoIcon\" data-icon=\"" + icon + "\" data-name=\"" + name + "\">";
icons += "<img class=\"mr-2\" src=\"svg/" + iconDefault + "/" + icon + ".svg\" alt=\"" + icon + "\" onerror=\"error(this);\">" + icon;
icons += "</a>";
icons += "</div>";
count++;
}
});
var icons = "";
var count = 0;
$.each(data.icons, function(key, val) {
// Display
$(".row.icons").html(icons);
// Construct icon
if (icons.indexOf("data-icon=\"" + val + "\"") == -1) {
icons += "<div class=\"col-6 col-sm-4 col-lg-3 col-xl-2 text-left icon\">";
icons += "<a href=\"#" + val + "\" class=\"bg-light text-muted text-uppercase d-block p-4\" data-toggle=\"modal\" data-target=\"#infoIcon\" data-icon=\"" + val + "\">";
icons += "<img class=\"mr-2\" src=\"svg/" + iconDefault + "/" + val + ".svg\" alt=\"" + val + "\" onerror=\"error(this);\">" + val;
icons += "</a>";
icons += "</div>";
count++;
}
// Hover
$(".icon").hover(function() {
changeFolder($(this), iconDefault, iconHover);
});
// Mouseleave
$(".icon").mouseleave(function() {
changeFolder($(this), iconHover, iconDefault );
});
// Count icons
$(".count-cryptos").text(count);
});
// Display
$(".row.icons").html(icons);
// Hover
$(".icon").hover(function() {
changeFolder($(this), iconDefault, iconHover);
});
// Mouseleave
$(".icon").mouseleave(function() {
changeFolder($(this), iconHover, iconDefault );
});
// Count icons
$(".count-cryptos").text(count);
});
@ -167,6 +171,7 @@ $(document).ready(function() {
// Filter icons
$(".icon").css("display", "none");
$("a[data-icon*='" + $(target).val().toLowerCase() + "']").parent().css("display", "block");
$("a[data-name*='" + $(target).val().toLowerCase() + "']").parent().css("display", "block");
// Close
$("<div class=\"close-search\"></div>").insertAfter(target);

2
js/main.min.js vendored
View File

@ -1 +1 @@
function error(t){$(t).parent().parent().remove()}$(document).ready(function(){function t(t,e,o){var t=$(t).find("img"),a=$(t).attr("src").replace(e,o);$(t).attr("src",a)}function e(t){$(t).val().length>0?($(".icon").css("display","none"),$("a[data-icon*='"+$(t).val().toLowerCase()+"']").parent().css("display","block"),$('<div class="close-search"></div>').insertAfter(t),$(".close-search").click(function(){o(t)})):o(t)}function o(t){$(".close-search").remove(),$(".icon").css("display","block"),$(t).val("")}var a=["svg","128","32","32@2x"],c=["color","black","icon","white"];$("form .search").on("input",function(){e($(this))}),$("form").submit(function(t){t.preventDefault(),e($("form .search"))}),$.getJSON("manifest.json",function(e){var o="",a=0;$.each(e.icons,function(t,e){-1==o.indexOf('data-icon="'+e+'"')&&(o+='<div class="col-6 col-sm-4 col-lg-3 col-xl-2 text-left icon">',o+='<a href="#'+e+'" class="bg-light text-muted text-uppercase d-block p-4" data-toggle="modal" data-target="#infoIcon" data-icon="'+e+'">',o+='<img class="mr-2" src="svg/black/'+e+'.svg" alt="'+e+'" onerror="error(this);">'+e,o+="</a>",o+="</div>",a++)}),$(".row.icons").html(o),$(".icon").hover(function(){t($(this),"black","color")}),$(".icon").mouseleave(function(){t($(this),"color","black")}),$(".count-cryptos").text(a)}),$("#infoIcon").on("show.bs.modal",function(t){var e=$(t.relatedTarget),o=$(this),n=e.data("icon"),r="",i=0,l=0;for(r+='<table class="table info-icon mb-0">',r+="<thead>",r+="<tr>",r+='<th class="text-center text-uppercase align-middle"><h5 class="mb-0">'+n+"</h5></th>";c[l];){s=a[i].replace("@","-");r+='<th class="variant-'+c[l]+' text-center font-weight-light text-muted align-middle">'+c[l]+"</th>",l++}for(l=0,r+="</tr>",r+="</thead>",r+="<tbody>";a[i];){var s;if(r+="<tr>",r+='<th class="format-'+(s=a[i].replace("@","-"))+' text-center font-weight-light text-muted align-middle" scope="row">'+a[i]+"</th>","svg"==a[i])d=".svg";else if("32@2x"==a[i])d="@2x.png";else var d=".png";for(;c[l];)r+='<td class="format-'+s+" variant-"+c[l]+' text-center">',r+='<img src="'+a[i]+"/"+c[l]+"/"+n+d+'" alt="'+n+'">',r+="</td>",l++;l=0,i++,r+="</tr>"}r+="</tbody>",r+="</table>",o.find(".modal-title").text(n),o.find(".modal-body").html(r)})});

View File

@ -1,297 +1,296 @@
{
"icons": {
"act": "act",
"ada": "ada",
"adx": "adx",
"ae": "ae",
"agi": "agi",
"agrs": "agrs",
"aion": "aion",
"amb": "amb",
"amp": "amp",
"ant": "ant",
"appc": "appc",
"ardr": "ardr",
"ark": "ark",
"arn": "arn",
"ast": "ast",
"atm": "atm",
"bat": "bat",
"bay": "bay",
"bcc": "bcc",
"bcd": "bcd",
"bch": "bch",
"bcn": "bcn",
"bco": "bco",
"bcpt": "bcpt",
"bdl": "bdl",
"bela": "bela",
"bix": "bix",
"blcn": "blcn",
"blk": "blk",
"block": "block",
"blz": "blz",
"bnb": "bnb",
"bnt": "bnt",
"bnty": "bnty",
"bpt": "bpt",
"bq": "bq",
"bqx": "bqx",
"brd": "brd",
"btc": "btc",
"btcd": "btcd",
"btcz": "btcz",
"btg": "btg",
"btm": "btm",
"bts": "bts",
"btx": "btx",
"burst": "burst",
"cdn": "cdn",
"cdt": "cdt",
"clam": "clam",
"cloak": "cloak",
"cmt": "cmt",
"cnd": "cnd",
"cnx": "cnx",
"cny": "cny",
"cob": "cob",
"cred": "cred",
"crpt": "crpt",
"cvc": "cvc",
"dash": "dash",
"dat": "dat",
"data": "data",
"dbc": "dbc",
"dcn": "dcn",
"dcr": "dcr",
"dent": "dent",
"dew": "dew",
"dgb": "dgb",
"dgd": "dgd",
"dlt": "dlt",
"dnt": "dnt",
"doge": "doge",
"drgn": "drgn",
"dta": "dta",
"dtr": "dtr",
"ebst": "ebst",
"edg": "edg",
"edo": "edo",
"edoge": "edoge",
"elf": "elf",
"ella": "ella",
"elix": "elix",
"emc": "emc",
"emc2": "emc2",
"eng": "eng",
"enj": "enj",
"equa": "equa",
"eos": "eos",
"etc": "etc",
"eth": "eth",
"ethos": "ethos",
"etn": "etn",
"etp": "etp",
"eur": "eur",
"evx": "evx",
"exmo": "exmo",
"exp": "exp",
"fair": "fair",
"fct": "fct",
"fil": "fil",
"fldc": "fldc",
"flo": "flo",
"ftc": "ftc",
"fuel": "fuel",
"fun": "fun",
"game": "game",
"gas": "gas",
"gbp": "gbp",
"gbx": "gbx",
"gbyte": "gbyte",
"gno": "gno",
"gnt": "gnt",
"grc": "grc",
"grs": "grs",
"gto": "gto",
"gvt": "gvt",
"gup": "gup",
"gxs": "gxs",
"hpb": "hpb",
"hsr": "hsr",
"html": "html",
"huc": "huc",
"hush": "hush",
"icn": "icn",
"icx": "icx",
"ignis": "ignis",
"ink": "ink",
"ins": "ins",
"ion": "ion",
"iop": "iop",
"iost": "iost",
"iot": "miota",
"iota": "miota",
"jnt": "jnt",
"jpy": "jpy",
"kcs": "kcs",
"kin": "kin",
"kmd": "kmd",
"knc": "knc",
"krb": "krb",
"lbc": "lbc",
"lend": "lend",
"link": "link",
"lkk": "lkk",
"lrc": "lrc",
"lsk": "lsk",
"ltc": "ltc",
"lun": "lun",
"maid": "maid",
"mana": "mana",
"mcap": "mcap",
"mco": "mco",
"mds": "mds",
"med": "med",
"miota": "miota",
"mkr": "mkr",
"mln": "mln",
"mnx": "mnx",
"mona": "mona",
"mth": "mth",
"mtl": "mtl",
"music": "music",
"nano": "nano",
"nav": "nav",
"nas": "nas",
"nebl": "nebl",
"neo": "neo",
"neos": "neos",
"ndz": "ndz",
"ngc": "ngc",
"nlc2": "nlc2",
"nlg": "nlg",
"nmc": "nmc",
"nuls": "nuls",
"nxs": "nxs",
"nxt": "nxt",
"oax": "oax",
"omg": "omg",
"omni": "omni",
"ost": "ost",
"ox": "ox",
"pac": "pac",
"part": "part",
"pasl": "pasl",
"pay": "pay",
"pink": "pink",
"pirl": "pirl",
"pivx": "pivx",
"plr": "plr",
"poe": "poe",
"poly": "poly",
"pot": "pot",
"powr": "powr",
"ppc": "ppc",
"ppp": "ppp",
"ppt": "ppt",
"prl": "prl",
"pura": "pura",
"qash": "qash",
"qiwi": "qiwi",
"qlc": "qlc",
"qrl": "qrl",
"qsp": "qsp",
"qtum": "qtum",
"r": "r",
"rads": "rads",
"rcn": "rcn",
"rdd": "rdd",
"rdn": "rdn",
"rep": "rep",
"req": "req",
"rhoc": "rhoc",
"ric": "ric",
"rise": "rise",
"rlc": "rlc",
"rpx": "rpx",
"rub": "rub",
"salt": "salt",
"san": "san",
"sbd": "sbd",
"sberbank": "sberbank",
"sc": "sc",
"sky": "sky",
"sls": "sls",
"smart": "smart",
"sngls": "sngls",
"snm": "sonm",
"snt": "snt",
"spank": "spank",
"sphtx": "sphtx",
"srn": "srn",
"start": "start",
"steem": "steem",
"storj": "storj",
"storm": "storm",
"strat": "strat",
"sub": "sub",
"sys": "sys",
"taas": "taas",
"tau": "tau",
"tel": "tel",
"theta": "theta",
"tix": "tix",
"tkn": "tkn",
"tnb": "tnb",
"tnc": "tnc",
"tnt": "tnt",
"trig": "trig",
"trx": "trx",
"tzc": "tzc",
"ubq": "ubq",
"unity": "unity",
"usd": "usd",
"usdt": "usdt",
"utk": "utk",
"ven": "ven",
"veri": "veri",
"via": "via",
"vibe": "vibe",
"vivo": "vivo",
"vrc": "vrc",
"vtc": "vtc",
"wabi": "wabi",
"waves": "waves",
"wax": "wax",
"wgr": "wgr",
"wpr": "wpr",
"wtc": "wtc",
"xas": "xas",
"xbc": "xbc",
"xby": "xby",
"xcp": "xcp",
"xdn": "xdn",
"xem": "xem",
"xlm": "xlm",
"xmg": "xmg",
"xmr": "xmr",
"xmy": "xmy",
"xp": "xp",
"xpa": "xpa",
"xpm": "xpm",
"xrb": "nano",
"xrp": "xrp",
"xtz": "xtz",
"xuc": "xuc",
"xvc": "xvc",
"xvg": "xvg",
"xzc": "xzc",
"yoyow": "yoyow",
"zcl": "zcl",
"zec": "zec",
"zen": "zen",
"zil": "zil",
"zrx": "zrx"
}
"icons": [
"act",
"ada",
"adx",
"ae",
"agi",
"agrs",
"aion",
"amb",
"amp",
"ant",
"appc",
"ardr",
"ark",
"arn",
"ast",
"atm",
"bat",
"bay",
"bcc",
"bcd",
"bch",
"bcn",
"bco",
"bcpt",
"bdl",
"bela",
"bix",
"blcn",
"blk",
"block",
"blz",
"bnb",
"bnt",
"bnty",
"bpt",
"bq",
"bqx",
"brd",
"btc",
"btcd",
"btcz",
"btg",
"btm",
"bts",
"btx",
"burst",
"cdn",
"cdt",
"clam",
"cloak",
"cmt",
"cnd",
"cnx",
"cny",
"cob",
"cred",
"crpt",
"cvc",
"dash",
"dat",
"data",
"dbc",
"dcn",
"dcr",
"dent",
"dew",
"dgb",
"dgd",
"dlt",
"dnt",
"doge",
"drgn",
"dta",
"dtr",
"ebst",
"edg",
"edo",
"edoge",
"elf",
"ella",
"elix",
"emc",
"emc2",
"eng",
"enj",
"equa",
"eos",
"etc",
"eth",
"ethos",
"etn",
"etp",
"eur",
"evx",
"exmo",
"exp",
"fair",
"fct",
"fil",
"fldc",
"flo",
"ftc",
"fuel",
"fun",
"game",
"gas",
"gbp",
"gbx",
"gbyte",
"gno",
"gnt",
"grc",
"grs",
"gto",
"gvt",
"gup",
"gxs",
"hpb",
"hsr",
"html",
"huc",
"hush",
"icn",
"icx",
"ignis",
"ink",
"ins",
"ion",
"iop",
"iost",
"iot",
"miota",
"jnt",
"jpy",
"kcs",
"kin",
"kmd",
"knc",
"krb",
"lbc",
"lend",
"link",
"lkk",
"lrc",
"lsk",
"ltc",
"lun",
"maid",
"mana",
"mcap",
"mco",
"mds",
"med",
"miota",
"mkr",
"mln",
"mnx",
"mona",
"mth",
"mtl",
"music",
"nano",
"nav",
"nas",
"nebl",
"neo",
"neos",
"ndz",
"ngc",
"nlc2",
"nlg",
"nmc",
"nuls",
"nxs",
"nxt",
"oax",
"omg",
"omni",
"ost",
"ox",
"pac",
"part",
"pasl",
"pay",
"pink",
"pirl",
"pivx",
"plr",
"poe",
"poly",
"pot",
"powr",
"ppc",
"ppp",
"ppt",
"prl",
"pura",
"qash",
"qiwi",
"qlc",
"qrl",
"qsp",
"qtum",
"r",
"rads",
"rcn",
"rdd",
"rdn",
"rep",
"req",
"rhoc",
"ric",
"rise",
"rlc",
"rpx",
"rub",
"salt",
"san",
"sbd",
"sberbank",
"sc",
"sky",
"sls",
"smart",
"sngls",
"snt",
"spank",
"sphtx",
"srn",
"start",
"steem",
"storj",
"storm",
"strat",
"sub",
"sys",
"taas",
"tau",
"tel",
"theta",
"tix",
"tkn",
"tnb",
"tnc",
"tnt",
"trig",
"trx",
"tzc",
"ubq",
"unity",
"usd",
"usdt",
"utk",
"ven",
"veri",
"via",
"vibe",
"vivo",
"vrc",
"vtc",
"wabi",
"waves",
"wax",
"wgr",
"wpr",
"wtc",
"xas",
"xbc",
"xby",
"xcp",
"xdn",
"xem",
"xlm",
"xmg",
"xmr",
"xmy",
"xp",
"xpa",
"xpm",
"nano",
"xrp",
"xtz",
"xuc",
"xvc",
"xvg",
"xzc",
"yoyow",
"zcl",
"zec",
"zen",
"zil",
"zrx"
]
}