carlsednaoui / add-to-calendar-buttons

Easily add a "add to calendar" button to your websites. This JavaScript library supports Google Calendar, iCal, Outlook and Yahoo Calendar.
476 stars 171 forks source link

Add unique name for link for accessibility #31

Open tboggia opened 5 years ago

tboggia commented 5 years ago

In cases where there are more than one Add to Calendar button per page, the various links need to be unique in order for users of assistive technology to be able to differentiate them.

Accessibility-wise, a link that simply says 'Google Calendar' isn't descriptive enough for someone using a screen reader to be able to use it to navigate successfullly.

This is my first time contributing to an open source thing, so please let me know if I'm doing this all wrong.

tboggia commented 5 years ago

Hi @carlsednaoui !

In implementing your calendar tool on my site (UC Berkeley Extension), I also added this function to make it work with an existing way I was implementing calendars (using a recently paywalled library, ugh). Basically my XML feed builds a div with the fields in spans, then the function plugs those spans into your createCalendar function. If you are interested, I'll do another pull request for it.


if (calendarItems) {
  for ( var i = 0 ; i < calendarItems.length ; i++ ) {
    var thisItem = calendarItems[i],
        itemCalendarObject = {}, 
        myCalendar, itemClass, itemId, title, start, duration, end, address, description;
    itemCalendarObject.options = {};
    itemCalendarObject.data = {};

    for ( var p = 0 ; p < thisItem.children.length ; p++ ) {
      var thisField = thisItem.children[p],
          thisValue = thisField.innerText;
      switch(thisField.classList[0]) {
        case "itemClass": 
          itemCalendarObject.options.class = thisValue;
          break;
        case "itemId": 
          itemCalendarObject.options.id = thisValue;
          break;
        case "start": 
        case "end": 
          if ( thisValue.slice(-1) === "Z" ) {
            thisValue = thisValue.split('');
            thisValue.splice(4,0,'-');
            thisValue.splice(7,0,'-');
            thisValue.splice(13,0,':');
            thisValue.pop();
            thisValue = thisValue.join('');
          }
          itemCalendarObject.data[thisField.classList[0]] = new Date(thisValue);
          break;
        default:
          itemCalendarObject.data[thisField.classList[0]] = thisValue;
          break;
      }
    }

    myCalendar = createCalendar(itemCalendarObject);
    calendarItems[i].appendChild(myCalendar);
  }
}```