@@ -127,6 +127,73 @@ Hooks.LazyLoadQueuePreviews = {
127127 }
128128}
129129
130+ Hooks . DashboardAnimations = {
131+ mounted ( ) {
132+ this . readyClass = "dashboard-animations-ready"
133+
134+ this . onWindowLoad = ( ) => this . scheduleReady ( )
135+ this . onPageLoadingStart = ( ) => this . clearReady ( )
136+ this . onPageLoadingStop = ( ) => this . scheduleReady ( )
137+
138+ if ( document . readyState === "complete" ) {
139+ this . scheduleReady ( )
140+ } else {
141+ window . addEventListener ( "load" , this . onWindowLoad , { once : true } )
142+ }
143+
144+ window . addEventListener ( "phx:page-loading-start" , this . onPageLoadingStart )
145+ window . addEventListener ( "phx:page-loading-stop" , this . onPageLoadingStop )
146+ } ,
147+
148+ scheduleReady ( ) {
149+ if ( this . idleCallback && "cancelIdleCallback" in window ) {
150+ window . cancelIdleCallback ( this . idleCallback )
151+ }
152+
153+ if ( this . readyTimeout ) {
154+ clearTimeout ( this . readyTimeout )
155+ }
156+
157+ const markReady = ( ) => {
158+ window . requestAnimationFrame ( ( ) => {
159+ window . requestAnimationFrame ( ( ) => {
160+ if ( this . el . isConnected ) {
161+ this . el . classList . add ( this . readyClass )
162+ }
163+ } )
164+ } )
165+ }
166+
167+ if ( "requestIdleCallback" in window ) {
168+ this . idleCallback = window . requestIdleCallback ( markReady , { timeout : 1500 } )
169+ } else {
170+ this . readyTimeout = setTimeout ( markReady , 150 )
171+ }
172+ } ,
173+
174+ clearReady ( ) {
175+ this . el . classList . remove ( this . readyClass )
176+ } ,
177+
178+ destroyed ( ) {
179+ this . clearReady ( )
180+
181+ window . removeEventListener ( "phx:page-loading-start" , this . onPageLoadingStart )
182+ window . removeEventListener ( "phx:page-loading-stop" , this . onPageLoadingStop )
183+ window . removeEventListener ( "load" , this . onWindowLoad )
184+
185+ if ( this . idleCallback && "cancelIdleCallback" in window ) {
186+ window . cancelIdleCallback ( this . idleCallback )
187+ this . idleCallback = null
188+ }
189+
190+ if ( this . readyTimeout ) {
191+ clearTimeout ( this . readyTimeout )
192+ this . readyTimeout = null
193+ }
194+ }
195+ }
196+
130197let csrfToken = document . querySelector ( "meta[name='csrf-token']" ) . getAttribute ( "content" )
131198// Use embedded socket for iframe pages
132199let socketUrl = window . location . pathname . startsWith ( "/embed/" ) ? "/embed/live" : "/live"
@@ -141,30 +208,6 @@ topbar.config({barColors: {0: "#29d"}, shadowColor: "rgba(0, 0, 0, .3)"})
141208window . addEventListener ( "phx:page-loading-start" , _info => topbar . show ( 300 ) )
142209window . addEventListener ( "phx:page-loading-stop" , _info => topbar . hide ( ) )
143210
144- const dashboardAnimationsReadyClass = "dashboard-animations-ready"
145-
146- const scheduleDashboardAnimationsReady = ( ) => {
147- window . requestAnimationFrame ( ( ) => {
148- window . requestAnimationFrame ( ( ) => {
149- document . documentElement . classList . add ( dashboardAnimationsReadyClass )
150- } )
151- } )
152- }
153-
154- if ( document . readyState === "complete" ) {
155- scheduleDashboardAnimationsReady ( )
156- } else {
157- window . addEventListener ( "load" , scheduleDashboardAnimationsReady , { once : true } )
158- }
159-
160- window . addEventListener ( "phx:page-loading-start" , ( ) => {
161- document . documentElement . classList . remove ( dashboardAnimationsReadyClass )
162- } )
163-
164- window . addEventListener ( "phx:page-loading-stop" , ( ) => {
165- scheduleDashboardAnimationsReady ( )
166- } )
167-
168211// connect if there are any LiveViews on the page
169212liveSocket . connect ( )
170213
0 commit comments