-
Notifications
You must be signed in to change notification settings - Fork 9
/
index.html
363 lines (317 loc) · 16.6 KB
/
index.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
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>jQuery LetterPic plugin</title>
<meta property="og:type" content="website" />
<meta property="og:title" content="jQuery LetterPic plugin" />
<meta property="og:description" content="LetterPic converts usernames into canvas based avatar pictures. " />
<meta property="og:url" content="https://goo.gl/tJAevN" />
<meta property="article:author" content="George Yakovlev" />
<meta property="og:image" content="https://raw.githubusercontent.com/yakovlevga/letterpic/master/resources/letterpic.png" />
<meta property="og:image:type" content="image/jpeg" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
<script src="js/jquery-3.1.1.min.js"></script>
<script src="js/jquery.letterpic.js"></script>
<script>
$(function() {
$(".letterpic").letterpic({
onElementReplaced: function($el, isBrokenImage) {
console.log($el, isBrokenImage);
},
onImageError: function($el, url) {
console.log('Image loading error: ' + url);
}
}).click(function() { alert('chaining'); });
var letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
function getRandomInitials() {
var name = "";
name += letters.charAt(Math.floor(Math.random() * letters.length));
name += " ";
name += letters.charAt(Math.floor(Math.random() * letters.length));
return name;
}
function addLetterpicEl($el) {
$el.append("<div class='letterpic' title='" + getRandomInitials() + "'></div>");
}
// gradient demo
var $gradientDemo = $(".gradient-demo");
for(var i = 0; i < 19; i++) {
addLetterpicEl($gradientDemo);
}
$gradientDemo.find(".letterpic").letterpic().click(function() { alert('chaining'); });
// custom gradient demo
var $gradientCustomDemo = $(".gradient-custom-demo");
var customGradients = [
["#fff", "#333", "#000", "#777"],
["#aaafff", "#aaa777"],
["#dddfff", "#ddd333", "#ddd777"],
];
for(var i = 0; i < customGradients.length; i++) {
addLetterpicEl($gradientCustomDemo);
}
$gradientCustomDemo.find(".letterpic").letterpic({
gradients: customGradients
});
// colors demo
var $colorDemo = $(".color-demo");
for(var i = 0; i < 19; i++) {
addLetterpicEl($colorDemo);
}
$colorDemo.find(".letterpic").letterpic({ fill: 'color' });
// custom colors demo
var $colorCustomDemo = $(".color-custom-demo");
var customColors = [ "#111", "#222", "#333", "#444", "#555" ];
for(var i = 0; i < customColors.length; i++) {
addLetterpicEl($colorCustomDemo);
}
$colorCustomDemo.find(".letterpic").letterpic({
fill: 'color',
colors: customColors
});
// image demo
var $imageDemo = $(".image-demo");
for(var i = 0; i < 8; i++) {
addLetterpicEl($imageDemo);
}
$imageDemo.find(".letterpic").letterpic({ fill: 'image' });
// custom images demo
var images = [
"https://image.freepik.com/free-vector/floral-background-with-watercolor-leaves_1085-886.jpg",
"https://image.freepik.com/free-vector/watercolor-feathers-background_23-2147607455.jpg",
"https://image.freepik.com/free-vector/octopus-pattern-design_1235-151.jpg"
];
var $imageCustomDemo = $(".image-custom-demo");
for(var i = 0; i < images.length; i++) {
addLetterpicEl($imageCustomDemo);
}
$imageCustomDemo.find(".letterpic").letterpic({
fill: 'image',
images: images,
fontColor: "#CCC",
imageOverlayColor: "rgba(0, 0, 0, .5)" });
});
</script>
<style>
.letterpic {
width: 60px;
height: 60px;
margin-right: 5px;
border-radius: 30px;
}
</style>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-10">
<h1 class="display-3 mt-4">jQuery LetterPic plugin</h1>
<p class="lead">
LetterPic converts usernames into canvas based avatar pictures.<br/>
View it on github: <a href="https://github.com/yakovlevga/letterpic">jQuery LetterPic github page</a>.
</p>
<h2 class="display-4 mt-4">Basic usage</h2>
<hr />
<p>
Define html-element with user name in <code>title="John Doe"</code> attribute.
Then call .letterpic() on proper selector or image with your jquery selector.
</p>
<h4 class="mt-2">Avatar caching by user name</h4>
<div class="media mb-4">
<div style="width:60px;" class="mr-3 text-center">
<div class="letterpic" title="Jon Snow"/></div>
<small>Jon Snow</small>
</div>
<div class="media-body">
<h5 class="mt-0">Avatar caching by user name.</h5>
By default user's color is cached by user's name (Jon Snow in this example).
</div>
</div>
<div class="media mb-4">
<div style="width:60px;" class="mr-3 text-center">
<div class="letterpic" title="Jon Snow"></div>
<small>Jon Snow</small>
</div>
<div class="media-body">
<h5 class="mt-0">Avatar caching by user id</h5>
This img has the same attribute <code>title="Jon Snow"</code>. So it's looks same too.
</div>
</div>
<div class="media">
<div style="width:60px;" class="mr-3 text-center">
<div class="letterpic" title="Jon Snow" data-userid="1"></div>
<small>Jon Snow</small>
</div>
<div class="media-body">
<h5 class="mt-0">Avatar caching</h5>
To avoid collision situations, when two different users can have same name,<br/>
you should add <code>data-userid=YourInternalUserId</code> attribute to element.<br>
In this way user's colors will be cached by this id, not by name.<br>
For example, this user has same name, but different <code>data-userid="1"</code> value.
</div>
</div>
<h4 class="mt-2">Broken image replacement</h4>
<p>
You could use letterpic to replace images with broken sources. <br/>
Don't forget to place user name to img <code>title</code> attribute.
</p>
<div class="media">
<div style="width:60px;" class="mr-3 text-center">
<img class="letterpic" src="brokenImageUrl.jpg" title="Jon Snow" data-userid="1"/>
<small>Jon Snow</small>
</div>
<div class="media-body">
<h5 class="mt-0">Broken image replacement</h5>
There are wrong image <code>src="brokenImageUrl.jpg"</code> attribute.<br/>
LetterPic replace it with letter avatar after loading error event.
</div>
</div>
<h2 class="display-4 mt-4">Color, gradient or image background</h2>
<hr/>
<h3>Gradients</h3>
<div>
<p>
By default letterpic uses gradients as background. It has 19 predefined gradient color scheme,<br/>
based on google material colors. You can change this scheme, just pass <code>gradients</code> to options on init.<br/>
</p>
<h5 class="mt-4">Default gradient backgrounds:</h5>
<pre><code>
$(".letterpic").letterpic();
</code></pre>
<div class="gradient-demo"></div>
<h5 class="mt-4">Custom gradient backgrounds:</h5>
You should pass array of arrays with gradient colors ([ ["#color1", "$color2", ...], [...], ...]).
<pre><code>
$(".letterpic").letterpic({
gradients: [
["#fff", "#333", "#000", "#777"],
["#aaafff", "#aaa777"],
["#dddfff", "#ddd333", "#ddd777"],
]
});</code></pre>
<div class="gradient-custom-demo"></div>
</div>
<h3 class="mt-4">Colors</h3>
<div>
<p>
If you want to use solid color as background, you show pass <code>fill: 'color'</code> parameter as option on init.
By default letterpic has predefined color scheme with 19 colors, based on google material styles. <br/>
You can change this scheme, just pass array of <code>colors: ["#color1", "#color2", ...]</code> to options on init.<br/>
</p>
<h5 class="mt-4">Default color backgrounds:</h5>
<pre><code>
$(".letterpic").letterpic({ fill: 'color' });
</code></pre>
<div class="color-demo"></div>
<h5 class="mt-4">Custom color scheme:</h5>
<pre><code>
$(".letterpic").letterpic({
fill: 'color',
colors: [ "#111", "#222", "#333", "#444", "#555" ]
});</code></pre>
<div class="color-custom-demo"></div>
</div>
<h3 class="mt-4">Images</h3>
<div>
<p>
Another possibility is to use image with <code>fill: 'image'</code> parameter as option on init.
By default letterpic has few example background pattens from <a href="http://www.colourlovers.com/">colourlovers.com</a>.<br/>
You can change this scheme, just pass array of <code>image: ["imageUrl1", "imageUrl2", ...]</code> to options on init.<br/>
Try to define custom <code>fontColor: "#color"</code> and <code>imageOverlayColor: "#rgbaColor"</code> to increase the contrast of final image.
</p>
<h5 class="mt-4">Default image backgrounds:</h5>
<pre><code>
$(".letterpic").letterpic({ fill: 'image' });
</code></pre>
<div class="image-demo"></div>
<h5 class="mt-4">Custom images (images taken from <a href="http://www.freepik.com/">freepik.com</a>):</h5>
<pre><code>
$(".letterpic").letterpic({
fill: 'image',
images: [
"https://image.freepik.com/free-vector/floral-background-with-watercolor-leaves_1085-886.jpg",
"https://image.freepik.com/free-vector/watercolor-feathers-background_23-2147607455.jpg",
"https://image.freepik.com/free-vector/octopus-pattern-design_1235-151.jpg"
],
fontColor: "#CCC",
imageOverlayColor: "rgba(0, 0, 0, .5)"
});</code></pre>
<div class="image-custom-demo"></div>
</div>
<h2 class="display-4 mt-4">Options</h2>
<table class="table mb-4">
<tr>
<th>
Option
</th>
<th>
Default value
</th>
<th>
Possible values
</th>
<th>
Description
</th>
</tr>
<tr>
<td>fill</td>
<td>'gradient'</td>
<td>'color', 'gradient' or 'image'</td>
<td>
Background drawing style.
</td>
</tr>
<tr>
<td>colors</td>
<td>Array of 19 predifined colors.</td>
<td>Array of colors: ["#453445", "#546343", ...]</td>
<td>Color scheme for color background. It works only if 'fill': 'color' passed to options.</td>
</tr>
<tr>
<td>gradients</td>
<td>Array of 19 predifined gradients.</td>
<td>Array of array of colors: <br/>
[["#111", "#222", ...],<br/>
[["#444", "#555", "#000", ...],<br/>
[["#453445", "#546343"],<br/>
...]<br/>
</td>
<td>Color scheme for gradient background. It works only if no 'fill' or 'fill': 'gradient' passed to options.</td>
</tr>
<tr>
<td>images</td>
<td>Array of 8 predifined images.</td>
<td>Array of image urls: ["http://url1", "/images/img2", ...]</td>
<td>Image array for image background. It works only if 'fill': 'image' passed to options.</td>
</tr>
<tr>
<td>imageOverlayColor</td>
<td>Transparent.</td>
<td>RGBa color with transparency, e.g. 'rgba(0,0,0,.5))'</td>
<td>Overlay color for 'fill': 'image'. Use it to increase the contrast of avatar.</td>
</tr>
<tr>
<td>font</td>
<td>'Arial'</td>
<td>Font family name, e.g. 'Arial', 'Verdana', 'Tahomf'</td>
<td>Font family for avatar text.</td>
</tr>
<tr>
<td>fontColor</td>
<td>'#fff'</td>
<td>String with color, e.g. '#fff', '#000' and etc.</td>
<td>Font color for avatar text.</td>
</tr>
<tr>
<td>fontSize</td>
<td>.45</td>
<td>Relative size of font, any decimal in range from 0 to 1</td>
<td>Relative size of font for avatar text</td>
</tr>
</table>
</div>
</div>
</body>
</html>