Skip to content

Commit

Permalink
Adding event.js
Browse files Browse the repository at this point in the history
  • Loading branch information
imightbeamy committed Apr 25, 2014
1 parent ac6d589 commit 28bf3f0
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions events.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
function EventMerger (key_function, parent_selector) {
this.makeKey = key_function;
this.parent_selector = parent_selector;
}

EventMerger.prototype = {
getEventSets: function($events) {
var event_sets = {},
makeKey = this.makeKey;
$events.each(function() {
var $event = $(this),
key = makeKey($event).replace(/\s/g,'');
console.log(key);
event_sets[key] = event_sets[key] || [];
event_sets[key].push($event);
});
return event_sets;
},
makeStripes: function (colors) {
var gradient = "repeating-linear-gradient( 45deg,",
pos = 0;
$.each(colors, function(i, c) {
gradient += c + " " + pos + "px,";
pos+=10;
gradient += c + " " + pos + "px,";
})
gradient = gradient.slice(0, -1);
gradient += ")"
return gradient;
},
mergeEvents: function (name, event_set) {
if (event_set.length > 1) {
var colors = $.map(event_set, function(event) {
return $(event).css('background-color');
});
var keep = event_set.shift();
$(event_set).each(function() {$(this).remove()});

keep.css('background-image', this.makeStripes(colors));
keep.parents('.chip').css('width', '100%');
}
},
mergeSets: function ($events) {
var sets = this.getEventSets($events);
console.log(sets);
$.each(sets, $.proxy(this.mergeEvents, this));
}
};

/*****************************************************************************/

function eventKey ($event) {
var event_name = $event.find('dd span').text(),
event_time = $event.find('dt').text(),
col = $event.parents('.tg-col-eventwrapper').attr('id');
return event_name + event_time + col;
}

merger = new EventMerger(eventKey);
$(document).on("DOMNodeInserted", ".tg-mainwrapper", function(e) {
merger.mergeSets($('dl'));
});

0 comments on commit 28bf3f0

Please sign in to comment.