Skip to content

Commit

Permalink
feat(tooltip): Prevent close tooltip with 'esc' key
Browse files Browse the repository at this point in the history
  • Loading branch information
RDD2017 committed Aug 31, 2017
1 parent a2dee1b commit d11f1a0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
7 changes: 4 additions & 3 deletions src/stackedMap/stackedMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ angular.module('ui.bootstrap.stackedMap', [])
var stack = [];

return {
add: function(key, value) {
add: function(key, value, options) {
stack.push({
key: key,
value: value
value: value,
options: options
});
},
get: function(key) {
Expand Down Expand Up @@ -51,4 +52,4 @@ angular.module('ui.bootstrap.stackedMap', [])
};
}
};
});
});
14 changes: 8 additions & 6 deletions src/tooltip/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ angular.module('ui.bootstrap.tooltip', ['ui.bootstrap.position', 'ui.bootstrap.s
function keypressListener(e) {
if (e.which === 27) {
var last = openedTooltips.top();
if (last) {
var enableEsc = last.options.enableEsc;
if (last && enableEsc) {
last.value.close();
last = null;
}
Expand Down Expand Up @@ -146,6 +147,7 @@ angular.module('ui.bootstrap.tooltip', ['ui.bootstrap.position', 'ui.bootstrap.s
var positionTimeout;
var adjustmentTimeout;
var appendToBody = angular.isDefined(options.appendToBody) ? options.appendToBody : false;
var enableEsc = !angular.isDefined(attrs[prefix + 'EnableEsc']);
var triggers = getTriggers(undefined);
var hasEnableExp = angular.isDefined(attrs[prefix + 'Enable']);
var ttScope = scope.$new(true);
Expand Down Expand Up @@ -334,9 +336,9 @@ angular.module('ui.bootstrap.tooltip', ['ui.bootstrap.position', 'ui.bootstrap.s
}
});

openedTooltips.add(ttScope, {
close: hide
});
openedTooltips.add(ttScope,
{ close: hide },
{ enableEsc: enableEsc });

prepObservers();
}
Expand All @@ -348,15 +350,15 @@ angular.module('ui.bootstrap.tooltip', ['ui.bootstrap.position', 'ui.bootstrap.s

if (tooltip) {
tooltip.remove();

tooltip = null;
if (adjustmentTimeout) {
$timeout.cancel(adjustmentTimeout);
}
}

openedTooltips.remove(ttScope);

if (tooltipLinkedScope) {
tooltipLinkedScope.$destroy();
tooltipLinkedScope = null;
Expand Down

0 comments on commit d11f1a0

Please sign in to comment.