-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.js
184 lines (164 loc) · 5.34 KB
/
main.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
//three buttons
//add paragraph button
$('#add').click(function(){
generate();
return false;
});
$('#add-ul').click(function(){
uList();
return false;
});
$('#add-ol').click(function(){
oList();
return false;
});
//remove last element button
$('#removeSingle').click(function(){
$('.lotripsum:last').remove();
return false;
});
//remove it all and add a funny line
$('#removeAll').click(function(){
$('#text').empty();
return false;
});
$('#raw').click(function(){
raw();
return false;
});
//HTML tag button
var tags = false; //determins if 'add' or 'removal' is appropriate
$('#html-button').click(function(){
if(tags == false){
addHTML();
tags = true;
$('#html-button').text('Remove <html>');
} else {
removeHTML();
tags = false;
$('#html-button').text('Add <html>');
}
return false;
});
//prepare the entire paragraph
function generate() {
var lotrLength = lotr.length,
ipsumLength = ipsum.length,
paragraph, sentence, lotrBrick, ipsumBrick = null,
ipsumBrickLength = Math.round(Math.random()*(2-1)+1);
//create paragraph
paraLength = Math.round(Math.random()*(8-2)+2);
for(p=0; p<paraLength; p++){
//create sentence
sentence = null;
sentenceBricks = Math.round(Math.random()*(3-1)+1);
//console.log("sentence bricks: ", sentenceBricks);
for(s=0; s<sentenceBricks; s++){
//create a single lotr brick
lotrBrick = null;
lotrBrickLength = Math.round(Math.random()*(4-1)+1);
for(i=0; i<=lotrBrickLength; i++){
lotrSingle = Math.round(Math.random()*lotrLength)
if(lotrBrick == null) {
lotrBrick = lotr[lotrSingle];
} else {
lotrBrick = lotrBrick + ' ' + lotr[lotrSingle];
}
//console.log(lotrBrick);
}
//add single lotr brick to sentence
if(sentence == null){
sentence = lotrBrick;
} else {
sentence = sentence + ' ' + lotrBrick;
}
lotrBrick = null;
//create a single ipsum brick
for(i=0; i<=ipsumBrickLength; i++){
ipsumSingle = Math.round(Math.random()*ipsumLength)
if(ipsumBrick == null){
ipsumBrick = ipsum[ipsumSingle];
} else {
ipsumBrick = ipsumBrick + ' ' + ipsum[ipsumSingle];
}
}
//add single ipsum brick to the sentence
sentence = sentence + ' ' + ipsumBrick;
ipsumBrick = null;
}
sentence = sentence.charAt(0).toUpperCase() + sentence.slice(1); //uppercase first letter of sentence and add rest of sentence after first character
sentence = sentence + '.' //put a period at the end of the sentence
if(paragraph == null){
paragraph = sentence;
} else {
paragraph = paragraph + ' ' + sentence;
}
sentence = null;
}
paragraph = "<p class='lotripsum'>"+paragraph+"</p>"; //attach the <p> tags for styling
$('#text').append(paragraph); //append the paragraph to the specific id
paragraph = null; //revert to null so the paragraph doesn't concatenate
window.scrollTo(0,document.body.scrollHeight);
}
function uList() {
var lotrLength = lotr.length,
listBrick = null,
listBrickLength = Math.round(Math.random()*(7-1)+1);
for(i=0; i<=listBrickLength; i++){
var lotrSingle = Math.round(Math.random()*lotrLength)
if(listBrick == null) {
listBrick = '<li>' + lotr[lotrSingle] + '</li>';
} else {
listBrick = listBrick + '<li>' + lotr[lotrSingle] + '</li>';
}
}
listBrick = '<ul class="lotripsum">' + listBrick + '</ul>';
$('#text').append(listBrick);
window.scrollTo(0,document.body.scrollHeight);
}
function oList() {
var lotrLength = lotr.length,
listBrick = null,
listBrickLength = Math.round(Math.random()*(7-1)+1);
for(i=0; i<=listBrickLength; i++){
var lotrSingle = Math.round(Math.random()*lotrLength)
if(listBrick == null) {
listBrick = '<li>' + lotr[lotrSingle] + '</li>';
} else {
listBrick = listBrick + '<li>' + lotr[lotrSingle] + '</li>';
}
}
listBrick = '<ol class="lotripsum">' + listBrick + '</ol>';
$('#text').append(listBrick);
window.scrollTo(0,document.body.scrollHeight);
}
function addHTML() {
$('#text h1').prepend('<span class="html"><h1></span>').append('<span class="html"></h1></span>');
$('#text p').prepend('<span class="html"><p></span>').append('<span class="html"></p></span>');
$('#text a, #content p a').prepend('<span class="html"><a href=""></span>').append('<span class="html"></a></span>');
$('#text ul').prepend('<span class="html"><ul></span>').append('<span class="html"></ul></span>');
$('#text ul li').prepend('<span class="html"><li></span>').append('<span class="html"></li></span>');
$('#text ol').prepend('<span class="html"><ol></span>').append('<span class="html"></ol></span>');
$('#text ol li').prepend('<span class="html"><li></span>').append('<span class="html"></li></span>');
}
function removeHTML() {
$('.html').remove();
}
// select text for highlight
function selectText(containerid) {
if (document.selection) {
var range = document.body.createTextRange();
range.moveToElementText(document.getElementById(containerid));
range.select();
} else if (window.getSelection) {
var range = document.createRange();
range.selectNode(document.getElementById(containerid));
window.getSelection().addRange(range);
}
}
function loadThree() {
generate();
generate();
generate();
}
window.onLoad = loadThree(); //do this right away so the page starts with three paragraphs instead of empty page