mirror of
https://github.com/hodgef/simple-keyboard.git
synced 2025-05-14 03:01:34 +08:00
146 lines
5.5 KiB
HTML
146 lines
5.5 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<base data-ice="baseUrl" href="../../../">
|
|
<title data-ice="title">src/demo/App.js | simple-keyboard</title>
|
|
<link type="text/css" rel="stylesheet" href="css/style.css">
|
|
<link type="text/css" rel="stylesheet" href="css/prettify-tomorrow.css">
|
|
<script src="script/prettify/prettify.js"></script>
|
|
<script src="script/manual.js"></script>
|
|
<meta name="description" content="On-screen Javascript Virtual Keyboard"><meta property="twitter:card" content="summary"><meta property="twitter:title" content="simple-keyboard"><meta property="twitter:description" content="On-screen Javascript Virtual Keyboard"></head>
|
|
<body class="layout-container" data-ice="rootContainer">
|
|
|
|
<header>
|
|
<a href="./">Home</a>
|
|
|
|
<a href="identifiers.html">Reference</a>
|
|
<a href="source.html">Source</a>
|
|
|
|
<div class="search-box">
|
|
<span>
|
|
<img src="./image/search.png">
|
|
<span class="search-input-edge"></span><input class="search-input"><span class="search-input-edge"></span>
|
|
</span>
|
|
<ul class="search-result"></ul>
|
|
</div>
|
|
<a style="position:relative; top:3px;" href="https://github.com/hodgef/simple-keyboard"><img width="20px" src="./image/github.png"></a></header>
|
|
|
|
<nav class="navigation" data-ice="nav"><div>
|
|
<ul>
|
|
|
|
<li data-ice="doc"><a data-ice="dirPath" class="nav-dir-path" href="identifiers.html#demo">demo</a><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/demo/App.js~App.html">App</a></span></span></li>
|
|
<li data-ice="doc"><a data-ice="dirPath" class="nav-dir-path" href="identifiers.html#lib-components">lib/components</a><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/lib/components/Keyboard.js~SimpleKeyboard.html">SimpleKeyboard</a></span></span></li>
|
|
<li data-ice="doc"><a data-ice="dirPath" class="nav-dir-path" href="identifiers.html#lib-services">lib/services</a><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/lib/services/KeyboardLayout.js~KeyboardLayout.html">KeyboardLayout</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/lib/services/PhysicalKeyboard.js~PhysicalKeyboard.html">PhysicalKeyboard</a></span></span></li>
|
|
<li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/lib/services/Utilities.js~Utilities.html">Utilities</a></span></span></li>
|
|
<li data-ice="doc"><a data-ice="dirPath" class="nav-dir-path" href="identifiers.html#lib-tests">lib/tests</a><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/lib/tests/TestUtility.js~TestUtility.html">TestUtility</a></span></span></li>
|
|
</ul>
|
|
</div>
|
|
</nav>
|
|
|
|
<div class="content" data-ice="content"><h1 data-ice="title">src/demo/App.js</h1>
|
|
<pre class="source-code line-number raw-source-code"><code class="prettyprint linenums" data-ice="content">import Keyboard from '../lib';
|
|
import './css/App.css';
|
|
|
|
/**
|
|
* simple-keyboard demo
|
|
*/
|
|
class App {
|
|
/**
|
|
* Instantiates the demo class
|
|
*/
|
|
constructor(){
|
|
document.addEventListener('DOMContentLoaded', this.onDOMLoaded);
|
|
|
|
/**
|
|
* Default input name
|
|
* @type {string}
|
|
*/
|
|
this.layoutName = "default";
|
|
}
|
|
|
|
/**
|
|
* Executed when the DOM is ready
|
|
*/
|
|
onDOMLoaded = () => {
|
|
/**
|
|
* Creates a new simple-keyboard instance
|
|
*/
|
|
this.keyboard = new Keyboard({
|
|
debug: true,
|
|
layoutName: this.layoutName,
|
|
onChange: input => this.onChange(input),
|
|
onKeyPress: button => this.onKeyPress(button),
|
|
newLineOnEnter: true,
|
|
physicalKeyboardHighlight: true,
|
|
});
|
|
|
|
/**
|
|
* Adding preview (demo only)
|
|
*/
|
|
document.querySelector('.simple-keyboard').insertAdjacentHTML('beforebegin', `
|
|
<div class="simple-keyboard-preview">
|
|
<textarea class="input"></textarea>
|
|
</div>
|
|
`);
|
|
|
|
document.querySelector('.input').addEventListener('change', (event) => {
|
|
this.keyboard.setInput(event.target.value);
|
|
});
|
|
|
|
console.log(this.keyboard);
|
|
}
|
|
|
|
/**
|
|
*
|
|
*/
|
|
handleShiftButton = () => {
|
|
let layoutName = this.layoutName;
|
|
let shiftToggle = this.layoutName = layoutName === "default" ? "shift" : "default";
|
|
|
|
this.keyboard.setOptions({
|
|
layoutName: shiftToggle
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Called when simple-keyboard input has changed
|
|
*/
|
|
onChange = input => {
|
|
document.querySelector('.input').value = input;
|
|
}
|
|
|
|
/**
|
|
* Called when a simple-keyboard key is pressed
|
|
*/
|
|
onKeyPress = button => {
|
|
console.log("Button pressed", button);
|
|
|
|
/**
|
|
* Shift functionality
|
|
*/
|
|
if(button === "{lock}" || button === "{shift}")
|
|
this.handleShiftButton();
|
|
}
|
|
|
|
}
|
|
|
|
export default App;</code></pre>
|
|
|
|
</div>
|
|
|
|
<footer class="footer">
|
|
Generated by <a href="https://esdoc.org">ESDoc<span data-ice="esdocVersion">(1.1.0)</span><img src="./image/esdoc-logo-mini-black.png"></a>
|
|
</footer>
|
|
|
|
<script src="script/search_index.js"></script>
|
|
<script src="script/search.js"></script>
|
|
<script src="script/pretty-print.js"></script>
|
|
<script src="script/inherited-summary.js"></script>
|
|
<script src="script/test-summary.js"></script>
|
|
<script src="script/inner-link.js"></script>
|
|
<script src="script/patch-for-local.js"></script>
|
|
</body>
|
|
</html>
|