| @@ 3034-3096 (lines=63) @@ | ||
| 3031 | openClass: 'open' |
|
| 3032 | }) |
|
| 3033 | ||
| 3034 | .service('uibDropdownService', ['$document', '$rootScope', function($document, $rootScope) { |
|
| 3035 | var openScope = null; |
|
| 3036 | ||
| 3037 | this.open = function(dropdownScope, element) { |
|
| 3038 | if (!openScope) { |
|
| 3039 | $document.on('click', closeDropdown); |
|
| 3040 | element.on('keydown', keybindFilter); |
|
| 3041 | } |
|
| 3042 | ||
| 3043 | if (openScope && openScope !== dropdownScope) { |
|
| 3044 | openScope.isOpen = false; |
|
| 3045 | } |
|
| 3046 | ||
| 3047 | openScope = dropdownScope; |
|
| 3048 | }; |
|
| 3049 | ||
| 3050 | this.close = function(dropdownScope, element) { |
|
| 3051 | if (openScope === dropdownScope) { |
|
| 3052 | openScope = null; |
|
| 3053 | $document.off('click', closeDropdown); |
|
| 3054 | element.off('keydown', keybindFilter); |
|
| 3055 | } |
|
| 3056 | }; |
|
| 3057 | ||
| 3058 | var closeDropdown = function(evt) { |
|
| 3059 | // This method may still be called during the same mouse event that |
|
| 3060 | // unbound this event handler. So check openScope before proceeding. |
|
| 3061 | if (!openScope) { return; } |
|
| 3062 | ||
| 3063 | if (evt && openScope.getAutoClose() === 'disabled') { return; } |
|
| 3064 | ||
| 3065 | if (evt && evt.which === 3) { return; } |
|
| 3066 | ||
| 3067 | var toggleElement = openScope.getToggleElement(); |
|
| 3068 | if (evt && toggleElement && toggleElement[0].contains(evt.target)) { |
|
| 3069 | return; |
|
| 3070 | } |
|
| 3071 | ||
| 3072 | var dropdownElement = openScope.getDropdownElement(); |
|
| 3073 | if (evt && openScope.getAutoClose() === 'outsideClick' && |
|
| 3074 | dropdownElement && dropdownElement[0].contains(evt.target)) { |
|
| 3075 | return; |
|
| 3076 | } |
|
| 3077 | ||
| 3078 | openScope.isOpen = false; |
|
| 3079 | ||
| 3080 | if (!$rootScope.$$phase) { |
|
| 3081 | openScope.$apply(); |
|
| 3082 | } |
|
| 3083 | }; |
|
| 3084 | ||
| 3085 | var keybindFilter = function(evt) { |
|
| 3086 | if (evt.which === 27) { |
|
| 3087 | evt.stopPropagation(); |
|
| 3088 | openScope.focusToggleElement(); |
|
| 3089 | closeDropdown(); |
|
| 3090 | } else if (openScope.isKeynavEnabled() && [38, 40].indexOf(evt.which) !== -1 && openScope.isOpen) { |
|
| 3091 | evt.preventDefault(); |
|
| 3092 | evt.stopPropagation(); |
|
| 3093 | openScope.focusDropdownEntry(evt.which); |
|
| 3094 | } |
|
| 3095 | }; |
|
| 3096 | }]) |
|
| 3097 | ||
| 3098 | .controller('UibDropdownController', ['$scope', '$element', '$attrs', '$parse', 'uibDropdownConfig', 'uibDropdownService', '$animate', '$uibPosition', '$document', '$compile', '$templateRequest', function($scope, $element, $attrs, $parse, dropdownConfig, uibDropdownService, $animate, $position, $document, $compile, $templateRequest) { |
|
| 3099 | var self = this, |
|
| @@ 3033-3095 (lines=63) @@ | ||
| 3030 | openClass: 'open' |
|
| 3031 | }) |
|
| 3032 | ||
| 3033 | .service('uibDropdownService', ['$document', '$rootScope', function($document, $rootScope) { |
|
| 3034 | var openScope = null; |
|
| 3035 | ||
| 3036 | this.open = function(dropdownScope, element) { |
|
| 3037 | if (!openScope) { |
|
| 3038 | $document.on('click', closeDropdown); |
|
| 3039 | element.on('keydown', keybindFilter); |
|
| 3040 | } |
|
| 3041 | ||
| 3042 | if (openScope && openScope !== dropdownScope) { |
|
| 3043 | openScope.isOpen = false; |
|
| 3044 | } |
|
| 3045 | ||
| 3046 | openScope = dropdownScope; |
|
| 3047 | }; |
|
| 3048 | ||
| 3049 | this.close = function(dropdownScope, element) { |
|
| 3050 | if (openScope === dropdownScope) { |
|
| 3051 | openScope = null; |
|
| 3052 | $document.off('click', closeDropdown); |
|
| 3053 | element.off('keydown', keybindFilter); |
|
| 3054 | } |
|
| 3055 | }; |
|
| 3056 | ||
| 3057 | var closeDropdown = function(evt) { |
|
| 3058 | // This method may still be called during the same mouse event that |
|
| 3059 | // unbound this event handler. So check openScope before proceeding. |
|
| 3060 | if (!openScope) { return; } |
|
| 3061 | ||
| 3062 | if (evt && openScope.getAutoClose() === 'disabled') { return; } |
|
| 3063 | ||
| 3064 | if (evt && evt.which === 3) { return; } |
|
| 3065 | ||
| 3066 | var toggleElement = openScope.getToggleElement(); |
|
| 3067 | if (evt && toggleElement && toggleElement[0].contains(evt.target)) { |
|
| 3068 | return; |
|
| 3069 | } |
|
| 3070 | ||
| 3071 | var dropdownElement = openScope.getDropdownElement(); |
|
| 3072 | if (evt && openScope.getAutoClose() === 'outsideClick' && |
|
| 3073 | dropdownElement && dropdownElement[0].contains(evt.target)) { |
|
| 3074 | return; |
|
| 3075 | } |
|
| 3076 | ||
| 3077 | openScope.isOpen = false; |
|
| 3078 | ||
| 3079 | if (!$rootScope.$$phase) { |
|
| 3080 | openScope.$apply(); |
|
| 3081 | } |
|
| 3082 | }; |
|
| 3083 | ||
| 3084 | var keybindFilter = function(evt) { |
|
| 3085 | if (evt.which === 27) { |
|
| 3086 | evt.stopPropagation(); |
|
| 3087 | openScope.focusToggleElement(); |
|
| 3088 | closeDropdown(); |
|
| 3089 | } else if (openScope.isKeynavEnabled() && [38, 40].indexOf(evt.which) !== -1 && openScope.isOpen) { |
|
| 3090 | evt.preventDefault(); |
|
| 3091 | evt.stopPropagation(); |
|
| 3092 | openScope.focusDropdownEntry(evt.which); |
|
| 3093 | } |
|
| 3094 | }; |
|
| 3095 | }]) |
|
| 3096 | ||
| 3097 | .controller('UibDropdownController', ['$scope', '$element', '$attrs', '$parse', 'uibDropdownConfig', 'uibDropdownService', '$animate', '$uibPosition', '$document', '$compile', '$templateRequest', function($scope, $element, $attrs, $parse, dropdownConfig, uibDropdownService, $animate, $position, $document, $compile, $templateRequest) { |
|
| 3098 | var self = this, |
|