Skip to content

Commit 21dab64

Browse files
authored
Close image, examples and wrapper added
- added attribute data-tooltip-close-img to insert an image in close button - added a wrapper for close button text ```<span class="$tooltip_prefix_class + 'tooltip__closetext__container"``` in order to make it stylable - added another example "It’s customisable" on https://a11y.nicolas-hoffmann.net/dialog-tooltip/ - another feature: when you click on a button that launches a modal tooltip, the class <code>is-active</code> is added to this button. Closed #5
1 parent dcc3983 commit 21dab64

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

jquery-accessible-dialog-tooltip-aria.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ jQuery(document).ready(function($){
22

33
/*
44
* jQuery simple and accessible dialog tooltip window, using ARIA
5-
* @version v1.1.2
5+
* @version v1.3.0
66
* Website: https://a11y.nicolas-hoffmann.net/dialog-tooltip/
77
* License MIT: https://github.com/nico3333fr/jquery-accessible-dialog-tooltip-aria/blob/master/LICENSE
88
*/
@@ -35,10 +35,14 @@ jQuery(document).ready(function($){
3535

3636
// events ------------------
3737
$body.on('click', function(event) {
38-
var $target = $(event.target);
38+
var $target = $(event.target),
39+
$focus_back = $('#' + $('#js-tooltip-close').attr('data-focus-back')),
40+
$dialog_tooltip = $('.js-dialogtooltip');
41+
3942
// if click outside => close
4043
if ( !$target.is('.js-dialogtooltip') && !$target.is('.js-tooltip') && !$target.parents(".js-dialogtooltip").is(".js-dialogtooltip")) {
41-
$('.js-dialogtooltip').remove();
44+
$dialog_tooltip.remove();
45+
$focus_back.removeClass('is-active');
4246
}
4347
})
4448
.on( 'click', '.js-tooltip', function( event ) {
@@ -50,6 +54,7 @@ jQuery(document).ready(function($){
5054
$tooltip_title = options.tooltipTitle || '',
5155
$tooltip_close_text = options.tooltipCloseText || 'Close',
5256
$tooltip_close_title = options.tooltipCloseTitle || options.tooltipCloseText,
57+
$tooltip_close_img = options.tooltipCloseImg || '',
5358
$tooltip_starter_id = $this.attr('id'),
5459
$tooltip_code;
5560

@@ -59,7 +64,13 @@ jQuery(document).ready(function($){
5964

6065
// insert code at the end
6166
$tooltip_code = '<dialog id="js-tooltip" class="js-dialogtooltip ' + $tooltip_prefix_class + 'tooltip" data-launched-by="click" role="dialog" aria-labelledby="tooltip-title" open><div role="document">';
62-
$tooltip_code += '<button id="js-tooltip-close" class="' + $tooltip_prefix_class + 'tooltip__close" data-focus-back="' + $tooltip_starter_id + '" title="' + $tooltip_close_title + '" type="button">' + $tooltip_close_text + '</button>';
67+
$tooltip_code += '<button id="js-tooltip-close" class="' + $tooltip_prefix_class + 'tooltip__close" data-focus-back="' + $tooltip_starter_id + '" title="' + $tooltip_close_title + '" type="button"><span class="' + $tooltip_prefix_class + 'tooltip__closetext__container">';
68+
if ( $tooltip_close_img !== '' ){
69+
$tooltip_code += '<img src="' + $tooltip_close_img + '" alt="' + $tooltip_close_text + '" class="' + $tooltip_prefix_class + 'tooltip__closeimg" />';
70+
}
71+
else { $tooltip_code += $tooltip_close_text; }
72+
$tooltip_code += '</span></button>';
73+
6374
if ($tooltip_title !== ''){
6475
$tooltip_code += '<h1 id="tooltip-title" class="tooltip-title ' + $tooltip_prefix_class + 'tooltip__title">' + $tooltip_title + '</h1>';
6576
}
@@ -82,7 +93,7 @@ jQuery(document).ready(function($){
8293

8394
event.preventDefault();
8495

85-
})
96+
})/*
8697
.on( 'mouseleave', '#js-tooltip', function( event ) {
8798
var $this = $(this),
8899
options = $this.data(),
@@ -93,14 +104,13 @@ jQuery(document).ready(function($){
93104
$close_button.click();
94105
$focus_back.removeClass('is-active');
95106
96-
});
107+
})*/;
97108

98109
// close button and esc key
99110
$body.on( 'click', '#js-tooltip-close', function( event ) {
100111
var $this = $(this),
101112
$tooltip_launched_by = $this.parents('#js-tooltip').attr('data-launched-by'),
102113
$focus_back = $('#' + $this.attr('data-focus-back'));
103-
104114

105115
$('#js-tooltip').remove();
106116
$focus_back.focus();

0 commit comments

Comments
 (0)