2
0
Fork 0
ff-sdl-emcc-test/preboot.js

41 lines
1.6 KiB
JavaScript

mergeInto(LibraryManager.library, {
ff_browser_add_resize_handler : function(resizeHandler) {
var handlerFuncResize = function(event) {
var pageCanvas = document.getElementById('canvas');
if (pageCanvas === null) {
return;
}
Runtime.dynCall('vii', resizeHandler, [ pageCanvas.clientWidth, pageCanvas.clientHeight ]);
}
window.addEventListener('resize', handlerFuncResize, true);
},
ff_browser_add_popstate_handler : function(popstateHandler) {
var handlerFuncPopState = function(event) {
if (event.state == null || event.state.hash === null) {
return;
}
var hashPtr = allocate(intArrayFromString(event.state.hash), 'i8', ALLOC_NORMAL); // free in c code
console.log('js popstate: '+event.state.hash+' ptr: '+hashPtr);
Runtime.dynCall('vi', popstateHandler, [ hashPtr ]);
}
window.addEventListener('popstate', handlerFuncPopState);
if (window.location.hash && window.location.hash !== '') {
console.log('calling init page: '+window.location.hash.substring(1));
handlerFuncPopState({state:{page:window.location.hash.substring(1)}});
}
},
ff_browser_pushstate : function(hrefHash) {
var hrefHashStr = Pointer_stringify(hrefHash); // only display then in pop we don't need to reverse again.
console.log('js pushstate: '+hrefHashStr);
history.pushState({hash:hrefHashStr}, document.title, window.location.protocol+window.location.hostname+window.location.pathname+'#'+hrefHashStr);
},
ff_browser_openlink : function(urlPtr) {
var url = Pointer_stringify(urlPtr);
console.log('js openurl: '+url);
window.open(url,'_self');
}
});