-
Notifications
You must be signed in to change notification settings - Fork 3
/
card.js
105 lines (100 loc) · 2.61 KB
/
card.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
var Card = {
//
// Separator used to split the custom values
// from the rest of the title
//
mainSeparator : ")",
secondarySeparator: "/",
startSeparator: "(",
//
// Parses the title to obtain the estimated number of units
// E.g. "2--This is a string" will output the number 2.
//
estimationFromTitle : function(title) {
var trimmedTitle = $.trim(title);
if (!stringStartsWith(trimmedTitle, this.startSeparator)){
return 0;
}
trimmedTitle = trimmedTitle.substring(1, trimmedTitle.length);
var splits = trimmedTitle.split(this.mainSeparator);
if (splits.length >= 2) {
var splits2 = splits[0].split(this.secondarySeparator);
if (splits2.length == 2) {
var value = parseFloat(splits2[1]);
if (isNaN(value)) {
return 0;
}
return value;
} else {
var value = parseFloat(splits[0]);
if (isNaN(value)) {
return 0;
}
return value;
}
}
return 0;
},
spentFromTitle : function(title) {
var trimmedTitle = $.trim(title);
if (!stringStartsWith(trimmedTitle, this.startSeparator)){
return 0;
}
trimmedTitle = trimmedTitle.substring(1, trimmedTitle.length);
var splits = trimmedTitle.split(this.mainSeparator);
if (splits.length == 2) {
var splits2 = splits[0].split(this.secondarySeparator);
if (splits2.length == 2) {
var value = parseFloat(splits2[0]);
if (isNaN(value)) {
return 0;
}
return value;
}
}
return 0;
},
hashtagsFromTitle: function(title) {
var hashtags = [];
var regexp = /#([\w-]+)/g;
var result = regexp.exec(title);
while (result != null) {
hashtags.push(result[1]);
result = regexp.exec(title);
}
return hashtags;
},
//
// Return the clean version of the title, w/o the prefixes.
// E.g. For "(2) This task rocks" this will give "This task rocks"
// E.g. For "(1/2) This task rocks" this will give "This task rocks"
//
cleanTitle : function(title) {
// Strip hashtags
title = title.replace(/#[\w-]+/g, "");
var trimmedTitle = $.trim(title);
if (!stringStartsWith(trimmedTitle, this.startSeparator)){
return title;
}
var splits = trimmedTitle.split(this.mainSeparator);
if (splits.length == 2) {
return splits[1];
}
return trimmedTitle;
},
estimationLabelText : function(estimationNumber) {
return "E: " + String(estimationNumber);
},
spentLabelText : function(spentNumber) {
return "S: " + String(spentNumber);
},
remainingLabelText: function(number) {
return "R: " + String(number);
},
randomNumber: function () {
return Math.floor(Math.random()*11);
},
titleTag: function (card) {
return $(card).children('a.list-card-title').eq(0);
}
}