diff --git a/js/angular/directive/keyboardAttach.js b/js/angular/directive/keyboardAttach.js index dfecf9e067e..4c71f8fa083 100644 --- a/js/angular/directive/keyboardAttach.js +++ b/js/angular/directive/keyboardAttach.js @@ -16,7 +16,7 @@ * `` or no preference in your `config.xml` file, * this directive is unnecessary since it is the default behavior. * - On iOS, if there is an input in your footer, you will need to set - * `cordova.plugins.Keyboard.disableScroll(true)`. + * `ionic.keyboard.getPlugin().disableScroll(true)`. * * @usage * diff --git a/js/utils/keyboard.js b/js/utils/keyboard.js index 9a1655980e6..9b69336df74 100644 --- a/js/utils/keyboard.js +++ b/js/utils/keyboard.js @@ -68,7 +68,7 @@ * * ### iOS Notes * - If the content of your app (including the header) is being pushed up and - * out of view on input focus, try setting `cordova.plugins.Keyboard.disableScroll(true)`. + * out of view on input focus, try setting `keyboardPlugin().disableScroll(true)`. * This does **not** disable scrolling in the Ionic scroll view, rather it * disables the native overflow scrolling that happens automatically as a * result of focusing on inputs below the keyboard. @@ -184,18 +184,18 @@ ionic.keyboard = { */ hide: function() { if (keyboardHasPlugin()) { - cordova.plugins.Keyboard.close(); + keyboardPlugin().close(); } keyboardActiveElement && keyboardActiveElement.blur(); }, /** - * An alias for cordova.plugins.Keyboard.show(). If the keyboard plugin + * An alias for keyboardPlugin().show(). If the keyboard plugin * is installed, show the keyboard. */ show: function() { if (keyboardHasPlugin()) { - cordova.plugins.Keyboard.show(); + keyboardPlugin().show(); } }, @@ -229,6 +229,13 @@ ionic.keyboard = { */ enable: function() { keyboardInit(); + }, + + /** + * Alias for keyboardPlugin, initialize all keyboard related event listeners. + */ + getPlugin: function() { + return keyboardPlugin(); } }; @@ -567,7 +574,7 @@ function keyboardHide() { if (ionic.Platform.isAndroid()) { // on android closing the keyboard with the back/dismiss button won't remove // focus and keyboard can re-appear on subsequent taps (like scrolling) - if (keyboardHasPlugin()) cordova.plugins.Keyboard.close(); + if (keyboardHasPlugin()) keyboardPlugin().close(); keyboardActiveElement && keyboardActiveElement.blur(); } @@ -729,8 +736,30 @@ function getViewportHeight() { return windowHeight; } +function cordovaPlugin() { + if (window.cordova && cordova.plugins) { + return cordova.plugins.Keyboard; + } +} + +function forgeModule() { + if (window.forge) { + return window.forge.ionic_keyboard; + } +} + function keyboardHasPlugin() { - return !!(window.cordova && cordova.plugins && cordova.plugins.Keyboard); + return !!(cordovaPlugin()) || !!(forgeModule()); +} + +function keyboardPlugin() { + var plugin = cordovaPlugin(); + if (plugin != null) { + return plugin; + } + else { + return forgeModule(); + } } ionic.Platform.ready(function() { diff --git a/test/unit/utils/keyboard.unit.js b/test/unit/utils/keyboard.unit.js index c0696419ba3..e15bec99559 100644 --- a/test/unit/utils/keyboard.unit.js +++ b/test/unit/utils/keyboard.unit.js @@ -83,6 +83,7 @@ describe('Ionic Keyboard', function() { beforeEach(module('ionic')); beforeEach(inject(function($rootScope, $compile) { + window.forge = undefined window.cordova = undefined; window.device = undefined; @@ -515,4 +516,36 @@ describe('Ionic Keyboard', function() { ionic.keyboard.disable(); expect(ionic.keyboard.isInitialized).toBe(false); }); + + it('getPlugin() should return undefined if no plugin setup', function(){ + expect(cordovaPlugin()).toBe(undefined); + expect(forgeModule()).toBe(undefined); + expect(keyboardPlugin()).toBe(undefined); + expect(keyboardHasPlugin()).toBe(false); + expect(ionic.keyboard.getPlugin()).toBe(undefined); + }); + + it('getPlugin() should return cordova plugin if cordova plugin setup', function(){ + cordova = { + 'plugins': { + 'Keyboard': {} + } + }; + expect(cordovaPlugin()).toBe(cordova.plugins.Keyboard); + expect(forgeModule()).toBe(undefined); + expect(keyboardPlugin()).toBe(cordova.plugins.Keyboard); + expect(keyboardHasPlugin()).toBe(true); + expect(ionic.keyboard.getPlugin()).toBe(cordova.plugins.Keyboard); + }); + + it('getPlugin() should return forge module if forge module setup', function(){ + forge = { + 'ionic_keyboard': {} + }; + expect(cordovaPlugin()).toBe(undefined); + expect(forgeModule()).toBe(forge.ionic_keyboard); + expect(keyboardPlugin()).toBe(forge.ionic_keyboard); + expect(keyboardHasPlugin()).toBe(true); + expect(ionic.keyboard.getPlugin()).toBe(forge.ionic_keyboard); + }); }); diff --git a/test/unit/utils/viewport.unit.js b/test/unit/utils/viewport.unit.js index 2777d2a402d..5582d6ef4f0 100644 --- a/test/unit/utils/viewport.unit.js +++ b/test/unit/utils/viewport.unit.js @@ -43,6 +43,7 @@ describe('Ionic Viewport', function() { window._setTimeout = window.setTimeout; window.setTimeout = function(){}; _activeElement = null; // the element which has focus + window.forge = undefined; window.cordova = undefined; window.device = undefined; window.navigator = {};