From e3e8843f3eda6d994023c52a2bdaff75f6405931 Mon Sep 17 00:00:00 2001 From: "zodiac@gmail.com" Date: Sun, 12 Sep 2010 02:50:02 +0000 Subject: [PATCH] Store the keyboard layout in its own HTML file. git-svn-id: https://shellinabox.googlecode.com/svn/trunk@225 0da03de8-d603-11dd-86c2-0f8696b7b6f9 --- Makefile.am | 13 ++-- Makefile.in | 13 ++-- config.h | 2 +- configure | 2 +- configure.ac | 2 +- demo/keyboard.html | 62 ++++++++++++++++ demo/vt100.js | 52 ++++++++----- shellinabox/keyboard-layout.html | 121 ++++++++++++++++--------------- shellinabox/shell_in_a_box.js | 2 +- shellinabox/shellinaboxd.c | 7 +- shellinabox/vt100.js | 52 ++++++++----- shellinabox/vt100.jspp | 50 +++++++++---- 12 files changed, 252 insertions(+), 126 deletions(-) create mode 100644 demo/keyboard.html diff --git a/Makefile.am b/Makefile.am index 2f28df2..92df0bc 100644 --- a/Makefile.am +++ b/Makefile.am @@ -32,6 +32,7 @@ EXTRA_DIST = INSTALL.Debian \ demo/demo.jspp \ demo/demo.xml \ demo/enabled.gif \ + demo/keyboard.html \ demo/keyboard.png \ demo/styles.css \ demo/print-styles.css \ @@ -153,6 +154,7 @@ ${top_srcdir}/demo/demo.js: ${top_srcdir}/demo/beep.wav \ ${top_srcdir}/demo/demo.jspp \ ${top_srcdir}/demo/enabled.gif \ ${top_srcdir}/demo/favicon.ico \ + ${top_srcdir}/demo/keyboard.html \ ${top_srcdir}/demo/keyboard.png \ ${top_srcdir}/demo/styles.css \ ${top_srcdir}/demo/print-styles.css \ @@ -174,6 +176,10 @@ ${top_srcdir}/demo/favicon.ico: ${top_srcdir}/shellinabox/favicon.ico @rm -f "$@" ln "$?" "$@" +${top_srcdir}/demo/keyboard.html: ${top_srcdir}/shellinabox/keyboard-layout.html + @rm -f "$@" + ln "$?" "$@" + ${top_srcdir}/demo/keyboard.png: ${top_srcdir}/shellinabox/keyboard.png @rm -f "$@" ln "$?" "$@" @@ -292,20 +298,15 @@ clean-local: shellinabox/shell_in_a_box.o: ${top_srcdir}/shellinabox/shell_in_a_box.js \ ${top_srcdir}/config.h -${top_srcdir}/shellinabox/vt100.js: ${top_srcdir}/shellinabox/vt100.jspp \ - ${top_srcdir}/shellinabox/keyboard-layout.html +${top_srcdir}/shellinabox/vt100.js: ${top_srcdir}/shellinabox/vt100.jspp .jspp.js: @echo preprocess "$<" "$@" - @kbd=`while read i; do \ - printf '%s' "\`echo "$$i" | sed 's/&/\\\\\\&/g'\`"; \ - done <${top_srcdir}/shellinabox/keyboard-layout.html`; \ sed -e "`sed -e 's/^#define *\([^ ]*\) *\(.*\)/\/^[^#]\/s\/\1\/\2 \\\\\/* \1 *\\\\\/\/g/' \ -e t \ -e d "$<"`" \ -e "s/^#/\/\/ #/" \ -e "s/VERSION/\"@VERSION@ (revision @VCS_REVISION@)\"/g" \ - -e "s%KEYBOARD%'$${kbd}'%" \ "$<" >"$@" .js.o: diff --git a/Makefile.in b/Makefile.in index 018f234..1fb1a2b 100644 --- a/Makefile.in +++ b/Makefile.in @@ -290,6 +290,7 @@ EXTRA_DIST = INSTALL.Debian \ demo/demo.jspp \ demo/demo.xml \ demo/enabled.gif \ + demo/keyboard.html \ demo/keyboard.png \ demo/styles.css \ demo/print-styles.css \ @@ -1175,6 +1176,7 @@ ${top_srcdir}/demo/demo.js: ${top_srcdir}/demo/beep.wav \ ${top_srcdir}/demo/demo.jspp \ ${top_srcdir}/demo/enabled.gif \ ${top_srcdir}/demo/favicon.ico \ + ${top_srcdir}/demo/keyboard.html \ ${top_srcdir}/demo/keyboard.png \ ${top_srcdir}/demo/styles.css \ ${top_srcdir}/demo/print-styles.css \ @@ -1196,6 +1198,10 @@ ${top_srcdir}/demo/favicon.ico: ${top_srcdir}/shellinabox/favicon.ico @rm -f "$@" ln "$?" "$@" +${top_srcdir}/demo/keyboard.html: ${top_srcdir}/shellinabox/keyboard-layout.html + @rm -f "$@" + ln "$?" "$@" + ${top_srcdir}/demo/keyboard.png: ${top_srcdir}/shellinabox/keyboard.png @rm -f "$@" ln "$?" "$@" @@ -1312,20 +1318,15 @@ clean-local: shellinabox/shell_in_a_box.o: ${top_srcdir}/shellinabox/shell_in_a_box.js \ ${top_srcdir}/config.h -${top_srcdir}/shellinabox/vt100.js: ${top_srcdir}/shellinabox/vt100.jspp \ - ${top_srcdir}/shellinabox/keyboard-layout.html +${top_srcdir}/shellinabox/vt100.js: ${top_srcdir}/shellinabox/vt100.jspp .jspp.js: @echo preprocess "$<" "$@" - @kbd=`while read i; do \ - printf '%s' "\`echo "$$i" | sed 's/&/\\\\\\&/g'\`"; \ - done <${top_srcdir}/shellinabox/keyboard-layout.html`; \ sed -e "`sed -e 's/^#define *\([^ ]*\) *\(.*\)/\/^[^#]\/s\/\1\/\2 \\\\\/* \1 *\\\\\/\/g/' \ -e t \ -e d "$<"`" \ -e "s/^#/\/\/ #/" \ -e "s/VERSION/\"@VERSION@ (revision @VCS_REVISION@)\"/g" \ - -e "s%KEYBOARD%'$${kbd}'%" \ "$<" >"$@" .js.o: diff --git a/config.h b/config.h index 14cbbcc..347a300 100644 --- a/config.h +++ b/config.h @@ -153,7 +153,7 @@ #define STDC_HEADERS 1 /* Most recent revision number in the version control system */ -#define VCS_REVISION "223" +#define VCS_REVISION "225" /* Version number of package */ #define VERSION "2.10" diff --git a/configure b/configure index 118c49a..ca1d7a8 100755 --- a/configure +++ b/configure @@ -2328,7 +2328,7 @@ ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $ ac_compiler_gnu=$ac_cv_c_compiler_gnu -VCS_REVISION=223 +VCS_REVISION=225 cat >>confdefs.h <<_ACEOF diff --git a/configure.ac b/configure.ac index ecd2bf9..65d2ff8 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ AC_PREREQ(2.57) dnl This is the one location where the authoritative version number is stored AC_INIT(shellinabox, 2.10, markus@shellinabox.com) -VCS_REVISION=223 +VCS_REVISION=225 AC_SUBST(VCS_REVISION) AC_DEFINE_UNQUOTED(VCS_REVISION, "${VCS_REVISION}", [Most recent revision number in the version control system]) diff --git a/demo/keyboard.html b/demo/keyboard.html new file mode 100644 index 0000000..6a95f3b --- /dev/null +++ b/demo/keyboard.html @@ -0,0 +1,62 @@ + + + + + +
EscF1F2F3F4F5F6F7F8F9F10F11F12
`~1!2@3#4$5%6^7&8*9(0)-_=+ ← 
TabQWERTYUIOP[{]}\|
Tab  ASDFGHJKL;:'"Enter
  ShiftZXCVBNM,<.>/?Shift
XXXCtrlAlt 
   
InsDelHomeEnd
 
 
Ins   
Ins 
diff --git a/demo/vt100.js b/demo/vt100.js index a36b768..6b25ce5 100644 --- a/demo/vt100.js +++ b/demo/vt100.js @@ -716,15 +716,20 @@ VT100.prototype.initializeKeyBindings = function(elem) { } } else { var child = elem.firstChild; - if (child.nodeName == "#text") { - // If the key only has a text node as a child, then it is a letter. - // Automatically compute the lower and upper case version of the key. - this.addKeyBinding(elem, this.getTextContent(child).toLowerCase()); - } else { - // If the key has two children, they are the lower and upper case - // character code, respectively. - this.addKeyBinding(elem, this.getTextContent(child), undefined, - this.getTextContent(child.nextSibling)); + if (child) { + if (child.nodeName == "#text") { + // If the key only has a text node as a child, then it is a letter. + // Automatically compute the lower and upper case version of the + // key. + var text = this.getTextContent(child) || + this.getTextContent(elem); + this.addKeyBinding(elem, text.toLowerCase()); + } else if (child.nextSibling) { + // If the key has two children, they are the lower and upper case + // character code, respectively. + this.addKeyBinding(elem, this.getTextContent(child), undefined, + this.getTextContent(child.nextSibling)); + } } } } @@ -735,14 +740,13 @@ VT100.prototype.initializeKeyBindings = function(elem) { } }; -VT100.prototype.initializeKeyboard = function() { +VT100.prototype.initializeKeyboardButton = function() { // Configure mouse event handlers for button that displays/hides keyboard - var box = this.keyboard.firstChild; - this.hideSoftKeyboard(); this.addListener(this.keyboardImage, 'click', function(vt100) { return function(e) { if (vt100.keyboard.style.display != '') { if (vt100.reconnectBtn.style.visibility != '') { + vt100.initializeKeyboard(); vt100.showSoftKeyboard(); } } else { @@ -755,6 +759,18 @@ VT100.prototype.initializeKeyboard = function() { if (this.softKeyboard) { this.keyboardImage.style.visibility = 'visible'; } +}; + +VT100.prototype.initializeKeyboard = function() { + // Only need to initialize the keyboard the very first time. When doing so, + // copy the keyboard layout from the iframe. + if (this.keyboard.firstChild) { + return; + } + this.keyboard.innerHTML = + this.layout.contentDocument.body.innerHTML; + var box = this.keyboard.firstChild; + this.hideSoftKeyboard(); // Configure mouse event handlers for on-screen keyboard this.addListener(this.keyboard, 'click', @@ -808,6 +824,7 @@ VT100.prototype.initializeElements = function(container) { !this.getChildById(this.container, 'keyboard') || !this.getChildById(this.container, 'kbd_button') || !this.getChildById(this.container, 'kbd_img') || + !this.getChildById(this.container, 'layout') || !this.getChildById(this.container, 'scrollable') || !this.getChildById(this.container, 'console') || !this.getChildById(this.container, 'alt_console') || @@ -851,7 +868,6 @@ VT100.prototype.initializeElements = function(container) { '' + '' + '
' + - '
EscF1F2F3F4F5F6F7F8F9F10F11F12
`~1!2@3#4$5%6^7&8*9(0)-_=+ ← 
TabQWERTYUIOP[{]}\|
Tab  ASDFGHJKL;:'"Enter
  ShiftZXCVBNM,<.>/?Shift
XXXCtrlAlt 
   
InsDelHomeEnd
 
 
Ins   
Ins 
' + '
' + '
' + '' + @@ -876,6 +892,7 @@ VT100.prototype.initializeElements = function(container) { (typeof suppressAllAudio != 'undefined' && suppressAllAudio ? "" : embed + '') + + '