Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

Commit

Permalink
feat(tooltip): change back to jqLite listeners
Browse files Browse the repository at this point in the history
- Change event listeners to be handled by jqLite

Closes #4886
Closes #5157
wesleycho committed Jan 7, 2016
1 parent d320df8 commit a5ca78a
Showing 4 changed files with 22 additions and 41 deletions.
4 changes: 1 addition & 3 deletions src/tooltip/test/tooltip-template.spec.js
Original file line number Diff line number Diff line change
@@ -37,9 +37,7 @@ describe('tooltip template', function() {
});

function trigger(element, evt) {
evt = new Event(evt);

element[0].dispatchEvent(evt);
element.trigger(evt);
element.scope().$$childTail.$digest();
}

24 changes: 7 additions & 17 deletions src/tooltip/test/tooltip.spec.js
Original file line number Diff line number Diff line change
@@ -31,9 +31,7 @@ describe('tooltip', function() {
});

function trigger(element, evt) {
evt = new Event(evt);

element[0].dispatchEvent(evt);
element.trigger(evt);
element.scope().$$childTail.$digest();
}

@@ -750,9 +748,7 @@ describe('tooltipWithDifferentSymbols', function() {
}));

function trigger(element, evt) {
evt = new Event(evt);

element[0].dispatchEvent(evt);
element.trigger(evt);
element.scope().$$childTail.$digest();
}

@@ -798,9 +794,7 @@ describe('tooltip positioning', function() {
}));

function trigger(element, evt) {
evt = new Event(evt);

element[0].dispatchEvent(evt);
element.trigger(evt);
element.scope().$$childTail.$digest();
}

@@ -856,9 +850,7 @@ describe('tooltipHtml', function() {
}));

function trigger(element, evt) {
evt = new Event(evt);

element[0].dispatchEvent(evt);
element.trigger(evt);
element.scope().$$childTail.$digest();
}

@@ -897,9 +889,7 @@ describe('$uibTooltipProvider', function() {
tooltipScope;

function trigger(element, evt) {
evt = new Event(evt);

element[0].dispatchEvent(evt);
element.trigger(evt);
element.scope().$$childTail.$digest();
}

@@ -1030,7 +1020,7 @@ describe('$uibTooltipProvider', function() {
});

describe('triggers', function() {
describe('triggers with a mapped value', function() {
describe('with a mapped value', function() {
beforeEach(module('ui.bootstrap.tooltip', function($uibTooltipProvider) {
$uibTooltipProvider.options({trigger: 'focus'});
}));
@@ -1077,7 +1067,7 @@ describe('$uibTooltipProvider', function() {
}));
});

describe('triggers with a custom mapped value', function() {
describe('with a custom mapped value', function() {
beforeEach(module('ui.bootstrap.tooltip', function($uibTooltipProvider) {
$uibTooltipProvider.setTriggers({ customOpenTrigger: 'foo bar' });
$uibTooltipProvider.options({trigger: 'customOpenTrigger'});
4 changes: 1 addition & 3 deletions src/tooltip/test/tooltip2.spec.js
Original file line number Diff line number Diff line change
@@ -56,9 +56,7 @@ describe('tooltip directive', function() {
}

function trigger(element, evt) {
evt = new Event(evt);

element[0].dispatchEvent(evt);
element.trigger(evt);
element.scope().$$childTail.$digest();
}

31 changes: 13 additions & 18 deletions src/tooltip/tooltip.js
Original file line number Diff line number Diff line change
@@ -481,20 +481,18 @@ angular.module('ui.bootstrap.tooltip', ['ui.bootstrap.position', 'ui.bootstrap.s
var unregisterTriggers = function() {
triggers.show.forEach(function(trigger) {
if (trigger === 'outsideClick') {
element[0].removeEventListener('click', toggleTooltipBind);
element.off('click', toggleTooltipBind);
} else {
element[0].removeEventListener(trigger, showTooltipBind);
element[0].removeEventListener(trigger, toggleTooltipBind);
element.off(trigger, showTooltipBind);
element.off(trigger, toggleTooltipBind);
}
});
triggers.hide.forEach(function(trigger) {
trigger.split(' ').forEach(function(hideTrigger) {
if (trigger === 'outsideClick') {
$document[0].removeEventListener('click', bodyHideTooltipBind);
} else {
element[0].removeEventListener(hideTrigger, hideTooltipBind);
}
});
if (trigger === 'outsideClick') {
$document.off('click', bodyHideTooltipBind);
} else {
element.off(trigger, hideTooltipBind);
}
});
};

@@ -506,17 +504,14 @@ angular.module('ui.bootstrap.tooltip', ['ui.bootstrap.position', 'ui.bootstrap.s

if (triggers.show !== 'none') {
triggers.show.forEach(function(trigger, idx) {
// Using raw addEventListener due to jqLite/jQuery bug - #4060
if (trigger === 'outsideClick') {
element[0].addEventListener('click', toggleTooltipBind);
$document[0].addEventListener('click', bodyHideTooltipBind);
element.on('click', toggleTooltipBind);
$document.on('click', bodyHideTooltipBind);
} else if (trigger === triggers.hide[idx]) {
element[0].addEventListener(trigger, toggleTooltipBind);
element.on(trigger, toggleTooltipBind);
} else if (trigger) {
element[0].addEventListener(trigger, showTooltipBind);
triggers.hide[idx].split(' ').forEach(function(trigger) {
element[0].addEventListener(trigger, hideTooltipBind);
});
element.on(trigger, showTooltipBind);
element.on(triggers.hide[idx], hideTooltipBind);
}

element.on('keypress', function(e) {

0 comments on commit a5ca78a

Please sign in to comment.