PageSourceSearch

https://vocalendar.jp/js/jquery.gcal_flow.js

js vocalendar.jp collected 2026-10-06 19:47:53 UTC 12,347 bytes, 311 lines download raw bytes

1// Generated by CoffeeScript 1.3.1
2(function() {
3  var $, gCalFlow, log, methods, pad_zero;
4
5  $ = jQuery;
6
7  if ((typeof window !== "undefined" && window !== null) && (window._gCalFlow_debug != null) && (typeof console !== "undefined" && console !== null)) {
8    log = console;
9    if (log.debug == null) {
10      log.debug = log.log;
11    }
12  } else {
13    log = {};
14    log.error = log.warn = log.log = log.info = log.debug = function() {};
15  }
16
17  pad_zero = function(num, size) {
18    var i, ret, _i, _ref;
19    if (size == null) {
20      size = 2;
21    }
22    if (10 * (size - 1) <= num) {
23      return num;
24    }
25    ret = "";
26    for (i = _i = 1, _ref = size - ("" + num).length; 1 <= _ref ? _i <= _ref : _i >= _ref; i = 1 <= _ref ? ++_i : --_i) {
27      ret = ret.concat("0");
28    }
29    return ret.concat(num);
30  };
31
32  gCalFlow = (function() {
33
34    gCalFlow.name = 'gCalFlow';
35
36    gCalFlow.prototype.target = null;
37
38    gCalFlow.prototype.template = $("<div class=\"gCalFlow\">\n  <div class=\"gcf-header-block\">\n    <div class=\"gcf-title-block\">
38\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>\n    </div>\n  </div>\n  <div class=\"gcf-last-update-block\">\n    LastUpdate: <span class=\"gcf-last-update\"></span>\n  </div>\n</div>");
39
40    gCalFlow.prototype.opts = {
41      maxitem: 15,
42      calid: null,
43      mode: 'upcoming',
44      feed_url: null,
45      auto_scroll: true,
46      scroll_interval: 10 * 1000,
47      link_title: true,
48      link_item_title: true,
49      link_item_description: false,
50      link_target: '_blank',
51      callback: null,
52      date_formatter: function(d, allday_p) {
53        if (allday_p) {
54          return "" + (d.getFullYear()) + "-" + (pad_zero(d.getMonth() + 1)) + "-" + (pad_zero(d.getDate()));
55        } else {
56          return "" + (d.getFullYear()) + "-" + (pad_zero(d.getMonth() + 1)) + "-" + (pad_zero(d.getDate())) + " " + (pad_zero(d.getHours())) + ":" + (pad_zero(d.getMinutes()));
57        }
58      },
59      daterange_formatter: function(sd, ed, allday_p) {
60        if (allday_p) {
61          ed = new Date(ed.getTime() - 86400 * 1000);
62          if (sd.getDate() !== ed.getDate() || sd.getMonth() !== ed.getMonth()) {
63            return "" + (this.date_formatter(sd, allday_p)) + " - " + (pad_zero(ed.getMonth() + 1)) + "-" + (pad_zero(ed.getDate()));
64          } else {
65            return this.date_formatter(sd, allday_p);
66          }
67        } else {
68          if (sd.getDate() !== ed.getDate() || sd.getMonth() !== ed.getMonth()) {
69            return "" + (this.date_formatter(sd, allday_p)) + " - " + (pad_zero(ed.getMonth() + 1)) + "-" + (pad_zero(ed.getDate())) + " " + (pad_zero(ed.getHours())) + ":" + (pad_zero(ed.getMinutes()));
70          } else if (sd.getHours() !== ed.getHours() || sd.getMinutes() !== ed.getMinutes()) {
71            return "" + (this.date_formatter(sd, allday_p)) + " - " + (pad_zero(ed.getHours())) + ":" + (pad_zero(ed.getMinutes()));
72          } else {
73            return this.date_formatter(sd, allday_p);
74          }
75        }
76      }
77    };
78
79    function gCalFlow(target, opts) {
80      this.target = target;
81      target.addClass('gCalFlow');
82      if (target.children().size() > 0) {
83        log.debug("Target node has children, use target element as template.");
84        this.template = target;
85      }
86      this.update_opts(opts);
87    }
88
89    gCalFlow.prototype.update_opts = function(new_opts) {
90      log.debug("update_opts was called");
91      log.debug("old options:", this.opts);
92      this.opts = $.extend({}, this.opts, new_opts);
93      return log.debug("new options:", this.opts);
94    };
95
96    gCalFlow.prototype.gcal_url = function() {
97      if (!this.opts.calid && !this.opts.feed_url) {
98        log.error("Option calid and feed_url are missing. Abort URL generation");
99        this.target.text("Error: You need to set 'calid' or 'feed_url' option.");
100        throw "gCalFlow: calid and feed_url missing";
101      }
102      if (this.opts.feed_url) {
103        return this.opts.feed_url;
104      } else if (this.opts.mode === 'updates') {
105        return "https://www.google.com/calendar/feeds/" + this.opts.calid + "/public/full?alt=json-in-script&max-results=" + this.opts.maxitem + "&orderby=lastmodified&sortorder=descending";
106      } else {
107        return "https://www.google.com/calendar/feeds/" + this.opts.calid + "/public/full?alt=json-in-script&max-results=" + this.opts.maxitem + "&orderby=starttime&futureevents=true&sortorder=ascending&singleevents=true";
108      }
109    };
110
111    gCalFlow.prototype.fetch = function() {
112      var success_handler,
113        _this = this;
114      log.debug("Starting ajax call for " + (this.gcal_url()));
115      success_handler = function(data) {
116        log.debug("Ajax call success. Response data:", data);
117        return _this.render_data(data, _this);
118      };
119      return $.ajax({
120        success: success_handler,
121        dataType: "jsonp",
122        url: this.gcal_url()
123      });
124    };
125
126    gCalFlow.prototype.parse_date = function(dstr) {
127      var day, hour, m, min, mon, offset, ret, sec, year;
128      if (m = dstr.match(/^(\d{4})-(\d{2})-(\d{2})$/)) {
129        return new Date(parseInt(m[1], 10), parseInt(m[2], 10) - 1, parseInt(m[3], 10), 0, 0, 0);
130      }
131      offset = (new Date()).getTimezoneOffset() * 60 * 1000;
132      year = mon = day = null;
133      hour = min = sec = 0;
134      if (m = dstr.match(/^(\d{4})-(\d{2})-(\d{2})[T ](\d{2}):(\d{2}):(\d{2}(?:\.\d+)?)(Z|([+-])(\d{2}):(\d{2}))$/)) {
135        year = parseInt(m[1], 10);
136        mon = parseInt(m[2], 10);
137        day = parseInt(m[3], 10);
138        hour = parseInt(m[4], 10);
139        min = parseInt(m[5], 10);
140        sec = parseInt(m[6], 10);
141        if (m[7] !== "Z") {
142          offset += (m[8] === "+" ? 1 : -1) * (parseInt(m[9], 10) * 60 + parseInt(m[10], 10)) * 1000 * 60;
143        }
144      } else {
145        log.warn("Time prase error! Unknown time pattern: " + dstr);
146        return new Date(1970, 1, 1, 0, 0, 0);
147      }
148      log.debug("time parse (gap to local): " + offset);
149      ret = new Date(new Date(year, mon - 1, day, hour, min, sec).getTime() - offset);
150      log.debug("time parse: " + dstr + " -> ", ret);
151      return ret;
152    };
153
154    gCalFlow.prototype.render_data = function(data) {
155      var ci, ed, ent, et, etf, feed, ic, it, items, link, sd, st, stf, t, titlelink, _i, _len, _ref, _ref1;
156      log.debug("start rendering for data:", data);
157      feed = data.feed;
158      t = this.template.clone();
159      titlelink = (_ref = this.opts.titlelink) != null ? _ref : "http://www.google.com/calendar/embed?src=" + this.opts.calid;
160      if (this.opts.link_title) {
161        t.find('.gcf-title').html($("<a />").attr({
162          target: this.opts.link_target,
163          href: titlelink
164        }).text(feed.title.$t));
165      } else {
166        t.find('.gcf-title').text(feed.title.$t);
167      }
168      t.find('.gcf-link').attr({
169        target: this.opts.link_target,
170        href: titlelink
171      });
172      t.find('.gcf-last-update').html(this.opts.date_formatter(this.parse_date(feed.updated.$t)));
173      it = t.find('.gcf-item-block');
174      it.detach();
175      it = $(it[0]);
176      log.debug("item block template:", it);
177      items = $();
178      log.debug("render entries:", feed.entry);
179      _ref1 = feed.entry.slice(0, this.opts.maxitem + 1 || 9e9);
180      for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
181        ent = _ref1[_i];
182        log.debug("formatting entry:", ent);
183        ci = it.clone();
184        if (ent.gd$when) {
185          st = ent.gd$when[0].startTime;
186          sd = this.parse_date(st);
187          stf = this.opts.date_formatter(sd, st.indexOf(':') < 0);
188          ci.find('.gcf-item-date').html(stf);
189          ci.find('.gcf-item-start-date').html(stf);
190          et = ent.gd$when[0].endTime;
191          ed = this.parse_date(et);
192          etf = this.opts.date_formatter(ed, et.indexOf(':') < 0);
193          ci.find('.gcf-item-end-date').html(etf);
194          ci.find('.gcf-item-daterange').html(this.opts.daterange_formatter(sd, ed, st.indexOf(':') < 0));
195        }
196        ci.find('.gcf-item-update-date').html(this.opts.date_formatter(this.parse_date(ent.updated.$t), false));
197        link = $('<a />').attr({
198          target: this.opts.link_target,
199          href: ent.link[0].href
200        });
201        if (this.opts.link_item_title) {
202          ci.find('.gcf-item-title').html(link.clone().text(ent.title.$t));
203        } else {
204          ci.find('.gcf-item-title').text(ent.title.$t);
205        }
206        if (this.opts.link_item_description) {
207          ci.find('.gcf-item-description').html(link.clone().text(ent.content.$t));
208        } else {
209          ci.find('.gcf-item-description').text(ent.content.$t);
210        }
211        ci.find('.gcf-item-link').attr({
212          href: ent.link[0].href
213        });
214        log.debug("formatted item entry:", ci[0]);
215        items.push(ci[0]);
216      }
217      log.debug("formatted item entry array:", items);
218      ic = t.find('.gcf-item-container-block');
219      log.debug("item container element:", ic);
220      ic.html(items);
221      this.target.html(t.html());
222      this.bind_scroll();
223      if (this.opts.callback) {
224        return this.opts.callback.apply(this.target);
225      }
226    };
227
228    gCalFlow.prototype.bind_scroll = function() {
229      var scroll_children, scroll_container, scroll_timer, scroller, state;
230      scroll_container = this.target.find('.gcf-item-container-block');
231      scroll_children = scroll_container.find(".gcf-item-block");
232      log.debug("scroll container:", scroll_container);
233      if (!this.opts.auto_scroll || scroll_container.size() < 1 || scroll_children.size() < 2) {
234        return;
235      }
236      state = {
237        idx: 0
238      };
239      scroller = function() {
240        var scroll_to;
241        log.debug("current scroll position:", scroll_container.scrollTop());
242        log.debug("scroll capacity:", scroll_container[0].scrollHeight - scroll_container[0].clientHeight);
243        if (typeof scroll_children[state.idx] === 'undefined' || scroll_container.scrollTop() >= scroll_container[0].scrollHeight - scroll_container[0].clientHeight) {
244          log.debug("scroll to top");
245          state.idx = 0;
246          return scroll_container.animate({
247            scrollTop: scroll_children[0].offsetTop
248          });
249        } else {
250          scroll_to = scroll_children[state.idx].offsetTop;
251          log.debug("scroll to " + scroll_to + "px");
252          scroll_container.animate({
253            scrollTop: scroll_to
254          });
255          return state.idx += 1;
256        }
257      };
258      return scroll_timer = setInterval(scroller, this.opts.scroll_interval);
259    };
260
261    return gCalFlow;
262
263  })();
264
265  methods = {
266    init: function(opts) {
267      var data;
268      if (opts == null) {
269        opts = {};
270      }
271      data = this.data('gCalFlow');
272      if (!data) {
273        return this.data('gCalFlow', {
274          target: this,
275          obj: new gCalFlow(this, opts)
276        });
277      }
278    },
279    destroy: function() {
280      var data;
281      data = this.data('gCalFlow');
282      data.obj.target = null;
283      $(window).unbind('.gCalFlow');
284      data.gCalFlow.remove();
285      return this.removeData('gCalFlow');
286    },
287    render: function() {
288      return this.data('gCalFlow').obj.fetch();
289    }
290  };
291
292  $.fn.gCalFlow = function(method) {
293    var orig_args;
294    orig_args = arguments;
295    if (typeof method === 'object' || !method) {
296      return this.each(function() {
297        methods.init.apply($(this), orig_args);
298        return methods.render.apply($(this), orig_args);
299      });
300    } else if (methods[method]) {
301      return this.each(function() {
302        return methods[method].apply($(this), Array.prototype.slice.call(orig_args, 1));
303      });
304    } else if (method === 'version') {
305      return "1.2.1";
306    } else {
307      return $.error("Method " + method + " dose not exist on jQuery.gCalFlow");
308    }
309  };
310
311}).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.