keyboard.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. var argscheck = require('cordova/argscheck'),
  2. utils = require('cordova/utils'),
  3. exec = require('cordova/exec'),
  4. channel = require('cordova/channel');
  5. var Keyboard = function () {};
  6. Keyboard.fireOnShow = function (height) {
  7. Keyboard.isVisible = true;
  8. cordova.fireWindowEvent('keyboardDidShow', {
  9. 'keyboardHeight': height
  10. });
  11. // To support the keyboardAttach directive listening events
  12. // inside Ionic's main bundle
  13. cordova.fireWindowEvent('native.keyboardshow', {
  14. 'keyboardHeight': height
  15. });
  16. };
  17. Keyboard.fireOnHide = function () {
  18. Keyboard.isVisible = false;
  19. cordova.fireWindowEvent('keyboardDidHide');
  20. // To support the keyboardAttach directive listening events
  21. // inside Ionic's main bundle
  22. cordova.fireWindowEvent('native.keyboardhide');
  23. };
  24. Keyboard.fireOnHiding = function () {
  25. cordova.fireWindowEvent('keyboardWillHide');
  26. };
  27. Keyboard.fireOnShowing = function (height) {
  28. cordova.fireWindowEvent('keyboardWillShow', {
  29. 'keyboardHeight': height
  30. });
  31. };
  32. Keyboard.hideFormAccessoryBar = Keyboard.hideKeyboardAccessoryBar = function (hide) {
  33. exec(null, null, "Keyboard", "hideKeyboardAccessoryBar", [hide]);
  34. };
  35. Keyboard.hide = function () {
  36. exec(null, null, "Keyboard", "hide", []);
  37. };
  38. Keyboard.show = function () {
  39. exec(null, null, "Keyboard", "show", []);
  40. };
  41. Keyboard.disableScroll = function (disable) {
  42. console.warn("Keyboard.disableScroll() was removed");
  43. };
  44. Keyboard.setResizeMode = function (mode) {
  45. console.warn("Keyboard.setResizeMode() not supported in Android");
  46. }
  47. channel.onCordovaReady.subscribe(function () {
  48. exec(success, null, 'Keyboard', 'init', []);
  49. function success(msg) {
  50. var action = msg.charAt(0);
  51. if (action === 'S') {
  52. var keyboardHeight = parseInt(msg.substr(1));
  53. Keyboard.fireOnShowing(keyboardHeight);
  54. Keyboard.fireOnShow(keyboardHeight);
  55. } else if (action === 'H') {
  56. Keyboard.fireOnHiding();
  57. Keyboard.fireOnHide();
  58. }
  59. }
  60. });
  61. Keyboard.isVisible = false;
  62. module.exports = Keyboard;