Created
July 27, 2018 15:37
-
-
Save eudesgit/58bb46af54e0c0eee8a6d74728e429df to your computer and use it in GitHub Desktop.
Script to make WordPress Slider Revolution Plugin slides more accessibile
This file contains hidden or 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
/** | |
* Manipulates Slider Revolution HTML to make it more W3C compliant | |
* | |
* It's required to meet basic W3C accessibility standards. | |
* To make it work out, the following Slider Revolutions options have to be filled: | |
* - Slider title | |
* - Slider > Link & Seo > Enable Link = Enable | |
* - Slider > Link & Seo > Link Type = Regular | |
* - Slider > Slide Link > "The full page URL" | |
* - Slider > Slide info > A description with the same words from the slider image. | |
* | |
* Although hidden, this information will be semantically printed for special browsers. | |
* | |
* This script has to be run after Slider loading. | |
* | |
* @version 1.0.0 | |
* | |
*/ | |
/** | |
* Adds compliance to Slider Revolution | |
* | |
* It's a global function that has to be called inside Custom JavaScript | |
* area of Slider Revolution plugin config. | |
* | |
* Ex: | |
* revapi3.bind("revolution.slide.onloaded",function (e) { | |
* ac_slider_rev_compliance(revapi) | |
* }) | |
* | |
* @param {object} revapi Script API | |
*/ | |
function ac_slider_rev_compliance ( revapi ) { | |
jQuery(document).ready(function($) { | |
/* | |
* Main selectors and attributes | |
*/ | |
const container = '#slider' | |
const slider_selector = 'li' | |
const link_selector = '.slidelink a' | |
const slider_title_data = 'title' | |
const slider_desc_data = 'description' | |
const hidden_class = 'visuallyhidden' | |
/* | |
* Processin slides | |
*/ | |
$(container + ' ' + slider_selector).each(function () { | |
let title = $(this).data(slider_title_data) | |
let desc = $(this).data(slider_desc_data) | |
// Adding headings and description | |
$(this).append( | |
$('<h3>').text(title).addClass(hidden_class), | |
$('<p>').text(desc).addClass(hidden_class) | |
) | |
// Adding link text | |
let $link_span = $($(this).find(link_selector)[0]) | |
$link_span.addClass(hidden_class) | |
$link_span.append('Go to ' + title + ' page') | |
}) | |
}) // jQuery | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment