Skip to content

Commit 7b88878

Browse files
committed
Sample is now loaded on slide activation
Old method caused "Too many active contexts" error on chrome
1 parent d705664 commit 7b88878

File tree

1 file changed

+14
-21
lines changed

1 file changed

+14
-21
lines changed

js/samples.js

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,40 +18,33 @@
1818
};
1919

2020
window.samples = {};
21+
function createSample($el) {
22+
var index = $el.data("sample");
23+
var instance = window.samples[index].initialize($el[0]);
24+
$el.data("instance", instance);
25+
return instance;
26+
};
2127

22-
function initializeOnLoad() {
23-
24-
// Initialize samples and assign them to dom data.
25-
$("[data-sample]").each(function() {
26-
var index = $(this).data("sample");
27-
var instance = window.samples[index].initialize(this);
28-
$(this).data("instance", instance);
29-
30-
// Hack to force samples to render at least once before pause.
28+
function runCurrentSample(currentSlide) {
29+
$(currentSlide).find("[data-sample]").each(function() {
30+
var instance = createSample($(this));
3131
if(instance) instance.active = true;
3232
});
33+
};
3334

34-
// Hack to force samples to render at least once before pause.
35-
setInterval(function() {
36-
$("[data-sample]").each(function() {
37-
var instance = $(this).data("instance");
38-
if(!$(this).closest("section").hasClass("present") && instance)
39-
instance.active = false;
40-
});
41-
}, 1000);
35+
function initializeOnLoad() {
36+
runCurrentSample($("section.present"));
4237

4338
// Activate appropriate sample on slide change.
4439
Reveal.addEventListener('slidechanged', function(event) {
40+
// Clear all slides
4541
$("[data-sample]").each(function() {
4642
var instance = $(this).data("instance");
4743
if(instance) instance.active = false;
4844
});
4945

5046
var currentSlide = event.currentSlide;
51-
$(currentSlide).find("[data-sample]").each(function() {
52-
var instance = $(this).data("instance");
53-
if(instance) instance.active = true;
54-
});
47+
runCurrentSample(currentSlide);
5548
});
5649

5750
eventEmitter.emitEvent("initialized");

0 commit comments

Comments
 (0)