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