-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from froboy/DS-858-event-atc
feat: DS-858 AddToCalendar Accessibility
- Loading branch information
Showing
24 changed files
with
1,649 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
AddToCalendar | ||
============= | ||
|
||
AddToCalendar — free customizable JavaScript widget "Add to Calendar" for event page. It allows users to easily schedule the event in their calendar. | ||
|
||
The widget uses fast (HTTP/2) and secure (SSL A+ grade from SSL Labs) server of https://addtocalendar.com service. By default the widget adds small link to the service on the bottom of event and you can ask [email protected] for changes. | ||
|
||
Install from NPM | ||
================ | ||
``` | ||
$ npm install addtocalendar | ||
``` | ||
|
||
Install from Bower | ||
================ | ||
``` | ||
$ npm install -g bower | ||
$ bower install addtocalendar | ||
``` |
345 changes: 345 additions & 0 deletions
345
openy_system/assets/addtocalendar-master/addtocalendar.js
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 |
---|---|---|
@@ -0,0 +1,345 @@ | ||
/* http://addtocalendar.com/ | ||
* | ||
* | ||
* @license | ||
The MIT License (MIT) | ||
Copyright (c) 2015 AddToCalendar | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
*/ | ||
|
||
(function (w, d) { | ||
var | ||
atc_url = '//addtocalendar.com/atc/', | ||
atc_version = '1.5'; | ||
|
||
|
||
if (!Array.indexOf) { | ||
Array.prototype.indexOf = function (obj) { | ||
for (var i = 0, l = this.length; i < l; i++) { | ||
if (this[i] == obj) { | ||
return i | ||
} | ||
} | ||
return -1 | ||
} | ||
} | ||
|
||
if (!Array.prototype.map) { | ||
Array.prototype.map = function (f) { | ||
var result = []; | ||
for (var i = 0, l = this.length; i < l; i++) { | ||
result.push(f(this[i])) | ||
} | ||
return result | ||
} | ||
} | ||
|
||
var isArray = function (obj) { | ||
return Object.prototype.toString.call(obj) === "[object Array]" | ||
}; | ||
|
||
var isFunc = function (obj) { | ||
return Object.prototype.toString.call(obj) === "[object Function]" | ||
}; | ||
|
||
var ready = function (w, d) { | ||
var inited = false, | ||
loaded = false, | ||
queue = [], | ||
done, old; | ||
|
||
function go() { | ||
if (!inited) { | ||
if (!d.body) return setTimeout(go, 13); | ||
inited = true; | ||
if (queue) { | ||
var j, k = 0; | ||
while (j = queue[k++]) j.call(null); | ||
queue = null | ||
} | ||
} | ||
} | ||
|
||
function check() { | ||
if (loaded) return; | ||
loaded = true; | ||
if (d.readyState === "complete") return go(); | ||
if (d.addEventListener) { | ||
d.addEventListener("DOMContentLoaded", done, false); | ||
w.addEventListener("load", go, false) | ||
} else { | ||
if (d.attachEvent) { | ||
d.attachEvent("onreadystatechange", done); | ||
w.attachEvent("onload", go); | ||
var k = false; | ||
try { | ||
k = w.frameElement == null | ||
} catch (j) { | ||
} | ||
if (b.doScroll && k) ie() | ||
} else { | ||
old = w.onload; | ||
w.onload = function (e) { | ||
old(e); | ||
go() | ||
} | ||
} | ||
} | ||
} | ||
|
||
if (d.addEventListener) { | ||
done = function () { | ||
d.removeEventListener("DOMContentLoaded", done, false); | ||
go() | ||
} | ||
} else { | ||
if (d.attachEvent) { | ||
done = function () { | ||
if (d.readyState === "complete") { | ||
d.detachEvent("onreadystatechange", done); | ||
go() | ||
} | ||
} | ||
} | ||
} | ||
|
||
function ie() { | ||
if (inited) return; | ||
try { | ||
b.doScroll("left") | ||
} catch (j) { | ||
setTimeout(ie, 1); | ||
return | ||
} | ||
go() | ||
} | ||
|
||
return function (callback) { | ||
check(); | ||
if (inited) { | ||
callback.call(null) | ||
} else { | ||
queue.push(callback) | ||
} | ||
} | ||
}(w, d); | ||
|
||
if (w.addtocalendar && typeof w.addtocalendar.start == "function") return; | ||
if (!w.addtocalendar) w.addtocalendar = {}; | ||
|
||
addtocalendar.languages = { | ||
'de': 'In den Kalender', | ||
'en': 'Add to Calendar', | ||
'es': 'Añadir al Calendario', | ||
'fi': 'Lisää kalenteriin', | ||
'fr': 'Ajouter au calendrier', | ||
'hi': 'कैलेंडर में जोड़ें', | ||
'in': 'Tambahkan ke Kalender', | ||
'ja': 'カレンダーに追加', | ||
'ko': '캘린더에 추가', | ||
'pt': 'Adicionar ao calendário', | ||
'ru': 'Добавить в календарь', | ||
'sv': 'Lägg till i kalender', | ||
'uk': 'Додати в календар', | ||
'zh': '添加到日历', | ||
'no': 'Legg til i kalender' | ||
}; | ||
|
||
addtocalendar.calendar_urls = {} | ||
|
||
addtocalendar.loadSettings = function (element) { | ||
var settings = { | ||
'language': 'auto', | ||
'show-list-on': 'click', | ||
'calendars': [ | ||
'iCalendar', | ||
'Google Calendar', | ||
'Outlook', | ||
'Outlook Online', | ||
'Yahoo! Calendar' | ||
], | ||
'secure': 'auto', | ||
'on-button-click': function () { | ||
}, | ||
'on-calendar-click': function () { | ||
} | ||
}; | ||
|
||
for (var option in settings) { | ||
var pname = 'data-' + option; | ||
var eattr = element.getAttribute(pname); | ||
if (eattr != null) { | ||
|
||
if (isArray(settings[option])) { | ||
settings[option] = eattr.replace(/\s*,\s*/g, ',').replace(/^\s+|\s+$/g, '').split(','); | ||
continue; | ||
} | ||
|
||
if (isFunc(settings[option])) { | ||
var fn = window[eattr]; | ||
if (isFunc(fn)) { | ||
settings[option] = fn; | ||
} else { | ||
settings[option] = eval('(function(mouseEvent){' + eattr + '})'); | ||
} | ||
continue; | ||
} | ||
|
||
settings[option] = element.getAttribute(pname); | ||
} | ||
} | ||
|
||
return settings; | ||
}; | ||
|
||
addtocalendar.load = function () { | ||
|
||
var calendarsUrl = { | ||
'iCalendar': 'ical', | ||
'Google Calendar': 'google', | ||
'Outlook': 'outlook', | ||
'Outlook Online': 'outlookonline', | ||
'Yahoo! Calendar': 'yahoo' | ||
}; | ||
var utz = (-(new Date()).getTimezoneOffset().toString()); | ||
|
||
var languages = addtocalendar.languages; | ||
|
||
var dom = document.getElementsByTagName('*'); | ||
for (var tagnum = 0; tagnum < dom.length; tagnum++) { | ||
var tag_class = dom[tagnum].className; | ||
|
||
if (tag_class.length && tag_class.split(" ").indexOf('addtocalendar') != -1) { | ||
|
||
var settings = addtocalendar.loadSettings(dom[tagnum]); | ||
|
||
var protocol = 'http:'; | ||
if (settings['secure'] == 'auto') { | ||
protocol = location.protocol == 'https:' ? 'https:' : 'http:'; | ||
} else if (settings['secure'] == 'true') { | ||
protocol = 'https:'; | ||
} | ||
|
||
var tag_id = dom[tagnum].id; | ||
var atc_button_title = languages['en']; | ||
if (settings['language'] == 'auto') { | ||
var user_lang = "no_lang"; | ||
if (typeof navigator.language === "string") { | ||
user_lang = navigator.language.substr(0, 2) | ||
} else if (typeof navigator.browserLanguage === "string") { | ||
user_lang = navigator.browserLanguage.substr(0, 2) | ||
} | ||
|
||
if (languages.hasOwnProperty(user_lang)) { | ||
atc_button_title = languages[user_lang]; | ||
} | ||
} else if (languages.hasOwnProperty(settings['language'])) { | ||
atc_button_title = languages[settings['language']]; | ||
} | ||
|
||
var url_parameters = [ | ||
'utz=' + utz, | ||
'uln=' + navigator.language, | ||
'vjs=' + atc_version | ||
]; | ||
|
||
var addtocalendar_div = dom[tagnum].getElementsByTagName('var'); | ||
var event_number = -1; | ||
for (var varnum = 0; varnum < addtocalendar_div.length; varnum++) { | ||
var param_name = addtocalendar_div[varnum].className.replace("atc_", "").split(" ")[0]; | ||
var param_value = addtocalendar_div[varnum].innerHTML; | ||
|
||
if (param_name == 'event') { | ||
event_number++; | ||
continue; | ||
} | ||
|
||
if (param_name == addtocalendar_div[varnum].className) { | ||
if (param_name == 'atc-body') { | ||
atc_button_title = param_value; | ||
} | ||
continue; | ||
} | ||
|
||
if (event_number == -1) { | ||
continue; | ||
} | ||
|
||
url_parameters.push('e[' + event_number + '][' + param_name + ']' + '=' + encodeURIComponent(param_value)); | ||
} | ||
|
||
|
||
var atcb_link_id_val = (tag_id == '' ? '' : (tag_id + '_link') ); | ||
var atcb_list = document.createElement('ul'); | ||
atcb_list.className = 'atcb-list'; | ||
|
||
var menu_links = ''; | ||
for (var cnum in settings['calendars']) { | ||
if (!calendarsUrl.hasOwnProperty(settings['calendars'][cnum])) { | ||
continue; | ||
} | ||
var cal_id = calendarsUrl[settings['calendars'][cnum]]; | ||
var atcb_cal_link_id = (tag_id == '' ? '' : ('id="' + tag_id + '_' + cal_id + '_link"') ); | ||
menu_links += '<li class="atcb-item"><a ' + atcb_cal_link_id + ' class="atcb-item-link" href="' | ||
+ (cal_id == 'ical' && /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream ? 'webcal:' : protocol) | ||
+ atc_url | ||
+ cal_id + '?' + url_parameters.join('&') | ||
+ '" target="_blank" rel="nofollow">' + settings['calendars'][cnum] + '</a></li>'; | ||
} | ||
atcb_list.innerHTML = menu_links; | ||
|
||
var atcb_link; | ||
if (dom[tagnum].querySelector('.atcb-link') == undefined) { | ||
atcb_link = document.createElement('a'); | ||
atcb_link.className = 'atcb-link'; | ||
atcb_link.innerHTML = atc_button_title; | ||
atcb_link.id = atcb_link_id_val; | ||
atcb_link.tabIndex = 0; | ||
|
||
dom[tagnum].appendChild(atcb_link); | ||
dom[tagnum].appendChild(atcb_list); | ||
} else { | ||
atcb_link = dom[tagnum].querySelector('.atcb-link'); | ||
atcb_link.parentNode.appendChild(atcb_list); | ||
atcb_link.tabIndex = 0; | ||
if (atcb_link.id == '') { | ||
atcb_link.id = atcb_link_id_val; | ||
} | ||
} | ||
|
||
if (atcb_link.addEventListener) { | ||
atcb_link.addEventListener('click', settings['on-button-click'], false); | ||
} else { | ||
atcb_link.attachEvent('onclick', settings['on-button-click']); | ||
} | ||
|
||
var item_links = dom[tagnum].querySelectorAll('atcb-item-link'); | ||
|
||
for (var varnum = 0; varnum < item_links.length; varnum++) { | ||
var item_link = item_links[varnum]; | ||
if (item_link.addEventListener) { | ||
item_link.addEventListener('click', settings['on-calendar-click'], false); | ||
}else{ | ||
item_link.attachEvent('onclick', settings['on-calendar-click']); | ||
} | ||
|
||
} | ||
} | ||
} | ||
}; | ||
addtocalendar.load(); | ||
})(window, document); |
Oops, something went wrong.