git ssb

16+

Dominic / patchbay



Commit 1d93c63544059ee8195e84d178b24ed4b2c39a2f

Render and suggest emoji

cel committed on 11/24/2016, 2:48:32 AM
Parent: f00625ab123486916f87fdac226a199db6ad70bf

Files changed

modules_basic/markdown.jschanged
modules_extra/index.jschanged
modules_extra/emoji.jsadded
style.csschanged
modules_basic/markdown.jsView
@@ -1,10 +1,21 @@
11 var markdown = require('ssb-markdown')
22 var h = require('hyperscript')
33 var ref = require('ssb-ref')
44
5-var blob_url = require('../plugs').first(exports.blob_url = [])
5 +var plugs = require('../plugs')
6 +var blob_url = plugs.first(exports.blob_url = [])
7 +var emoji_url = plugs.first(exports.emoji_url = [])
68
9 +function renderEmoji(emoji) {
10 + var url = emoji_url(emoji)
11 + if (!url) return ':' + emoji + ':'
12 + return '<img src="' + encodeURI(url) + '"'
13 + + ' alt=":' + escape(emoji) + ':"'
14 + + ' title=":' + escape(emoji) + ':"'
15 + + ' class="emoji">'
16 +}
17 +
718 exports.markdown = function (content) {
819 if('string' === typeof content)
920 content = {text: content}
1021 //handle patchwork style mentions.
@@ -15,8 +26,9 @@
1526 })
1627
1728 var md = h('div.markdown')
1829 md.innerHTML = markdown.block(content.text, {
30 + emoji: renderEmoji,
1931 toUrl: function (id) {
2032 if(ref.isBlob(id)) return blob_url(id)
2133 return '#'+(mentions[id]?mentions[id]:id)
2234 }
modules_extra/index.jsView
@@ -1,7 +1,9 @@
11 module.exports = {
22 "audio-mp3.js": require('./audio-mp3.js'),
33 "channel.js": require('./channel.js'),
4 + "emoji.js": require('./emoji.js'),
5 + "suggest-emoji.js": require('./suggest-emoji.js'),
46 "git.js": require('./git.js'),
57 "notifications.js": require('./notifications.js'),
68 "meta-image.js": require('./meta-image.js'),
79 "music-release-cc.js": require('./music-release-cc.js'),
modules_extra/emoji.jsView
@@ -1,0 +1,14 @@
1 +var emojis = require('emoji-named-characters')
2 +var emojiNames = Object.keys(emojis)
3 +
4 +var plugs = require('../plugs')
5 +var blob_url = plugs.first(exports.blob_url = [])
6 +
7 +exports.emoji_names = function () {
8 + return emojiNames
9 +}
10 +
11 +exports.emoji_url = function (emoji) {
12 + return emoji in emojis &&
13 + blob_url(emoji).replace(/\/blobs\/get/, '/img/emoji') + '.png'
14 +}
style.cssView
@@ -259,9 +259,15 @@
259259 border-right: 2px solid #eee;
260260 padding-right: 5px;
261261 }
262262
263 +.emoji {
264 + height: 1em;
265 + width: 1em;
266 + vertical-align: middle;
267 +}
263268
269 +
264270 /* -- suggest box */
265271
266272 .suggest-box > * {
267273 display: block;
@@ -285,8 +291,14 @@
285291 background: #white;
286292 border-radius: 1em;
287293 }
288294
295 +/* emoji */
296 +.suggest-box img {
297 + height: 20px;
298 + width: 20px;
299 +}
300 +
289301 /* avatar */
290302
291303 .avatar--large,
292304 .avatar--thumbnail,

Built with git-ssb-web