UNPKG

2.92 kBJavaScriptView Raw
1/*
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 */
21
22var argscheck = require('cordova/argscheck'),
23 utils = require('cordova/utils'),
24 exec = require('cordova/exec');
25
26var Keyboard = function () {};
27
28Keyboard.fireOnShow = function (height) {
29 Keyboard.isVisible = true;
30 cordova.fireWindowEvent('keyboardDidShow', {
31 'keyboardHeight': height
32 });
33
34 // To support the keyboardAttach directive listening events
35 // inside Ionic's main bundle
36 cordova.fireWindowEvent('native.keyboardshow', {
37 'keyboardHeight': height
38 });
39};
40
41Keyboard.fireOnHide = function () {
42 Keyboard.isVisible = false;
43 cordova.fireWindowEvent('keyboardDidHide');
44
45 // To support the keyboardAttach directive listening events
46 // inside Ionic's main bundle
47 cordova.fireWindowEvent('native.keyboardhide');
48};
49
50Keyboard.fireOnHiding = function () {
51 cordova.fireWindowEvent('keyboardWillHide');
52};
53
54Keyboard.fireOnShowing = function (height) {
55 cordova.fireWindowEvent('keyboardWillShow', {
56 'keyboardHeight': height
57 });
58};
59
60Keyboard.fireOnResize = function (height, screenHeight, ele) {
61 if (!ele) {
62 return;
63 }
64 if (height === 0) {
65 ele.style.height = null;
66 } else {
67 ele.style.height = (screenHeight - height) + 'px';
68 }
69};
70
71Keyboard.hideFormAccessoryBar = function (hide, success) {
72 if (hide !== null && hide !== undefined) {
73 exec(success, null, "Keyboard", "hideFormAccessoryBar", [hide]);
74 } else {
75 exec(success, null, "Keyboard", "hideFormAccessoryBar", []);
76 }
77};
78
79Keyboard.hide = function () {
80 exec(null, null, "Keyboard", "hide", []);
81};
82
83Keyboard.show = function () {
84 console.warn('Showing keyboard not supported in iOS due to platform limitations.');
85 console.warn('Instead, use input.focus(), and ensure that you have the following setting in your config.xml: \n');
86 console.warn(' <preference name="KeyboardDisplayRequiresUserAction" value="false"/>\n');
87};
88
89Keyboard.disableScroll = function (disable) {
90 console.warn("Keyboard.disableScroll() was removed");
91};
92
93Keyboard.isVisible = false;
94
95module.exports = Keyboard;
\No newline at end of file