-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCountEscapeEncodedGSMChars.diff
More file actions
122 lines (111 loc) · 3.75 KB
/
CountEscapeEncodedGSMChars.diff
File metadata and controls
122 lines (111 loc) · 3.75 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
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
Index: user-tool/src/webapp/content/js/sms.send.js
===================================================================
--- user-tool/src/webapp/content/js/sms.send.js (revision 77950)
+++ user-tool/src/webapp/content/js/sms.send.js (working copy)
@@ -1,6 +1,9 @@
/**
* JS Onload code for the SMS User Tool's Send view.
* @Author lovemore.nalube@uct.ac.za
+ *
+ * Edited By edmore.moyo@uct.ac.za
+ *
**/
$(document).ready(function() {
@@ -8,7 +11,7 @@
history.go(-1);
return false;
});
-
+
//Counter for the SMS Textarea
$("#messageBody")
@@ -36,15 +39,21 @@
few: "#5C0002",
fewer: "#D40D12"
},
+ countOfEscapedChars = 0,
lengthLeft = 160;
if (len > 0) {
//SMS-170: When entering an SMS message, detect non-GSM chars and adjust max length to 70
//sms has 140 bytes. if it's utf-16, that's 70 chars, if it's gsm alphabet, 160 chars are packed into 140 bytes (because the alphabet is 7bit)
limit = !smsUtils.isEncodeableInGsm0338(boxValue) ? 70 : 160;
-
lengthLeft = limit - len;
+ // Get a count of the escape-encoded GSM characters in the string
+ if( limit === 160 ){
+ countOfEscapedChars = smsUtils.numberOfEscapeEncodedGSMChars(boxValue);
+ lengthLeft = lengthLeft - countOfEscapedChars;
+ }
+
if( lengthLeft >= 20 ){
$('#smsBoxCounter').css("color", counterColour.enough);
}else if( lengthLeft < 20 && lengthLeft > 9 ){
@@ -55,10 +64,10 @@
}
$('#smsBoxCounter').text(lengthLeft);
-
+
//is message is too long?
smsUtils.error.isMessageLengthValid = lengthLeft >= 0;
-
+
$.fn.SMS.set.setSubmitTaskButton();
});
@@ -224,4 +233,4 @@
}
-});
\ No newline at end of file
+});
Index: user-tool/src/webapp/content/js/sms.utils.js
===================================================================
--- user-tool/src/webapp/content/js/sms.utils.js (revision 77950)
+++ user-tool/src/webapp/content/js/sms.utils.js (working copy)
@@ -1,6 +1,8 @@
/**
* JS library for the SMS User Tool Utilities.
* @author lovemore.nalube@uct.ac.za
+ *
+ * Edited By edmore.moyo@uct.ac.za
**/
var smsUtils = (function($) {
@@ -92,9 +94,30 @@
//log(true);
return true;
+ },
+
+
+ // @memberof smsUtils
+ // @description Get the count of the number of Escape-encoded GSM characters
+ // @author edmore.moyo@uct.ac.za
+
+ numberOfEscapeEncodedGSMChars = function(utfString){
+ var utfChars = utfString.split(''),
+ GSMEscaped = [0x000C, 0x005E, 0x007B, 0x007D, 0x005C, 0x005B, 0x007E, 0x005D, 0x007C, 0x20AC],
+ i,j,
+ count = 0;
+
+ outer: for(var j = 0; j < utfChars.length; j+=1){
+ for (var i = 0; i < GSMEscaped.length; i+=1) {
+ if (String.fromCharCode( GSMEscaped[i] ) === utfChars[j]) {
+ count+=1;
+ continue outer;
+ }
+ }
+ }
+ return count;
};
-
//public methods
return {
error: {
@@ -108,6 +131,7 @@
},
isEncodeableInGsm0338: function(utfString){
return _isEncodeableInGsm0338(utfString);
- }
+ },
+ numberOfEscapeEncodedGSMChars: numberOfEscapeEncodedGSMChars
};
-})($);
\ No newline at end of file
+})($);