Skip to content

Instantly share code, notes, and snippets.

@adzialocha
Last active December 31, 2015 03:29
Show Gist options
  • Save adzialocha/7927599 to your computer and use it in GitHub Desktop.
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)
'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