Last active
April 12, 2017 13:08
-
-
Save AdrienLemaire/6872603461ac0380916ffacda4ab4214 to your computer and use it in GitHub Desktop.
Tixit coding primer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <title>tixit</title> | |
| <style type="text/css" media="screen"> | |
| table, input {width: 100%} | |
| td {width: 50%} | |
| </style> | |
| </head> | |
| <body> | |
| <table> | |
| <!-- Messages --> | |
| <tr> | |
| <td id='msg1' style="border: 1px solid gray;"></td> | |
| <td id='msg2' style="border: 1px solid gray;"></td> | |
| </tr> | |
| <!-- Input --> | |
| <tr> | |
| <td><input type="text" id="input1" onkeypress='recordMsg(event, "msg1")'></td> | |
| <td><input type="text" id="input2" onkeypress='recordMsg(event, "msg2")'></td> | |
| </tr> | |
| </table> | |
| <script charset="utf-8"> | |
| var msg1 = document.getElementById('msg1'); | |
| var msg2 = document.getElementById('msg2'); | |
| function recordMsg(event, outputId) { | |
| if (event.keyCode != 13) { return } | |
| var newText = event.srcElement.value; | |
| event.srcElement.value = ''; // clear input text | |
| var meLine = '<span style="color: gray;">Me: </span>' + newText + '<br />'; | |
| var youLine = '<span style="color: blue;">You: </span>' + newText + '<br />'; | |
| var msgList = (outputId == 'msg1') ? [meLine, youLine] : [youLine, meLine]; | |
| msg1.innerHTML += msgList[0]; | |
| msg2.innerHTML += msgList[1]; | |
| } | |
| </script> | |
| </body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <title>Tixit part2</title> | |
| <script src="Gem.umd.js"></script> | |
| </head> | |
| <body> | |
| <script charset="utf-8"> | |
| function recordMsg() { | |
| if (!this.val) { return; } | |
| var newText = this.val; | |
| // Prepare line | |
| var MeSuffix = Gem.Text('gray', 'Me: ') | |
| var MeLine = Gem.Block(MeSuffix, Gem.Text(newText)); | |
| var YouSuffix = Gem.Text('blue', 'You: ') | |
| var YouLine = Gem.Block(YouSuffix, Gem.Text(newText)); | |
| var LineList = (this.label == 'a') ? [MeLine, YouLine] : [YouLine, MeLine]; | |
| AText.add(LineList[0]); | |
| BText.add(LineList[1]); | |
| this.val = ''; // clear input text | |
| } | |
| // Elements | |
| var AText = Gem.Text(); | |
| var BText = Gem.Text(); | |
| var OutBlock = Gem.Block(AText, BText); | |
| var AInput = Gem.TextField('a', ''); | |
| var BInput = Gem.TextField('b', ''); | |
| var InBlock = Gem.Block(AInput, BInput); | |
| var Container = Gem.Block(OutBlock, InBlock); | |
| Container.attach(); | |
| // Style | |
| Container.style = Gem.Style({ | |
| width: '100%', | |
| Block: {width: '100%'}, | |
| TextField: { width: '50%' }, | |
| $blue: {color: 'blue'}, | |
| $gray: {color: 'gray'}, | |
| }); | |
| AText.style = Gem.Style({ | |
| width: '50%', | |
| border: '1px solid gray', | |
| }); | |
| BText.style = AText.style; | |
| // Logic | |
| AInput.on('change', recordMsg); | |
| BInput.on('change', recordMsg); | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment