Skip to content

Commit bb166d7

Browse files
committed
Removed timesheet.bubble.js
1 parent dc7a1a6 commit bb166d7

File tree

3 files changed

+76
-83
lines changed

3 files changed

+76
-83
lines changed

source/javascripts/timesheet.bubble.js

Lines changed: 0 additions & 78 deletions
This file was deleted.

source/javascripts/timesheet.js

Lines changed: 75 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// require 'timesheet.bubble'
2-
31
/* global TimesheetBubble */
42

53
(function() {
@@ -33,7 +31,7 @@
3331

3432
for (var n = 0, m = this.data.length; n < m; n++) {
3533
var cur = this.data[n];
36-
var bubble = new TimesheetBubble(widthMonth, this.year.min, cur.start, cur.end);
34+
var bubble = new Bubble(widthMonth, this.year.min, cur.start, cur.end);
3735

3836
var line = [
3937
'<span style="margin-left: ' + bubble.getStartOffset() + 'px; width: ' + bubble.getWidth() + 'px;" class="bubble bubble-' + (cur.type || 'default') + '" data-duration="' + (cur.end ? Math.round((cur.end-cur.start)/1000/60/60/24/39) : '') + '"></span>',
@@ -100,6 +98,79 @@
10098
this.data.push({start: beg, end: end, label: lbl, type: cat});
10199
}
102100
};
101+
102+
/**
103+
* Timesheet Bubble
104+
*/
105+
var Bubble = function(wMonth, min, start, end) {
106+
this.min = min;
107+
this.start = start;
108+
this.end = end;
109+
this.widthMonth = wMonth;
110+
};
111+
112+
/**
113+
* Format month number
114+
*/
115+
Bubble.prototype.formatMonth = function(num) {
116+
num = parseInt(num, 10);
117+
118+
return num >= 10 ? num : '0' + num;
119+
};
120+
121+
/**
122+
* Calculate starting offset for bubble
123+
*/
124+
Bubble.prototype.getStartOffset = function() {
125+
return (this.widthMonth/12) * (12 * (this.start.getFullYear() - this.min) + this.start.getMonth());
126+
};
127+
128+
/**
129+
* Get count of full years from start to end
130+
*/
131+
Bubble.prototype.getFullYears = function() {
132+
return ((this.end && this.end.getFullYear()) || this.start.getFullYear()) - this.start.getFullYear();
133+
};
134+
135+
/**
136+
* Get count of all months in Timesheet Bubble
137+
*/
138+
Bubble.prototype.getMonths = function() {
139+
var fullYears = this.getFullYears();
140+
var months = 0;
141+
142+
if (!this.end) {
143+
months += !this.start.hasMonth ? 12 : 1;
144+
} else {
145+
if (!this.end.hasMonth) {
146+
months += 12 - (this.start.hasMonth ? this.start.getMonth() : 0);
147+
months += 12 * (fullYears-1 > 0 ? fullYears-1 : 0);
148+
} else {
149+
months += this.end.getMonth() + 1;
150+
months += 12 - (this.start.hasMonth ? this.start.getMonth() : 0);
151+
months += 12 * (fullYears-1);
152+
}
153+
}
154+
155+
return months;
156+
};
157+
158+
/**
159+
* Get bubble's width in pixel
160+
*/
161+
Bubble.prototype.getWidth = function() {
162+
return (this.widthMonth/12) * this.getMonths();
163+
};
164+
165+
/**
166+
* Get the bubble's label
167+
*/
168+
Bubble.prototype.getDateLabel = function() {
169+
return [
170+
(this.start.hasMonth ? this.formatMonth(this.start.getMonth() + 1) + '/' : '' ) + this.start.getFullYear(),
171+
(this.end ? '-' + ((this.end.hasMonth ? this.formatMonth(this.end.getMonth() + 1) + '/' : '' ) + this.end.getFullYear()) : '')
172+
].join('');
173+
};
103174

104175
window.Timesheet = Timesheet;
105-
})();
176+
})();

source/layouts/layout.haml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
%meta{:property => 'og:title', :content => 'Timesheet.js'}
77
%meta{:property => 'og:description', :content => 'With Timesheet.js you can easily create simple time and data sheets or timelines using HTML5, JavaScript and CSS3. Yep, it\'s a Vanilla JS library!'}
88
%meta{:property => 'og:url', :content => 'https://sbstjn.github.io/timesheet.js/'}
9-
%meta{:property => 'og:image', :content => 'https://raw.githubusercontent.com/%3Cspan%20class="x x-first x-last">semu/timesheet.js/master/screen.png'}
9+
%meta{:property => 'og:image', :content => 'https://raw.githubusercontent.com/%3Cspan%20class="x x-first x-last">sbstjn/timesheet.js/master/screen.png'}
1010
%meta{:property => 'fb:admins', :content => '669118929'}
1111

1212
%title Timesheet.js - Open time tables with HTML, JavaScript and CSS …

0 commit comments

Comments
 (0)