1// Generated by CoffeeScript 1.4.0 2(function() { 3 var $, gCalFlow, log, methods, pad_zero, prio, _i, _len, _ref; 4 5 $ = jQuery; 6 7 log = {}; 8 9 log.error = log.warn = log.log = log.info = log.debug = function() {}; 10 11 if ((typeof window !== "undefined" && window !== null) && (typeof console !== "undefined" && console !== null) && (console.log != null)) { 12 if (!window._gCalFlow_quiet) { 13 _ref = ['error', 'warn', 'info']; 14 for (_i = 0, _len = _ref.length; _i < _len; _i++) { 15 prio = _ref[_i]; 16 log[prio] = function() { 17 if (console[prio]) { 18 return console[prio].apply(console, arguments); 19 } else { 20 return console.log.apply(console, arguments); 21 } 22 }; 23 } 24 } 25 if (window._gCalFlow_debug) { 26 log.debug = function() { 27 if (console.debug != null) { 28 return console.debug.apply(console, arguments); 29 } else { 30 return console.log.apply(console, arguments); 31 } 32 }; 33 } 34 } 35 36 pad_zero = function(num, size) { 37 var i, ret, _j, _ref1; 38 if (size == null) { 39 size = 2; 40 } 41 if (10 * (size - 1) <= num) { 42 return num; 43 } 44 ret = ""; 45 for (i = _j = 1, _ref1 = size - ("" + num).length; 1 <= _ref1 ? _j <= _ref1 : _j >= _ref1; i = 1 <= _ref1 ? ++_j : --_j) { 46 ret = ret.concat("0"); 47 } 48 return ret.concat(num); 49 }; 50 51 gCalFlow = (function() { 52 53 gCalFlow.demo_apikey = 'AIzaSyD0vtTUjLXzH4oKCzNRDymL6E3jKBympf0'; 54 55 gCalFlow.prototype.target = null; 56 57 gCalFlow.prototype.template = $("<div class=\"gCalFlow\">\n <div class=\"gcf-header-block\">\n <div class=\"gcf-title-block\">
57\n <span class=\"gcf-title\"></span>\n </div>\n </div>\n <div class=\"gcf-item-container-block\">\n <div class=\"gcf-item-block\">\n <div class=\"gcf-item-header-block\">\n <div class=\"gcf-item-date-block\">\n [<span class=\"gcf-item-daterange\"></span>]\n </div>\n <div class=\"gcf-item-title-block\">\n <strong class=\"gcf-item-title\"></strong>\n </div>\n </div>\n <div class=\"gcf-item-body-block\">\n <div class=\"gcf-item-description\">\n </div>\n <div class=\"gcf-item-location\">\n </div>\n </div>\n </div>\n </div>\n <div class=\"gcf-last-update-block\">\n LastUpdate: <span class=\"gcf-last-update\"></span>\n </div>\n</div>"); 58 59 gCalFlow.prototype.opts = { 60 maxitem: 15, 61 calid: null, 62 apikey: gCalFlow.demo_apikey, 63 mode: 'upcoming', 64 feed_url: null, 65 auto_scroll: true, 66 scroll_interval: 10 * 1000, 67 link_title: true, 68 link_item_title: true, 69 link_item_description: false, 70 link_item_location: false, 71 link_target: '_blank', 72 item_description_as_html: false, 73 callback: null, 74 no_items_html: '', 75 globalize_culture: (typeof navigator !== "undefined" && navigator !== null) && (navigator.browserLanguage || navigator.language || navigator.userLanguage), 76 globalize_fmt_datetime: 'f', 77 globalize_fmt_date: 'D', 78 globalize_fmt_time: 't', 79 globalize_fmt_monthday: 'M', 80 date_formatter: function(d, allday_p) { 81 var fmtstr; 82 if ((typeof Globalize !== "undefined" && Globalize !== null) && (Globalize.format != null)) { 83 if (allday_p) { 84 fmtstr = this.globalize_fmt_date; 85 } else { 86 fmtstr = this.globalize_fmt_datetime; 87 } 88 return Globalize.format(d, fmtstr); 89 } else { 90 if (allday_p) { 91 return "" + (d.getFullYear()) + "-" + (pad_zero(d.getMonth() + 1)) + "-" + (pad_zero(d.getDate())); 92 } else { 93 return "" + (d.getFullYear()) + "-" + (pad_zero(d.getMonth() + 1)) + "-" + (pad_zero(d.getDate())) + " " + (pad_zero(d.getHours())) + ":" + (pad_zero(d.getMinutes())); 94 } 95 } 96 }, 97 daterange_formatter: function(sd, ed, allday_p) { 98 var endstr, ret; 99 ret = this.date_formatter(sd, allday_p); 100 if (allday_p) { 101 ed = new Date(ed.getTime() - 86400 * 1000); 102 } 103 endstr = ''; 104 if (sd.getDate() !== ed.getDate() || sd.getMonth() !== ed.getMonth()) { 105 if ((typeof Globalize !== "undefined" && Globalize !== null) && (Globalize.format != null)) { 106 endstr += Globalize.format(ed, this.globalize_fmt_monthday); 107 } else { 108 endstr += "" + (pad_zero(ed.getMonth() + 1)) + "-" + (pad_zero(ed.getDate())); 109 } 110 } 111 if (!allday_p && (sd.getHours() !== ed.getHours() || sd.getMinutes() !== ed.getMinutes())) { 112 if ((typeof Globalize !== "undefined" && Globalize !== null) && (Globalize.format != null)) { 113 endstr += Globalize.format(ed, this.globalize_fmt_time); 114 } else { 115 endstr += " " + (pad_zero(ed.getHours())) + ":" + (pad_zero(ed.getMinutes())); 116 } 117 } 118 if (endstr) { 119 ret += " - " + endstr; 120 } 121 return ret; 122 } 123 }; 124 125 function gCalFlow(target, opts) { 126 this.target = target; 127 target.addClass('gCalFlow'); 128 if (target.children().size() > 0) { 129 log.debug("Target node has children, use target element as template."); 130 this.template = target; 131 } 132 this.update_opts(opts); 133 } 134 135 gCalFlow.prototype.update_opts = function(new_opts) { 136 log.debug("update_opts was called"); 137 log.debug("old options:", this.opts); 138 this.opts = $.extend({}, this.opts, new_opts); 139 return log.debug("new options:", this.opts); 140 }; 141 142 gCalFlow.prototype.gcal_url = function() { 143 var now; 144 if (!this.opts.calid && !this.opts.feed_url) { 145 log.error("Option calid and feed_url are missing. Abort URL generation"); 146 this.target.text("Error: You need to set 'calid' or 'feed_url' option."); 147 throw "gCalFlow: calid and feed_url missing"; 148 } 149 if (this.opts.feed_url) { 150 return this.opts.feed_url; 151 } else if (this.opts.mode === 'updates') { 152 now = new Date().toJSON(); 153 return "https://www.googleapis.com/calendar/v3/calendars/" + this.opts.calid + "/events?key=" + this.opts.apikey + "&maxResults=" + this.opts.maxitem + "&orderBy=updated&timeMin=" + now + "&singleEvents=true"; 154 } else { 155 now = new Date().toJSON(); 156 return "https://www.googleapis.com/calendar/v3/calendars/" + this.opts.calid + "/events?key=" + this.opts.apikey + "&maxResults=" + this.opts.maxitem + "&orderBy=startTime&timeMin=" + now + "&singleEvents=true"; 157 } 158 }; 159 160 gCalFlow.prototype.fetch = function() { 161 var success_handler, 162 _this = this; 163 log.debug("Starting ajax call for " + (this.gcal_url())); 164 if (this.opts.apikey === this.constructor.demo_apikey) { 165 log.warn("You are using built-in demo API key! This key is provided for tiny use or demo only. Your access may be limited."); 166 log.warn("Please check document and consider to use your own key."); 167 } 168 success_handler = function(data) { 169 log.debug("Ajax call success. Response data:", data); 170 return _this.render_data(data, _this); 171 }; 172 return $.ajax({ 173 type: 'GET', 174 success: success_handler, 175 dataType: "jsonp", 176 url: this.gcal_url() 177 }); 178 }; 179 180 gCalFlow.prototype.parse_date = function(dstr) { 181 var day, hour, m, min, mon, offset, ret, sec, year; 182 if (m = dstr.match(/^(\d{4})-(\d{2})-(\d{2})$/)) { 183 return new Date(parseInt(m[1], 10), parseInt(m[2], 10) - 1, parseInt(m[3], 10), 0, 0, 0); 184 } 185 offset = (new Date()).getTimezoneOffset() * 60 * 1000; 186 year = mon = day = null; 187 hour = min = sec = 0; 188 if (m = dstr.match(/^(\d{4})-(\d{2})-(\d{2})[T ](\d{2}):(\d{2}):(\d{2}(?:\.\d+)?)(Z|([+-])(\d{2}):(\d{2}))$/)) { 189 year = parseInt(m[1], 10); 190 mon = parseInt(m[2], 10); 191 day = parseInt(m[3], 10); 192 hour = parseInt(m[4], 10); 193 min = parseInt(m[5], 10); 194 sec = parseInt(m[6], 10); 195 offset = (new Date(year, mon - 1, day, hour, min, sec)).getTimezoneOffset() * 60 * 1000; 196 if (m[7] !== "Z") { 197 offset += (m[8] === "+" ? 1 : -1) * (parseInt(m[9], 10) * 60 + parseInt(m[10], 10)) * 1000 * 60; 198 } 199 } else { 200 log.warn("Time parse error! Unknown time pattern: " + dstr); 201 return new Date(1970, 1, 1, 0, 0, 0); 202 } 203 log.debug("time parse (gap to local): " + offset); 204 ret = new Date(new Date(year, mon - 1, day, hour, min, sec).getTime() - offset); 205 log.debug("time parse: " + dstr + " -> ", ret); 206 return ret; 207 }; 208 209 gCalFlow.prototype.render_data = function(data) { 210 var ci, desc_body_method, ed, ent, et, etf, gmapslink, ic, it, items, link, sd, st, stf, t, titlelink, _j, _len1, _ref1, _ref2; 211 log.debug("start rendering for data:", data); 212 t = this.template.clone(); 213 titlelink = (_ref1 = this.opts.titlelink) != null ? _ref1 : "http://www.google.com/calendar/embed?src=" + this.opts.calid; 214 if (this.opts.link_title) { 215 t.find('.gcf-title').html($("<a />").attr({ 216 target: this.opts.link_target, 217 href: titlelink 218 }).text(data.summary)); 219 } else { 220 t.find('.gcf-title').text(data.summary); 221 } 222 t.find('.gcf-link').attr({ 223 target: this.opts.link_target, 224 href: titlelink 225 }); 226 t.find('.gcf-last-update').html(this.opts.date_formatter(this.parse_date(data.updated))); 227 it = t.find('.gcf-item-block'); 228 it.detach(); 229 it = $(it[0]); 230 log.debug("item block template:", it); 231 items = $(); 232 log.debug("render entries:", data.items); 233 if (this.opts.item_description_as_html) { 234 desc_body_method = 'html'; 235 } else { 236 desc_body_method = 'text'; 237 } 238 if ((data.items != null) && data.items.length > 0) { 239 _ref2 = data.items.slice(0, +this.opts.maxitem + 1 || 9e9); 240 for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) { 241 ent = _ref2[_j]; 242 log.debug("formatting entry:", ent); 243 ci = it.clone(); 244 if (ent.start) { 245 if (ent.start.dateTime) { 246 st = ent.start.dateTime; 247 } else { 248 st = ent.start.date; 249 } 250 sd = this.parse_date(st); 251 stf = this.opts.date_formatter(sd, st.indexOf(':') < 0); 252 ci.find('.gcf-item-date').html(stf); 253 ci.find('.gcf-item-start-date').html(stf); 254 } 255 if (ent.end) { 256 if (ent.end.dateTime) { 257 et = ent.end.dateTime; 258 } else { 259 et = ent.end.date; 260 } 261 ed = this.parse_date(et); 262 etf = this.opts.date_formatter(ed, et.indexOf(':') < 0); 263 ci.find('.gcf-item-end-date').html(etf); 264 ci.find('.gcf-item-daterange').html(this.opts.daterange_formatter(sd, ed, st.indexOf(':') < 0)); 265 } 266 ci.find('.gcf-item-update-date').html(this.opts.date_formatter(this.parse_date(ent.updated), false)); 267 link = $('<a />').attr({ 268 target: this.opts.link_target, 269 href: ent.htmlLink 270 }); 271 if (this.opts.link_item_title) { 272 ci.find('.gcf-item-title').html(link.clone().text(ent.summary)); 273 } else { 274 ci.find('.gcf-item-title').text(ent.summary); 275 } 276 if (this.opts.link_item_description) { 277 ci.find('.gcf-item-description').html(link.clone()[desc_body_method](ent.description)); 278 } else { 279 ci.find('.gcf-item-description')[desc_body_method](ent.description); 280 } 281 if (this.opts.link_item_location) { 282 gmapslink = "<a href='https://maps.google.de/maps?q=" + encodeURI(ent.location.replace(" ", "+")) + "' target='new'>" + ent.location + "</a>"; 283 ci.find('.gcf-item-location').html(gmapslink); 284 } else { 285 ci.find('.gcf-item-location').text(ent.location); 286 } 287 ci.find('.gcf-item-link').attr({ 288 href: ent.htmlLink 289 }); 290 log.debug("formatted item entry:", ci[0]); 291 items.push(ci[0]); 292 } 293 } else { 294 items = $('<div class="gcf-no-items"></div>').html(this.opts.no_items_html); 295 } 296 log.debug("formatted item entry array:", items); 297 ic = t.find('.gcf-item-container-block'); 298 log.debug("item container element:", ic); 299 ic.html(items); 300 this.target.html(t.html()); 301 this.bind_scroll(); 302 if (this.opts.callback) { 303 return this.opts.callback.apply(this.target); 304 } 305 }; 306 307 gCalFlow.prototype.bind_scroll = function() { 308 var scroll_children, scroll_container, scroll_timer, scroller, state; 309 scroll_container = this.target.find('.gcf-item-container-block'); 310 scroll_children = scroll_container.find(".gcf-item-block"); 311 log.debug("scroll container:", scroll_container); 312 if (!this.opts.auto_scroll || scroll_container.size() < 1 || scroll_children.size() < 2) { 313 return; 314 } 315 state = { 316 idx: 0 317 }; 318 scroller = function() { 319 var scroll_to; 320 log.debug("current scroll position:", scroll_container.scrollTop()); 321 log.debug("scroll capacity:", scroll_container[0].scrollHeight - scroll_container[0].clientHeight); 322 if (typeof scroll_children[state.idx] === 'undefined' || scroll_container.scrollTop() >= scroll_container[0].scrollHeight - scroll_container[0].clientHeight) { 323 log.debug("scroll to top"); 324 state.idx = 0; 325 return scroll_container.animate({ 326 scrollTop: scroll_children[0].offsetTop 327 }); 328 } else { 329 scroll_to = scroll_children[state.idx].offsetTop; 330 log.debug("scroll to " + scroll_to + "px"); 331 scroll_container.animate({ 332 scrollTop: scroll_to 333 }); 334 return state.idx += 1; 335 } 336 }; 337 return scroll_timer = setInterval(scroller, this.opts.scroll_interval); 338 }; 339 340 return gCalFlow; 341 342 })(); 343 344 methods = { 345 init: function(opts) { 346 var data; 347 if (opts == null) { 348 opts = {}; 349 } 350 data = this.data('gCalFlow'); 351 if (!data) { 352 return this.data('gCalFlow', { 353 target: this, 354 obj: new gCalFlow(this, opts) 355 }); 356 } 357 }, 358 destroy: function() { 359 var data; 360 data = this.data('gCalFlow'); 361 data.obj.target = null; 362 $(window).unbind('.gCalFlow'); 363 data.gCalFlow.remove(); 364 return this.removeData('gCalFlow'); 365 }, 366 render: function() { 367 if ((typeof Globalize !== "undefined" && Globalize !== null) && (Globalize.culture != null)) { 368 Globalize.culture(this.data('gCalFlow').obj.opts.globalize_culture); 369 } 370 return this.data('gCalFlow').obj.fetch(); 371 } 372 }; 373 374 $.fn.gCalFlow = function(method) { 375 var orig_args; 376 orig_args = arguments; 377 if (typeof method === 'object' || !method) { 378 return this.each(function() { 379 methods.init.apply($(this), orig_args); 380 return methods.render.apply($(this), orig_args); 381 }); 382 } else if (methods[method]) { 383 return this.each(function() { 384 return methods[method].apply($(this), Array.prototype.slice.call(orig_args, 1)); 385 }); 386 } else if (method === 'version') { 387 return "3.0.1"; 388 } else { 389 return $.error("Method " + method + " does not exist on jQuery.gCalFlow"); 390 } 391 }; 392 393}).call(this);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.