This repository has been archived by the owner on May 4, 2022. It is now read-only.
/
keyboardAttach.js
81 lines (70 loc) · 2.41 KB
/
keyboardAttach.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/**
* @ngdoc directive
* @name keyboardAttach
* @module ionic
* @restrict A
*
* @description
* keyboard-attach is an attribute directive which will cause an element to float above
* the keyboard when the keyboard shows. Currently only supports the
* [ion-footer-bar]({{ page.versionHref }}/api/directive/ionFooterBar/) directive.
*
* ### Notes
* - This directive requires the
* [Ionic Keyboard Plugin](https://github.com/ionic-team/ionic-plugins-keyboard).
* - On Android not in fullscreen mode, i.e. you have
* `<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)`.
*
* @usage
*
* ```html
* <ion-footer-bar align-title="left" keyboard-attach class="bar-assertive">
* <h1 class="title">Title!</h1>
* </ion-footer-bar>
* ```
*/
IonicModule
.directive('keyboardAttach', function() {
return function(scope, element) {
ionic.on('native.keyboardshow', onShow, window);
ionic.on('native.keyboardhide', onHide, window);
//deprecated
ionic.on('native.showkeyboard', onShow, window);
ionic.on('native.hidekeyboard', onHide, window);
var scrollCtrl;
function onShow(e) {
if (ionic.Platform.isAndroid() && !ionic.Platform.isFullScreen) {
return;
}
//for testing
var keyboardHeight = e.keyboardHeight || (e.detail && e.detail.keyboardHeight);
element.css('bottom', keyboardHeight + "px");
scrollCtrl = element.controller('$ionicScroll');
if (scrollCtrl) {
scrollCtrl.scrollView.__container.style.bottom = keyboardHeight + keyboardAttachGetClientHeight(element[0]) + "px";
}
}
function onHide() {
if (ionic.Platform.isAndroid() && !ionic.Platform.isFullScreen) {
return;
}
element.css('bottom', '');
if (scrollCtrl) {
scrollCtrl.scrollView.__container.style.bottom = '';
}
}
scope.$on('$destroy', function() {
ionic.off('native.keyboardshow', onShow, window);
ionic.off('native.keyboardhide', onHide, window);
//deprecated
ionic.off('native.showkeyboard', onShow, window);
ionic.off('native.hidekeyboard', onHide, window);
});
};
});
function keyboardAttachGetClientHeight(element) {
return element.clientHeight;
}