mirror of
https://github.com/google/blockly.git
synced 2026-01-08 01:20:12 +01:00
Merge pull request #821 from rachel-fenichel/cleanup/mirror_naming
Naming changes in mirror demo
This commit is contained in:
@@ -21,7 +21,7 @@
|
|||||||
<h1><a href="https://developers.google.com/blockly/">Blockly</a> >
|
<h1><a href="https://developers.google.com/blockly/">Blockly</a> >
|
||||||
<a href="../index.html">Demos</a> > Mirrored Blockly</h1>
|
<a href="../index.html">Demos</a> > Mirrored Blockly</h1>
|
||||||
|
|
||||||
<p>This is a simple demo of a master Blockly that controls a slave Blockly.
|
<p>This is a simple demo of a primary Blockly instance that controls a secondary Blockly instance with events.
|
||||||
Open the JavaScript console to see the event passing.</p>
|
Open the JavaScript console to see the event passing.</p>
|
||||||
|
|
||||||
<p>→ More info on <a href="https://developers.google.com/blockly/guides/configure/web/events">events</a>…</p>
|
<p>→ More info on <a href="https://developers.google.com/blockly/guides/configure/web/events">events</a>…</p>
|
||||||
@@ -29,10 +29,10 @@
|
|||||||
<table width="100%">
|
<table width="100%">
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<div id="masterDiv" style="height: 480px; width: 600px;"></div>
|
<div id="primaryDiv" style="height: 480px; width: 600px;"></div>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<div id="slaveDiv" style="height: 480px; width: 430px;"></div>
|
<div id="secondaryDiv" style="height: 480px; width: 430px;"></div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
@@ -51,29 +51,29 @@
|
|||||||
</xml>
|
</xml>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
// Inject master workspace.
|
// Inject primary workspace.
|
||||||
var masterWorkspace = Blockly.inject('masterDiv',
|
var primaryWorkspace = Blockly.inject('primaryDiv',
|
||||||
{media: '../../media/',
|
{media: '../../media/',
|
||||||
toolbox: document.getElementById('toolbox')});
|
toolbox: document.getElementById('toolbox')});
|
||||||
// Inject slave workspace.
|
// Inject secondary workspace.
|
||||||
var slaveWorkspace = Blockly.inject('slaveDiv',
|
var seconaryWorkspace = Blockly.inject('secondaryDiv',
|
||||||
{media: '../../media/',
|
{media: '../../media/',
|
||||||
readOnly: true});
|
readOnly: true});
|
||||||
// Listen to events on master workspace.
|
// Listen to events on primary workspace.
|
||||||
masterWorkspace.addChangeListener(mirrorEvent);
|
primaryWorkspace.addChangeListener(mirrorEvent);
|
||||||
|
|
||||||
function mirrorEvent(masterEvent) {
|
function mirrorEvent(primaryEvent) {
|
||||||
if (masterEvent.type == Blockly.Events.UI) {
|
if (primaryEvent.type == Blockly.Events.UI) {
|
||||||
return; // Don't mirror UI events.
|
return; // Don't mirror UI events.
|
||||||
}
|
}
|
||||||
// Convert event to JSON. This could then be transmitted across the net.
|
// Convert event to JSON. This could then be transmitted across the net.
|
||||||
var json = masterEvent.toJson();
|
var json = primaryEvent.toJson();
|
||||||
console.log(json);
|
console.log(json);
|
||||||
// Convert JSON back into an event, then execute it.
|
// Convert JSON back into an event, then execute it.
|
||||||
var slaveEvent = Blockly.Events.fromJson(json, slaveWorkspace);
|
var secondaryEvent = Blockly.Events.fromJson(json, seconaryWorkspace);
|
||||||
slaveEvent.run(true);
|
secondaryEvent.run(true);
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Reference in New Issue
Block a user