Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update ionic.keyboard to support trigger.io keyboard module #4079

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion js/angular/directive/keyboardAttach.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* `<preference name="Fullscreen" value="false" />` 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
*
Expand Down
41 changes: 35 additions & 6 deletions js/utils/keyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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();
}
},

Expand Down Expand Up @@ -229,6 +229,13 @@ ionic.keyboard = {
*/
enable: function() {
keyboardInit();
},

/**
* Alias for keyboardPlugin, initialize all keyboard related event listeners.
*/
getPlugin: function() {
return keyboardPlugin();
}
};

Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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() {
Expand Down
33 changes: 33 additions & 0 deletions test/unit/utils/keyboard.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
});
});
1 change: 1 addition & 0 deletions test/unit/utils/viewport.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand Down