keyboard.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. };
  7. Keyboard.hideKeyboardAccessoryBar = function(hide) {
  8. exec(null, null, "Keyboard", "hideKeyboardAccessoryBar", [hide]);
  9. };
  10. Keyboard.close = function() {
  11. exec(null, null, "Keyboard", "close", []);
  12. };
  13. Keyboard.show = function() {
  14. exec(null, null, "Keyboard", "show", []);
  15. };
  16. Keyboard.disableScroll = function(disable) {
  17. exec(null, null, "Keyboard", "disableScroll", [disable]);
  18. };
  19. /*
  20. Keyboard.styleDark = function(dark) {
  21. exec(null, null, "Keyboard", "styleDark", [dark]);
  22. };
  23. */
  24. Keyboard.isVisible = false;
  25. channel.onCordovaReady.subscribe(function() {
  26. exec(success, null, 'Keyboard', 'init', []);
  27. function success(msg) {
  28. var action = msg.charAt(0);
  29. if ( action === 'S' ) {
  30. var keyboardHeight = msg.substr(1);
  31. cordova.plugins.Keyboard.isVisible = true;
  32. cordova.fireWindowEvent('native.keyboardshow', { 'keyboardHeight': + keyboardHeight });
  33. //deprecated
  34. cordova.fireWindowEvent('native.showkeyboard', { 'keyboardHeight': + keyboardHeight });
  35. } else if ( action === 'H' ) {
  36. cordova.plugins.Keyboard.isVisible = false;
  37. cordova.fireWindowEvent('native.keyboardhide');
  38. //deprecated
  39. cordova.fireWindowEvent('native.hidekeyboard');
  40. }
  41. }
  42. });
  43. module.exports = Keyboard;