function Programm( elem, params ){ this.element = jQuery(elem); this.params = params || {}; this.minHeight = 60; this.rowHeight = 100; this.__construct(); } Programm.prototype.__construct = function(){ this.stamps = {}; this.rows = this.element.find('.programm__grid-row'); this.pivots = this.element.find('.programm__time-scale__pivot').empty(); this._init(); }; Programm.prototype._init = function(){ var i, l; for( i=0, l=this.rows.length; i < l; i++ ){ this._setRowHeight(i); } for( i=0, l=this.rows.length; i < l; i++ ){ this._setEventsHeight(i); } }; Programm.prototype._setRowHeight = function( index ){ var i, j, l, m, rowHeight, events, _max, _min, min = false, max = 0, row = this.rows.eq(index), cols = row.find('.programm__grid-cell'); for( i=0, l=cols.length; i < l; i++ ){ events = cols.eq(i).find('.programm__event'); _max = events.length; max = _max > max ? _max : max; for( j=0, m=events.length; j < m; j++ ){ _min = this._getEventTiming(events.eq(j)).duration; min = min === false || _min < min ? _min : min; } } rowHeight = this.minHeight / (min !== false && min < 1 ? min : 1); rowHeight = rowHeight < this.rowHeight ? this.rowHeight : rowHeight; row.css({'height' : rowHeight+'px'}).data('programm__rowHeight', rowHeight); cols.css({'height' : rowHeight+'px'}); this.pivots.eq(index).css({'height' : rowHeight+'px'}); }; Programm.prototype._setEventsHeight = function( rowIndex ){ var i, l, events = this.rows.eq(rowIndex).find('.programm__event'); for( i=0, l=events.length; i < l; i++ ){ this._setEventHeight(events.eq(i), rowIndex); } }; Programm.prototype._setEventHeight = function( event, rowIndex ){ var i, l, height, top, hour, stamp, row = this.rows.eq(rowIndex), rowHeight = row.data('programm__rowHeight'), timing = this._getEventTiming(event); top = timing.start.mins / 60 * rowHeight; if( timing.start.hour == timing.stop.hour || (timing.start.hour == timing.stop.hour - 1 && timing.stop.mins == 0) ){ height = timing.duration * rowHeight; }else{ height = rowHeight - top; for( hour = timing.start.hour+1; hour < timing.stop.hour; hour++ ){ height += 1 + this.rows.eq(rowIndex + hour - timing.start.hour).data('programm__rowHeight'); } if( timing.stop.mins != 0 ){ height += 1 + this.rows.eq(rowIndex + timing.stop.hour - timing.start.hour).data('programm__rowHeight') * timing.stop.mins / 60; } } event.css({'position' : 'absolute', 'top' : top+'px', 'height' : height+'px', 'overflow' : 'hidden'}); if( timing.start.mins != 0 ){ event.addClass('programm__event_border-t'); } stamp = '' + timing.start.hour + ':' + (timing.start.mins < 10 ? '0' : '') + timing.start.mins; if( !this.stamps[stamp] ){ this.stamps[stamp] = true; jQuery('
' + stamp + '
') .css({'top' : top+'px'}) .appendTo(this.pivots.eq(rowIndex)); } stamp = '' + timing.stop.hour + ':' + (timing.stop.mins < 10 ? '0' : '') + timing.stop.mins; if( !this.stamps[stamp] ){ this.stamps[stamp] = true; jQuery('
' + stamp + '
') .css({'top' : top+height+'px'}) .appendTo(this.pivots.eq(rowIndex)); } }; Programm.prototype._getEventTiming = function( event ){ var time, split, hour, mins, start, stop; time = event.find('.programm__event__start-time').val(); split = time.indexOf(':'); hour = parseInt(time.substr(0, split), 10); mins = parseInt(time.substr(split + 1), 10); start = { 'hour' : hour, 'mins' : mins, 'time' : hour * 60 + mins, } time = event.find('.programm__event__stop-time').val(); split = time.indexOf(':'); hour = parseInt(time.substr(0, split), 10); mins = parseInt(time.substr(split + 1), 10); stop = { 'hour' : hour, 'mins' : mins, 'time' : hour * 60 + mins, } return { 'start' : start, 'stop' : stop, 'duration' : (stop.time - start.time) / 60, }; }; /*--/menu--*/