-
Notifications
You must be signed in to change notification settings - Fork 2
/
jquery.loremipsum.js
196 lines (178 loc) · 7.25 KB
/
jquery.loremipsum.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
185
186
187
188
189
190
191
192
193
194
195
196
/**
* @VERSION@
*
* Copyright (c) 2008-2009 Chris Thatcher (claypooljs.com)
* Dual licensed under the MIT (MIT-LICENSE.txt)
* and GPL (GPL-LICENSE.txt) licenses.
*
* jQuery Lorimipsum
*
* Ported with love (and little change or effort) from the
* Django Python Application Framework (djangoproject.com)
*
* """
* Utility functions for generating "lorem ipsum" Latin text.
* """
*/
(function($){
var COMMON_P = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.';
var WORDS = ['exercitationem', 'perferendis', 'perspiciatis', 'laborum', 'eveniet',
'sunt', 'iure', 'nam', 'nobis', 'eum', 'cum', 'officiis', 'excepturi',
'odio', 'consectetur', 'quasi', 'aut', 'quisquam', 'vel', 'eligendi',
'itaque', 'non', 'odit', 'tempore', 'quaerat', 'dignissimos',
'facilis', 'neque', 'nihil', 'expedita', 'vitae', 'vero', 'ipsum',
'nisi', 'animi', 'cumque', 'pariatur', 'velit', 'modi', 'natus',
'iusto', 'eaque', 'sequi', 'illo', 'sed', 'ex', 'et', 'voluptatibus',
'tempora', 'veritatis', 'ratione', 'assumenda', 'incidunt', 'nostrum',
'placeat', 'aliquid', 'fuga', 'provident', 'praesentium', 'rem',
'necessitatibus', 'suscipit', 'adipisci', 'quidem', 'possimus',
'voluptas', 'debitis', 'sint', 'accusantium', 'unde', 'sapiente',
'voluptate', 'qui', 'aspernatur', 'laudantium', 'soluta', 'amet',
'quo', 'aliquam', 'saepe', 'culpa', 'libero', 'ipsa', 'dicta',
'reiciendis', 'nesciunt', 'doloribus', 'autem', 'impedit', 'minima',
'maiores', 'repudiandae', 'ipsam', 'obcaecati', 'ullam', 'enim',
'totam', 'delectus', 'ducimus', 'quis', 'voluptates', 'dolores',
'molestiae', 'harum', 'dolorem', 'quia', 'voluptatem', 'molestias',
'magni', 'distinctio', 'omnis', 'illum', 'dolorum', 'voluptatum', 'ea',
'quas', 'quam', 'corporis', 'quae', 'blanditiis', 'atque', 'deserunt',
'laboriosam', 'earum', 'consequuntur', 'hic', 'cupiditate',
'quibusdam', 'accusamus', 'ut', 'rerum', 'error', 'minus', 'eius',
'ab', 'ad', 'nemo', 'fugit', 'officia', 'at', 'in', 'id', 'quos',
'reprehenderit', 'numquam', 'iste', 'fugiat', 'sit', 'inventore',
'beatae', 'repellendus', 'magnam', 'recusandae', 'quod', 'explicabo',
'doloremque', 'aperiam', 'consequatur', 'asperiores', 'commodi',
'optio', 'dolor', 'labore', 'temporibus', 'repellat', 'veniam',
'architecto', 'est', 'esse', 'mollitia', 'nulla', 'a', 'similique',
'eos', 'alias', 'dolore', 'tenetur', 'deleniti', 'porro', 'facere',
'maxime', 'corrupti'];
var COMMON_WORDS = ['lorem', 'ipsum', 'dolor', 'sit', 'amet', 'consectetur',
'adipisicing', 'elit', 'sed', 'do', 'eiusmod', 'tempor', 'incididunt',
'ut', 'labore', 'et', 'dolore', 'magna', 'aliqua'];
$.words = function(count, common){
/*"""
Returns a string of `count` lorem ipsum words separated by a single space.
If `common` is True, then the first 19 words will be the standard
'lorem ipsum' words. Otherwise, all words will be selected randomly.
"""*/
common = common?true:false;
var word_list;
if (common)
word_list = COMMON_WORDS;
else
word_list = [];
var c = word_list.length;
if (count > c){
word_list = word_list.concat( randomSample(WORDS, count-c) );
}else{
word_list = word_list.slice(0,count);
} return word_list.join(' ');
};
$.fn.words = function(){
var args = arguments;
this.each(function(){
this.text( $.words.apply($,args) );
});
};
$.titled = function(count, common){
//a convience function to upper case the resulting words
var title = [],
words = $.words(count, common);
$.each(words.split(' '), function(pos, word){
title.push(word.charAt(0).toUpperCase()+word.slice(1));
}); return title.join(' ');
};
$.fn.titled = function(){
var args = arguments;
this.each(function(){
this.text( $.titled.apply($, args) );
});
};
$.sentence = function(common){
/*"""
Returns a randomly generated sentence of lorem ipsum text.
The first word is capitalized, and the sentence ends in either a period or
question mark. Commas are added at random.
"""*/
//# Determine the number of comma-separated sections and number of words in
//# each section for this sentence.
common = common?true:false;
var sections = [],
range = randomNumber(8,15);
sections = $.words(range, common).split(' ');
for(var i=0;i<sections.length-1;i++){
if(Math.random() < 0.15){
sections[i] += ',';
}
}
var s = sections.join(' ');
//# Convert to sentence case and add end punctuation.
return (s.charAt(0).toUpperCase() + s.slice(1) + '.');
};
$.fn.sentence = function(){
var args = arguments;
this.each(function(){
this.text( $.sentence.apply($,args) );
});
};
$.paragraph = function(common){
/*"""
Returns a randomly generated paragraph of lorem ipsum text.
The paragraph consists of between 3 and 6 sentences, inclusive.
"""*/
common = common?true:false;
var paragraph = [],
range = randomNumber(3,6),
i;
if(common){
paragraph.push(COMMON_P);
}else{
for(i=0;i<range;i++){
paragraph.push($.sentence());
}
}
return paragraph.join(' ');
};
$.fn.paragraph = function(){
var args = arguments;
this.each(function(){
this.$ = $.paragraph.apply(_,args);
});
};
$.paragraphs = function(count, common){
/*"""
Returns a list of paragraphs as returned by paragraph().
If `common` is True, then the first paragraph will be the standard
'lorem ipsum' paragraph. Otherwise, the first paragraph will be random
Latin text. Either way, subsequent paragraphs will be random Latin text.
"""*/
common = common?true:false;
var paras = [];
for ( var i=0; i<count;i++){
if (common && i == 0)
paras = paras.concat(COMMON_P);
else
paras = paras.concat($.paragraph());
} return paras;
};
$.fn.paragraphs = function(){
var args = arguments;
this.each(function(){
this.$ = $.paragraphs.apply(_,args);
});
};
var randomSample = function(array, count){
var i,randomArray = [];
for(i=0;i<count;i++){
randomArray.push(array[randomNumber(0, array.length)]);
}
return randomArray;
};
var randomNumber = function(startRange, endRange){
var range = endRange - startRange,
randomNumber = endRange - Math.ceil(Math.random()*range);
return randomNumber;
};
var randomLetter = function(letters){
return letters.charAt(randomNumber(0, letters.length-1));
};
})(jQuery);