KeyboardProxy.js 1.07 KB
Newer Older
李晓兵's avatar
李晓兵 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37

/*global Windows, WinJS, cordova, module, require*/

var inputPane = Windows.UI.ViewManagement.InputPane.getForCurrentView();
var keyboardScrollDisabled = false;

inputPane.addEventListener('hiding', function() {
    cordova.fireWindowEvent('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.fireWindowEvent('native.keyboardshow', { keyboardHeight: e.occludedRect.height });
    cordova.plugins.Keyboard.isVisible = true;
});

module.exports.disableScroll = function (disable) {
    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);