diff --git a/README.md b/README.md index 63f7001..04b57c6 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ Close the keyboard if it is open. Supported Platforms ------------------- -- iOS, Android, Blackberry 10 +- iOS, Android, Blackberry 10, Windows Keyboard.disableScroll @@ -65,18 +65,18 @@ Disable native scrolling, useful if you are using JavaScript to scroll Supported Platforms ------------------- -- iOS +- iOS, Windows Keyboard.show ================= -Force keyboard to be shown on Android. This typically helps if autofocus on a text element does not pop up the keyboard automatically +Force keyboard to be shown. This typically helps if autofocus on a text element does not pop up the keyboard automatically cordova.plugins.Keyboard.show(); Supported Platforms -- Android, Blackberry 10 +- Android, Blackberry 10, Windows native.keyboardshow ================= @@ -98,7 +98,7 @@ keyboardHeight: the height of the keyboard in pixels Supported Platforms ------------------- -- iOS, Android, Blackberry 10 +- iOS, Android, Blackberry 10, Windows native.keyboardhide @@ -120,4 +120,4 @@ None Supported Platforms ------------------- -- iOS, Android, Blackberry 10 +- iOS, Android, Blackberry 10, Windows diff --git a/plugin.xml b/plugin.xml index 0668891..0880c08 100644 --- a/plugin.xml +++ b/plugin.xml @@ -52,4 +52,11 @@ + + + + + + + diff --git a/src/windows/KeyboardProxy.js b/src/windows/KeyboardProxy.js new file mode 100644 index 0000000..c5f6fd0 --- /dev/null +++ b/src/windows/KeyboardProxy.js @@ -0,0 +1,38 @@ + +/*global Windows, WinJS, cordova, module, require*/ + +var inputPane = Windows.UI.ViewManagement.InputPane.getForCurrentView(); +var keyboardScrollDisabled = false; + +inputPane.addEventListener('hiding', function() { + cordova.fireDocumentEvent('native.keyboardhide'); + cordova.plugins.Keyboard.isVisible = false; +}); + +inputPane.addEventListener('showing', function(e) { + if (keyboardScrollDisabled) { + // this disables automatic scrolling of view contents to show focused control + e.ensuredFocusedElementInView = true; + } + cordova.fireDocumentEvent('native.keyboardshow', { keyboardHeight: e.occludedRect.height }); + cordova.plugins.Keyboard.isVisible = true; +}); + +module.exports.disableScroll = function (win, fail, args) { + var disable = args[0]; + keyboardScrollDisabled = disable; +}; + +module.exports.show = function () { + if (typeof inputPane.tryShow === 'function') { + inputPane.tryShow(); + } +}; + +module.exports.close = function () { + if (typeof inputPane.tryShow === 'function') { + inputPane.tryHide(); + } +}; + +require("cordova/exec/proxy").add("Keyboard", module.exports);