Skip to content

Commit 6776a0d

Browse files
giflwhenrikingo
authored andcommitted
Add pause and play events to autoplay (impress#713)
This is useful to request pause/resume from other plugins
1 parent 24e28cc commit 6776a0d

File tree

2 files changed

+22
-16
lines changed

2 files changed

+22
-16
lines changed

js/impress.js

+11-8
Original file line numberDiff line numberDiff line change
@@ -1304,6 +1304,16 @@
13041304
// triggered for the first slide, so that's where code flow continues.
13051305
}, false );
13061306

1307+
document.addEventListener( "impress:autoplay:pause", function( event ) {
1308+
status = "paused";
1309+
reloadTimeout( event );
1310+
}, false );
1311+
1312+
document.addEventListener( "impress:autoplay:play", function( event ) {
1313+
status = "playing";
1314+
reloadTimeout( event );
1315+
}, false );
1316+
13071317
// If default autoplay time was defined in the presentation root, or
13081318
// in this step, set timeout.
13091319
var reloadTimeout = function( event ) {
@@ -1342,13 +1352,6 @@
13421352
var status = "not clicked";
13431353
var toolbarButton = null;
13441354

1345-
// Copied from core impress.js. Good candidate for moving to a utilities collection.
1346-
var triggerEvent = function( el, eventName, detail ) {
1347-
var event = document.createEvent( "CustomEvent" );
1348-
event.initCustomEvent( eventName, true, true, detail );
1349-
el.dispatchEvent( event );
1350-
};
1351-
13521355
var makeDomElement = function( html ) {
13531356
var tempDiv = document.createElement( "div" );
13541357
tempDiv.innerHTML = html;
@@ -1407,7 +1410,7 @@
14071410
}
14081411
} );
14091412

1410-
triggerEvent( toolbar, "impress:toolbar:appendChild",
1413+
util.triggerEvent( toolbar, "impress:toolbar:appendChild",
14111414
{ group: 10, element: toolbarButton } );
14121415
};
14131416

src/plugins/autoplay/autoplay.js

+11-8
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@
4949
// triggered for the first slide, so that's where code flow continues.
5050
}, false );
5151

52+
document.addEventListener( "impress:autoplay:pause", function( event ) {
53+
status = "paused";
54+
reloadTimeout( event );
55+
}, false );
56+
57+
document.addEventListener( "impress:autoplay:play", function( event ) {
58+
status = "playing";
59+
reloadTimeout( event );
60+
}, false );
61+
5262
// If default autoplay time was defined in the presentation root, or
5363
// in this step, set timeout.
5464
var reloadTimeout = function( event ) {
@@ -87,13 +97,6 @@
8797
var status = "not clicked";
8898
var toolbarButton = null;
8999

90-
// Copied from core impress.js. Good candidate for moving to a utilities collection.
91-
var triggerEvent = function( el, eventName, detail ) {
92-
var event = document.createEvent( "CustomEvent" );
93-
event.initCustomEvent( eventName, true, true, detail );
94-
el.dispatchEvent( event );
95-
};
96-
97100
var makeDomElement = function( html ) {
98101
var tempDiv = document.createElement( "div" );
99102
tempDiv.innerHTML = html;
@@ -152,7 +155,7 @@
152155
}
153156
} );
154157

155-
triggerEvent( toolbar, "impress:toolbar:appendChild",
158+
util.triggerEvent( toolbar, "impress:toolbar:appendChild",
156159
{ group: 10, element: toolbarButton } );
157160
};
158161

0 commit comments

Comments
 (0)