/* jquery.gcal_flow_126_Weddings20190609.txt */ // Version: 1.2.6 // Generated by CoffeeScript 1.4.0 // Function gCalFlow.prototype.parse_date // Added "offset=0;" because when in Summer time and looking at times in non-Summer time, the hour was out by an hour. Ignoring the offset corrects this as times are not stored according to BST or not. // Function gCalFlow.prototype.gcal_url // Changed function to handle Google's V3 API // Added new option 'apikey' // Function gCalFlow.prototype.render_data // Removed call to gcf-item-update-date as don't use it so unnecessary call. // Added code to restrict description to 70 characters max. // Added code to delete Map coordinates and Postcode in Location. // Added code to restrict weddings displayed to a particular church or to all churches - can't do this in the query string! // Added code to hide the header if no weddings found // Added IF to amend page header to include the name of the church if specified // Changed function to handle Google's V3 API // Added code to handle if these fields are blank: ent.summary, ent.description, ent.location (function() { var $, gCalFlow, log, methods, pad_zero, _ref; // Turn on logging via Browser Console // window._gCalFlow_debug = true; $ = jQuery; if ((typeof window !== "undefined" && window !== null) && (window._gCalFlow_debug != null) && (typeof console !== "undefined" && console !== null)) { log = console; if ((_ref = log.debug) == null) { log.debug = log.log; } } else { log = {}; log.error = log.warn = log.log = log.info = log.debug = function() {}; } pad_zero = function(num, size) { var i, ret, _i, _ref1; if (size == null) { size = 2; } if (10 * (size - 1) <= num) { return num; } ret = ""; for (i = _i = 1, _ref1 = size - ("" + num).length; 1 <= _ref1 ? _i <= _ref1 : _i >= _ref1; i = 1 <= _ref1 ? ++_i : --_i) { ret = ret.concat("0"); } return ret.concat(num); }; gCalFlow = (function() { gCalFlow.prototype.target = null; gCalFlow.prototype.template = $("
\n
\n
\n \n
\n
\n
\n
\n
\n
\n []\n
\n
\n \n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n LastUpdate: \n
\n
"); gCalFlow.prototype.opts = { maxitem: 15, calid: null, mode: 'upcoming', feed_url: null, auto_scroll: true, scroll_interval: 10 * 1000, link_title: true, link_item_title: true, link_item_description: false, link_target: '_blank', item_description_as_html: false, callback: null, no_items_html: '', globalize_culture: (typeof navigator !== "undefined" && navigator !== null) && (navigator.browserLanguage || navigator.language || navigator.userLanguage), globalize_fmt_datetime: 'f', globalize_fmt_date: 'D', globalize_fmt_time: 't', globalize_fmt_monthday: 'M', date_formatter: function(d, allday_p) { var fmtstr; if ((typeof Globalize !== "undefined" && Globalize !== null) && (Globalize.format != null)) { if (allday_p) { fmtstr = this.globalize_fmt_date; } else { fmtstr = this.globalize_fmt_datetime; } return Globalize.format(d, fmtstr); } else { if (allday_p) { return "" + (d.getFullYear()) + "-" + (pad_zero(d.getMonth() + 1)) + "-" + (pad_zero(d.getDate())); } else { return "" + (d.getFullYear()) + "-" + (pad_zero(d.getMonth() + 1)) + "-" + (pad_zero(d.getDate())) + " " + (pad_zero(d.getHours())) + ":" + (pad_zero(d.getMinutes())); } } }, daterange_formatter: function(sd, ed, allday_p) { var endstr, ret; ret = this.date_formatter(sd, allday_p); if (allday_p) { ed = new Date(ed.getTime() - 86400 * 1000); } endstr = ''; if (sd.getDate() !== ed.getDate() || sd.getMonth() !== ed.getMonth()) { if ((typeof Globalize !== "undefined" && Globalize !== null) && (Globalize.format != null)) { endstr += Globalize.format(ed, this.globalize_fmt_monthday); } else { endstr += "" + (pad_zero(ed.getMonth() + 1)) + "-" + (pad_zero(ed.getDate())); } } if (!allday_p && (sd.getHours() !== ed.getHours() || sd.getMinutes() !== ed.getMinutes())) { if ((typeof Globalize !== "undefined" && Globalize !== null) && (Globalize.format != null)) { endstr += Globalize.format(ed, this.globalize_fmt_time); } else { endstr += " " + (pad_zero(ed.getHours())) + ":" + (pad_zero(ed.getMinutes())); } } if (endstr) { ret += " - " + endstr; } return ret; } }; function gCalFlow(target, opts) { this.target = target; target.addClass('gCalFlow'); if (target.children().length > 0) { log.debug("Target node has children, use target element as template."); this.template = target; } this.update_opts(opts); } gCalFlow.prototype.update_opts = function(new_opts) { log.debug("update_opts was called"); log.debug("old options:", this.opts); this.opts = $.extend({}, this.opts, new_opts); return log.debug("new options:", this.opts); }; gCalFlow.prototype.gcal_url = function() { if (!this.opts.calid && !this.opts.feed_url) { log.error("Option calid and feed_url are missing. Abort URL generation"); this.target.text("Error: You need to set 'calid' or 'feed_url' option."); throw "gCalFlow: calid and feed_url missing"; } if (this.opts.feed_url) { return this.opts.feed_url; } else if (this.opts.mode === 'updates') { return "https://www.googleapis.com/calendar/v3/calendars/" + this.opts.calid + "/events?orderBy=updated&singleEvents=true&maxResults=" + this.opts.maxitem + "&key=" + this.opts.apikey; } else { return "https://www.googleapis.com/calendar/v3/calendars/" + this.opts.calid + "/events?orderBy=startTime&singleEvents=true&maxResults=" + this.opts.maxitem + "&key=" + this.opts.apikey; } }; gCalFlow.prototype.fetch = function() { var success_handler, _this = this; log.debug("Starting ajax call for " + (this.gcal_url())); success_handler = function(data) { log.debug("Ajax call success. Response data:", data); return _this.render_data(data, _this); }; return $.ajax({ success: success_handler, dataType: "jsonp", url: this.gcal_url() }); }; gCalFlow.prototype.parse_date = function(dstr) { var day, hour, m, min, mon, offset, ret, sec, year; if (m = dstr.match(/^(\d{4})-(\d{2})-(\d{2})$/)) { return new Date(parseInt(m[1], 10), parseInt(m[2], 10) - 1, parseInt(m[3], 10), 0, 0, 0); } offset = (new Date()).getTimezoneOffset() * 60 * 1000; year = mon = day = null; hour = min = sec = 0; if (m = dstr.match(/^(\d{4})-(\d{2})-(\d{2})[T ](\d{2}):(\d{2}):(\d{2}(?:\.\d+)?)(Z|([+-])(\d{2}):(\d{2}))$/)) { year = parseInt(m[1], 10); mon = parseInt(m[2], 10); day = parseInt(m[3], 10); hour = parseInt(m[4], 10); min = parseInt(m[5], 10); sec = parseInt(m[6], 10); if (m[7] !== "Z") { offset += (m[8] === "+" ? 1 : -1) * (parseInt(m[9], 10) * 60 + parseInt(m[10], 10)) * 1000 * 60; } } else { log.warn("Time parse error! Unknown time pattern: " + dstr); return new Date(1970, 1, 1, 0, 0, 0); } log.debug("time parse (gap to local): " + offset); offset = 0; // RC: Ignore timezone offsets as the time does not take it into account! ret = new Date(new Date(year, mon - 1, day, hour, min, sec).getTime() - offset); log.debug("time parse: " + dstr + " -> ", ret); return ret; }; gCalFlow.prototype.render_data = function(data) { var ci, desc_body_method, ed, ent, et, etf, feed, ic, it, items, link, sd, st, stf, t, titlelink, _i, _len, _ref1, _ref2; var tmp, myCount = 0; // RC: Added tmp for substring manipulation and myCount for counting number of weddings log.debug("start rendering for data:", data); //**log.debug("summary:", data['summary']); //**items = data['items']; //**log.debug("Item 3:", items[3].summary); // Was: feed = data.feed; t = this.template.clone(); titlelink = (_ref1 = this.opts.titlelink) != null ? _ref1 : "https://www.google.com/calendar/embed?src=" + this.opts.calid; if (this.opts.link_title) { t.find('.gcf-title').html($("").attr({ target: this.opts.link_target, href: titlelink }).text(data['summary'])); // Was: .text(feed.title.$t) } else { t.find('.gcf-title').text(data['summary']); // Was: .text(feed.title.$t) } t.find('.gcf-link').attr({ target: this.opts.link_target, href: titlelink }); //t.find('.gcf-last-update').html(this.opts.date_formatter(this.parse_date(feed.updated.$t))); // RC: Don't need this so don't call date_formatter it = t.find('.gcf-item-block'); it.detach(); it = $(it[0]); log.debug("item block template:", it); items = $(); log.debug("render entries:", data['items'].length); // Was: feed.entry); if (this.opts.item_description_as_html) { desc_body_method = 'html'; } else { desc_body_method = 'text'; } if ((data['items'] != null) && data['items'].length > 0) { // Was: if ((feed.entry != null) && feed.entry.length > 0) { _ref2 = data['items'].slice(0, +this.opts.maxitem + 1 || 9e9); // Was: _ref2 = feed.entry.slice(0, +this.opts.maxitem + 1 || 9e9); for (_i = 0, _len = _ref2.length; _i < _len; _i++) { ent = _ref2[_i]; log.debug("formatting entry:", ent); ci = it.clone(); if (ent.start) { // Was: if (ent.gd$when) { if (ent.start.dateTime) { st = ent.start.dateTime; } else { st = ent.start.date; } // Was: st = ent.gd$when[0].startTime; sd = this.parse_date(st); stf = this.opts.date_formatter(sd, st.indexOf(':') < 0); ci.find('.gcf-item-date').html(stf); ci.find('.gcf-item-start-date').html(stf); if (ent.end.dateTime) { et = ent.end.dateTime; } else { et = ent.end.date; } // Was: et = ent.gd$when[0].endTime; ed = this.parse_date(et); //etf = this.opts.date_formatter(ed, et.indexOf(':') < 0); // RC: Don't need this so don't call date_formatter ci.find('.gcf-item-end-date').html(etf); ci.find('.gcf-item-daterange').html(this.opts.daterange_formatter(sd, ed, st.indexOf(':') < 0)); } //ci.find('.gcf-item-update-date').html(this.opts.date_formatter(this.parse_date(ent.updated.$t), false)); // RC: Don't need this so don't call date_formatter link = $('').attr({ target: this.opts.link_target, href: ent.htmlLink }); // Was: href: ent.link[0].href tmp = "Event"; if (ent.summary) { tmp = ent.summary; } if (this.opts.link_item_title) { ci.find('.gcf-item-title').html(link.clone().text(tmp)); // Was: (ent.title.$t) } else { ci.find('.gcf-item-title').text(tmp); // Was: (ent.title.$t) } // RC: Added IF to restrict entries to a particular church if (!(this.opts.my_church) || ((this.opts.my_church) && (((ent.summary).substr(0,4)).toLowerCase() == (this.opts.my_church_is.substr(0,4)).toLowerCase()))) { // Was: if (!(this.opts.my_church) || ((this.opts.my_church) && (((ent.title.$t).substr(0,4)).toLowerCase() == (this.opts.my_church_is.substr(0,4)).toLowerCase()))) { myCount += 1; // RC: Added 2 lines to restrict description to 70 characters max. if (ent.description) { tmp = ent.description; // Was: ent.content.$t; // if (tmp.length > 70) { tmp = tmp.substr(0,70)+"..."; } // RC: Replaced "ent.content.$t" with "tmp" in IF statement if (this.opts.link_item_description) { ci.find('.gcf-item-description').html(link.clone()[desc_body_method](tmp)); } else { ci.find('.gcf-item-description')[desc_body_method](tmp); } } // // RC: Added 2 lines to remove Map coordinates and Postcode in Location // if (ent.location) { // tmp = (ent.location).replace("52.865548,-1.204816",""); // Was: tmp = (ent.gd$where[0].valueString).replace("52.865548,-1.204816",""); // tmp = tmp.replace(", NG11 0HW",""); // ci.find('.gcf-item-location').text(tmp); // Replaced "ent.gd$where[0].valueString" with "tmp" // } ci.find('.gcf-item-link').attr({ href: ent.htmlLink }); // Was: href: ent.link[0].href log.debug("formatted item entry:", ci[0]); items.push(ci[0]); } } // } else { // items = $('').html(this.opts.no_items_html); // RC: Was: '
' } log.debug("Number of weddings:", myCount); // RC: Added IF to check if no weddings found for church, and hide the table header if (myCount == 0) { items = $('').html(this.opts.no_items_html); t.find('#with-my-template-head').css('display','none'); } // RC: Added IF to amend page header to include the name of the church if specified if (this.opts.my_church) { $('#headingContainer').html('

Weddings List ~ '+this.opts.my_church_is+'

'); } $('#id_453_logoX').html('
List By Church:
'); log.debug("rendering done. number of entries:", items.length); log.debug("formatted item entry array:", items); ic = t.find('.gcf-item-container-block'); log.debug("item container element:", ic); ic.html(items); this.target.html(t.html()); this.bind_scroll(); if (this.opts.callback) { return this.opts.callback.apply(this.target); } }; gCalFlow.prototype.bind_scroll = function() { var scroll_children, scroll_container, scroll_timer, scroller, state; scroll_container = this.target.find('.gcf-item-container-block'); scroll_children = scroll_container.find(".gcf-item-block"); log.debug("scroll container:", scroll_container); if (!this.opts.auto_scroll || scroll_container.size() < 1 || scroll_children.size() < 2) { return; } state = { idx: 0 }; scroller = function() { var scroll_to; log.debug("current scroll position:", scroll_container.scrollTop()); log.debug("scroll capacity:", scroll_container[0].scrollHeight - scroll_container[0].clientHeight); if (typeof scroll_children[state.idx] === 'undefined' || scroll_container.scrollTop() >= scroll_container[0].scrollHeight - scroll_container[0].clientHeight) { log.debug("scroll to top"); state.idx = 0; return scroll_container.animate({ scrollTop: scroll_children[0].offsetTop }); } else { scroll_to = scroll_children[state.idx].offsetTop; log.debug("scroll to " + scroll_to + "px"); scroll_container.animate({ scrollTop: scroll_to }); return state.idx += 1; } }; return scroll_timer = setInterval(scroller, this.opts.scroll_interval); }; return gCalFlow; })(); methods = { init: function(opts) { var data; if (opts == null) { opts = {}; } data = this.data('gCalFlow'); if (!data) { return this.data('gCalFlow', { target: this, obj: new gCalFlow(this, opts) }); } }, destroy: function() { var data; data = this.data('gCalFlow'); data.obj.target = null; $(window).unbind('.gCalFlow'); data.gCalFlow.remove(); return this.removeData('gCalFlow'); }, render: function() { if ((typeof Globalize !== "undefined" && Globalize !== null) && (Globalize.culture != null)) { Globalize.culture(this.data('gCalFlow').obj.opts.globalize_culture); } return this.data('gCalFlow').obj.fetch(); } }; $.fn.gCalFlow = function(method) { var orig_args; orig_args = arguments; if (typeof method === 'object' || !method) { return this.each(function() { methods.init.apply($(this), orig_args); return methods.render.apply($(this), orig_args); }); } else if (methods[method]) { return this.each(function() { return methods[method].apply($(this), Array.prototype.slice.call(orig_args, 1)); }); } else if (method === 'version') { return "1.2.6"; } else { return $.error("Method " + method + " does not exist on jQuery.gCalFlow"); } }; }).call(this);