Skip to content

Commit

Permalink
Added - support for FacetWP dynamic content
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveJonesDev committed Aug 29, 2023
1 parent 7daab95 commit 5c1d272
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 75 deletions.
5 changes: 4 additions & 1 deletion README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Contributors: equalizedigital, alh0319, stevejonesdev
Tags: accessibility, accessible, wcag, ada, a11y, section 508, links, open new window, open new tab
Requires at least: 5.0.0
Tested up to: 6.3.1
Stable tag: 1.0.7
Stable tag: 1.0.8
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -74,6 +74,9 @@ If you would like to contribute a translation to this plugin, please [contact us

== Changelog ==

= 1.0.8 =
* Added - support for FacetWP dynamic content

= 1.0.7 =
* Updated - textdomain to plugin slug
* Updated - member variable doc comment
Expand Down
4 changes: 2 additions & 2 deletions accessibility-new-window-warnings.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Accessibility New Window Warnings
* Plugin URI: https://a11ychecker.com
* Description: Make links that open in a new window accessible by adding a warning.
* Version: 1.0.7
* Version: 1.0.8
* Author: Equalize Digital
* Author URI: https://equalizedigital.com
* License: GPL-2.0+
Expand All @@ -13,7 +13,7 @@
* @package ANWW
*/

define( 'ANWW_VERSION', '1.0.7' );
define( 'ANWW_VERSION', '1.0.8' );
define( 'ANWW_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
define( 'ANWW_PLUGIN_URL', plugin_dir_url( __FILE__ ) );

Expand Down
2 changes: 1 addition & 1 deletion assets/js/accessibility-new-window-warnings-min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

148 changes: 77 additions & 71 deletions assets/js/accessibility-new-window-warnings.js
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);

0 comments on commit 5c1d272

Please sign in to comment.