1(function ($) { 2 "use strict"; 3 4 function update_ultimeter() { 5 $(".ultimeter-container").each(function () { 6 let meter = JSON.parse($(this).attr("data-meter")); 7 8 debug(meter); 9 10 animate_meter($(this), meter); 11 render_labels($(this), meter); 12 }); 13 } 14 15 function debug(d) { 16 console.log(d); 17 console.log("Current: " + get_current(d)); 18 console.log("Total: " + get_total(d)); 19 console.log("Progress: " + get_progress(d)); 20 console.log("Formatted Current: " + get_formatted_current(d)); 21 console.log("Formatted Total: " + get_formatted_total(d)); 22 } 23 24 function animate_meter(e, d) { 25 if (d.physics === "height") { 26 e.find(".ultimeter_meter_progress").animate( 27 { height: get_progress(d) + "%" }, 28 3000 29 ); 30 } else { 31 e.find(".ultimeter_meter_progress").animate( 32 { width: get_progress(d) + "%" }, 33 3000 34 ); 35 } 36 } 37 38 function render_labels(e, d) { 39 e.find(".ultimeter_meter_progress .calculated").text( 40 get_formatted_current(d) 41 ); 42 e.find(".ultimeter_meter_goal .calculated").text(get_formatted_total(d)); 43 } 44 45 function get_current(meter) { 46 return parseFloat(meter.current).toFixed(2); 47 } 48 49 function get_total(meter) { 50 return parseFloat(meter.total).toFixed(2); 51 } 52 53 function get_progress(meter) { 54 let current = get_current(meter); 55 let total = get_total(meter); 56 57 // Calculate the percentage 58 let percentage = (current * 100) / total; 59 60 // Ensure the percentage does not exceed 100 61 if (percentage > 100) { 62 percentage = 100; 63 } 64 65 return parseFloat(percentage); 66 } 67 68 function get_formatted_current(meter) { 69 return number_formatter(meter, get_current(meter)); 70 } 71 72 function get_formatted_total(meter) { 73 return number_formatter(meter, get_total(meter)); 74 } 75 76 function number_formatter(meter, value) { 77 switch (meter.output_type) { 78 case "ultimeter_currency": 79 default: 80 return new Intl.NumberFormat(meter.language, { 81 style: "currency", 82 currency: meter.currency, 83 minimumFractionDigits: value % 1 === 0 ? 0 : 2, 84 }).format(value); 85 case "ultimeter_percentage": 86 return new Intl.NumberFormat(meter.language, { 87 style: "percent", 88 }).format(value / 100); 89 } 90 } 91 92 $(document).ready(function () { 93 update_ultimeter(); 94 }); 95})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.