diff --git a/components/ionKeyboard/ionKeyboard.js b/components/ionKeyboard/ionKeyboard.js index 4e65130..cbd21db 100644 --- a/components/ionKeyboard/ionKeyboard.js +++ b/components/ionKeyboard/ionKeyboard.js @@ -3,45 +3,98 @@ Meteor.startup(function () { IonKeyboard.disableScroll(); } }); - +//TODO: Added backward compatibility using if statements to test for newer keyboard plugin +//... cordova-plugin-keyboard. in the future we should remove ionic-plugin-keyboard +//... and take out the if statements below. IonKeyboard = { close: function () { if (Meteor.isCordova) { - cordova.plugins.Keyboard.close(); + if(typeof(Keyboard) === "undefined"){ + cordova.plugins.Keyboard.close(); + } else { + Keyboard.hide(); + } } }, show: function () { if (Meteor.isCordova) { - cordova.plugins.Keyboard.show(); + if(typeof(Keyboard) === "undefined"){ + cordova.plugins.Keyboard.show(); + } else { + Keyboard.show(); + } } }, hideKeyboardAccessoryBar: function () { if (Meteor.isCordova) { - cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true); + if(typeof(Keyboard) === "undefined"){ + cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true); + } else { + Keyboard.hideFormAccessoryBar(true); + } } }, showKeyboardAccessoryBar: function () { if (Meteor.isCordova) { - cordova.plugins.Keyboard.hideKeyboardAccessoryBar(false); + if(typeof(Keyboard) === "undefined"){ + cordova.plugins.Keyboard.hideKeyboardAccessoryBar(false); + } else { + Keyboard.hideFormAccessoryBar(false); + } } }, disableScroll: function () { if (Meteor.isCordova) { - cordova.plugins.Keyboard.disableScroll(true); + if(typeof(Keyboard) === "undefined"){ + cordova.plugins.Keyboard.disableScroll(true); + } else { + Keyboard.disableScrollingInShrinkView(true); + } } }, enableScroll: function () { if (Meteor.isCordova) { - cordova.plugins.Keyboard.disableScroll(false); + if(typeof(Keyboard) === "undefined"){ + cordova.plugins.Keyboard.disableScroll(false); + } else { + Keyboard.disableScrollingInShrinkView(false); + } } } }; +window.addEventListener('keyboardHeightWillChange', function (event) { + // TODO: Android is having problems + if (Platform.isAndroid()) { + return; + } + + $('body').addClass('keyboard-open'); + var keyboardHeight = event.keyboardHeight; + + // Scroll to the focused element + scrollToFocusedElement(null, keyboardHeight); + +}); + +window.addEventListener('keyboardDidHide', function (event) { + + // TODO: Android is having problems + if (Platform.isAndroid()) { + return; + } + + // $('input, textarea').blur(); + $('body').removeClass('keyboard-open'); + +}); + + window.addEventListener('native.keyboardshow', function (event) { // TODO: Android is having problems diff --git a/package.js b/package.js index 7ccb336..2046b3e 100644 --- a/package.js +++ b/package.js @@ -6,6 +6,7 @@ Package.describe({ }); Cordova.depends({ + 'cordova-plugin-keyboard': '1.1.3', 'ionic-plugin-keyboard': '1.0.8' });