-
Notifications
You must be signed in to change notification settings - Fork 0
/
hello-grouper-test.html
117 lines (81 loc) · 2.51 KB
/
hello-grouper-test.html
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
<html>
<head>
<title>Hello - Grouper Test</title>
<style type="text/css">
#container {
font-family: arial;
font-size: 14px;
line-height: 150%;
}
</style>
</head>
<body>
<div id="container"></div>
<script type="text/javascript">
//Demo text
var text = [ { content: "The information contained in this communication is confidential and may be legally privileged. It is intended solely for the use of the individual or the entity to whom it is addressed and the others authorised to receive it" } ];
var ranges = [
{ start:10, end:21, style: { fontWeight:'bold' } },
{ start:45, end:80, style: { fontWeight:'bold' } },
{ start:20, end:50, style: { fontStyle:'italic' } },
{ start:40, end:200, style: { textDecoration:'underline' } }
];
//Split string into two parts
var stringSplitter = function( Str, Pos ) {
return [ Str.substring(0, Pos), Str.substring(Pos) ];
};
//
var i = 0;
while( i < ranges.length || i > 10) {
var ii = 0;
var totalTextCount = 0;
while( ii < text.length || ii > 10) {
var start = (
ranges[i].start > totalTextCount &&
ranges[i].start < (totalTextCount + text[ii].content.length)
) ? true : false;
var end = (
ranges[i].end > totalTextCount &&
ranges[i].end <= (totalTextCount + text[ii].content.length) &&
start === false
) ? true : false;
var testString = ( start === true ) ? ranges[i].start-totalTextCount : ranges[i].end-totalTextCount;
var textArray = stringSplitter ( text[ii].content, testString );
text[ii].content = textArray[0];
//add second part if string is greater than zero
if( textArray[1].length > 0) {
text.splice(ii+1, 0, {
content: textArray[1]
} );
}
totalTextCount += text[ii].content.length;
if( end === true ) {
break;
}
ii++;
}
i++;
};
//Load text into container
var container = document.querySelector('#container');
container.innerHTML = '';
var totalTextCount = 0;
for (var i = 0; i < text.length; i++) {
var span = document.createElement('span');
span.innerHTML = text[i].content;
for (var ii = 0; ii < ranges.length; ii++) {
for (style in ranges[ii].style) {
if(
ranges[ii].start <= totalTextCount &&
ranges[ii].end >= totalTextCount+text[i].content.length
) {
span.style[style] = ranges[ii].style[style];
}
}
}
totalTextCount += text[i].content.length;
container.appendChild( span );
};
</script>
</body>
</html>