Commit d12e173c by Braden MacDonald

Change TooltipManager API so we can remove fake event

parent e833d9c2
...@@ -37,14 +37,9 @@ class @Problem ...@@ -37,14 +37,9 @@ class @Problem
# Accessibility helper for sighted keyboard users to show <clarification> tooltips on focus: # Accessibility helper for sighted keyboard users to show <clarification> tooltips on focus:
@$('.clarification').focus (ev) => @$('.clarification').focus (ev) =>
icon = $(ev.target).children "i" icon = $(ev.target).children "i"
iconPos = icon.offset() window.globalTooltipManager.openTooltip icon
fakeEvent = jQuery.Event "mouseover", {
pageX: iconPos.left + icon.width()/2,
pageY: iconPos.top + icon.height()/2
}
icon.trigger(fakeEvent).trigger "click"
@$('.clarification').blur (ev) => @$('.clarification').blur (ev) =>
$(ev.target).children("i").trigger "mouseout" window.globalTooltipManager.hide()
@bindResetCorrectness() @bindResetCorrectness()
......
...@@ -76,6 +76,11 @@ describe('TooltipManager', function () { ...@@ -76,6 +76,11 @@ describe('TooltipManager', function () {
expect($('.tooltip')).toBeVisible(); expect($('.tooltip')).toBeVisible();
}); });
it('can be be triggered manually', function () {
this.tooltip.openTooltip(this.element);
expect($('.tooltip')).toBeVisible();
});
it('should moves correctly', function () { it('should moves correctly', function () {
showTooltip(this.element); showTooltip(this.element);
expect($('.tooltip')).toBeVisible(); expect($('.tooltip')).toBeVisible();
......
...@@ -46,15 +46,29 @@ ...@@ -46,15 +46,29 @@
}, },
showTooltip: function(event) { showTooltip: function(event) {
var tooltipText = $(event.currentTarget).attr('data-tooltip'); this.prepareTooltip(event.currentTarget, event.pageX, event.pageY);
if (this.tooltipTimer) {
clearTimeout(this.tooltipTimer);
}
this.tooltipTimer = setTimeout(this.show, 500);
},
prepareTooltip: function(element, pageX, pageY) {
pageX = typeof pageX !== 'undefined' ? pageX : element.offset().left + element.width()/2;
pageY = typeof pageY !== 'undefined' ? pageY : element.offset().top + element.height()/2;
var tooltipText = $(element).attr('data-tooltip');
this.tooltip this.tooltip
.html(tooltipText) .html(tooltipText)
.css(this.getCoords(event.pageX, event.pageY)); .css(this.getCoords(pageX, pageY));
},
// To manually trigger a tooltip to reveal, other than through user mouse movement:
openTooltip: function(element) {
this.prepareTooltip(element);
this.show();
if (this.tooltipTimer) { if (this.tooltipTimer) {
clearTimeout(this.tooltipTimer); clearTimeout(this.tooltipTimer);
} }
this.tooltipTimer = setTimeout(this.show, 500);
}, },
moveTooltip: function(event) { moveTooltip: function(event) {
...@@ -90,6 +104,6 @@ ...@@ -90,6 +104,6 @@
window.TooltipManager = TooltipManager; window.TooltipManager = TooltipManager;
$(document).ready(function () { $(document).ready(function () {
new TooltipManager(document.body); window.globalTooltipManager = new TooltipManager(document.body);
}); });
}()); }());
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment