Last active
December 31, 2015 03:29
-
-
Save adzialocha/7927599 to your computer and use it in GitHub Desktop.
Simple Listener directive for firing on keyboard state change ('onKeyboardShow', 'onKeyboardHide') in cordova angular apps (with fixed orientation)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
angular.module('app') | |
.directive 'keyboardListener', [ '$rootScope', ($rootScope) -> | |
restrict: 'A' | |
link: ($scope, $element, attrs) -> | |
_height = undefined | |
_update = () -> | |
currentHeight = angular.element($element)[0].offsetHeight | |
if _height? | |
if currentHeight < _height | |
$rootScope.$broadcast 'onKeyboardShow' | |
else if currentHeight > _height | |
$rootScope.$broadcast 'onKeyboardHide' | |
_height = currentHeight | |
# window resize event | |
angular.element(window).bind 'resize', () -> | |
$rootScope.$apply () -> | |
_update() | |
# init | |
_update() | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment