-
Notifications
You must be signed in to change notification settings - Fork 2
/
clippy.js
32 lines (28 loc) · 1.06 KB
/
clippy.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
clippy.load('Clippy', function (agent) {
const animations = agent.animations();
$('.js-states').text(animations.join(' '));
agent.show();
agent.moveTo(100, 100);
agent.speak('Stay safe from COVID-19');
setTimeout(animate.bind(null, agent, animations), 8000);
});
function animate(agent, animations) {
function doneCallback(animation) {
console.log('done ' + animation);
}
let statesText = animations.join(' '),
$state = $('.js-state'),
$states = $('.js-states');
for (var i = 0; i < animations.length; i++) {
if (window.CP.shouldStopExecution(0)) break;
(index => {
setTimeout(_ => {
let animation = animations[index];
let currentStateInStates = statesText.replace(animation, `<b>${animation}</b>`);
$state.text(animation);
$states.html(currentStateInStates);
agent.play(animation, undefined, doneCallback.bind(null, animation));
}, index * 8000);
})(i);
} window.CP.exitedLoop(0);
}