More than one HypeDocumentLoad on same page


#1

Hi!

i have two hype-infographics on my page. i need for each a callback when its loaded (HypeDocumentLoad). each infographic is a independent module (they don’t know each other). i tried this:

...

if ('HYPE_eventListeners' in window === false) {
	window.HYPE_eventListeners = [];
}

window.HYPE_eventListeners.push(
	{
		'type': 'HypeDocumentLoad',
		'callback': (function (hypeDocument, element) {
			if (element.id === 'first-infographic_hype_container') {
				hypeDocument.languageObject = this.i18n;
			}
			return false;
		}).bind(this),
	});

second hype document

...

if ('HYPE_eventListeners' in window === false) {
	window.HYPE_eventListeners = [];
}

window.HYPE_eventListeners.push(
	{
		'type': 'HypeDocumentLoad',
		'callback': (function (hypeDocument, element) {
			if (element.id === 'second-infographic_hype_container') {
				hypeDocument.languageObject = this.i18n;
			}
			return false;
		}).bind(this),
	});

the problem is, that only the first callback is fired. is it only possible, to have one eventListener of type=‘HypeDocumentLoad’? can anyone tell me what im doing wrong?

thanks!
felix


#2

I would probably just add an if… else if conditional.

if (element.id === 'first-infographic_hype_container') {
	hypeDocument.languageObject = this.i18n;
} else if (element.id === 'second-infographic_hype_container') {
	hypeDocument.languageObject = this.i18n;
}

I’ve just consolidated your code above.


#3

the problem is, the infographics are isolated components. so the javascript-code is not in the same place… i can’t put the code together.
any other solutions?


#4

You can detect the HypeDocumentLoad for two documents as long as they are both occuring in the same window (frame). Are they in different iframes? How are they isolated?


#5

they are in the same window (no iframes) but in different components. each component has its own js-code. so i need to define two HypeDocumentLoad Callback-Functions in each component. but right now, only the first callback is fired…


(Jonathan Deutsch) #6

Your code looks fine to me; both should be called. Do you mind sending a sample document (the combined export and zips each .hype doc would be useful)? I’d like to take a look and see what is happening.


#7

hi!

sorry for not answering. it works now!
the problem was “return false” in the callback-function. with “return true” it works like expected.

thanks for your help!


(Jonathan Deutsch) #8

Oh, sorry I missed that! Returning false is a way to indicate that it should not load the default first scene (generally because you’ve already loaded another one).