This repository has been archived by the owner on Nov 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 495
/
emoji.html
429 lines (392 loc) · 12.1 KB
/
emoji.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
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Emoji</title>
</head>
<body>
<a href="https://github.com/rongcloud/websdk-demo/blob/master/emoji.html" class="get-source">获取源码</a>
<style>
body{
font-family:arial;
font-size: 14px;
color: #333;
line-height: 1.42857143;
}
.chatbox {
margin-bottom: 20px;
}
.get-source {
text-decoration:none;
background:#000;
color:#fff;
padding:10px 30px;
border-radius:5px;
position:fixed;
right:5px;
top:5px;
}
pre.code{
padding:5px;
border:1px solid #ccc;
background:#f5f5f5;
border-radius:3px;
font-family:arial;
line-height:2;
}
p {
margin: 5px;
margin-left: 0;
}
h1 {
font-size: 36px;
}
h2 {
font-size: 30px;
}
ol li {
margin-bottom: 10px;
}
ol ol, ol ul, ul ol, ul ul {
padding-left: 17px;
}
.support-list{
background:#f5f5f5;
line-height: 2;
font-size: 12px;
}
.doc-content {
font-size: 13px;
background:#f5f5f5;
padding-bottom: 10px;
padding-top: 10px;
}
a {
cursor: pointer;
color: #337ab7;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
pre {
margin: 0;
border: none;
background-color: #f5f5f5;
padding: 9.5px;
font-size: 13px;
}
.table-bordered, td, tr, th {
border: 1px solid #ddd;
}
.table>caption+thead>tr:first-child>td, .table>caption+thead>tr:first-child>th, .table>colgroup+thead>tr:first-child>td, .table>colgroup+thead>tr:first-child>th, .table>thead:first-child>tr:first-child>td, .table>thead:first-child>tr:first-child>th {
border-top: none;
}
td, th {
padding: 8px;
vertical-align: top;
border-top: 1px solid #ddd;
}
th {
vertical-align: bottom;
}
#chatbox-send {
margin-left: 1%;
}
.chatbox-emoji-btn {
margin-left: 1%;
}
.chatbox-emoji-panel {
margin-left: 1%;
width: 50%;
}
.chatbox-message {
margin-left: 1%;
width: 50%;
height: 150px;
font-size: 14px;
}
.chatbox-show {
float: right;
width: 365px;
height: 150px;
border: 1px solid black;
overflow: auto;
margin-right: 2%;
}
.chatbox-btn {
margin-left: 1%;
padding: 2px 5px;
}
</style>
<script src="https://cdn.ronghub.com/RongEmoji-2.2.7.js"></script>
<h1>Emoji</h1>
<h2>融云消息 message 里的 emoji 说明</h2>
<ol>
<li>
<p>发消息时, 必须直接发送emoji原生字符. 如:😀 , 转换方法:symbolToEmoji</p>
</li>
<li>
<p>Web SDK接收消息时接收到的是unicode编码格式, 如:”ef600”.需要转化才能正确显示原生emoji</p>
</li>
</ol>
<h2>Emoji 说明</h2>
<ol>
<li>
<p>emoji 插件内置了128个emoji表情的图片, <strong>主要是为了做消息输入框的表情选项, </strong>也可自行扩展配置.</p>
</li>
<li>
<p>
支持范围:
<p>(1), IE7+、Edge、Chrome 30+、Firefox 30+、Safari 10+ 等主流桌面版浏览器</p>
<p>(2), Android 4.4+系统的Chrome浏览器以及微信浏览器</p>
<p>(3), iPhone 操作系统iOS 8.0+ 的Safari浏览器以及微信浏览器</p>
</p>
</li>
<li>
<p><a onclick="setupExpand('initCode')">Emoji 初始化设置</a></p>
<pre id="initCode" style="display: none">
// 直接初始化
RongIMLib.RongIMEmoji.init();
// 通过配置初始化
// 表情信息可参考 <a href="http://unicode.org/emoji/charts/full-emoji-list.html">http://unicode.org/emoji/charts/full-emoji-list.html</a>
var config = {
size: 24, // 大小, 默认 24, 建议15 - 55
url: '//f2e.cn.ronghub.com/sdk/emoji-48.png', // 所有 emoji 的背景图片
lang: 'zh', // 选择的语言, 默认 zh
// 扩展表情
extension: {
dataSource: {
"u1F914":{
"en":"thinking face", // 英文名称
"zh":"思考", // 中文名称
"tag":"🤔", // 原生emoji
"position":"0px 0px" // 所在背景图位置坐标
},
.....
.....
},
// 新增 emoji 的背景图 url
url: 'https://emojipedia-us.s3.amazonaws.com/thumbs/160/apple/96/thinking-face_1f914.png'
}
};
RongIMLib.RongIMEmoji.init(config);
</pre>
</li>
<li>
<p><a onclick="setupExpand('sdkFuc')">Emoji API</a></p>
<table id="sdkFuc" class="table table-bordered" style="display: none; width: 97%">
<thead>
<tr>
<th>方法</th>
<th>使用示例</th>
<th>方法说明</th>
</tr>
</thead>
<tbody>
<tr>
<td>list</td>
<td>
<!-- start -->
<pre>
var list = RongIMEmoji.list;</pre>
<!-- end -->
</td>
<td>获取所有数据,方便二次开发<br>
[{unicode: "u1F600", emoji: "😀", symbol:"[笑嘻嘻]", shadowDom: span }, { }, ………]
</td>
</tr>
<tr>
<td>emojiToSymbol(emoji, reg, func)</td>
<td>
<!-- start -->
<pre>
var symbol = RongIMEmoji.emojiToSymbol('我是一个表情😁');
<strong>返回值: 我是一个表情[露齿而笑]</strong></pre>
<!-- end -->
</td>
<td>将原生emoji转化为对应文字</td>
</tr>
<tr>
<td>symbolToEmoji(symbol, func)</td>
<td>
<!-- start -->
<pre>
var emoji = RongIMEmoji.symbolToEmoji('我是一个表情[露齿而笑]');
<strong>返回值: 我是一个表情😁</strong>
var emoji = RongIMEmoji.symbolToEmoji('我是一个表情[露齿而笑]', function(emoji) {
return '[emoji]';
});
<strong>返回值: 我是一个表情[emoji]</strong></pre>
<!-- end -->
</td>
<td>将emoji的对应名称转化为原生emoji字符</td>
</tr>
<tr>
<td>emojiToHTML(emoji, size, reg, func)</td>
<td>
<!-- start -->
<pre>
var html = RongIMEmoji.emojiToHTML('我是一个表情😁');</pre>
<!-- end -->
</td>
<td>将原生emoji转化为span标签, 默认标签大小为24px</td>
</tr>
<tr>
<td>symbolToHTML(symbol, size, reg, func)</td>
<td>
<!-- start -->
<pre>
var html = RongIMEmoji.symbolToHTML('我是一个表情[露齿而笑]')</pre>
<!-- end -->
</td>
<td>将原生emoji转化为span标签</td>
</tr>
<tr>
<td>isSupportEmoji</td>
<td>
<!-- start -->
<pre>
var isSupportEmoji = RongIMEmoji.isSupportEmoji;</pre>
<!-- end -->
</td>
<td>判断是否支持emoji的渲染</td>
</tr>
</tbody>
</table>
</li>
</ol>
<script>
function setupExpand(expandId) {
var expandDom = document.getElementById(expandId);
var display = expandDom.style.display;
display = display === "none" ? "block" : "none";
expandDom.style.display = display;
}
</script>
<div class="chatbox">
<h2>发送表情极简demo</h3>
<div class="chatbox-tools">
<div class="chatbox-tools-emoji">
<a href="#emoji" class="chatbox-emoji-btn" id="chatbox-emoji-btn">表情</a>
<div class="chatbox-emoji-panel" id="chatbox-emoji-panel"></div>
</div>
</div>
<ol class="chatbox-show" id="chatbox-show"></ol>
<textarea class="chatbox-message" id="chatbox-message">今天心情很不错[笑嘻嘻]</textarea>
<p>
<a class="chatbox-btn" id="symbol-emoji">SymbolToEmoji</a>
<a class="chatbox-btn" id="emoji-symbol" onclick="emojiToSymbol">EmojiToSymbol</a>
<a class="chatbox-btn" id="emoji-html" onclick="emojiToHtml">EmojiToHtml</a>
<a class="chatbox-btn" id="symbol-html" onclick="symbolToHtml">SymbolToHtml</a>
</p>
<p>
<a class="chatbox-btn" id="symbol-emoji-invalid">SymbolToEmoji( 不支持emoji时, 原生emoji字符显示为 [emoji] )</a>
</p>
</div>
<script>
/*
发送表情极简Demo
*/
(function(){
var chatbox = document.getElementById("chatbox-message");
var btn = document.getElementById("chatbox-emoji-btn");
var panel = document.getElementById("chatbox-emoji-panel");
var chatshow = document.getElementById("chatbox-show");
var RongIMEmoji = RongIMLib.RongIMEmoji;
var config = {
size: 24,
// url: '//cdn.ronghub.com/emojis-hd.png?replace', // 传入服务器路径
url: 'res/emojis-hd.png?replace', // 传入本地路径
lang: 'zh',
extension: {
dataSource: {
u1F914: {
zh: '思考',
en: 'thinking face',
tag: '🤔',
position: '0px 0px'
}
},
url: 'https://cdn.ronghub.com/thinking-face.png'
}
};
RongIMEmoji.init(config);
appendChild('init: 初始化RongIMEmoji');
btn.onclick = function(){
panel.style.display = "block";
var emojis = getEmojiDetailList();
bindClickEmoji(emojis);
return false;
};
var symbolToEmojiBtn = document.getElementById("symbol-emoji");
symbolToEmojiBtn.onclick = function(){
var message = chatbox.value;
message = RongIMEmoji.symbolToEmoji(message);
appendChild('symbolToEmoji: ' + message);
return false;
};
var emojiToSymbol = document.getElementById("emoji-symbol");
emojiToSymbol.onclick = function(){
var message = chatbox.value;
message = RongIMEmoji.emojiToSymbol(message);
appendChild('emojiToSymbol: ' + message);
return false;
};
var emojiToHtmlBtn = document.getElementById("emoji-html");
emojiToHtmlBtn.onclick = function(){
var message = chatbox.value;
message = RongIMEmoji.emojiToHTML(message, 33);
appendChild('emojiToHtml: ' + message);
return false;
};
var symbolToHtmlBtn = document.getElementById("symbol-html");
symbolToHtmlBtn.onclick = function(){
var message = chatbox.value;
message = RongIMEmoji.symbolToHTML(message);
appendChild('symbolToHtml: ' + message);
return false;
};
var symbolToEmojiInvalid = document.getElementById("symbol-emoji-invalid");
symbolToEmojiInvalid.onclick = function() {
var message = chatbox.value;
var isSupportEmoji = RongIMEmoji.isSupportEmoji;
message = RongIMEmoji.symbolToEmoji(message, function(emoji) {
return isSupportEmoji ? emoji : '<span style="color: rgb(182, 182, 182)">[emoji]</span>';
});
appendChild('symbolToEmoji: ' + message);
return false;
};
function appendChild(text) {
var div = document.createElement('div');
div.innerHTML = '<li>' + text + '</li>';
var child = div.childNodes[0];
chatshow.appendChild(child);
}
function getEmojiDetailList() {
var shadowDomList = [];
for (var i = 0; i < RongIMEmoji.list.length; i++) {
var value = RongIMEmoji.list[i];
shadowDomList.push(value.node);
}
return shadowDomList;
}
function bindClickEmoji(emojis) {
for(var i=0;i<emojis.length;i++){
var emojiHtml = emojis[i];
panel.appendChild(emojiHtml);
emojiHtml.onclick = clickEmoji;
}
}
function clickEmoji(event) {
var e = event || window.event;
var target = e.target || e.srcElement;
if (document.all && !document.addEventListener === false) {
console.log(target);
}
chatbox.value = chatbox.value + target.getAttribute("name");
}
})();
</script>
</body>
</html>