From 7e8c559dea7579cb7e45660bcfa380ccc489b443 Mon Sep 17 00:00:00 2001 From: Mickey Elliott Date: Wed, 13 Jul 2016 16:09:55 -0700 Subject: [PATCH 01/13] Added extensibility to support frameworks like bootstrap. Adding some extra settings: 'dropdownLinkClass': 'atcb-link', 'dropdownLinkAttrs': [], // { key: 'data-toggle', value: 'dropdown' } 'dropdownMenuClass': 'atcb-list', 'dropdownMenuType': 'ul', // ul, div 'dropdownMenuItemClass': 'atcb-item', 'dropdownMenuItemType': 'li', // li, div, none 'dropdownMenuItemLinkClass': 'atcb-item-link', --- addtocalendar.js | 639 ++++++++++++++++++++++++----------------------- 1 file changed, 331 insertions(+), 308 deletions(-) diff --git a/addtocalendar.js b/addtocalendar.js index ca2e031..695cc77 100644 --- a/addtocalendar.js +++ b/addtocalendar.js @@ -1,308 +1,331 @@ -(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', - 'fr': 'Ajouter au calendrier', - 'hi': 'कैलेंडर में जोड़ें', - 'in': 'Tambahkan ke Kalender', - 'ja': 'カレンダーに追加', - 'ko': '캘린더에 추가', - 'pt': 'Adicionar ao calendário', - 'ru': 'Добавить в календарь', - 'uk': 'Додати в календар', - 'zh': '添加到日历' - }; - - 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 = ready(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_paramteres = [ - '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_paramteres.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 += '
  • ' + settings['calendars'][cnum] + '
  • '; - } - atcb_list.innerHTML = menu_links; - - if(dom[tagnum].getElementsByClassName('atcb-link')[0] == undefined){ - var 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 = 1; - - dom[tagnum].appendChild(atcb_link); - dom[tagnum].appendChild(atcb_list); - }else{ - var atcb_link = dom[tagnum].getElementsByClassName('atcb-link')[0]; - atcb_link.parentNode.appendChild(atcb_list); - atcb_link.tabIndex=1; - if(atcb_link.id == ''){ - atcb_link.id = atcb_link_id_val; - } - } - - dom[tagnum] - .getElementsByClassName('atcb-link')[0] - .addEventListener("click", settings['on-button-click'], false); - - var item_links = dom[tagnum].getElementsByClassName('atcb-item-link'); - - for (var varnum = 0; varnum < item_links.length; varnum++) { - item_links[varnum].addEventListener("click", settings['on-calendar-click'], false); - } - - } - } - }); - addtocalendar.load(); -})(window, document); + (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', + 'fr': 'Ajouter au calendrier', + 'hi': 'कैलेंडर में जोड़ें', + 'in': 'Tambahkan ke Kalender', + 'ja': 'カレンダーに追加', + 'ko': '캘린더에 추가', + 'pt': 'Adicionar ao calendário', + 'ru': 'Добавить в календарь', + 'uk': 'Додати в календар', + 'zh': '添加到日历' + }; + + 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', + + // Added extensibility for bootstrap support. + 'dropdownLinkClass': 'atcb-link', + 'dropdownMenuClass': 'atcb-list', + 'dropdownMenuType': 'ul', // ul, div + 'dropdownMenuItemClass': 'atcb-item', + 'dropdownMenuItemType': 'li', // li, div, none + 'dropdownMenuItemLinkClass': 'atcb-item-link', + '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 = ready(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_paramteres = [ + '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_paramteres.push('e['+event_number+']['+param_name+']' + '=' + encodeURIComponent(param_value)); + } + + + var atcb_link_id_val = (tag_id == ''?'':(tag_id + '_link') ); + var atcb_list = document.createElement(settings['dropdownMenuType']); + atcb_list.className = settings['dropdownMenuClass']; + + 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"')); + + + + if (settings['dropdownMenuItemType'] != 'none') { + menu_links += '<' + settings['dropdownMenuItemType'] + ' class="' + settings['dropdownMenuItemClass'] + '">'; // Create link with wrapper. + } + + menu_links += + '' + settings['calendars'][cnum] + + ''; + + if (settings['dropdownMenuItemType'] != 'none') { + menu_links += ''; // Create link with wrapper. + } + + + + } + atcb_list.innerHTML = menu_links; + + if (dom[tagnum].getElementsByClassName(settings['dropdownLinkClass'])[0] == undefined) { + var atcb_link = document.createElement('a'); + atcb_link.className = settings['dropdownLinkClass']; + atcb_link.innerHTML = atc_button_title; + atcb_link.id = atcb_link_id_val; + atcb_link.tabIndex = 1; + + dom[tagnum].appendChild(atcb_link); + dom[tagnum].appendChild(atcb_list); + }else{ + var atcb_link = dom[tagnum].getElementsByClassName(settings['dropdownLinkClass'])[0]; + atcb_link.parentNode.appendChild(atcb_list); + atcb_link.tabIndex=1; + if(atcb_link.id == ''){ + atcb_link.id = atcb_link_id_val; + } + } + + dom[tagnum] + .getElementsByClassName(settings['dropdownMenuClass'])[0] + .addEventListener("click", settings['on-button-click'], false); + + var item_links = dom[tagnum].getElementsByClassName(settings['dropdownMenuItemLinkClass']); + + for (var varnum = 0; varnum < item_links.length; varnum++) { + item_links[varnum].addEventListener("click", settings['on-calendar-click'], false); + } + + } + } + }); + addtocalendar.load(); + })(window, document); From f8b45f492ebf270213b90c5202a1c4e93151bf9f Mon Sep 17 00:00:00 2001 From: Mickey Elliott Date: Wed, 13 Jul 2016 16:10:27 -0700 Subject: [PATCH 02/13] Update addtocalendar.js --- addtocalendar.js | 43 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/addtocalendar.js b/addtocalendar.js index 695cc77..431806f 100644 --- a/addtocalendar.js +++ b/addtocalendar.js @@ -1,3 +1,31 @@ +/* http://addtocalendar.com/ + * + * +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/', @@ -149,6 +177,8 @@ // Added extensibility for bootstrap support. 'dropdownLinkClass': 'atcb-link', + 'dropdownLinkAttrs': [], // { key: 'data-toggle', value: 'dropdown' } + 'dropdownMenuClass': 'atcb-list', 'dropdownMenuType': 'ul', // ul, div 'dropdownMenuItemClass': 'atcb-item', @@ -276,20 +306,19 @@ - if (settings['dropdownMenuItemType'] != 'none') { - menu_links += '<' + settings['dropdownMenuItemType'] + ' class="' + settings['dropdownMenuItemClass'] + '">'; // Create link with wrapper. - } + if (settings['dropdownMenuItemType'] != 'none') { menu_links += '<' + settings['dropdownMenuItemType'] + ' class="' + settings['dropdownMenuItemClass'] + '">'; } // Create link with wrapper. + + menu_links += - ' 0)?( + Object.keys(settings['dropdownLinkAttrs']).forEach(function(key) { console.log(key);})):'') + ' href="' + (cal_id == 'ical' && /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream ? 'webcal:' : protocol) + atc_url + cal_id + '?' + url_paramteres.join('&') + '" target="_blank">' + settings['calendars'][cnum] + ''; - if (settings['dropdownMenuItemType'] != 'none') { - menu_links += ''; // Create link with wrapper. - } + if (settings['dropdownMenuItemType'] != 'none') { menu_links += ''; } // Create link with wrapper. From f11175130c7c34bbe707a092ec85192603889361 Mon Sep 17 00:00:00 2001 From: Mickey Elliott Date: Thu, 14 Jul 2016 10:28:55 -0700 Subject: [PATCH 03/13] Added Extensibility for frameworks like bootstrap. Added some more properties to make it easier to reformat the dropdown. // Added extensibility for bootstrap support. 'dropdownLinkClass': 'atcb-link', // btn btn-secondary dropdown-toggle 'dropdownLinkAttrs': [], // { key: 'data-toggle', value: 'dropdown' } 'dropdownMenuClass': 'atcb-list', // dropdown-menu 'dropdownMenuType': 'ul', // ul, div 'dropdownMenuItemClass': '', 'dropdownMenuItemType': 'li', // li, div, none 'dropdownMenuItemLinkClass': 'atcb-item-link', // dropdown-item --- addtocalendar.js | 110 +++++++++++++++++++++++++---------------------- 1 file changed, 59 insertions(+), 51 deletions(-) diff --git a/addtocalendar.js b/addtocalendar.js index 431806f..98432d6 100644 --- a/addtocalendar.js +++ b/addtocalendar.js @@ -1,31 +1,3 @@ -/* http://addtocalendar.com/ - * - * -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/', @@ -140,6 +112,14 @@ SOFTWARE. } }(w, d); + Object.size = function (obj) { + var size = 0, key; + for (key in obj) { + if (obj.hasOwnProperty(key)) size++; + } + return size; + }; + if (w.addtocalendar && typeof w.addtocalendar.start == "function") return; if (!w.addtocalendar) w.addtocalendar = {}; @@ -176,14 +156,13 @@ SOFTWARE. 'secure': 'auto', // Added extensibility for bootstrap support. - 'dropdownLinkClass': 'atcb-link', + 'dropdownLinkClass': 'atcb-link', // btn btn-secondary dropdown-toggle 'dropdownLinkAttrs': [], // { key: 'data-toggle', value: 'dropdown' } - - 'dropdownMenuClass': 'atcb-list', + 'dropdownMenuClass': 'atcb-list', // dropdown-menu 'dropdownMenuType': 'ul', // ul, div - 'dropdownMenuItemClass': 'atcb-item', + 'dropdownMenuItemClass': '', 'dropdownMenuItemType': 'li', // li, div, none - 'dropdownMenuItemLinkClass': 'atcb-item-link', + 'dropdownMenuItemLinkClass': 'atcb-item-link', // dropdown-item 'on-button-click':function(){}, 'on-calendar-click':function(){} }; @@ -191,24 +170,48 @@ SOFTWARE. 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 (eattr != null) { + console.log(eattr); + + // convert string to array. + if (pname == 'data-dropdownLinkAttrs') { + + // JavaScript array of JavaScript objects + var objs = eattr.replace(/([a-zA-Z0-9]+?):/g, '"$1":'); + objs = objs.replace(/'/g, '"'); + var data = JSON.parse(objs); + //console.log('----------------------'); + console.log(data); + console.log(data.length); + //console.log('----------------------'); - if(isFunc(settings[option])){ - var fn = window[eattr]; - if(isFunc(fn)) { - settings[option]=fn; - }else { - settings[option]=eval('(function(mouseEvent){'+eattr+'})'); + eattr = data; + settings[option] = eattr; + } else { + + 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; } - continue; + + settings[option] = element.getAttribute(pname); + } + - settings[option]=element.getAttribute(pname); + } } @@ -308,18 +311,15 @@ SOFTWARE. if (settings['dropdownMenuItemType'] != 'none') { menu_links += '<' + settings['dropdownMenuItemType'] + ' class="' + settings['dropdownMenuItemClass'] + '">'; } // Create link with wrapper. - + menu_links += - ' 0)?( - Object.keys(settings['dropdownLinkAttrs']).forEach(function(key) { console.log(key);})):'') + ' href="' + '' + settings['calendars'][cnum] + ''; - if (settings['dropdownMenuItemType'] != 'none') { menu_links += ''; } // Create link with wrapper. - } @@ -332,6 +332,14 @@ SOFTWARE. atcb_link.id = atcb_link_id_val; atcb_link.tabIndex = 1; + if (settings['dropdownLinkAttrs'] != undefined && settings['dropdownLinkAttrs'].length > 0) { + for (i = 0; i < settings['dropdownLinkAttrs'].length; ++i) { + //console.log('*******************************'); + atcb_link.setAttribute(settings['dropdownLinkAttrs'][i].key, settings['dropdownLinkAttrs'][i].value) + } + } + + dom[tagnum].appendChild(atcb_link); dom[tagnum].appendChild(atcb_list); }else{ From 6157380bef3abe7a36466d2b6bb47b3051433733 Mon Sep 17 00:00:00 2001 From: Mickey Elliott Date: Thu, 14 Jul 2016 10:33:45 -0700 Subject: [PATCH 04/13] Update sample.html --- sample.html | 71 +++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 55 insertions(+), 16 deletions(-) diff --git a/sample.html b/sample.html index 8f9dea4..48d0059 100644 --- a/sample.html +++ b/sample.html @@ -4,23 +4,26 @@ It allows users to easily schedule the event in their calendar. Learn more: http://addtocalendar.com --> - - + + + + + + + + + + + - - - - - - + + + +

    Hello, world!

    + + + 2014-05-04 12:00:00 @@ -33,5 +36,41 @@ luke@starwars.com - + + + +
    + + +
    + + + + + + + + + + + + + From edc3b04b2fcf4dfe2076c029290b768dbda992a4 Mon Sep 17 00:00:00 2001 From: Mickey Elliott Date: Thu, 14 Jul 2016 10:34:29 -0700 Subject: [PATCH 05/13] Delete addtocalendar.min.js --- addtocalendar.min.js | 1 - 1 file changed, 1 deletion(-) delete mode 100644 addtocalendar.min.js diff --git a/addtocalendar.min.js b/addtocalendar.min.js deleted file mode 100644 index f56a129..0000000 --- a/addtocalendar.min.js +++ /dev/null @@ -1 +0,0 @@ -!function(w,d){var atc_url="//addtocalendar.com/atc/",atc_version="1.5";Array.indexOf||(Array.prototype.indexOf=function(e){for(var t=0,a=this.length;a>t;t++)if(this[t]==e)return t;return-1}),Array.prototype.map||(Array.prototype.map=function(e){for(var t=[],a=0,n=this.length;n>a;a++)t.push(e(this[a]));return t});var isArray=function(e){return"[object Array]"===Object.prototype.toString.call(e)},isFunc=function(e){return"[object Function]"===Object.prototype.toString.call(e)},ready=function(e,t){function a(){if(!i){if(!t.body)return setTimeout(a,13);if(i=!0,c){for(var e,n=0;e=c[n++];)e.call(null);c=null}}}function n(){if(!d){if(d=!0,"complete"===t.readyState)return a();if(t.addEventListener)t.addEventListener("DOMContentLoaded",r,!1),e.addEventListener("load",a,!1);else if(t.attachEvent){t.attachEvent("onreadystatechange",r),e.attachEvent("onload",a);var n=!1;try{n=null==e.frameElement}catch(i){}b.doScroll&&n&&o()}else l=e.onload,e.onload=function(e){l(e),a()}}}function o(){if(!i){try{b.doScroll("left")}catch(e){return void setTimeout(o,1)}a()}}var r,l,i=!1,d=!1,c=[];return t.addEventListener?r=function(){t.removeEventListener("DOMContentLoaded",r,!1),a()}:t.attachEvent&&(r=function(){"complete"===t.readyState&&(t.detachEvent("onreadystatechange",r),a())}),function(e){n(),i?e.call(null):c.push(e)}}(w,d);w.addtocalendar&&"function"==typeof w.addtocalendar.start||(w.addtocalendar||(w.addtocalendar={}),addtocalendar.languages={de:"In den Kalender",en:"Add to Calendar",es:"Añadir al Calendario",fr:"Ajouter au calendrier",hi:"कैलेंडर में जोड़ें","in":"Tambahkan ke Kalender",ja:"カレンダーに追加",ko:"캘린더에 추가",pt:"Adicionar ao calendário",ru:"Добавить в календарь",uk:"Додати в календар",zh:"添加到日历"},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,eattr=element.getAttribute(pname);if(null!=eattr){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];isFunc(fn)?settings[option]=fn:settings[option]=eval("(function(mouseEvent){"+eattr+"})");continue}settings[option]=element.getAttribute(pname)}}return settings},addtocalendar.load=ready(function(){for(var e={iCalendar:"ical","Google Calendar":"google",Outlook:"outlook","Outlook Online":"outlookonline","Yahoo! Calendar":"yahoo"},t=-(new Date).getTimezoneOffset().toString(),a=addtocalendar.languages,n=document.getElementsByTagName("*"),o=0;o'+l.calendars[k]+""}if(y.innerHTML=b,void 0==n[o].getElementsByClassName("atcb-link")[0]){var C=document.createElement("a");C.className="atcb-link",C.innerHTML=c,C.id=h,C.tabIndex=1,n[o].appendChild(C),n[o].appendChild(y)}else{var C=n[o].getElementsByClassName("atcb-link")[0];C.parentNode.appendChild(y),C.tabIndex=1,""==C.id&&(C.id=h)}n[o].getElementsByClassName("atcb-link")[0].addEventListener("click",l["on-button-click"],!1);for(var O=n[o].getElementsByClassName("atcb-item-link"),p=0;p Date: Thu, 14 Jul 2016 10:34:53 -0700 Subject: [PATCH 06/13] Delete package.json --- package.json | 26 -------------------------- 1 file changed, 26 deletions(-) delete mode 100644 package.json diff --git a/package.json b/package.json deleted file mode 100644 index 0c74384..0000000 --- a/package.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "name": "addtocalendar", - "version": "1.5.3", - "description": "Free customizable widget \\\"Add to Calendar\\\" for event page. It allows users to easily schedule the event in their calendar.", - "main": "atc.min.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/AddToCalendar/addtocalendar.git" - }, - "keywords": [ - "calendar", - "widget", - "button", - "event", - "schedule" - ], - "author": "support@addtocalendar.com", - "license": "MIT", - "bugs": { - "url": "https://github.com/AddToCalendar/addtocalendar/issues" - }, - "homepage": "http://addtocalendar.com" -} From 419efe61a20d7aa3e7f8e64169596873cea93597 Mon Sep 17 00:00:00 2001 From: Mickey Elliott Date: Thu, 14 Jul 2016 10:36:12 -0700 Subject: [PATCH 07/13] Update README.md --- README.md | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 4de071b..45ec1b4 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,8 @@ AddToCalendar ============= -Free customizable JavaScript widget "Add to Calendar" for event page. It allows users to easily schedule the event in their calendar. Learn more: http://addtocalendar.com +This is a fork from http://addtocalendar.com. + +I added some data properties so that I could add this gracefully into my bootstrap framework. -Install from NPM -================ -``` -$ npm install addtocalendar -``` +Free customizable JavaScript widget "Add to Calendar" for event page. It allows users to easily schedule the event in their calendar. Learn more: http://addtocalendar.com From bb09fbe77db79305333d9dd04be9be7a6fce1555 Mon Sep 17 00:00:00 2001 From: Mickey Elliott Date: Thu, 14 Jul 2016 10:36:32 -0700 Subject: [PATCH 08/13] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 45ec1b4..4c1c483 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ AddToCalendar ============= -This is a fork from http://addtocalendar.com. +This is a fork from https://github.com/AddToCalendar/addtocalendar I added some data properties so that I could add this gracefully into my bootstrap framework. From 9fcb32761b3cbb8c9adb69a0f27694714ec021df Mon Sep 17 00:00:00 2001 From: Mickey Elliott Date: Thu, 14 Jul 2016 10:37:09 -0700 Subject: [PATCH 09/13] Update sample.html --- sample.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sample.html b/sample.html index 48d0059..1ea9602 100644 --- a/sample.html +++ b/sample.html @@ -70,7 +70,7 @@

    Hello, world!

    - + From 741e8e3aba1dbb5df190c1e600638a5b19e23591 Mon Sep 17 00:00:00 2001 From: Mickey Elliott Date: Thu, 14 Jul 2016 10:37:25 -0700 Subject: [PATCH 10/13] Update sample.html --- sample.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sample.html b/sample.html index 1ea9602..80f4dee 100644 --- a/sample.html +++ b/sample.html @@ -70,7 +70,7 @@

    Hello, world!

    - + From f6d193cef7a9cb24b600e44e8ed550060f20f020 Mon Sep 17 00:00:00 2001 From: Mickey Elliott Date: Thu, 14 Jul 2016 10:39:09 -0700 Subject: [PATCH 11/13] Update sample.html --- sample.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sample.html b/sample.html index 80f4dee..16b60a9 100644 --- a/sample.html +++ b/sample.html @@ -70,7 +70,7 @@

    Hello, world!

    - + From 5072004731ea67c27d26749ae5d368075b447ee7 Mon Sep 17 00:00:00 2001 From: Mickey Elliott Date: Thu, 14 Jul 2016 10:44:22 -0700 Subject: [PATCH 12/13] Update sample.html --- sample.html | 123 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 74 insertions(+), 49 deletions(-) diff --git a/sample.html b/sample.html index 16b60a9..fc23f3f 100644 --- a/sample.html +++ b/sample.html @@ -1,6 +1,6 @@ @@ -14,63 +14,88 @@ - + - + - +

    Hello, world!

    - - - - - - 2014-05-04 12:00:00 - 2014-05-04 18:00:00 - Europe/London - Star Wars Day Party - May the force be with you - Tatooine - Luke Skywalker - luke@starwars.com - - - - - -
    - - + + + + +
    + +
    +
    +

    AddToCalendar

    +

    + This is a fork from https://github.com/AddToCalendar/addtocalendar. I added some data properties so that I could add this gracefully into my bootstrap framework. Free customizable JavaScript widget "Add to Calendar" for event page. It allows users to easily schedule the event in their calendar. Learn more: http://addtocalendar.com +

    +
    +
    + +
    +
    +

    Origional Template

    + + + + 2014-05-04 12:00:00 + 2014-05-04 18:00:00 + Europe/London + Star Wars Day Party + May the force be with you + Tatooine + Luke Skywalker + luke@starwars.com + + + +
    + +
    +

    Bootstrap Template

    + +
    + +
    + + +
    +
    +
    - - - - - - - + From e93887ffe53b241ec81394834eaa7a4e56d78329 Mon Sep 17 00:00:00 2001 From: Mickey Elliott Date: Thu, 14 Jul 2016 10:51:22 -0700 Subject: [PATCH 13/13] Update sample.html --- sample.html | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/sample.html b/sample.html index fc23f3f..88485c8 100644 --- a/sample.html +++ b/sample.html @@ -36,16 +36,21 @@

    Hello, world!

    -

    AddToCalendar

    -

    - This is a fork from https://github.com/AddToCalendar/addtocalendar. I added some data properties so that I could add this gracefully into my bootstrap framework. Free customizable JavaScript widget "Add to Calendar" for event page. It allows users to easily schedule the event in their calendar. Learn more: http://addtocalendar.com -

    + +
    +
    +

    AddToCalendar

    +

    + This is a fork from https://github.com/AddToCalendar/addtocalendar. I added some data properties so that I could add this gracefully into my bootstrap framework. Free customizable JavaScript widget "Add to Calendar" for event page. It allows users to easily schedule the event in their calendar. Learn more: http://addtocalendar.com +

    +
    +
    -
    -

    Origional Template

    +
    +
    Origional
    @@ -62,12 +67,12 @@

    Origional Template

    -
    -

    Bootstrap Template

    +
    +
    Bootstrap
    -