-
Notifications
You must be signed in to change notification settings - Fork 676
/
Copy pathhelpers.js
55 lines (46 loc) · 1.54 KB
/
helpers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Functions to extend prototypes
function formatDate(date) {
var monthNames = [
"January", "February", "March",
"April", "May", "June", "July",
"August", "September", "October",
"November", "December"
];
var day = date.getDate();
var monthIndex = date.getMonth();
var year = date.getFullYear();
var hour = date.getHours()
var minutes = date.getMinutes()
return day + ' ' + monthNames[monthIndex] + ' ' + year + ' at ' + hour + ':' + minutes;
}
// console.log(formatDate(new Date())); // show current date-time in console
// Helper to generate hours:minutes:seconds for accumulated job time
// Adapted from StackOverflow
// http://stackoverflow.com/questions/6312993/javascript-seconds-to-time-string-with-format-hhmmss/6313008#6313008
Number.prototype.toHHMMSS = function() {
var sec_num = Math.round(this);
var hours = Math.floor(sec_num / 3600);
var minutes = Math.floor((sec_num - (hours * 3600)) / 60);
var seconds = sec_num - (hours * 3600) - (minutes * 60);
if (hours < 10) {
hours = "0" + hours;
}
if (minutes < 10) {
minutes = "0" + minutes;
}
if (seconds < 10) {
seconds = "0" + seconds;
}
return hours + ':' + minutes + ':' + seconds;
}
//JQuery extension to add additional event triggers
// This assumes JQuery has been loaded first!
! function($) {
$.each(['show', 'hide'], function(i, ev) {
var el = $.fn[ev];
$.fn[ev] = function() {
this.trigger(ev);
return el.apply(this, arguments);
};
});
}(jQuery);