@@ -104,39 +104,53 @@ function timedRefresh() {
104104 $ . idleTimer ( timeoutPeriod ) ;
105105}
106106
107- function calculateProgress ( ) {
108- let possible = 0 ;
109- let total = 1 ;
110- for ( let k in eBookConfig . activities ) {
111- if ( k !== undefined ) {
112- possible ++ ;
113- if ( eBookConfig . activities [ k ] > 0 ) {
114- total ++ ;
107+ class PageProgressBar {
108+
109+ constructor ( actDict ) {
110+ this . possible = 0 ;
111+ this . total = 1 ;
112+ this . activities = actDict ;
113+ this . calculateProgress ( ) ;
114+ this . renderProgress ( )
115+
116+ }
117+
118+ calculateProgress ( ) {
119+ for ( let k in this . activities ) {
120+ if ( k !== undefined ) {
121+ this . possible ++ ;
122+ if ( this . activities [ k ] > 0 ) {
123+ this . total ++ ;
124+ }
115125 }
116126 }
117127 }
118- return { possible : possible , total : total }
119- }
120128
121129
122- function addProgress ( ) {
123- let { possible, total} = calculateProgress ( )
124- $ ( "#scprogresstotal" ) . text ( total ) ;
125- $ ( "#scprogressposs" ) . text ( possible ) ;
126- $ ( "#subchapterprogress" ) . progressbar ( {
127- value : 100 * total / possible
128- } ) ;
129- }
130+ renderProgress ( ) {
131+ $ ( "#scprogresstotal" ) . text ( this . total ) ;
132+ $ ( "#scprogressposs" ) . text ( this . possible ) ;
133+ $ ( "#subchapterprogress" ) . progressbar ( {
134+ value : 100 * this . total / this . possible
135+ } ) ;
136+ }
137+
138+ updateProgress ( div_id ) {
139+ this . activities [ div_id ] ++ ;
140+ // We only update the progress bar on the first interaction with an object.
141+ if ( this . activities [ div_id ] === 1 ) {
142+ this . total ++ ;
143+ let val = 100 * this . total / this . possible ;
144+ $ ( "#scprogresstotal" ) . text ( this . total ) ;
145+ $ ( "#scprogressposs" ) . text ( this . possible ) ;
146+ $ ( "#subchapterprogress" ) . progressbar ( "option" , "value" , val )
147+ }
148+ }
130149
131- function updateProgress ( div_id ) {
132- eBookConfig . activities [ div_id ] ++ ;
133- let { possible, total} = calculateProgress ( ) ;
134- let val = 100 * total / possible ;
135- $ ( "#scprogresstotal" ) . text ( total ) ;
136- $ ( "#scprogressposs" ) . text ( possible ) ;
137- $ ( "#subchapterprogress" ) . progressbar ( "option" , "value" , val )
138150}
139151
152+ pageProgressTracker = { } ;
153+
140154function handlePageSetup ( ) {
141155
142156 let data = { timezoneoffset : ( new Date ( ) ) . getTimezoneOffset ( ) / 60 }
@@ -156,7 +170,7 @@ function handlePageSetup() {
156170 }
157171 $ ( ".loggedinuser" ) . html ( mess ) ;
158172
159- addProgress ( ) ;
173+ pageProgressTracker = new PageProgressBar ( eBookConfig . activities ) ;
160174 notifyRunestoneComponents ( ) ;
161175}
162176
0 commit comments