Skip to content

Commit f3a3c14

Browse files
authored
Merge branch 'develop' into feature/slides-spotlight
2 parents b6d6eb3 + 2f3f3c5 commit f3a3c14

File tree

3 files changed

+155
-2
lines changed

3 files changed

+155
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ If you want to spin up an instance and start using immediately, see [Docker depl
2929
If you want to contribute to the project, start with [manual deployment](https://hackmd.io/c/codimd-documentation/%2Fs%2Fcodimd-manual-deployment).
3030

3131
### Configuration
32-
CodiMD is highly customizable. Learn about all configuration options of networking, security, performance, resources, privilege, privacy, image storage, and authentication in [CodiMD Configuration](https://hackmd.io/c/codimd-documentation/%2Fs%2Fcodimd-configuration).
32+
CodiMD is highly customizable, learn about all configuration options of networking, security, performance, resources, privilege, privacy, image storage, and authentication in [CodiMD Configuration](https://hackmd.io/c/codimd-documentation/%2Fs%2Fcodimd-configuration).
3333

3434
### Upgrading and Migration
3535
Upgrade CodiMD from previous version? See [this guide](https://hackmd.io/c/codimd-documentation/%2Fs%2Fcodimd-upgrade)
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
var ElapsedTimeBar = {
2+
// default value
3+
barColor: 'rgb(200,0,0)',
4+
pausedBarColor: 'rgba(200,0,0,.6)',
5+
6+
isPaused: false,
7+
isFinished: false,
8+
9+
allottedTime: null,
10+
timeProgressBar: null,
11+
startTime: null,
12+
pauseTime: null,
13+
pauseTimeDuration: 0,
14+
15+
/**
16+
* initialize elements
17+
*/
18+
handleReady() {
19+
var config = Reveal.getConfig();
20+
21+
// activate this plugin if config.allottedTime exists.
22+
if (!config.allottedTime) {
23+
console.warn('Failed to start ElapsedTimeBar plugin. "allottedTime" property is required.');
24+
return;
25+
}
26+
27+
// set configurations
28+
this.barColor = config.barColor || this.barColor;
29+
this.pausedBarColor = config.pausedBarColor || this.pausedBarColor;
30+
31+
// calc barHeight from config.barHeight or page-progress container
32+
var barHeight;
33+
var pageProgressContainer = document.querySelector('.progress');
34+
if (config.progressBarHeight) {
35+
barHeight = parseInt(config.progressBarHeight, 10) + 'px';
36+
37+
// override height of page-progress container
38+
pageProgressContainer && (pageProgressContainer.style.height = barHeight);
39+
} else if (config.progress && pageProgressContainer) {
40+
// get height from page-progress container
41+
barHeight = pageProgressContainer.getBoundingClientRect().height + 'px';
42+
} else {
43+
// default
44+
barHeight = '3px';
45+
}
46+
47+
// create container of time-progress
48+
var timeProgressContainer = document.createElement('div');
49+
timeProgressContainer.classList.add('progress');
50+
Object.entries({
51+
display: 'block',
52+
position: 'fixed',
53+
bottom: config.progress ? barHeight : 0,
54+
width: '100%',
55+
height: barHeight
56+
}).forEach(([k, v]) => {
57+
timeProgressContainer.style[k] = v;
58+
});
59+
document.querySelector('.reveal').appendChild(timeProgressContainer);
60+
61+
// create content of time-progress
62+
this.timeProgressBar = document.createElement('div');
63+
Object.entries({
64+
height: '100%',
65+
willChange: 'width'
66+
}).forEach(([k, v]) => {
67+
this.timeProgressBar.style[k] = v;
68+
});
69+
timeProgressContainer.appendChild(this.timeProgressBar);
70+
71+
// start timer
72+
this.start(config.allottedTime);
73+
},
74+
75+
/**
76+
* update repeatedly using requestAnimationFrame.
77+
*/
78+
loop() {
79+
if (this.isPaused) return;
80+
var now = +new Date();
81+
var elapsedTime = now - this.startTime - this.pauseTimeDuration;
82+
if (elapsedTime > this.allottedTime) {
83+
this.timeProgressBar.style.width = '100%';
84+
this.isFinished = true;
85+
} else {
86+
this.timeProgressBar.style.width = elapsedTime / this.allottedTime * 100 + '%';
87+
requestAnimationFrame(this.loop.bind(this));
88+
}
89+
},
90+
91+
/**
92+
* set color of progress bar
93+
*/
94+
setBarColor() {
95+
if (this.isPaused) {
96+
this.timeProgressBar.style.backgroundColor = this.pausedBarColor;
97+
} else {
98+
this.timeProgressBar.style.backgroundColor = this.barColor;
99+
}
100+
},
101+
102+
/**
103+
* start(reset) timer with new allotted time.
104+
* @param {number} allottedTime
105+
* @param {number} [elapsedTime=0]
106+
*/
107+
start(allottedTime, elapsedTime = 0) {
108+
this.isFinished = false;
109+
this.isPaused = false;
110+
this.allottedTime = allottedTime;
111+
this.startTime = +new Date() - elapsedTime;
112+
this.pauseTimeDuration = 0;
113+
this.setBarColor();
114+
this.loop();
115+
},
116+
117+
reset() {
118+
this.start(this.allottedTime);
119+
},
120+
121+
pause() {
122+
if (this.isPaused) return;
123+
this.isPaused = true;
124+
this.pauseTime = +new Date();
125+
this.setBarColor();
126+
},
127+
128+
resume() {
129+
if (!this.isPaused) return;
130+
131+
// add paused time duration
132+
this.isPaused = false;
133+
this.pauseTimeDuration += new Date() - this.pauseTime;
134+
this.pauseTime = null;
135+
this.setBarColor();
136+
this.loop();
137+
}
138+
};
139+
140+
if (Reveal.isReady()) {
141+
ElapsedTimeBar.handleReady();
142+
} else {
143+
Reveal.addEventListener('ready', () => ElapsedTimeBar.handleReady());
144+
}

public/js/slide.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,16 @@ var options = meta.slideOptions || {}
7777
if (options.hasOwnProperty('spotlight')) {
7878
defaultOptions.dependencies.push({
7979
src: `${serverurl}/build/reveal.js/plugin/spotlight/spotlight.js`
80-
});
80+
})
81+
}
82+
83+
if (options.hasOwnProperty('allottedTime') || options.hasOwnProperty('allottedMinutes')) {
84+
defaultOptions.dependencies.push({
85+
src: `${serverurl}/build/reveal.js/plugin/elapsed-time-bar/elapsed-time-bar.js`
86+
})
87+
if (options.hasOwnProperty('allottedMinutes')) {
88+
options.allottedTime = options.allottedMinutes * 60 * 1000
89+
}
8190
}
8291

8392
const view = $('.reveal')

0 commit comments

Comments
 (0)