Skip to content

Instantly share code, notes, and snippets.

@faried
Created December 3, 2014 11:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save faried/78a38e2761b6f90d3d9f to your computer and use it in GitHub Desktop.
Save faried/78a38e2761b6f90d3d9f to your computer and use it in GitHub Desktop.
chibi-scheme web page.
<!DOCTYPE html>
<html>
<!--
Copyright (c) 2013 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<head>
<title>pn1</title>
<script type="text/javascript">
HelloTutorialModule = null; // Global application object.
statusText = 'NO-STATUS';
// Indicate load success.
function moduleDidLoad() {
HelloTutorialModule = document.getElementById('pn1');
updateStatus('SUCCESS');
// send a message
HelloTutorialModule.postMessage('(+ 2 3)');
}
// The 'message' event handler. This handler is fired when the NaCl module
// posts a message to the browser by calling PPB_Messaging.PostMessage()
// (in C) or pp::Instance.PostMessage() (in C++).
function handleMessage(message_event) {
msg = document.getElementById('message').innerText = message_event.data;
}
// If the page loads before the Native Client module loads, then set the
// status message indicating that the module is still loading. Otherwise,
// do not change the status message.
function pageDidLoad() {
if (HelloTutorialModule == null) {
updateStatus('LOADING...');
} else {
// It's possible that the Native Client module onload event fired
// before the page's onload event. In this case, the status message
// will reflect 'SUCCESS', but won't be displayed. This call will
// display the current message.
updateStatus();
}
}
// Set the global status message. If the element with id 'statusField'
// exists, then set its HTML to the status message as well.
// opt_message The message test. If this is null or undefined, then
// attempt to set the element with id 'statusField' to the value of
// |statusText|.
function updateStatus(opt_message) {
if (opt_message)
statusText = opt_message;
var statusField = document.getElementById('statusField');
if (statusField) {
statusField.innerHTML = statusText;
}
}
</script>
</head>
<body onload="pageDidLoad()">
<h1>NaCl C++ Tutorial: Getting Started</h1>
<p>
<!--
Load the published pexe.
Note: Since this module does not use any real-estate in the browser, its
width and height are set to 0.
Note: The <embed> element is wrapped inside a <div>, which has both a 'load'
and a 'message' event listener attached. This wrapping method is used
instead of attaching the event listeners directly to the <embed> element to
ensure that the listeners are active before the NaCl module 'load' event
fires. This also allows you to use PPB_Messaging.PostMessage() (in C) or
pp::Instance.PostMessage() (in C++) from within the initialization code in
your module.
-->
<div id="listener">
<script type="text/javascript">
var listener = document.getElementById('listener');
listener.addEventListener('load', moduleDidLoad, true);
listener.addEventListener('message', handleMessage, true);
</script>
<embed id="pn1"
width=0 height=0
src="pn1.nmf"
type="application/x-pnacl" />
</div>
</p>
<h2>message from the native side:</h2>
<p id="message"><em>nothing...</em></p>
<h2>Status <code id="statusField">NO-STATUS</code></h2>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment