-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
76 lines (65 loc) · 1.74 KB
/
script.js
File metadata and controls
76 lines (65 loc) · 1.74 KB
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
var tweetBoxes = [];
var idNum = 0;
$(function(){
document.getElementById('draft').addEventListener("input", onInput, false);
});
function onInput(){
document.getElementById('count').innerHTML = document.getElementById('draft').value.length;
splitTweets();
}
function splitTweets(){
parseTweetString();
}
function parseTweetString(){
var boxes = [];
var words = [];
var j = 0;
words = document.getElementById('draft').value.split(" ");
var tempTweet = [];
for (var i = 0; i < words.length; i++) {
tempTweet.push(words[i]);
if(tempTweet.join(" ").length < 134){
boxes[j] = tempTweet.join(" ");
}else{
tempTweet.pop();
boxes[j] = tempTweet.join(" ");
tempTweet = [];
tempTweet.push(words[i]);
j++;
}
};
if(boxes.length > tweetBoxes.length){
var diff = boxes.length - tweetBoxes.length;
for (var i = 0; i < diff; i++) {
new TweetBox(idNum, idNum);
idNum++;
}
}
for (var i = 0; i < tweetBoxes.length; i++) {
tweetBoxes[i].domElement.value = boxes[i];
var tweetCount = i + 1;
tweetBoxes[i].domElement.value += " (" + tweetCount + "/" + tweetBoxes.length + ")";
document.getElementById('count' + tweetBoxes[i].idNum).innerHTML = tweetBoxes[i].domElement.value.length;
};
}
function urls(){
var urls = countURLs();
var urlChars = 0;
var adjustment= 0;
if(urls){
for (var i = urls.length - 1; i >= 0; i--) {
urlChars += urls[i].length;
};
adjustment = urls.length*23;
}
var chars = self.charLength() - urlChars + adjustment;
document.getElementById('count' + self.idNum).innerHTML = chars;
self.checkMaxLength();
self.isEmpty();
}
function countURLs(){
var str = this.domElement.value;
var re = /(^|\s)((https?:\/\/)?[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?)/gi;
var res = str.match(re);
return res;
}