-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added - support for FacetWP dynamic content
- Loading branch information
1 parent
7daab95
commit 5c1d272
Showing
4 changed files
with
84 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,86 +1,92 @@ | ||
(function ($) { | ||
"use strict"; | ||
|
||
$(window).on('load',function () { | ||
var anww_link_tooltip; | ||
|
||
var anww_label = ''; | ||
|
||
/** | ||
* Accessible _blank link tooltip | ||
*/ | ||
var anww_link_tooltip = $('<div/>').css({ | ||
position: 'absolute', | ||
background: 'white', | ||
color: '#1e1e1e', | ||
fontSize: '16px', | ||
border: '1px solid black', | ||
padding: '5px 10px', | ||
zIndex: 9999, | ||
display: 'none' | ||
}).addClass('anww-tooltip').appendTo('body'); | ||
function initializeTooltip() { | ||
anww_link_tooltip = $('<div/>').css({ | ||
position: 'absolute', | ||
background: 'white', | ||
color: '#1e1e1e', | ||
fontSize: '16px', | ||
border: '1px solid black', | ||
padding: '5px 10px', | ||
zIndex: 9999, | ||
display: 'none' | ||
}).addClass('anww-tooltip').appendTo('body'); | ||
} | ||
|
||
/** | ||
* loop through each link with a target of _blank | ||
*/ | ||
$("a[target=_blank]").each(function(){ | ||
function processLinks() { | ||
var anww_label = ''; | ||
|
||
// add icon to link | ||
if($(':header',this).length){ | ||
$(':header',this).append('<i class="anww-external-link-icon" aria-hidden="true"></i>'); | ||
}else{ | ||
$(this).append('<i class="anww-external-link-icon" aria-hidden="true"></i>'); | ||
} | ||
|
||
// get aria label text | ||
if($(this).attr("aria-label")){ | ||
anww_label = $(this).attr("aria-label"); | ||
}else if($('img', $(this)).length){ | ||
anww_label = $(this).find("img").attr("alt"); | ||
}else if($(this).text()){ | ||
anww_label = $(this).text(); | ||
} | ||
// Remove previously appended icons to avoid duplication | ||
$(".anww-external-link-icon").remove(); | ||
|
||
// add warning label | ||
if(anww_label){ | ||
anww_label = anww_label.trimEnd(); | ||
anww_label += ", " + anww_localized.opens_a_new_window; | ||
}else{ | ||
anww_label += anww_localized.opens_a_new_window; | ||
} | ||
$("a[target=_blank]").each(function () { | ||
// Add icon to link | ||
if ($(':header', this).length) { | ||
$(':header', this).append('<i class="anww-external-link-icon" aria-hidden="true"></i>'); | ||
} else { | ||
$(this).append('<i class="anww-external-link-icon" aria-hidden="true"></i>'); | ||
} | ||
|
||
// add aria-label to link | ||
$(this).attr("aria-label", anww_label); | ||
// Get aria label text | ||
if ($(this).attr("aria-label")) { | ||
anww_label = $(this).attr("aria-label"); | ||
} else if ($('img', $(this)).length) { | ||
anww_label = $(this).find("img").attr("alt"); | ||
} else if ($(this).text()) { | ||
anww_label = $(this).text(); | ||
} | ||
|
||
// position and show link_tooltip on hover | ||
$(this).mousemove(function(e){ | ||
anww_link_tooltip.css({ | ||
top: e.pageY + 10 + 'px', | ||
left: e.pageX + 10 + 'px' | ||
}); | ||
}) | ||
.hover(function(){ | ||
anww_link_tooltip.show().html(anww_localized.opens_a_new_window); | ||
}, function(){ | ||
anww_link_tooltip.hide(); | ||
}); | ||
// Add warning label | ||
if (anww_label) { | ||
anww_label = anww_label.trimEnd(); | ||
anww_label += ", " + anww_localized.opens_a_new_window; | ||
} else { | ||
anww_label += anww_localized.opens_a_new_window; | ||
} | ||
|
||
// position and show link_tooltip on focus | ||
$(this).on({ | ||
focusin: function () { | ||
var position = $(this).offset(); | ||
anww_link_tooltip.css({ | ||
top: position.top + $(this).outerHeight() + 'px', | ||
left: position.left + 'px' | ||
}); | ||
// Add aria-label to link | ||
$(this).attr("aria-label", anww_label); | ||
|
||
anww_link_tooltip.show().html(anww_localized.opens_a_new_window); | ||
}, | ||
focusout: function () { | ||
anww_link_tooltip.hide(); | ||
} | ||
}); | ||
// Position and show link_tooltip on hover | ||
$(this).mousemove(function (e) { | ||
anww_link_tooltip.css({ | ||
top: e.pageY + 10 + 'px', | ||
left: e.pageX + 10 + 'px' | ||
}); | ||
}) | ||
.hover(function () { | ||
anww_link_tooltip.show().html(anww_localized.opens_a_new_window); | ||
}, function () { | ||
anww_link_tooltip.hide(); | ||
}); | ||
|
||
// Position and show link_tooltip on focus | ||
$(this).on({ | ||
focusin: function () { | ||
var position = $(this).offset(); | ||
anww_link_tooltip.css({ | ||
top: position.top + $(this).outerHeight() + 'px', | ||
left: position.left + 'px' | ||
}); | ||
|
||
}); | ||
anww_link_tooltip.show().html(anww_localized.opens_a_new_window); | ||
}, | ||
focusout: function () { | ||
anww_link_tooltip.hide(); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
$(window).on('load', function () { | ||
initializeTooltip(); | ||
processLinks(); | ||
}); | ||
|
||
// Support for FacetWP: Re-run the processLinks function when FacetWP refreshes the page | ||
$(document).on('facetwp-loaded', processLinks); | ||
|
||
})(jQuery); |