Skip to content

Instantly share code, notes, and snippets.

@UnquietCode
Created September 23, 2012 08:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save UnquietCode/3769415 to your computer and use it in GitHub Desktop.
Save UnquietCode/3769415 to your computer and use it in GitHub Desktop.
StrangeLoop schedule helper
javascript:(function()%7B(function%20()%20%7Bvar%20jsCode%20%3D%20document.createElement('script')%3BjsCode.setAttribute('src'%2C%20'https%3A%2F%2Fraw.github.com%2Fgist%2F3769415%2Fslcal.js')%3Bdocument.body.appendChild(jsCode)%3B%7D())%7D)()
// StrangeLoop schedule helper. Enjoy!
// -Ben
//
// https://gist.github.com/3769415
Slcal = {};
Slcal.parseTime = function(day, timeString) {
var parsingDateStrings = ["9/23/2012 ", "9/24/2012 ", "9/25/2012 ", "9/26/2012 "];
var split = timeString.indexOf("-");
var dateStr = parsingDateStrings[day-1];
var start = dateStr + timeString.substr(0, split-1) + " CDT";
start = new Date(Date.parse(start));
var end = dateStr + timeString.substr(split+1) + " CDT";
end = new Date(Date.parse(end));
// now convert to calendar time format
var pad = function(str) {
str = str + "";
if (str.length == 1) {
return "0"+str;
} else {
return str;
}
}
var startDate = "201209"+pad(start.getDate())+"T";
var endDate = "201209"+pad(end.getDate())+"T";
var tStart = pad(start.getHours()+"");
start = startDate+tStart+pad(start.getMinutes())+pad(start.getSeconds())+"CDT";
var tEnd = pad(end.getHours()+"");
end = endDate+tEnd+pad(end.getMinutes())+pad(end.getSeconds())+"CDT";
return [start, end];
};
Slcal.addCalendarMenu = function() {
var ul = $("<ul></ul>");
ul.css("position", "fixed");
ul.css("right", "0");
ul.css("top", "50%");
ul.css("width", "135px");
ul.css("margin-top", "-2.5em");
// gcal link
var li = $('<li class="track"></li>');
li.css("background", "#FFFFFF");
var a = $('<a href="#"></a>');
a.html("get selected event");
a.click(function() {
var eventNode = $(".evtSelected")[0];
if (eventNode) {
eventNode = $(eventNode).data("info");
Slcal.getCalendar(eventNode);
}
return false;
});
li.append(a);
ul.append(li);
// add to body
$("body").append(ul);
};
Slcal.getCalendar = function(event) {
if (!event) { return; }
// generate an ics download for the user
var data = [
"BEGIN:VCALENDAR",
"VERSION:2.0",
"PRODID:-//UnquietCode//NONSGML SLCAL//EN",
"BEGIN:VEVENT",
"DTSTAMP:"+event.startTime,
"DTSTART:"+event.startTime,
"DTEND:"+event.endTime,
"SUMMARY:"+event.title+" @"+event.room,
"DESCRIPTION:"+event.title+" with "+event.speaker+" ("+event.track+" Track)",
"LOCATION:"+event.room+" (StrangeLoop conference)",
"URL:"+event.url,
"END:VEVENT",
"END:VCALENDAR"
].join("\n");
// from http://pastebin.com/nUhwBe4Y
var data = "data:text/calendar;charset=utf8," + encodeURIComponent(data);
Slcal.download({
filename: "event.ics",
data: data
});
};
// http://download-data-uri.appspot.com
Slcal.download = function(options) {
if(!options) {
return;
}
$.isPlainObject(options) || (options = {data: options});
if(!$.browser.webkit) {
location.href = options.data;
}
options.filename || (options.filename = "download." + options.data.split(",")[0].split(";")[0].substring(5).split("/")[1]);
options.url || (options.url = "http://download-data-uri.appspot.com/");
$('<form method="post" target="_new" action="'+options.url+'" style="display:none"><input type="hidden" name="filename" value="'+options.filename+'"/><input type="hidden" name="data" value="'+options.data+'"/></form>').submit().remove();
};
Slcal.addCalendarLinks = function(event) {
// add click event to select
event.node.click(function() {
var item = $(this);
var wasSelected = item.hasClass("evtSelected");
var old = $(".evtSelected");
old.removeClass("evtSelected");
old.css("background", "");
if (!wasSelected) {
item.addClass("evtSelected");
item.css("background", "#830000");
}
});
};
// process a section
Slcal.processElementsInSection = function(section, day) {
var rooms = section.find("ul.schedule-header li");
// for every event cell
$(section.find("li.cell div.session")).each(function(idx, event) {
event = $(event);
// skip empty boxes
if (event.children().length == 0) {
return true;
}
var eventInfo = {};
event.data("info", eventInfo);
eventInfo.node = event;
eventInfo.day = day;
eventInfo.track = event.attr("data-track");
eventInfo.speaker = $(event.find("span.speaker")).html();
eventInfo.url = event.find("div.title a")[0].href;
// for room we need to know our column index in the row
var column = event.parent().index() - 1;
eventInfo.room = $(rooms[column]).text();
// tile is a chain of rendered cufons
eventInfo.title = "";
event.find("div.title cufontext").each(function(idx, text) {
eventInfo.title += $(text).text();
});
// time is in the parent row's first element
// unless it is overridden (half events)
var overrideTime = event.find("div.session-time")[0];
var time;
if (overrideTime) {
time = $.trim($(overrideTime).text());
} else {
var timeCell = $(event.parent().parent().children()[0]);
time = timeCell.find("div.time-period-short, div.time-period-tall")[0];
time = $.trim($(time).text());
}
time = Slcal.parseTime(day, time);
eventInfo.startTime = time[0];
eventInfo.endTime = time[1];
Slcal.addCalendarLinks(eventInfo);
});
};
Slcal.go = function() {
// setup some helpers
$_ = function(obj) {
return $($(obj));
};
$_$ = function(out) {
console.log(out);
return $_$;
};
$_$("loaded slcal");
// events are a single event on a single day
var elcSchedule = $($("div#preconf-elc > div.container_12")[0]);
var mainSchedules = $("div#main-conf-sessions > div.container_12");
var unschedules = $("div#unsessions > div.container_12");
var mondaySchedule = $(mainSchedules[0]);
var mondayUnSchedule = $(unschedules[0]);
var tuesdaySchedule = $(mainSchedules[1]);
var tuesdayUnSchedule = $(unschedules[1]);
Slcal.processElementsInSection(elcSchedule, 1);
Slcal.processElementsInSection(mondaySchedule, 2);
Slcal.processElementsInSection(mondayUnSchedule, 2);
Slcal.processElementsInSection(tuesdaySchedule, 3);
Slcal.processElementsInSection(tuesdayUnSchedule, 3);
Slcal.addCalendarMenu();
};
// fire when ready
$(Slcal.go);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment