[html5] r4866 - [e] (0) Fix the recently added examples.

whatwg at whatwg.org whatwg at whatwg.org
Thu Mar 25 00:56:29 PDT 2010


Author: ianh
Date: 2010-03-25 00:56:28 -0700 (Thu, 25 Mar 2010)
New Revision: 4866

Modified:
   complete.html
   source
Log:
[e] (0) Fix the recently added examples.

Modified: complete.html
===================================================================
--- complete.html	2010-03-25 00:52:55 UTC (rev 4865)
+++ complete.html	2010-03-25 07:56:28 UTC (rev 4866)
@@ -64625,26 +64625,54 @@
 
   <p>Here is the HTML page:</p>
 
-  <pre>EXAMPLE workers/shared/001/test.html</pre>
+  <pre><!DOCTYPE HTML>
+<title>Shared workers: demo 1</title>
+<pre id="log">Log:</pre>
+<script>
+  var worker = new SharedWorker('test.js');
+  var log = document.getElementById('log');
+  worker.port.onmessage = function(e) { // note: not worker.onmessage!
+    log.textContent += '\n' + e.data;
+  }
+</script>
+</pre>
 
   <p>Here is the JavaScript worker:</p>
 
-  <pre>EXAMPLE workers/shared/001/test.js</pre>
+  <pre>onconnect = function(e) {
+  var port = e.ports[0];
+  port.postMessage('Hello World!');
+}
+</pre>
 
   <hr><p>This second example extends the first one by changing two things:
   first, messages are received using <code title="">addEventListener()</code> instead of an <a href=#event-handler-idl-attributes title="event
   handler IDL attributes">event handler IDL attribute</a>, and
   second, a message is sent <em>to</em> the worker, causing the worker
   to send another message in return. Received messages are again
-  displayed in a lot.</p>
+  displayed in a log.</p>
 
   <p>Here is the HTML page:</p>
 
-  <pre>EXAMPLE workers/shared/001/test.html</pre>
+  <pre><!DOCTYPE HTML>
+<title>Shared workers: demo 1</title>
+<pre id="log">Log:</pre>
+<script>
+  var worker = new SharedWorker('test.js');
+  var log = document.getElementById('log');
+  worker.port.onmessage = function(e) { // note: not worker.onmessage!
+    log.textContent += '\n' + e.data;
+  }
+</script>
+</pre>
 
   <p>Here is the JavaScript worker:</p>
 
-  <pre>EXAMPLE workers/shared/001/test.js</pre>
+  <pre>onconnect = function(e) {
+  var port = e.ports[0];
+  port.postMessage('Hello World!');
+}
+</pre>
 
   <hr><p>Finally, the example is extended to show how two pages can
   connect to the same worker; in this case, the second page is merely
@@ -64654,15 +64682,47 @@
 
   <p>Here is the outer HTML page:</p>
 
-  <pre>EXAMPLE workers/shared/003/test.html</pre>
+  <pre><!DOCTYPE HTML>
+<title>Shared workers: demo 3</title>
+<pre id="log">Log:</pre>
+<script>
+  var worker = new SharedWorker('test.js');
+  var log = document.getElementById('log');
+  worker.port.addEventListener('message', function(e) {
+    log.textContent += '\n' + e.data;
+  }, false);
+  worker.port.start();
+  worker.port.postMessage('ping');
+</script>
+<iframe src="inner.html"></iframe>
+</pre>
 
   <p>Here is the inner HTML page:</p>
 
-  <pre>EXAMPLE workers/shared/003/inner.html</pre>
+  <pre><!DOCTYPE HTML>
+<title>Shared workers: demo 3 inner frame</title>
+<pre id=log>Inner log:</pre>
+<script>
+  var worker = new SharedWorker('test.js');
+  var log = document.getElementById('log');
+  worker.port.onmessage = function(e) {
+   log.textContent += '\n' + e.data;
+  }
+</script>
+</pre>
 
   <p>Here is the JavaScript worker:</p>
 
-  <pre>EXAMPLE workers/shared/003/test.js</pre>
+  <pre>var count = 0;
+onconnect = function(e) {
+  count += 1;
+  var port = e.ports[0];
+  port.postMessage('Hello World! You are connection #' + count);
+  port.onmessage = function(e) {
+    port.postMessage('pong');
+  }
+}
+</pre>
 
 
   <h5 id=shared-state-using-a-shared-worker><span class=secno>9.1.2.5 </span>Shared state using a shared worker</h5>

Modified: source
===================================================================
--- source	2010-03-25 00:52:55 UTC (rev 4865)
+++ source	2010-03-25 07:56:28 UTC (rev 4866)
@@ -73066,7 +73066,7 @@
   handler IDL attributes">event handler IDL attribute</span>, and
   second, a message is sent <em>to</em> the worker, causing the worker
   to send another message in return. Received messages are again
-  displayed in a lot.</p>
+  displayed in a log.</p>
 
   <p>Here is the HTML page:</p>
 




More information about the Commit-Watchers mailing list