11// We import the CSS which is extracted to its own file by esbuild.
22// Remove this line if you add a your own CSS build pipeline (e.g postcss).
3- import "../css/app.scss"
3+ import "../css/app.scss" ;
44
55// If you want to use Phoenix channels, run `mix help phx.gen.channel`
66// to get started and then uncomment the line below.
@@ -20,26 +20,68 @@ import "../css/app.scss"
2020//
2121
2222// Include phoenix_html to handle method=PUT/DELETE in forms and buttons.
23- import "phoenix_html"
23+ import "phoenix_html" ;
2424// Establish Phoenix Socket and LiveView configuration.
25- import { Socket } from "phoenix"
26- import { LiveSocket } from "phoenix_live_view"
27- import topbar from "../vendor/topbar"
25+ import { Socket } from "phoenix" ;
26+ import { LiveSocket } from "phoenix_live_view" ;
27+ import topbar from "../vendor/topbar" ;
28+ import ProgressBar from "progressbar.js" ;
2829
29- let csrfToken = document . querySelector ( "meta[name='csrf-token']" ) . getAttribute ( "content" )
30- let liveSocket = new LiveSocket ( "/live" , Socket , { params : { _csrf_token : csrfToken } } )
30+ let csrfToken = document
31+ . querySelector ( "meta[name='csrf-token']" )
32+ . getAttribute ( "content" ) ;
33+ let liveSocket = new LiveSocket ( "/live" , Socket , {
34+ params : { _csrf_token : csrfToken } ,
35+ } ) ;
3136
3237// Show progress bar on live navigation and form submits
33- topbar . config ( { barColors : { 0 : "#29d" } , shadowColor : "rgba(0, 0, 0, .3)" } )
34- window . addEventListener ( "phx:page-loading-start" , info => topbar . show ( ) )
35- window . addEventListener ( "phx:page-loading-stop" , info => topbar . hide ( ) )
38+ topbar . config ( { barColors : { 0 : "#29d" } , shadowColor : "rgba(0, 0, 0, .3)" } ) ;
39+ window . addEventListener ( "phx:page-loading-start" , ( info ) => topbar . show ( ) ) ;
40+ window . addEventListener ( "phx:page-loading-stop" , ( info ) => topbar . hide ( ) ) ;
3641
3742// connect if there are any LiveViews on the page
38- liveSocket . connect ( )
43+ liveSocket . connect ( ) ;
3944
4045// expose liveSocket on window for web console debug logs and latency simulation:
4146// >> liveSocket.enableDebug()
4247// >> liveSocket.enableLatencySim(1000) // enabled for duration of browser session
4348// >> liveSocket.disableLatencySim()
44- window . liveSocket = liveSocket
49+ window . liveSocket = liveSocket ;
4550
51+ // progressbar.js@1.0.0 version is used
52+ // Docs: http://progressbarjs.readthedocs.org/en/1.0.0/
53+
54+ window . loadStatusProgressBar = function ( divId ) {
55+ console . log ( `Loading bar for id ${ divId } ` ) ;
56+ let bar = new ProgressBar . Circle ( `#${ divId } ` , {
57+ color : "#aaa" ,
58+ // This has to be the same size as the maximum width to
59+ // prevent clipping
60+ strokeWidth : 4 ,
61+ trailWidth : 1 ,
62+ easing : "easeInOut" ,
63+ duration : 1400 ,
64+ text : {
65+ autoStyleContainer : false ,
66+ } ,
67+ from : { color : "#aaa" , width : 1 } ,
68+ to : { color : "#5cb571" , width : 4 } , // #333
69+
70+ // Set default step function for all animate calls
71+ step : function ( state , circle ) {
72+ circle . path . setAttribute ( "stroke" , state . color ) ;
73+ circle . path . setAttribute ( "stroke-width" , state . width ) ;
74+
75+ var value = Math . round ( circle . value ( ) * 100 ) ;
76+ if ( value === 0 ) {
77+ circle . setText ( "" ) ;
78+ } else {
79+ circle . setText ( value ) ;
80+ }
81+ } ,
82+ } ) ;
83+ bar . text . style . fontFamily = '"Raleway", Helvetica, sans-serif' ;
84+ bar . text . style . fontSize = "2rem" ;
85+
86+ bar . animate ( 1.0 ) ; // Number from 0.0 to 1.0
87+ }
0 commit comments