Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@coinpaprika/widget-currency

Package Overview
Dependencies
Maintainers
2
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@coinpaprika/widget-currency - npm Package Compare versions

Comparing version 1.1.1 to 1.1.2

2

dist/widget.min.js

@@ -1,1 +0,1 @@

!function r(s,o,l){function c(e,t){if(!o[e]){if(!s[e]){var n="function"==typeof require&&require;if(!t&&n)return n(e,!0);if(u)return u(e,!0);var a=new Error("Cannot find module '"+e+"'");throw a.code="MODULE_NOT_FOUND",a}var i=o[e]={exports:{}};s[e][0].call(i.exports,function(t){return c(s[e][1][t]||t)},i,i.exports,r,s,o,l)}return o[e].exports}for(var u="function"==typeof require&&require,t=0;t<l.length;t++)c(l[t]);return c}({1:[function(t,e,n){"use strict";var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},a=function(){function a(t,e){for(var n=0;n<e.length;n++){var a=e[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(t,a.key,a)}}return function(t,e,n){return e&&a(t.prototype,e),n&&a(t,n),t}}();function s(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}var i=function(){function t(){s(this,t),this.widgets=new o,this.bind()}return a(t,[{key:"bind",value:function(){var t=this;window[this.widgets.defaults.objectName]={},document.addEventListener("DOMContentLoaded",function(){return t.initWidgets()},!1),window[this.widgets.defaults.objectName].bindWidget=function(){window[t.widgets.defaults.objectName].init=!1,t.initWidgets()}}},{key:"initWidgets",value:function(){var i=this;if(!window[this.widgets.defaults.objectName].init){window[this.widgets.defaults.objectName].init=!0;var e=Array.prototype.slice.call(document.getElementsByClassName(this.widgets.defaults.className));this.widgets.setWidgetClass(e),window.addEventListener("resize",function(){i.widgets.setWidgetClass(e);for(var t=0;t<e.length;t++)i.widgets.setBeforeElementInFooter(t)},!1);var t=this.widgets.getScriptElement();if(t&&t.dataset&&t.dataset.cpCurrencyWidget){var n=JSON.parse(t.dataset.cpCurrencyWidget);if(Object.keys(n))for(var a=Object.keys(n),r=0;r<a.length;r++){var s=a[r].replace("-","_");this.widgets.defaults[s]=n[a[r]]}}setTimeout(function(){return i.widgets.states=[],f.loop(e,function(t,e){var n=JSON.parse(JSON.stringify(i.widgets.defaults));n.isWordpress=t.classList.contains("wordpress"),n.isNightMode=t.classList.contains("cp-widget__night-mode"),n.mainElement=t,i.widgets.states.push(n);var a=Promise.resolve();return a=(a=a.then(function(){return-1<n.modules.indexOf("chart")&&!window.Highcharts?f.loop(["http://code.highcharts.com/stock/highstock.js","https://code.highcharts.com/modules/exporting.js","https://code.highcharts.com/modules/no-data-to-display.js","https://highcharts.github.io/pattern-fill/pattern-fill-v2.js"],function(t){return d.fetchScript(t)}):null})).then(function(){return i.widgets.init(e)})})},50)}}}]),t}(),o=function(){function t(){s(this,t),this.states=[],this.defaults={objectName:"cpCurrencyWidgets",className:"coinpaprika-currency-widget",cssFileName:"widget.min.css",currency:"btc-bitcoin",primary_currency:"USD",range_list:["24h","7d","30d","1q","1y","ytd","all"],range:"7d",modules:["market_details","chart"],update_active:!1,update_timeout:"30s",language:"en",style_src:null,img_src:null,lang_src:null,origin_src:"https://unpkg.com/@coinpaprika/widget-currency",show_details_currency:!1,ticker:{name:void 0,symbol:void 0,price:void 0,price_change_24h:void 0,rank:void 0,price_ath:void 0,volume_24h:void 0,market_cap:void 0,percent_from_price_ath:void 0,volume_24h_change_24h:void 0,market_cap_change_24h:void 0},interval:null,isWordpress:!1,isNightMode:!1,isData:!1,availableModules:["price","chart","market_details"],message:"data_loading",translations:{},mainElement:null,noTranslationLabels:[],scriptsDownloaded:{},chart:null,rwd:{xs:280,s:320,m:370,l:462}}}return a(t,[{key:"init",value:function(t){var e=this;if(!this.getMainElement(t))return console.error('Bind failed, no element with class = "'+this.defaults.className+'"');var n=Promise.resolve();return n=(n=n.then(function(){return e.getDefaults(t)})).then(function(){return e.setOriginLink(t)})}},{key:"setWidgetClass",value:function(t){for(var e=0;e<t.length;e++)for(var n=t[e].getBoundingClientRect().width,a=Object.keys(this.defaults.rwd),i=0;i<a.length;i++){var r=a[i],s=this.defaults.rwd[r],o=this.defaults.className+"__"+r;n<=s&&t[e].classList.add(o),s<n&&t[e].classList.remove(o)}}},{key:"getMainElement",value:function(t){return this.states[t]?this.states[t].mainElement:null}},{key:"getDefaults",value:function(n){var a=this;return new Promise(function(t){var e=a.getMainElement(n);return e&&e.dataset&&(e.dataset.modules||"extended"!==e.dataset.version||a.updateData(n,"modules",["market_details"]),e.dataset.modules||"standard"!==e.dataset.version||a.updateData(n,"modules",[]),e.dataset.modules&&a.updateData(n,"modules",JSON.parse(e.dataset.modules)),e.dataset.primaryCurrency&&a.updateData(n,"primary_currency",e.dataset.primaryCurrency),e.dataset.currency&&a.updateData(n,"currency",e.dataset.currency),e.dataset.range&&a.updateData(n,"range",e.dataset.range),e.dataset.showDetailsCurrency&&a.updateData(n,"show_details_currency","true"===e.dataset.showDetailsCurrency),e.dataset.updateActive&&a.updateData(n,"update_active","true"===e.dataset.updateActive),e.dataset.updateTimeout&&a.updateData(n,"update_timeout",f.parseIntervalValue(e.dataset.updateTimeout)),e.dataset.language&&a.updateData(n,"language",e.dataset.language),e.dataset.originSrc&&a.updateData(n,"origin_src",e.dataset.originSrc),e.dataset.nodeModulesSrc&&a.updateData(n,"node_modules_src",e.dataset.nodeModulesSrc),e.dataset.bowerSrc&&a.updateData(n,"bower_src",e.dataset.bowerSrc),e.dataset.styleSrc&&a.updateData(n,"style_src",e.dataset.styleSrc),e.dataset.langSrc&&a.updateData(n,"logo_src",e.dataset.langSrc),e.dataset.imgSrc&&a.updateData(n,"logo_src",e.dataset.imgSrc)),t()})}},{key:"setOriginLink",value:function(t){var e=this;0===Object.keys(this.defaults.translations).length&&this.getTranslations(this.defaults.language);var n=Promise.resolve();return n=(n=(n=n.then(function(){return e.stylesheet()})).then(function(){return e.addWidgetElement(t)})).then(function(){return e.initInterval(t)})}},{key:"addWidgetElement",value:function(n){var a=this,t=this.getMainElement(n),i="",e=[],r=null,s=Promise.resolve();return s=(s=(s=(s=(s=(s=(s=s.then(function(){return f.loop(a.defaults.availableModules,function(t){return-1<a.states[n].modules.indexOf(t)?e.push(t):null})})).then(function(){return f.loop(e,function(t){var e=null;return"chart"===t&&(e="Chart"),"market_details"===t&&(e="MarketDetails"),e?a["widget"+e+"Element"](n).then(function(t){return i+=t}):null})})).then(function(){return t.innerHTML=a.widgetMainElement(n)+i+a.widgetFooter(n)})).then(function(){return(r=document.getElementById(a.defaults.className+"-price-chart-"+n))?r.parentElement.insertAdjacentHTML("beforeend",a.widgetSelectElement(n,"range")):null})).then(function(){return r&&(a.states[n].chart=new l(r,a.states[n]),a.setSelectListeners(n)),null})).then(function(){return a.setBeforeElementInFooter(n)})).then(function(){return a.getData(n)})}},{key:"setSelectListeners",value:function(e){for(var n=this,t=this.getMainElement(e).querySelectorAll(".cp-widget-select"),a=0;a<t.length;a++)for(var i=t[a].querySelectorAll(".cp-widget-select__options button"),r=0;r<i.length;r++)i[r].addEventListener("click",function(t){n.setSelectOption(t,e)},!1)}},{key:"setSelectOption",value:function(t,e){for(var n="cp-widget-active",a=0;a<t.target.parentNode.childNodes.length;a++){var i=t.target.parentNode.childNodes[a];i.classList.contains(n)&&i.classList.remove(n)}var r=t.target.closest(".cp-widget-select"),s=r.dataset.type,o=r.querySelector(".cp-widget-select__options > span"),l=t.target.dataset.option;o.innerText=this.getTranslation(e,l.toLowerCase()),this.updateData(e,s,l),t.target.classList.add(n),this.dispatchEvent(e,"-switch-range",l)}},{key:"dispatchEvent",value:function(t,e,n){var a=this.defaults.className+"-price-chart-"+t;return document.dispatchEvent(new CustomEvent(""+a+e,{detail:{data:n}}))}},{key:"getData",value:function(e){var n=this,t="https://api.coinpaprika.com/v1/widget/"+this.states[e].currency+"?quote="+this.states[e].primary_currency;return d.fetchData(t).then(function(t){return t.json().then(function(t){n.states[e].isData||n.updateData(e,"isData",!0),n.updateTicker(e,t)})}).catch(function(t){return n.onErrorRequest(e,t)})}},{key:"onErrorRequest",value:function(t,e){this.states[t].isData&&this.updateData(t,"isData",!1),this.updateData(t,"message","data_unavailable"),console.error("Request failed. Returned status of "+e,this.states[t])}},{key:"initInterval",value:function(t){var e=this;clearInterval(this.states[t].interval),this.states[t].update_active&&1e3<this.states[t].update_timeout&&(this.states[t].interval=setInterval(function(){e.getData(t)},this.states[t].update_timeout))}},{key:"setBeforeElementInFooter",value:function(t){if(!this.states[t].isWordpress){var e=this.getMainElement(t);if(e){"style"===e.children[0].localName&&e.removeChild(e.childNodes[0]);for(var n=e.querySelector(".cp-widget__footer"),a=n.getBoundingClientRect().width-43,i=0;i<n.childNodes.length;i++)a-=n.childNodes[i].getBoundingClientRect().width;var r=document.createElement("style");r.innerHTML=".cp-widget__footer--"+t+"::before{width:"+a.toFixed(0)+"px;}",e.insertBefore(r,e.children[0])}}}},{key:"updateWidgetElement",value:function(t,e,n,a){var i=this.states[t],r=this.getMainElement(t);if(r){var s=a?"Ticker":"";if("name"===e||"currency"===e){if("currency"===e)for(var o=r.querySelectorAll(".cp-widget__footer > a"),l=0;l<o.length;l++)o[l].href=this.coin_link(n);this.getImage(t)}if("isData"===e||"message"===e)for(var c=r.querySelectorAll(".cp-widget__main"),u=0;u<c.length;u++)c[u].innerHTML=i.isData?this.widgetMainElementData(t):this.widgetMainElementMessage(t);else for(var d=r.querySelectorAll("."+e+s),h=0;h<d.length;h++){var g=d[h];if(g.classList.contains("cp-widget__rank")){var p=0<parseFloat(n)?"cp-widget__rank-up":parseFloat(n)<0?"cp-widget__rank-down":"cp-widget__rank-neutral";g.classList.remove("cp-widget__rank-down"),g.classList.remove("cp-widget__rank-up"),g.classList.remove("cp-widget__rank-neutral"),n=void 0===n?f.emptyData:(g.classList.add(p),"price_change_24h"===e?"("+f.round(n,2)+"%)":f.round(n,2)+"%")}g.classList.contains("showDetailsCurrency")&&!i.show_details_currency&&(n=" "),g.classList.contains("parseNumber")?g.innerText=f.parseNumber(n)||f.emptyData:g.innerText=n||f.emptyData}}}},{key:"updateData",value:function(t,e,n,a){a?this.states[t].ticker[e]=n:this.states[t][e]=n,"language"===e&&this.getTranslations(n),this.updateWidgetElement(t,e,n,a)}},{key:"updateWidgetTranslations",value:function(e,t){var o=this;this.defaults.translations[e]=t;for(var n=function(s){var t=0<o.states[s].noTranslationLabels.length&&"en"===e;(o.states[s].language===e||t)&&function(){for(var t=o.states[s].mainElement,r=Array.prototype.slice.call(t.querySelectorAll(".cp-translation")),e=function(i){r[i].classList.forEach(function(t){if(-1<t.search("translation_")){var e=t.replace("translation_","");"message"===e&&(e=o.states[s].message);var n=o.states[s].noTranslationLabels.indexOf(e),a=o.getTranslation(s,e);-1<n&&a&&o.states[s].noTranslationLabels.splice(n,1),r[i].innerText=a,r[i].closest(".cp-widget__footer")&&setTimeout(function(){return o.setBeforeElementInFooter(s)},50)}})},n=0;n<r.length;n++)e(n)}()},a=0;a<this.states.length;a++)n(a)}},{key:"updateTicker",value:function(t,e){for(var n=Object.keys(e),a=0;a<n.length;a++)this.updateData(t,n[a],e[n[a]],!0)}},{key:"stylesheet",value:function(){if(!1===this.defaults.style_src)return Promise.resolve();var t=this.defaults.style_src||this.defaults.origin_src+"/dist/"+this.defaults.cssFileName;return document.body.querySelector('link[href="'+t+'"]')?Promise.resolve():d.fetchStyle(t)}},{key:"widgetMainElement",value:function(t){var e=this.states[t];return'<div class="cp-widget__header"><div class="cp-widget__img cp-widget__img-'+e.currency+'"><img/></div><div class="cp-widget__main">'+(e.isData?this.widgetMainElementData(t):this.widgetMainElementMessage(t))+"</div></div>"}},{key:"widgetMainElementData",value:function(t){var e=this.states[t];return'<h3><a href="'+this.coin_link(e.currency)+'"><span class="nameTicker">'+(e.ticker.name||f.emptyData)+'</span><span class="symbolTicker">'+(e.ticker.symbol||f.emptyData)+'</span></a></h3><strong><span class="priceTicker parseNumber">'+(f.parseNumber(e.ticker.price)||f.emptyData)+'</span> <span class="primaryCurrency">'+e.primary_currency+' </span><span class="price_change_24hTicker cp-widget__rank cp-widget__rank-'+(0<e.ticker.price_change_24h?"up":e.ticker.price_change_24h<0?"down":"neutral")+'">('+(f.round(e.ticker.price_change_24h,2)||f.emptyValue)+'%)</span></strong><span class="cp-widget__rank-label"><span class="cp-translation translation_rank">'+this.getTranslation(t,"rank")+'</span> <span class="rankTicker">'+(e.ticker.rank||f.emptyData)+"</span></span>"}},{key:"widgetMainElementMessage",value:function(t){var e=this.states[t].message;return'<div class="cp-widget__main-no-data cp-translation translation_message">'+this.getTranslation(t,e)+"</div>"}},{key:"widgetMarketDetailsElement",value:function(t){return Promise.resolve(-1<this.states[t].modules.indexOf("market_details")?'<div class="cp-widget__details">'+this.widgetAthElement(t)+this.widgetVolume24hElement(t)+this.widgetMarketCapElement(t)+"</div>":"")}},{key:"widgetAthElement",value:function(t){return'<div><small class="cp-translation translation_ath">'+this.getTranslation(t,"ath")+'</small><div><span class="price_athTicker parseNumber">'+f.emptyData+' </span><span class="symbolTicker showDetailsCurrency"></span></div><span class="percent_from_price_athTicker cp-widget__rank">'+f.emptyData+"</span></div>"}},{key:"widgetVolume24hElement",value:function(t){return'<div><small class="cp-translation translation_volume_24h">'+this.getTranslation(t,"volume_24h")+'</small><div><span class="volume_24hTicker parseNumber">'+f.emptyData+' </span><span class="symbolTicker showDetailsCurrency"></span></div><span class="volume_24h_change_24hTicker cp-widget__rank">'+f.emptyData+"</span></div>"}},{key:"widgetMarketCapElement",value:function(t){return'<div><small class="cp-translation translation_market_cap">'+this.getTranslation(t,"market_cap")+'</small><div><span class="market_capTicker parseNumber">'+f.emptyData+' </span><span class="symbolTicker showDetailsCurrency"></span></div><span class="market_cap_change_24hTicker cp-widget__rank">'+f.emptyData+"</span></div>"}},{key:"widgetChartElement",value:function(t){return Promise.resolve('<div class="cp-widget__chart"><div id="'+this.defaults.className+"-price-chart-"+t+'"></div></div>')}},{key:"widgetSelectElement",value:function(t,e){for(var n="",a=0;a<this.states[t][e+"_list"].length;a++){var i=this.states[t][e+"_list"][a];n+='<button class="'+(i.toLowerCase()===this.states[t][e].toLowerCase()?"cp-widget-active ":"")+("primary_currency"===e?"":"cp-translation translation_"+i.toLowerCase())+'" data-option="'+i+'">'+this.getTranslation(t,i.toLowerCase())+"</button>"}return'<div data-type="'+e+'" class="cp-widget-select"><label class="cp-translation translation_'+e+'">'+this.getTranslation(t,"zoom_in")+'</label><div class="cp-widget-select__options"><span class="arrow-down cp-widget__capitalize cp-translation translation_'+this.states[t][e].toLowerCase()+'">'+this.getTranslation(t,this.states[t][e].toLowerCase())+'</span><div class="cp-widget-select__dropdown">'+n+"</div></div></div>"}},{key:"widgetFooter",value:function(t){var e=this.states[t].currency;return this.states[t].isWordpress?"":'<p class="cp-widget__footer cp-widget__footer--'+t+'"><span class="cp-translation translation_powered_by">'+this.getTranslation(t,"powered_by")+' </span><img style="width: 16px" src="'+this.main_logo_link()+'" alt=""/><a target="_blank" href="'+this.coin_link(e)+'">coinpaprika.com</a></p>'}},{key:"getImage",value:function(t){for(var i=this,r=this.states[t],s=r.mainElement.getElementsByClassName("cp-widget__img"),e=function(t){var e=s[t];e.classList.add("cp-widget__img--hidden");var n=e.querySelector("img"),a=new Image;a.onload=function(){n.src=a.src,e.classList.remove("cp-widget__img--hidden")},a.src=i.img_src(r.currency)},n=0;n<s.length;n++)e(n)}},{key:"img_src",value:function(t){return"https://coinpaprika.com/coin/"+t+"/logo.png"}},{key:"coin_link",value:function(t){return"https://coinpaprika.com/coin/"+t}},{key:"main_logo_link",value:function(){return this.defaults.img_src||this.defaults.origin_src+"/dist/img/logo_widget.svg"}},{key:"getScriptElement",value:function(){return document.querySelector("script[data-cp-currency-widget]")}},{key:"getTranslation",value:function(t,e){var n=this.defaults.translations[this.states[t].language]?this.defaults.translations[this.states[t].language][e]:null;return!n&&this.defaults.translations.en&&(n=this.defaults.translations.en[e]),n||this.addLabelWithoutTranslation(t,e)}},{key:"addLabelWithoutTranslation",value:function(t,e){return this.defaults.translations.en||this.getTranslations("en"),this.states[t].noTranslationLabels.push(e)}},{key:"getTranslations",value:function(t){var e=this;if(!this.defaults.translations[t]){var n=new XMLHttpRequest,a=this.defaults.lang_src||this.defaults.origin_src+"/dist/lang";n.open("GET",a+"/"+t+".json"),n.onload=function(){200===n.status?e.updateWidgetTranslations(t,JSON.parse(n.responseText)):(e.onErrorRequest(0,n),e.getTranslations("en"),delete e.defaults.translations[t])},n.onerror=function(){e.onErrorRequest(0,n),e.getTranslations("en"),delete e.defaults.translations[t]},n.send(),this.defaults.translations[t]={}}}}]),t}(),l=function(){function e(t,i){var a=this;s(this,e),t&&(this.id=t.id,this.isNightMode=i.isNightMode,this.chartsWithActiveSeriesCookies=[],this.chart=null,this.currency=i.currency,this.container=t,this.options=this.setOptions(),this.defaultRange=i.range||"7d",this.callback=null,this.replaceCallback=null,this.extremesDataUrl=this.getExtremesDataUrl(t.id),this.defaultOptions={chart:{alignTicks:!1,marginTop:50,style:{fontFamily:"sans-serif"},events:{render:function(t){if(t.target.annotations){var n=t.target.annotations.chart;f.loop(n.annotations.allItems,function(t){var e=n.plotHeight+n.plotTop-n.spacing[0]-2-(a.isResponsiveModeActive(n)?10:0);t.update({y:e},!0)})}}}},scrollbar:{enabled:!1},annotationsOptions:{enabledButtons:!1},rangeSelector:{enabled:!1},plotOptions:{line:{series:{states:{hover:{enabled:!1}}}},series:{events:{legendItemClick:function(t){return t.browserEvent.isTrusted&&-1<a.chartsWithActiveSeriesCookies.indexOf(t.target.chart.renderTo.id)&&a.setVisibleChartCookies(t),t.browserEvent.isTrusted}}}},xAxis:{ordinal:!1}},this.chartDataParser=function(t,e){var n=i.primary_currency.toLowerCase(),a={data:{price:(t=t[0])[n]?t[n]:[],volume:t.volume}};return Promise.resolve(a)},this.isEventsHidden=!1,this.excludeSeriesIds=[],this.asyncUrl="/currency/data/"+i.currency+"/_range_/",this.init())}return a(e,[{key:"setOptions",value:function(){var t=new e;return{responsive:{rules:[{condition:{maxWidth:1500},chartOptions:{legend:{align:"right",verticalAlign:"middle",y:92,symbolRadius:0,itemDistance:20,itemStyle:{fontSize:10}},chart:{height:400,marginTop:35,marginBottom:0,spacingTop:0,spacingBottom:0},navigator:{height:50,margin:70,handles:{height:25,width:17}}}},{condition:{maxWidth:600},chartOptions:{chart:{marginTop:0,zoomType:"none",marginLeft:10,marginRight:10,height:350},yAxis:[{floor:0,tickAmount:7,tickWidth:0,tickLength:0,lineWidth:0,title:{enabled:!1},labels:{align:"left",x:1,y:-2,style:{color:"#9e9e9e",fontSize:"9px"}}},{floor:0,tickAmount:7,tickWidth:0,tickLength:0,lineWidth:0,title:{enabled:!1},labels:{align:"right",overflow:"justify",x:1,y:-2,style:{color:"#5085ec",fontSize:"9px"}}}]}},{condition:{maxWidth:450},chartOptions:{legend:{align:"right",verticalAlign:"middle",y:82,symbolRadius:0,itemDistance:20,itemStyle:{fontSize:10}},navigator:{margin:60,height:40,handles:{height:20}},chart:{height:300},yAxis:[{floor:0,tickAmount:7,tickWidth:0,tickLength:0,lineWidth:0,title:{enabled:!1},labels:{align:"left",x:1,y:-2,style:{color:"#9e9e9e",fontSize:"9px"}}},{floor:0,tickAmount:7,tickWidth:0,tickLength:0,lineWidth:0,title:{enabled:!1},labels:{align:"right",overflow:"justify",x:1,y:-2,style:{color:"#5085ec",fontSize:"9px"}}}]}}]},title:{text:void 0},chart:{backgroundColor:"none",marginTop:50,plotBorderWidth:0},cpEvents:!1,colors:["#5085ec","#1f9809","#985d65","#ee983b","#4c4c4c"],legend:{margin:0,enabled:!0,align:"right",symbolRadius:0,itemDistance:40,itemStyle:{fontWeight:"normal",color:this.isNightMode?"#80a6e5":"#0645ad"},itemMarginTop:8},navigator:!0,tooltip:{shared:!0,split:!1,animation:!1,borderWidth:1,borderColor:this.isNightMode?"#4c4c4c":"#e3e3e3",hideDelay:100,shadow:!1,backgroundColor:"#ffffff",style:{color:"#4c4c4c",fontSize:"10px"},useHTML:!0,formatter:function(){return t.tooltipFormatter(this)}},exporting:{buttons:{contextButton:{enabled:!1}}},xAxis:{lineColor:this.isNightMode?"#505050":"#e3e3e3",tickColor:this.isNightMode?"#505050":"#e3e3e3",tickLength:7},yAxis:[{lineWidth:1,lineColor:"#dedede",tickWidth:1,tickLength:4,gridLineDashStyle:"dash",gridLineWidth:0,floor:0,minPadding:0,opposite:!1,showEmpty:!1,showLastLabel:!1,showFirstLabel:!1},{gridLineColor:this.isNightMode?"#505050":"#e3e3e3",gridLineDashStyle:"dash",lineWidth:1,tickWidth:1,tickLength:4,floor:0,minPadding:0,showEmpty:!1,opposite:!0,gridZIndex:4,showLastLabel:!1,showFirstLabel:!1}],series:[{color:"#5085ec",name:"Price",id:"price",data:[],type:"area",fillOpacity:.15,lineWidth:2,yAxis:1,zIndex:2,visible:!0,clickable:!0,threshold:null,tooltip:{valueDecimals:0},showInNavigator:!0,showInLegend:!1},{color:"url(#fill-pattern"+(this.isNightMode?"-night":"")+")",name:"Volume",id:"volume",data:[],type:"area",fillOpacity:.5,lineWidth:0,yAxis:0,zIndex:0,visible:!0,clickable:!0,threshold:null,tooltip:{valueDecimals:0},showInNavigator:!0}]}}},{key:"init",value:function(){var e=this,t=Promise.resolve();return t=(t=t.then(function(){return e.parseOptions(e.options)})).then(function(t){return window.Highcharts?Highcharts.stockChart(e.container.id,t,function(t){return e.bind(t)}):null})}},{key:"parseOptions",value:function(t){var e=this,n=Promise.resolve();return n=(n=(n=(n=(n=n.then(function(){return f.updateObject(e.defaultOptions,t)})).then(function(t){return f.updateObject(e.getVolumePattern(),t)})).then(function(t){return e.setNavigator(t)})).then(function(t){return t.noData?e.setNoDataLabel(t):t})).then(function(t){return t})}},{key:"bind",value:function(t){var e=this,n=Promise.resolve();return n=(n=(n=(n=n.then(function(){return e.chart=t})).then(function(){return e.fetchDataPackage()})).then(function(){return e.setRangeSwitcher()})).then(function(){return e.callback?e.callback(e.chart,e.defaultRange):null})}},{key:"fetchDataPackage",value:function(e,n){var a=this,i=e&&n,t=Promise.resolve();return t=(t=(t=(t=(t=(t=t.then(function(){if(a.options.cpEvents){var t=i?a.getNavigatorExtremesUrl(e,n,"events"):a.getExtremesDataUrl(a.id,"events")+"/"+a.getRange()+"/";return t?a.fetchData(t,"events",!i):null}return null})).then(function(){var t=i?a.getNavigatorExtremesUrl(e,n):a.asyncUrl.replace("_range_",a.getRange());return t?a.fetchData(t,"data",!i):null})).then(function(){return a.chart.redraw(!1)})).then(function(){return i?null:a.chart.zoomOut()})).then(function(){return a.isLoaded=!0})).then(function(){return a.toggleEvents()})}},{key:"fetchData",value:function(t){var n=this,a=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"data",i=!(2<arguments.length&&void 0!==arguments[2])||arguments[2],e=Promise.resolve();return e=(e=e.then(function(){return n.chart.showLoading(),d.fetchChartData(t,!n.isLoaded)})).then(function(t){return n.chart.hideLoading(),200!==t.status?console.log("Looks like there was a problem. Status Code: "+t.status):t.json().then(function(t){var e=Promise.resolve();return e=(e=e.then(function(){return n.dataParser(t,a)})).then(function(t){return i?n.replaceData(t.data,a):n.updateData(t.data,a)})})}).catch(function(t){return n.chart.hideLoading(),console.log("Fetch Error",t)})}},{key:"setRangeSwitcher",value:function(){var e=this;document.addEventListener(this.id+"-switch-range",function(t){return e.defaultRange=t.detail.data,e.fetchDataPackage()})}},{key:"getRange",value:function(){return this.defaultRange||"1q"}},{key:"toggleEvents",value:function(){var e=this,t=Promise.resolve();return this.options.cpEvents&&(t=(t=(t=(t=t.then(function(){return document.getElementsByClassName("highcharts-annotation")})).then(function(t){return f.loop(t,function(t){return e.isEventsHidden?t.classList.contains("highcharts-annotation__hidden")?null:t.classList.add("highcharts-annotation__hidden"):t.classList.contains("highcharts-annotation__hidden")?t.classList.remove("highcharts-annotation__hidden"):null})})).then(function(){return document.getElementsByClassName("highcharts-plot-line")})).then(function(t){return f.loop(t,function(t){return e.isEventsHidden?t.classList.contains("highcharts-plot-line__hidden")?null:t.classList.add("highcharts-plot-line__hidden"):t.classList.contains("highcharts-plot-line__hidden")?t.classList.remove("highcharts-plot-line__hidden"):null})})),t}},{key:"dataParser",value:function(t){var e=this;switch(1<arguments.length&&void 0!==arguments[1]?arguments[1]:"data"){case"data":var n=Promise.resolve();return n=n.then(function(){return e.chartDataParser?e.chartDataParser(t):{data:t[0]}});case"events":return Promise.resolve(t);default:return null}}},{key:"updateData",value:function(n,a){var i=this,r=void 0,t=Promise.resolve();return t=(t=t.then(function(){switch(a){case"data":return r={},f.loop(Object.entries(n),function(t){if(!i.isExcluded(t[0])){var e=i.getOldData(a)[t[0]];r[t[0]]=e.filter(function(e){return-1===t[1].findIndex(function(t){return i.isTheSameElement(e,t,a)})}).concat(t[1]).sort(function(t,e){return i.sortCondition(t,e,a)})}});case"events":r=[];var t=i.getOldData(a);return r=t.filter(function(e){n.findIndex(function(t){return i.isTheSameElement(e,t,a)})}).concat(n).sort(function(t,e){return i.sortCondition(t,e,a)});default:return!1}})).then(function(){return i.replaceData(r,a)})}},{key:"isTheSameElement",value:function(t,e,n){switch(n){case"data":return t[0]===e[0];case"events":return t.ts===e.ts;default:return!1}}},{key:"sortCondition",value:function(t,e,n){switch(n){case"data":return t[0]-e[0];case"events":return t.ts-e.ts;default:return!1}}},{key:"getOldData",value:function(t){return this["chart_"+t.toLowerCase()]}},{key:"replaceData",value:function(t,e){var n=this,a=Promise.resolve();return a=(a=(a=a.then(function(){return n["chart_"+e.toLowerCase()]=t})).then(function(){return n.replaceDataType(t,e)})).then(function(){return n.replaceCallback?n.replaceCallback(n.chart,t,n.isLoaded,e):null})}},{key:"replaceDataType",value:function(n,t){var a=this;switch(t){case"data":return this.asyncUrl&&f.loop(["btc-bitcoin","eth-ethereum"],function(t){var e=t.split("-")[0];-1<a.asyncUrl.search(t)&&n[e]&&(n[e]=[],f.loop(a.chart.series,function(t){t.userOptions.id===e&&t.update({visible:!1})}))}),f.loop(Object.entries(n),function(t){if(!a.isExcluded(t[0]))return a.chart.get(t[0])?a.chart.get(t[0]).setData(t[1],!1,!1,!1):a.chart.addSeries({id:t[0],data:t[1],showInNavigator:!0})});case"events":var e=Promise.resolve();return e=(e=e.then(function(){return f.loop(a.chart.annotations.allItems,function(t){return t.destroy()})})).then(function(){return a.setAnnotationsObjects(n)});default:return null}}},{key:"isExcluded",value:function(t){return-1<this.excludeSeriesIds.indexOf(t)}},{key:"tooltipFormatter",value:function(t){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"",n=arguments[2];n||(n=e);var a='<div class="cp-chart-tooltip-currency"><small>'+new Date(t.x).toUTCString()+"</small><table>",i="";return t.points.forEach(function(t){i+='<tr><td><svg width="5" height="5"><rect x="0" y="0" width="5" height="5" fill="'+t.series.color+'" fill-opacity="1"></rect></svg>'+t.series.name+": "+t.y.toLocaleString("ru-RU",{maximumFractionDigits:8})+" "+(-1<t.series.name.toLowerCase().search(n.toLowerCase())?"":e)+"</td></tr>"}),a+i+"</table></div>"}},{key:"setAnnotationsObjects",value:function(t){var n=this;this.chart.series[0].xAxis.removePlotLine();var a=[],e=Promise.resolve();return e=(e=(e=e.then(function(){return t.sort(function(t,e){return e.ts-t.ts})})).then(function(){return f.loop(t,function(t){var e=Promise.resolve();return e=(e=e.then(function(){return a.push({width:1,value:t.ts,dashStyle:"solid",zIndex:4,color:n.getEventTagParams().color})})).then(function(){return n.chart.addAnnotation({xValue:t.ts,y:0,title:'<span title="Click to open" class="cp-chart-annotation__text">'+n.getEventTagParams(t.tag).label+'</span><span class="cp-chart-annotation__dataElement" style="display: none;">'+JSON.stringify(t)+"</span>",shape:{type:"circle",params:{r:11,cx:9,cy:10.5,"stroke-width":1.5,fill:n.getEventTagParams().color}},events:{mouseover:function(t){if(!MobileDetect.isMobile()){var e=n.getEventDataFromAnnotationEvent(t);n.openEventContainer(e,t)}},mouseout:function(){MobileDetect.isMobile()||n.closeEventContainer(event)},click:function(t){var e=n.getEventDataFromAnnotationEvent(t);MobileDetect.isMobile()?n.openEventContainer(e,t):n.openEventPage(e)}}})})})})).then(function(){return n.chart.series[0].xAxis.update({plotLines:a},!1)})}},{key:"setNavigator",value:function(t){var e=this,n={},a=Promise.resolve();return a=a.then(function(){return!0===t.navigator?(n={navigator:{enable:!0,margin:20,series:{lineWidth:1},maskFill:"rgba(102,133,194,0.15)"},chart:{zoomType:"x"},xAxis:{events:{setExtremes:function(t){("navigator"===t.trigger||"zoom"===t.trigger)&&t.min&&t.max&&document.dispatchEvent(new CustomEvent(e.id+"SetExtremes",{detail:{minDate:t.min,maxDate:t.max,e:t}}))}}}},e.navigatorExtremesListener(),e.setResetZoomButton()):t.navigator||(n={navigator:{enabled:!1}}),f.updateObject(t,n)})}},{key:"setResetZoomButton",value:function(){var e=this,t=Promise.resolve();return t=(t=(t=t.then(function(){return e.addContainer(e.id,"ResetZoom","cp-chart-reset-zoom","button")})).then(function(){return e.getContainer("ResetZoom")})).then(function(t){return t.classList.add("uk-button"),t.innerText="Reset zoom",t.addEventListener("click",function(){e.chart.zoomOut()})})}},{key:"navigatorExtremesListener",value:function(){var i=this,t=Promise.resolve();return t=t.then(function(){return document.addEventListener(i.id+"SetExtremes",function(t){var e=f.round(t.detail.minDate/1e3,0),n=f.round(t.detail.maxDate/1e3,0),a=Promise.resolve();return a=a.then(function(){return i.fetchDataPackage(e,n)})})})}},{key:"getNavigatorExtremesUrl",value:function(t,e,n){var a=n?this.getExtremesDataUrl(this.id,n):this.extremesDataUrl;return t&&e&&a?a+"/dates/"+t+"/"+e+"/":null}},{key:"setNoDataLabel",value:function(t){var e={},n=Promise.resolve();return n=n.then(function(){return e={lang:{noData:"We don't have data for this time period"},noData:{style:{fontFamily:"Arial",fontSize:"14px",color:"#000000"}}},f.updateObject(t,e)})}},{key:"addContainer",value:function(t,e,n){var a=3<arguments.length&&void 0!==arguments[3]?arguments[3]:"div",i=document.createElement(a),r=document.getElementById(t);i.id=t+e,i.classList.add(n),r.appendChild(i)}},{key:"getContainer",value:function(t){return document.getElementById(this.id+t)}},{key:"getExtremesDataUrl",value:function(t){return"/currency/"+(1<arguments.length&&void 0!==arguments[1]?arguments[1]:"data")+"/"+this.currency}},{key:"getVolumePattern",value:function(){return{defs:{patterns:[{id:"fill-pattern",path:{d:"M 3 0 L 3 10 M 8 0 L 8 10",stroke:"#e3e3e3",fill:"#f1f1f1",strokeWidth:2}},{id:"fill-pattern-night",path:{d:"M 3 0 L 3 10 M 8 0 L 8 10",stroke:"#9b9b9b",fill:"#383838",strokeWidth:2}}]}}}}]),e}(),c=function(){function t(){s(this,t),this.emptyValue=0,this.emptyData="-"}return a(t,[{key:"nodeListToArray",value:function(t){return Array.prototype.slice.call(t)}},{key:"parseIntervalValue",value:function(t){var e="",n=1;return-1<t.search("s")&&(e="s",n=1e3),-1<t.search("m")&&(e="m",n=6e4),-1<t.search("h")&&(e="h",n=36e5),-1<t.search("d")&&(e="d",n=864e5),parseFloat(t.replace(e,""))*n}},{key:"updateObject",value:function(t,n){var a=this,i=t,e=Promise.resolve();return e=(e=e.then(function(){return f.loop(Object.keys(n),function(e){return i.hasOwnProperty(e)&&"object"===r(i[e])?a.updateObject(i[e],n[e]).then(function(t){i[e]=t}):i[e]=n[e]})})).then(function(){return i})}},{key:"parseNumber",value:function(t){if(!t&&0!==t)return t;if(t===this.emptyValue||t===this.emptyData)return t;if(1e5<(t=parseFloat(t))){var e=t.toFixed(0),n="K",a=e.slice(0,e.length-1);return 1e9<t?(a=e.slice(0,e.length-7),n="B"):1e6<t&&(a=e.slice(0,e.length-4),n="M"),a.slice(0,a.length-2)+"."+a.slice(a.length-2)+" "+n}if(0<t%1){var i=2;return t<1?i=8:t<10?i=6:t<1e3&&(i=4),this.round(t,i)}return t.toFixed(2)}},{key:"round",value:function(t){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:8,n=arguments[2];return t=parseFloat(t),n||(n="round"),e=Math.pow(10,e),Math[n](t*e)/e}},{key:"loop",value:function(i,r,t,e){var s=this,o=4<arguments.length&&void 0!==arguments[4]?arguments[4]:0,l=function(t,e){try{var n=r(i[o],o,i);n&&n.then?n.then(t).catch(e):t(n)}catch(t){e(t)}},n=function(t,e){return o<i.length?new Promise(l).then((n=t,a=e,function(){return s.loop(i,r,n,a,++o)})).catch(e):t();var n,a};return t?n(t,e):new Promise(n)}}]),t}(),u=function(){function t(){s(this,t),this.state={}}return a(t,[{key:"fetchScript",value:function(a){var i=this;return this.state[a]?Promise.resolve(null):(this.state[a]="pending",new Promise(function(t,e){var n=document.createElement("script");document.body.appendChild(n),n.addEventListener("load",function(){i.state&&(i.state[a]="downloaded"),t()}),n.addEventListener("error",function(){i.state&&delete i.state[a],e(new Error("Failed to load image's URL: "+a))}),n.async=!0,n.src=a}))}},{key:"fetchStyle",value:function(a){var i=this;return this.state[a]?Promise.resolve(null):(this.state[a]="pending",new Promise(function(t,e){var n=document.createElement("link");n.setAttribute("rel","stylesheet"),document.body.appendChild(n),n.setAttribute("href",a),n.addEventListener("load",function(){i.state&&(i.state[a]="downloaded"),t()}),n.addEventListener("error",function(){i.state&&delete i.state[a],e(new Error("Failed to load style URL: "+a))}),n.href=a}))}},{key:"fetchChartData",value:function(t){var e=1<arguments.length&&void 0!==arguments[1]&&arguments[1],n="https://graphs.coinpaprika.com"+t;return this.fetchData(n,e)}},{key:"fetchData",value:function(n,a){var i=this,t=Promise.resolve();return t=t.then(function(){if(a){if("pending"===i.state[n])return new Promise(function(t,e){setTimeout(function(){t(i.fetchData(n,a))},100)});if(i.state[n])return Promise.resolve(i.state[n].clone())}var t=Promise.resolve();return t=(t=t.then(function(){return i.state[n]="pending",fetch(n)})).then(function(t){return(i.state[n]=t).clone()})})}}]),t}();new i;var f=new c,d=new u},{}]},{},[1]);
!function r(s,o,l){function c(e,t){if(!o[e]){if(!s[e]){var n="function"==typeof require&&require;if(!t&&n)return n(e,!0);if(u)return u(e,!0);var a=new Error("Cannot find module '"+e+"'");throw a.code="MODULE_NOT_FOUND",a}var i=o[e]={exports:{}};s[e][0].call(i.exports,function(t){return c(s[e][1][t]||t)},i,i.exports,r,s,o,l)}return o[e].exports}for(var u="function"==typeof require&&require,t=0;t<l.length;t++)c(l[t]);return c}({1:[function(t,e,n){"use strict";var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},a=function(){function a(t,e){for(var n=0;n<e.length;n++){var a=e[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(t,a.key,a)}}return function(t,e,n){return e&&a(t.prototype,e),n&&a(t,n),t}}();function s(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}var i=function(){function t(){s(this,t),this.widgets=new o,this.bind()}return a(t,[{key:"bind",value:function(){var t=this;window[this.widgets.defaults.objectName]={},document.addEventListener("DOMContentLoaded",function(){return t.initWidgets()},!1),window[this.widgets.defaults.objectName].bindWidget=function(){window[t.widgets.defaults.objectName].init=!1,t.initWidgets()}}},{key:"initWidgets",value:function(){var i=this;if(!window[this.widgets.defaults.objectName].init){window[this.widgets.defaults.objectName].init=!0;var e=Array.prototype.slice.call(document.getElementsByClassName(this.widgets.defaults.className));this.widgets.setWidgetClass(e),window.addEventListener("resize",function(){i.widgets.setWidgetClass(e);for(var t=0;t<e.length;t++)i.widgets.setBeforeElementInFooter(t)},!1);var t=this.widgets.getScriptElement();if(t&&t.dataset&&t.dataset.cpCurrencyWidget){var n=JSON.parse(t.dataset.cpCurrencyWidget);if(Object.keys(n))for(var a=Object.keys(n),r=0;r<a.length;r++){var s=a[r].replace("-","_");this.widgets.defaults[s]=n[a[r]]}}setTimeout(function(){return i.widgets.states=[],f.loop(e,function(t,e){var n=JSON.parse(JSON.stringify(i.widgets.defaults));n.isWordpress=t.classList.contains("wordpress"),n.isNightMode=t.classList.contains("cp-widget__night-mode"),n.mainElement=t,i.widgets.states.push(n);var a=Promise.resolve();return a=(a=a.then(function(){return-1<n.modules.indexOf("chart")&&!window.Highcharts?f.loop(["http://code.highcharts.com/stock/highstock.js","https://code.highcharts.com/modules/exporting.js","https://code.highcharts.com/modules/no-data-to-display.js","https://highcharts.github.io/pattern-fill/pattern-fill-v2.js"],function(t){return d.fetchScript(t)}):null})).then(function(){return i.widgets.init(e)})})},50)}}}]),t}(),o=function(){function t(){s(this,t),this.states=[],this.defaults={objectName:"cpCurrencyWidgets",className:"coinpaprika-currency-widget",cssFileName:"widget.min.css",currency:"btc-bitcoin",primary_currency:"USD",range_list:["24h","7d","30d","1q","1y","ytd","all"],range:"7d",modules:["market_details","chart"],update_active:!1,update_timeout:"30s",language:"en",style_src:null,img_src:null,lang_src:null,origin_src:"https://unpkg.com/@coinpaprika/widget-currency",show_details_currency:!1,ticker:{name:void 0,symbol:void 0,price:void 0,price_change_24h:void 0,rank:void 0,price_ath:void 0,volume_24h:void 0,market_cap:void 0,percent_from_price_ath:void 0,volume_24h_change_24h:void 0,market_cap_change_24h:void 0},interval:null,isWordpress:!1,isNightMode:!1,isData:!1,availableModules:["price","chart","market_details"],message:"data_loading",translations:{},mainElement:null,noTranslationLabels:[],scriptsDownloaded:{},chart:null,rwd:{xs:280,s:320,m:370,l:462}}}return a(t,[{key:"init",value:function(t){var e=this;if(!this.getMainElement(t))return console.error('Bind failed, no element with class = "'+this.defaults.className+'"');var n=Promise.resolve();return n=(n=n.then(function(){return e.getDefaults(t)})).then(function(){return e.setOriginLink(t)})}},{key:"setWidgetClass",value:function(t){for(var e=0;e<t.length;e++)for(var n=t[e].getBoundingClientRect().width,a=Object.keys(this.defaults.rwd),i=0;i<a.length;i++){var r=a[i],s=this.defaults.rwd[r],o=this.defaults.className+"__"+r;n<=s&&t[e].classList.add(o),s<n&&t[e].classList.remove(o)}}},{key:"getMainElement",value:function(t){return this.states[t]?this.states[t].mainElement:null}},{key:"getDefaults",value:function(n){var a=this;return new Promise(function(t){var e=a.getMainElement(n);return e&&e.dataset&&(e.dataset.modules||"extended"!==e.dataset.version||a.updateData(n,"modules",["market_details"]),e.dataset.modules||"standard"!==e.dataset.version||a.updateData(n,"modules",[]),e.dataset.modules&&a.updateData(n,"modules",JSON.parse(e.dataset.modules)),e.dataset.primaryCurrency&&a.updateData(n,"primary_currency",e.dataset.primaryCurrency),e.dataset.currency&&a.updateData(n,"currency",e.dataset.currency),e.dataset.range&&a.updateData(n,"range",e.dataset.range),e.dataset.showDetailsCurrency&&a.updateData(n,"show_details_currency","true"===e.dataset.showDetailsCurrency),e.dataset.updateActive&&a.updateData(n,"update_active","true"===e.dataset.updateActive),e.dataset.updateTimeout&&a.updateData(n,"update_timeout",f.parseIntervalValue(e.dataset.updateTimeout)),e.dataset.language&&a.updateData(n,"language",e.dataset.language),e.dataset.originSrc&&a.updateData(n,"origin_src",e.dataset.originSrc),e.dataset.nodeModulesSrc&&a.updateData(n,"node_modules_src",e.dataset.nodeModulesSrc),e.dataset.bowerSrc&&a.updateData(n,"bower_src",e.dataset.bowerSrc),e.dataset.styleSrc&&a.updateData(n,"style_src",e.dataset.styleSrc),e.dataset.langSrc&&a.updateData(n,"logo_src",e.dataset.langSrc),e.dataset.imgSrc&&a.updateData(n,"logo_src",e.dataset.imgSrc)),t()})}},{key:"setOriginLink",value:function(t){var e=this;0===Object.keys(this.defaults.translations).length&&this.getTranslations(this.defaults.language);var n=Promise.resolve();return n=(n=(n=n.then(function(){return e.stylesheet()})).then(function(){return e.addWidgetElement(t)})).then(function(){return e.initInterval(t)})}},{key:"addWidgetElement",value:function(n){var a=this,t=this.getMainElement(n),i="",e=[],r=null,s=Promise.resolve();return s=(s=(s=(s=(s=(s=(s=s.then(function(){return f.loop(a.defaults.availableModules,function(t){return-1<a.states[n].modules.indexOf(t)?e.push(t):null})})).then(function(){return f.loop(e,function(t){var e=null;return"chart"===t&&(e="Chart"),"market_details"===t&&(e="MarketDetails"),e?a["widget"+e+"Element"](n).then(function(t){return i+=t}):null})})).then(function(){return t.innerHTML=a.widgetMainElement(n)+i+a.widgetFooter(n)})).then(function(){return(r=document.getElementById(a.defaults.className+"-price-chart-"+n))?r.parentElement.insertAdjacentHTML("beforeend",a.widgetSelectElement(n,"range")):null})).then(function(){return r&&(a.states[n].chart=new l(r,a.states[n]),a.setSelectListeners(n)),null})).then(function(){return a.setBeforeElementInFooter(n)})).then(function(){return a.getData(n)})}},{key:"setSelectListeners",value:function(e){for(var n=this,t=this.getMainElement(e).querySelectorAll(".cp-widget-select"),a=0;a<t.length;a++)for(var i=t[a].querySelectorAll(".cp-widget-select__options button"),r=0;r<i.length;r++)i[r].addEventListener("click",function(t){n.setSelectOption(t,e)},!1)}},{key:"setSelectOption",value:function(t,e){for(var n="cp-widget-active",a=0;a<t.target.parentNode.childNodes.length;a++){var i=t.target.parentNode.childNodes[a];i.classList.contains(n)&&i.classList.remove(n)}var r=t.target.closest(".cp-widget-select"),s=r.dataset.type,o=r.querySelector(".cp-widget-select__options > span"),l=t.target.dataset.option;o.innerText=this.getTranslation(e,l.toLowerCase()),this.updateData(e,s,l),t.target.classList.add(n),this.dispatchEvent(e,"-switch-range",l)}},{key:"dispatchEvent",value:function(t,e,n){var a=this.defaults.className+"-price-chart-"+t;return document.dispatchEvent(new CustomEvent(""+a+e,{detail:{data:n}}))}},{key:"getData",value:function(e){var n=this,t="https://api.coinpaprika.com/v1/widget/"+this.states[e].currency+"?quote="+this.states[e].primary_currency;return d.fetchData(t).then(function(t){return t.json().then(function(t){n.states[e].isData||n.updateData(e,"isData",!0),n.updateTicker(e,t)})}).catch(function(t){return n.onErrorRequest(e,t)})}},{key:"onErrorRequest",value:function(t,e){this.states[t].isData&&this.updateData(t,"isData",!1),this.updateData(t,"message","data_unavailable"),console.error("Request failed. Returned status of "+e,this.states[t])}},{key:"initInterval",value:function(t){var e=this;clearInterval(this.states[t].interval),this.states[t].update_active&&1e3<this.states[t].update_timeout&&(this.states[t].interval=setInterval(function(){e.getData(t)},this.states[t].update_timeout))}},{key:"setBeforeElementInFooter",value:function(t){if(!this.states[t].isWordpress){var e=this.getMainElement(t);if(e){"style"===e.children[0].localName&&e.removeChild(e.childNodes[0]);for(var n=e.querySelector(".cp-widget__footer"),a=n.getBoundingClientRect().width-43,i=0;i<n.childNodes.length;i++)a-=n.childNodes[i].getBoundingClientRect().width;var r=document.createElement("style");r.innerHTML=".cp-widget__footer--"+t+"::before{width:"+a.toFixed(0)+"px;}",e.insertBefore(r,e.children[0])}}}},{key:"updateWidgetElement",value:function(t,e,n,a){var i=this.states[t],r=this.getMainElement(t);if(r){var s=a?"Ticker":"";if("name"===e||"currency"===e){if("currency"===e)for(var o=r.querySelectorAll(".cp-widget__footer > a"),l=0;l<o.length;l++)o[l].href=this.coin_link(n);this.getImage(t)}if("isData"===e||"message"===e)for(var c=r.querySelectorAll(".cp-widget__main"),u=0;u<c.length;u++)c[u].innerHTML=i.isData?this.widgetMainElementData(t):this.widgetMainElementMessage(t);else for(var d=r.querySelectorAll("."+e+s),h=0;h<d.length;h++){var g=d[h];if(g.classList.contains("cp-widget__rank")){var p=0<parseFloat(n)?"cp-widget__rank-up":parseFloat(n)<0?"cp-widget__rank-down":"cp-widget__rank-neutral";g.classList.remove("cp-widget__rank-down"),g.classList.remove("cp-widget__rank-up"),g.classList.remove("cp-widget__rank-neutral"),n=void 0===n?f.emptyData:(g.classList.add(p),"price_change_24h"===e?"("+f.round(n,2)+"%)":f.round(n,2)+"%")}g.classList.contains("showDetailsCurrency")&&!i.show_details_currency&&(n=" "),g.classList.contains("parseNumber")?g.innerText=f.parseNumber(n)||f.emptyData:g.innerText=n||f.emptyData}}}},{key:"updateData",value:function(t,e,n,a){a?this.states[t].ticker[e]=n:this.states[t][e]=n,"language"===e&&this.getTranslations(n),this.updateWidgetElement(t,e,n,a)}},{key:"updateWidgetTranslations",value:function(e,t){var o=this;this.defaults.translations[e]=t;for(var n=function(s){var t=0<o.states[s].noTranslationLabels.length&&"en"===e;(o.states[s].language===e||t)&&function(){for(var t=o.states[s].mainElement,r=Array.prototype.slice.call(t.querySelectorAll(".cp-translation")),e=function(i){r[i].classList.forEach(function(t){if(-1<t.search("translation_")){var e=t.replace("translation_","");"message"===e&&(e=o.states[s].message);var n=o.states[s].noTranslationLabels.indexOf(e),a=o.getTranslation(s,e);-1<n&&a&&o.states[s].noTranslationLabels.splice(n,1),r[i].innerText=a,r[i].closest(".cp-widget__footer")&&setTimeout(function(){return o.setBeforeElementInFooter(s)},50)}})},n=0;n<r.length;n++)e(n)}()},a=0;a<this.states.length;a++)n(a)}},{key:"updateTicker",value:function(t,e){for(var n=Object.keys(e),a=0;a<n.length;a++)this.updateData(t,n[a],e[n[a]],!0)}},{key:"stylesheet",value:function(){if(!1===this.defaults.style_src)return Promise.resolve();var t=this.defaults.style_src||this.defaults.origin_src+"/dist/"+this.defaults.cssFileName;return document.body.querySelector('link[href="'+t+'"]')?Promise.resolve():d.fetchStyle(t)}},{key:"widgetMainElement",value:function(t){var e=this.states[t];return'<div class="cp-widget__header"><div class="cp-widget__img cp-widget__img-'+e.currency+'"><img/></div><div class="cp-widget__main">'+(e.isData?this.widgetMainElementData(t):this.widgetMainElementMessage(t))+"</div></div>"}},{key:"widgetMainElementData",value:function(t){var e=this.states[t];return'<h3><a href="'+this.coin_link(e.currency)+'"><span class="nameTicker">'+(e.ticker.name||f.emptyData)+'</span><span class="symbolTicker">'+(e.ticker.symbol||f.emptyData)+'</span></a></h3><strong><span class="priceTicker parseNumber">'+(f.parseNumber(e.ticker.price)||f.emptyData)+'</span> <span class="primaryCurrency">'+e.primary_currency+' </span><span class="price_change_24hTicker cp-widget__rank cp-widget__rank-'+(0<e.ticker.price_change_24h?"up":e.ticker.price_change_24h<0?"down":"neutral")+'">('+(f.round(e.ticker.price_change_24h,2)||f.emptyValue)+'%)</span></strong><span class="cp-widget__rank-label"><span class="cp-translation translation_rank">'+this.getTranslation(t,"rank")+'</span> <span class="rankTicker">'+(e.ticker.rank||f.emptyData)+"</span></span>"}},{key:"widgetMainElementMessage",value:function(t){var e=this.states[t].message;return'<div class="cp-widget__main-no-data cp-translation translation_message">'+this.getTranslation(t,e)+"</div>"}},{key:"widgetMarketDetailsElement",value:function(t){return Promise.resolve(-1<this.states[t].modules.indexOf("market_details")?'<div class="cp-widget__details">'+this.widgetAthElement(t)+this.widgetVolume24hElement(t)+this.widgetMarketCapElement(t)+"</div>":"")}},{key:"widgetAthElement",value:function(t){return'<div><small class="cp-translation translation_ath">'+this.getTranslation(t,"ath")+'</small><div><span class="price_athTicker parseNumber">'+f.emptyData+' </span><span class="symbolTicker showDetailsCurrency"></span></div><span class="percent_from_price_athTicker cp-widget__rank">'+f.emptyData+"</span></div>"}},{key:"widgetVolume24hElement",value:function(t){return'<div><small class="cp-translation translation_volume_24h">'+this.getTranslation(t,"volume_24h")+'</small><div><span class="volume_24hTicker parseNumber">'+f.emptyData+' </span><span class="symbolTicker showDetailsCurrency"></span></div><span class="volume_24h_change_24hTicker cp-widget__rank">'+f.emptyData+"</span></div>"}},{key:"widgetMarketCapElement",value:function(t){return'<div><small class="cp-translation translation_market_cap">'+this.getTranslation(t,"market_cap")+'</small><div><span class="market_capTicker parseNumber">'+f.emptyData+' </span><span class="symbolTicker showDetailsCurrency"></span></div><span class="market_cap_change_24hTicker cp-widget__rank">'+f.emptyData+"</span></div>"}},{key:"widgetChartElement",value:function(t){return Promise.resolve('<div class="cp-widget__chart"><div id="'+this.defaults.className+"-price-chart-"+t+'"></div></div>')}},{key:"widgetSelectElement",value:function(t,e){for(var n="",a=0;a<this.states[t][e+"_list"].length;a++){var i=this.states[t][e+"_list"][a];n+='<button class="'+(i.toLowerCase()===this.states[t][e].toLowerCase()?"cp-widget-active ":"")+("primary_currency"===e?"":"cp-translation translation_"+i.toLowerCase())+'" data-option="'+i+'">'+this.getTranslation(t,i.toLowerCase())+"</button>"}return'<div data-type="'+e+'" class="cp-widget-select"><label class="cp-translation translation_'+e+'">'+this.getTranslation(t,"zoom_in")+'</label><div class="cp-widget-select__options"><span class="arrow-down cp-widget__capitalize cp-translation translation_'+this.states[t][e].toLowerCase()+'">'+this.getTranslation(t,this.states[t][e].toLowerCase())+'</span><div class="cp-widget-select__dropdown">'+n+"</div></div></div>"}},{key:"widgetFooter",value:function(t){var e=this.states[t].currency;return this.states[t].isWordpress?"":'<p class="cp-widget__footer cp-widget__footer--'+t+'"><span class="cp-translation translation_powered_by">'+this.getTranslation(t,"powered_by")+' </span><img style="width: 16px" src="'+this.main_logo_link()+'" alt=""/><a target="_blank" href="'+this.coin_link(e)+'">coinpaprika.com</a></p>'}},{key:"getImage",value:function(t){for(var i=this,r=this.states[t],s=r.mainElement.getElementsByClassName("cp-widget__img"),e=function(t){var e=s[t];e.classList.add("cp-widget__img--hidden");var n=e.querySelector("img"),a=new Image;a.onload=function(){n.src=a.src,e.classList.remove("cp-widget__img--hidden")},a.src=i.img_src(r.currency)},n=0;n<s.length;n++)e(n)}},{key:"img_src",value:function(t){return"https://coinpaprika.com/coin/"+t+"/logo.png"}},{key:"coin_link",value:function(t){return"https://coinpaprika.com/coin/"+t}},{key:"main_logo_link",value:function(){return this.defaults.img_src||this.defaults.origin_src+"/dist/img/logo_widget.svg"}},{key:"getScriptElement",value:function(){return document.querySelector("script[data-cp-currency-widget]")}},{key:"getTranslation",value:function(t,e){var n=this.defaults.translations[this.states[t].language]?this.defaults.translations[this.states[t].language][e]:null;return!n&&this.defaults.translations.en&&(n=this.defaults.translations.en[e]),n||this.addLabelWithoutTranslation(t,e)}},{key:"addLabelWithoutTranslation",value:function(t,e){return this.defaults.translations.en||this.getTranslations("en"),this.states[t].noTranslationLabels.push(e)}},{key:"getTranslations",value:function(t){var e=this;if(!this.defaults.translations[t]){var n=new XMLHttpRequest,a=this.defaults.lang_src||this.defaults.origin_src+"/dist/lang";n.open("GET",a+"/"+t+".json"),n.onload=function(){200===n.status?e.updateWidgetTranslations(t,JSON.parse(n.responseText)):(e.onErrorRequest(0,n),e.getTranslations("en"),delete e.defaults.translations[t])},n.onerror=function(){e.onErrorRequest(0,n),e.getTranslations("en"),delete e.defaults.translations[t]},n.send(),this.defaults.translations[t]={}}}}]),t}(),l=function(){function e(t,a){var i=this;s(this,e),t&&(this.id=t.id,this.isNightMode=a.isNightMode,this.chartsWithActiveSeriesCookies=[],this.chart=null,this.currency=a.currency,this.container=t,this.options=this.setOptions(),this.defaultRange=a.range||"7d",this.callback=null,this.replaceCallback=null,this.extremesDataUrl=this.getExtremesDataUrl(t.id),this.defaultOptions={chart:{alignTicks:!1,marginTop:50,style:{fontFamily:"sans-serif"},events:{render:function(t){if(t.target.annotations){var n=t.target.annotations.chart;f.loop(n.annotations.allItems,function(t){var e=n.plotHeight+n.plotTop-n.spacing[0]-2-(i.isResponsiveModeActive(n)?10:0);t.update({y:e},!0)})}}}},scrollbar:{enabled:!1},annotationsOptions:{enabledButtons:!1},rangeSelector:{enabled:!1},plotOptions:{line:{series:{states:{hover:{enabled:!1}}}},series:{events:{legendItemClick:function(t){return t.browserEvent.isTrusted&&-1<i.chartsWithActiveSeriesCookies.indexOf(t.target.chart.renderTo.id)&&i.setVisibleChartCookies(t),t.browserEvent.isTrusted}}}},xAxis:{ordinal:!1}},this.chartDataParser=function(n){return new Promise(function(t){n=n[0];var e=a.primary_currency.toLowerCase();return t({data:{price:n.price?n.price:n[e]?n[e]:[],volume:n.volume||[]}})})},this.isEventsHidden=!1,this.excludeSeriesIds=[],this.asyncUrl="/currency/data/"+a.currency+"/_range_/",this.asyncParams="?quote="+a.primary_currency.toUpperCase()+"&fields=price,volume",this.init())}return a(e,[{key:"setOptions",value:function(){var t=new e;return{responsive:{rules:[{condition:{maxWidth:1500},chartOptions:{legend:{align:"right",verticalAlign:"middle",y:92,symbolRadius:0,itemDistance:20,itemStyle:{fontSize:10}},chart:{height:400,marginTop:35,marginBottom:0,spacingTop:0,spacingBottom:0},navigator:{height:50,margin:70,handles:{height:25,width:17}}}},{condition:{maxWidth:600},chartOptions:{chart:{marginTop:0,zoomType:"none",marginLeft:10,marginRight:10,height:350},yAxis:[{floor:0,tickAmount:7,tickWidth:0,tickLength:0,lineWidth:0,title:{enabled:!1},labels:{align:"left",x:1,y:-2,style:{color:"#9e9e9e",fontSize:"9px"}}},{floor:0,tickAmount:7,tickWidth:0,tickLength:0,lineWidth:0,title:{enabled:!1},labels:{align:"right",overflow:"justify",x:1,y:-2,style:{color:"#5085ec",fontSize:"9px"}}}]}},{condition:{maxWidth:450},chartOptions:{legend:{align:"right",verticalAlign:"middle",y:82,symbolRadius:0,itemDistance:20,itemStyle:{fontSize:10}},navigator:{margin:60,height:40,handles:{height:20}},chart:{height:300},yAxis:[{floor:0,tickAmount:7,tickWidth:0,tickLength:0,lineWidth:0,title:{enabled:!1},labels:{align:"left",x:1,y:-2,style:{color:"#9e9e9e",fontSize:"9px"}}},{floor:0,tickAmount:7,tickWidth:0,tickLength:0,lineWidth:0,title:{enabled:!1},labels:{align:"right",overflow:"justify",x:1,y:-2,style:{color:"#5085ec",fontSize:"9px"}}}]}}]},title:{text:void 0},chart:{backgroundColor:"none",marginTop:50,plotBorderWidth:0},cpEvents:!1,colors:["#5085ec","#1f9809","#985d65","#ee983b","#4c4c4c"],legend:{margin:0,enabled:!0,align:"right",symbolRadius:0,itemDistance:40,itemStyle:{fontWeight:"normal",color:this.isNightMode?"#80a6e5":"#0645ad"},itemMarginTop:8},navigator:!0,tooltip:{shared:!0,split:!1,animation:!1,borderWidth:1,borderColor:this.isNightMode?"#4c4c4c":"#e3e3e3",hideDelay:100,shadow:!1,backgroundColor:"#ffffff",style:{color:"#4c4c4c",fontSize:"10px"},useHTML:!0,formatter:function(){return t.tooltipFormatter(this)}},exporting:{buttons:{contextButton:{enabled:!1}}},xAxis:{lineColor:this.isNightMode?"#505050":"#e3e3e3",tickColor:this.isNightMode?"#505050":"#e3e3e3",tickLength:7},yAxis:[{lineWidth:1,lineColor:"#dedede",tickWidth:1,tickLength:4,gridLineDashStyle:"dash",gridLineWidth:0,floor:0,minPadding:0,opposite:!1,showEmpty:!1,showLastLabel:!1,showFirstLabel:!1},{gridLineColor:this.isNightMode?"#505050":"#e3e3e3",gridLineDashStyle:"dash",lineWidth:1,tickWidth:1,tickLength:4,floor:0,minPadding:0,showEmpty:!1,opposite:!0,gridZIndex:4,showLastLabel:!1,showFirstLabel:!1}],series:[{color:"#5085ec",name:"Price",id:"price",data:[],type:"area",fillOpacity:.15,lineWidth:2,yAxis:1,zIndex:2,visible:!0,clickable:!0,threshold:null,tooltip:{valueDecimals:0},showInNavigator:!0,showInLegend:!1},{color:"url(#fill-pattern"+(this.isNightMode?"-night":"")+")",name:"Volume",id:"volume",data:[],type:"area",fillOpacity:.5,lineWidth:0,yAxis:0,zIndex:0,visible:!0,clickable:!0,threshold:null,tooltip:{valueDecimals:0},showInNavigator:!0}]}}},{key:"init",value:function(){var e=this,t=Promise.resolve();return t=(t=t.then(function(){return e.parseOptions(e.options)})).then(function(t){return window.Highcharts?Highcharts.stockChart(e.container.id,t,function(t){return e.bind(t)}):null})}},{key:"parseOptions",value:function(t){var e=this,n=Promise.resolve();return n=(n=(n=(n=(n=n.then(function(){return f.updateObject(e.defaultOptions,t)})).then(function(t){return f.updateObject(e.getVolumePattern(),t)})).then(function(t){return e.setNavigator(t)})).then(function(t){return t.noData?e.setNoDataLabel(t):t})).then(function(t){return t})}},{key:"bind",value:function(t){var e=this,n=Promise.resolve();return n=(n=(n=(n=n.then(function(){return e.chart=t})).then(function(){return e.fetchDataPackage()})).then(function(){return e.setRangeSwitcher()})).then(function(){return e.callback?e.callback(e.chart,e.defaultRange):null})}},{key:"fetchDataPackage",value:function(e,n){var a=this,i=e&&n,t=Promise.resolve();return t=(t=(t=(t=(t=(t=t.then(function(){if(a.options.cpEvents){var t=i?a.getNavigatorExtremesUrl(e,n,"events"):a.getExtremesDataUrl(a.id,"events")+"/"+a.getRange()+"/";return t?a.fetchData(t,"events",!i):null}return null})).then(function(){var t=(i?a.getNavigatorExtremesUrl(e,n):a.asyncUrl.replace("_range_",a.getRange()))+a.asyncParams;return t?a.fetchData(t,"data",!i):null})).then(function(){return a.chart.redraw(!1)})).then(function(){return i?null:a.chart.zoomOut()})).then(function(){return a.isLoaded=!0})).then(function(){return a.toggleEvents()})}},{key:"fetchData",value:function(t){var n=this,a=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"data",i=!(2<arguments.length&&void 0!==arguments[2])||arguments[2],e=Promise.resolve();return e=(e=e.then(function(){return n.chart.showLoading(),d.fetchChartData(t,!n.isLoaded)})).then(function(t){return n.chart.hideLoading(),200!==t.status?console.log("Looks like there was a problem. Status Code: "+t.status):t.json().then(function(t){var e=Promise.resolve();return e=(e=e.then(function(){return n.dataParser(t,a)})).then(function(t){return i?n.replaceData(t.data,a):n.updateData(t.data,a)})})}).catch(function(t){return n.chart.hideLoading(),n.hideChart(),console.log("Fetch Error",t)})}},{key:"hideChart",value:function(){var t=this,e=!(0<arguments.length&&void 0!==arguments[0])||arguments[0]?"add":"remove";console.log({container:this.container});var n=f.nodeListToArray(this.container.parentElement.childNodes),a=Promise.resolve();return a=(a=(a=a.then(function(){return n.filter(function(t){return-1===t.id.search("chart")})})).then(function(t){return f.loop(t,function(t){return t.classList[e]("cp-hidden")})})).then(function(){return t.container.classList[e]("cp-chart-no-data")})}},{key:"setRangeSwitcher",value:function(){var e=this;document.addEventListener(this.id+"-switch-range",function(t){return e.defaultRange=t.detail.data,e.fetchDataPackage()})}},{key:"getRange",value:function(){return this.defaultRange||"1q"}},{key:"toggleEvents",value:function(){var e=this,t=Promise.resolve();return this.options.cpEvents&&(t=(t=(t=(t=t.then(function(){return document.getElementsByClassName("highcharts-annotation")})).then(function(t){return f.loop(t,function(t){return e.isEventsHidden?t.classList.contains("highcharts-annotation__hidden")?null:t.classList.add("highcharts-annotation__hidden"):t.classList.contains("highcharts-annotation__hidden")?t.classList.remove("highcharts-annotation__hidden"):null})})).then(function(){return document.getElementsByClassName("highcharts-plot-line")})).then(function(t){return f.loop(t,function(t){return e.isEventsHidden?t.classList.contains("highcharts-plot-line__hidden")?null:t.classList.add("highcharts-plot-line__hidden"):t.classList.contains("highcharts-plot-line__hidden")?t.classList.remove("highcharts-plot-line__hidden"):null})})),t}},{key:"dataParser",value:function(t){var e=this;switch(1<arguments.length&&void 0!==arguments[1]?arguments[1]:"data"){case"data":var n=Promise.resolve();return n=n.then(function(){return e.chartDataParser?e.chartDataParser(t):{data:t[0]}});case"events":return Promise.resolve(t);default:return null}}},{key:"updateData",value:function(n,a){var i=this,r=void 0,t=Promise.resolve();return t=(t=t.then(function(){switch(a){case"data":return r={},f.loop(Object.entries(n),function(t){if(!i.isExcluded(t[0])){var e=i.getOldData(a)[t[0]];r[t[0]]=e.filter(function(e){return-1===t[1].findIndex(function(t){return i.isTheSameElement(e,t,a)})}).concat(t[1]).sort(function(t,e){return i.sortCondition(t,e,a)})}});case"events":r=[];var t=i.getOldData(a);return r=t.filter(function(e){n.findIndex(function(t){return i.isTheSameElement(e,t,a)})}).concat(n).sort(function(t,e){return i.sortCondition(t,e,a)});default:return!1}})).then(function(){return i.replaceData(r,a)})}},{key:"isTheSameElement",value:function(t,e,n){switch(n){case"data":return t[0]===e[0];case"events":return t.ts===e.ts;default:return!1}}},{key:"sortCondition",value:function(t,e,n){switch(n){case"data":return t[0]-e[0];case"events":return t.ts-e.ts;default:return!1}}},{key:"getOldData",value:function(t){return this["chart_"+t.toLowerCase()]}},{key:"replaceData",value:function(t,e){var n=this,a=Promise.resolve();return a=(a=(a=a.then(function(){return n["chart_"+e.toLowerCase()]=t})).then(function(){return n.replaceDataType(t,e)})).then(function(){return n.replaceCallback?n.replaceCallback(n.chart,t,n.isLoaded,e):null})}},{key:"replaceDataType",value:function(n,t){var a=this;switch(t){case"data":return this.asyncUrl&&f.loop(["btc-bitcoin","eth-ethereum"],function(t){var e=t.split("-")[0];-1<a.asyncUrl.search(t)&&n[e]&&(n[e]=[],f.loop(a.chart.series,function(t){t.userOptions.id===e&&t.update({visible:!1})}))}),f.loop(Object.entries(n),function(t){if(!a.isExcluded(t[0]))return a.chart.get(t[0])?a.chart.get(t[0]).setData(t[1],!1,!1,!1):a.chart.addSeries({id:t[0],data:t[1],showInNavigator:!0})});case"events":var e=Promise.resolve();return e=(e=e.then(function(){return f.loop(a.chart.annotations.allItems,function(t){return t.destroy()})})).then(function(){return a.setAnnotationsObjects(n)});default:return null}}},{key:"isExcluded",value:function(t){return-1<this.excludeSeriesIds.indexOf(t)}},{key:"tooltipFormatter",value:function(t){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"",n=arguments[2];n||(n=e);var a='<div class="cp-chart-tooltip-currency"><small>'+new Date(t.x).toUTCString()+"</small><table>",i="";return t.points.forEach(function(t){i+='<tr><td><svg width="5" height="5"><rect x="0" y="0" width="5" height="5" fill="'+t.series.color+'" fill-opacity="1"></rect></svg>'+t.series.name+": "+t.y.toLocaleString("ru-RU",{maximumFractionDigits:8})+" "+(-1<t.series.name.toLowerCase().search(n.toLowerCase())?"":e)+"</td></tr>"}),a+i+"</table></div>"}},{key:"setAnnotationsObjects",value:function(t){var n=this;this.chart.series[0].xAxis.removePlotLine();var a=[],e=Promise.resolve();return e=(e=(e=e.then(function(){return t.sort(function(t,e){return e.ts-t.ts})})).then(function(){return f.loop(t,function(t){var e=Promise.resolve();return e=(e=e.then(function(){return a.push({width:1,value:t.ts,dashStyle:"solid",zIndex:4,color:n.getEventTagParams().color})})).then(function(){return n.chart.addAnnotation({xValue:t.ts,y:0,title:'<span title="Click to open" class="cp-chart-annotation__text">'+n.getEventTagParams(t.tag).label+'</span><span class="cp-chart-annotation__dataElement" style="display: none;">'+JSON.stringify(t)+"</span>",shape:{type:"circle",params:{r:11,cx:9,cy:10.5,"stroke-width":1.5,fill:n.getEventTagParams().color}},events:{mouseover:function(t){if(!MobileDetect.isMobile()){var e=n.getEventDataFromAnnotationEvent(t);n.openEventContainer(e,t)}},mouseout:function(){MobileDetect.isMobile()||n.closeEventContainer(event)},click:function(t){var e=n.getEventDataFromAnnotationEvent(t);MobileDetect.isMobile()?n.openEventContainer(e,t):n.openEventPage(e)}}})})})})).then(function(){return n.chart.series[0].xAxis.update({plotLines:a},!1)})}},{key:"setNavigator",value:function(t){var e=this,n={},a=Promise.resolve();return a=a.then(function(){return!0===t.navigator?(n={navigator:{enable:!0,margin:20,series:{lineWidth:1},maskFill:"rgba(102,133,194,0.15)"},chart:{zoomType:"x"},xAxis:{events:{setExtremes:function(t){("navigator"===t.trigger||"zoom"===t.trigger)&&t.min&&t.max&&document.dispatchEvent(new CustomEvent(e.id+"SetExtremes",{detail:{minDate:t.min,maxDate:t.max,e:t}}))}}}},e.navigatorExtremesListener(),e.setResetZoomButton()):t.navigator||(n={navigator:{enabled:!1}}),f.updateObject(t,n)})}},{key:"setResetZoomButton",value:function(){var e=this,t=Promise.resolve();return t=(t=(t=t.then(function(){return e.addContainer(e.id,"ResetZoom","cp-chart-reset-zoom","button")})).then(function(){return e.getContainer("ResetZoom")})).then(function(t){return t.classList.add("uk-button"),t.innerText="Reset zoom",t.addEventListener("click",function(){e.chart.zoomOut()})})}},{key:"navigatorExtremesListener",value:function(){var i=this,t=Promise.resolve();return t=t.then(function(){return document.addEventListener(i.id+"SetExtremes",function(t){var e=f.round(t.detail.minDate/1e3,0),n=f.round(t.detail.maxDate/1e3,0),a=Promise.resolve();return a=a.then(function(){return i.fetchDataPackage(e,n)})})})}},{key:"getNavigatorExtremesUrl",value:function(t,e,n){var a=n?this.getExtremesDataUrl(this.id,n):this.extremesDataUrl;return t&&e&&a?a+"/dates/"+t+"/"+e+"/":null}},{key:"setNoDataLabel",value:function(t){var e={},n=Promise.resolve();return n=n.then(function(){return e={lang:{noData:"We don't have data for this time period"},noData:{style:{fontFamily:"Arial",fontSize:"14px",color:"#000000"}}},f.updateObject(t,e)})}},{key:"addContainer",value:function(t,e,n){var a=3<arguments.length&&void 0!==arguments[3]?arguments[3]:"div",i=document.createElement(a),r=document.getElementById(t);i.id=t+e,i.classList.add(n),r.appendChild(i)}},{key:"getContainer",value:function(t){return document.getElementById(this.id+t)}},{key:"getExtremesDataUrl",value:function(t){return"/currency/"+(1<arguments.length&&void 0!==arguments[1]?arguments[1]:"data")+"/"+this.currency}},{key:"getVolumePattern",value:function(){return{defs:{patterns:[{id:"fill-pattern",path:{d:"M 3 0 L 3 10 M 8 0 L 8 10",stroke:"#e3e3e3",fill:"#f1f1f1",strokeWidth:2}},{id:"fill-pattern-night",path:{d:"M 3 0 L 3 10 M 8 0 L 8 10",stroke:"#9b9b9b",fill:"#383838",strokeWidth:2}}]}}}}]),e}(),c=function(){function t(){s(this,t),this.emptyValue=0,this.emptyData="-"}return a(t,[{key:"nodeListToArray",value:function(t){return Array.prototype.slice.call(t)}},{key:"parseIntervalValue",value:function(t){var e="",n=1;return-1<t.search("s")&&(e="s",n=1e3),-1<t.search("m")&&(e="m",n=6e4),-1<t.search("h")&&(e="h",n=36e5),-1<t.search("d")&&(e="d",n=864e5),parseFloat(t.replace(e,""))*n}},{key:"updateObject",value:function(t,n){var a=this,i=t,e=Promise.resolve();return e=(e=e.then(function(){return f.loop(Object.keys(n),function(e){return i.hasOwnProperty(e)&&"object"===r(i[e])?a.updateObject(i[e],n[e]).then(function(t){i[e]=t}):i[e]=n[e]})})).then(function(){return i})}},{key:"parseNumber",value:function(t){if(!t&&0!==t)return t;if(t===this.emptyValue||t===this.emptyData)return t;if(1e5<(t=parseFloat(t))){var e=t.toFixed(0),n="K",a=e.slice(0,e.length-1);return 1e9<t?(a=e.slice(0,e.length-7),n="B"):1e6<t&&(a=e.slice(0,e.length-4),n="M"),a.slice(0,a.length-2)+"."+a.slice(a.length-2)+" "+n}if(0<t%1){var i=2;return t<1?i=8:t<10?i=6:t<1e3&&(i=4),this.round(t,i)}return t.toFixed(2)}},{key:"round",value:function(t){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:8,n=arguments[2];return t=parseFloat(t),n||(n="round"),e=Math.pow(10,e),Math[n](t*e)/e}},{key:"loop",value:function(i,r,t,e){var s=this,o=4<arguments.length&&void 0!==arguments[4]?arguments[4]:0,l=function(t,e){try{var n=r(i[o],o,i);n&&n.then?n.then(t).catch(e):t(n)}catch(t){e(t)}},n=function(t,e){return o<i.length?new Promise(l).then((n=t,a=e,function(){return s.loop(i,r,n,a,++o)})).catch(e):t();var n,a};return t?n(t,e):new Promise(n)}}]),t}(),u=function(){function t(){s(this,t),this.state={}}return a(t,[{key:"fetchScript",value:function(a){var i=this;return this.state[a]?Promise.resolve(null):(this.state[a]="pending",new Promise(function(t,e){var n=document.createElement("script");document.body.appendChild(n),n.addEventListener("load",function(){i.state&&(i.state[a]="downloaded"),t()}),n.addEventListener("error",function(){i.state&&delete i.state[a],e(new Error("Failed to load image's URL: "+a))}),n.async=!0,n.src=a}))}},{key:"fetchStyle",value:function(a){var i=this;return this.state[a]?Promise.resolve(null):(this.state[a]="pending",new Promise(function(t,e){var n=document.createElement("link");n.setAttribute("rel","stylesheet"),document.body.appendChild(n),n.setAttribute("href",a),n.addEventListener("load",function(){i.state&&(i.state[a]="downloaded"),t()}),n.addEventListener("error",function(){i.state&&delete i.state[a],e(new Error("Failed to load style URL: "+a))}),n.href=a}))}},{key:"fetchChartData",value:function(t){var e=1<arguments.length&&void 0!==arguments[1]&&arguments[1],n="https://graphs.coinpaprika.com"+t;return this.fetchData(n,e)}},{key:"fetchData",value:function(n,a){var i=this,t=Promise.resolve();return t=t.then(function(){if(a){if("pending"===i.state[n])return new Promise(function(t,e){setTimeout(function(){t(i.fetchData(n,a))},100)});if(i.state[n])return Promise.resolve(i.state[n].clone())}var t=Promise.resolve();return t=(t=t.then(function(){return i.state[n]="pending",fetch(n)})).then(function(t){return(i.state[n]=t).clone()})})}}]),t}();new i;var f=new c,d=new u},{}]},{},[1]);
{
"name": "@coinpaprika/widget-currency",
"version": "1.1.1",
"version": "1.1.2",
"description": "A widget showing cryptocurrency stats that you can easily embed in your website.",

@@ -5,0 +5,0 @@ "main": "src/widget.js",

@@ -158,4 +158,3 @@ # Coinpaprika Currency Widget

<div class="coinpaprika-currency-widget"
data-currency="xrp-xrp"
data-version="standard"
data-currency="xrp-xrp"
data-update-active="true"></div>

@@ -162,0 +161,0 @@ <script src="https://unpkg.com/@coinpaprika/widget-currency/dist/widget.min.js"></script>

@@ -680,12 +680,17 @@ class widgetsController {

};
this.chartDataParser = (data, dataType) => {
let priceCurrency = state.primary_currency.toLowerCase();
data = data[0];
let newData = {
data: {
price: (data[priceCurrency]) ? data[priceCurrency] : [],
volume: data.volume,
}
};
return Promise.resolve(newData);
this.chartDataParser = (data) => {
return new Promise((resolve) => {
data = data[0];
const priceCurrency = state.primary_currency.toLowerCase();
return resolve({
data: {
price: (data.price)
? data.price
: ((data[priceCurrency])
? data[priceCurrency]
: []),
volume: data.volume || [],
}
});
});
};

@@ -695,2 +700,3 @@ this.isEventsHidden = false;

this.asyncUrl = `/currency/data/${ state.currency }/_range_/`;
this.asyncParams = `?quote=${ state.primary_currency.toUpperCase() }&fields=price,volume`;
this.init();

@@ -1051,3 +1057,3 @@ }

promise = promise.then(() => {
let url = (isPreciseRange) ? this.getNavigatorExtremesUrl(minDate, maxDate) : this.asyncUrl.replace('_range_', this.getRange());
let url = ((isPreciseRange) ? this.getNavigatorExtremesUrl(minDate, maxDate) : this.asyncUrl.replace('_range_', this.getRange())) + this.asyncParams;
return (url) ? this.fetchData(url, 'data', !isPreciseRange) : null;

@@ -1093,2 +1099,3 @@ });

this.chart.hideLoading();
this.hideChart();
return console.log('Fetch Error', error);

@@ -1099,2 +1106,19 @@ });

hideChart(bool = true){
const classFunc = (bool) ? 'add' : 'remove';
console.log({container: this.container});
const siblings = cpBootstrap.nodeListToArray(this.container.parentElement.childNodes);
let promise = Promise.resolve();
promise = promise.then(() => {
return siblings.filter(element => element.id.search('chart') === -1);
});
promise = promise.then((result) => {
return cpBootstrap.loop(result, element => element.classList[classFunc]('cp-hidden'));
});
promise = promise.then(() => {
return this.container.classList[classFunc]('cp-chart-no-data');
});
return promise;
}
setRangeSwitcher(){

@@ -1101,0 +1125,0 @@ document.addEventListener(`${ this.id }-switch-range`, (event) => {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc