forked from jamestomasino/read_plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReadWord.js
104 lines (86 loc) · 1.83 KB
/
ReadWord.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
( function ( window ){
"use strict";
var textRegex = /\w/g;
var numRegex = /\d/g;
var ReadWord = function ( val ) {
this.val = val;
// Center value for alignment
this.index = 0;
// ReadWord Status Values
this.hasLeadingQuote = false;
this.hasTrailingQuote = false;
this.hasPeriod = false;
this.hasOtherPunc = false;
this.isShort = false;
this.isLong = false;
this.isNumeric = false;
this.process();
};
var p = ReadWord.prototype;
p.process = function () {
var match = this.val.match(textRegex);
this.length = (match) ? match.length : 0;
var lastChar = this.val.substr(-1);
var firstChar = this.val[0];
if (lastChar == "\"" || lastChar == "'" || lastChar == ")" || lastChar =="”" || lastChar == "’" ) {
this.hasTrailingQuote = true;
}
if (firstChar == "\"" || firstChar == "'" || firstChar == "(" || firstChar =="“" || firstChar == "‘" ) {
this.hasLeadingQuote = true;
this.hasOtherPunc = true;
}
if (this.hasTrailingQuote) {
lastChar = this.val.substr(-2,1);
}
this.isNumeric = this.val.match(numRegex);
switch (lastChar) {
case ".":
case "!":
case "?":
this.hasPeriod = true;
break;
case ":":
case ";":
case ",":
case "-":
this.hasOtherPunc = true;
break;
}
switch (this.length) {
case 0:
case 1:
this.index = 0;
this.isShort = true;
break;
case 2:
case 3:
case 4:
this.index = 1;
this.isShort = true;
break;
case 5:
case 6:
case 7:
case 8:
this.index = 2;
break;
case 9:
case 10:
case 11:
case 12:
case 13:
this.index = 3;
this.isLong = true;
break;
default:
this.index = 4;
this.isLong = true;
break;
}
// Adjust index for leading quote
if (this.hasLeadingQuote) {
this.index ++;
}
};
window.ReadWord = ReadWord;
}(window) );