From 54ab15002462db8d586f9fe6666a4b8dbbe2fa53 Mon Sep 17 00:00:00 2001 From: Philipp Burgmer Date: Wed, 3 Feb 2016 00:34:04 +0100 Subject: [PATCH] feat(dropdown): provide hooks for dropdown open and dropdown close events It is implemented via w11kSelectConfig.dropdown.onOpen and .onClose. Closes #24 --- src/w11k-select.js | 12 ++++++++++++ test/test.js | 10 +++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/w11k-select.js b/src/w11k-select.js index f06a848..4c0e81f 100644 --- a/src/w11k-select.js +++ b/src/w11k-select.js @@ -36,6 +36,10 @@ angular.module('w11k.select').constant('w11kSelectConfig', { */ text: undefined }, + dropdown: { + onOpen: undefined, + onClose: undefined + }, /** all the configuration for the filter section within the dropdown */ filter: { /** activate filter input to search for options */ @@ -386,6 +390,10 @@ angular.module('w11k.select').directive('w11kSelect', [ } }); jqWindow.on('resize', adjustHeight); + + if (angular.isFunction(scope.config.dropdown.onOpen)) { + scope.config.dropdown.onOpen(); + } }, onClose: function () { // important: set properties of filter.values to empty strings not to null, @@ -397,6 +405,10 @@ angular.module('w11k.select').directive('w11kSelect', [ }); $document.off('keyup', onEscPressed); jqWindow.off('resize', adjustHeight); + + if (angular.isFunction(scope.config.dropdown.onClose)) { + scope.config.dropdown.onClose(); + } } }; diff --git a/test/test.js b/test/test.js index e6a98dd..293ea12 100644 --- a/test/test.js +++ b/test/test.js @@ -2,7 +2,7 @@ angular.module('demo', ['w11k.select']); -angular.module('demo').controller('TestCtrl', function ($scope) { +angular.module('demo').controller('TestCtrl', function ($scope, $log) { var amount = 1000; @@ -31,6 +31,14 @@ angular.module('demo').controller('TestCtrl', function ($scope) { disabled: false, header: { placeholder: 'test' + }, + dropdown: { + onOpen: function () { + $log.debug('dropdown onOpen callback called'); + }, + onClose: function () { + $log.debug('dropdown onClose callback called'); + } } };