git ssb

0+

ev / microbay



forked from Dominic / patchbay

Tree: b36938964724c375a4405fe69f835799cc9746a6

Files: b36938964724c375a4405fe69f835799cc9746a6 / modules / raw.js

1376 bytesRaw
1var h = require('hyperscript')
2var u = require('../util')
3var pull = require('pull-stream')
4var Scroller = require('pull-scroll')
5
6var plugs = require('../plugs')
7var message_render = plugs.first(exports.message_render = [])
8var message_compose = plugs.first(exports.message_compose = [])
9
10// from ssb-ref
11var refRegex = /((?:@|%|&)[A-Za-z0-9\/+]{43}=\.[\w\d]+)/g
12
13function linkify(text) {
14 var arr = text.split(refRegex)
15 for (var i = 1; i < arr.length; i += 2) {
16 arr[i] = h('a', {href: '#' + arr[i]}, arr[i])
17 }
18 return arr
19}
20
21exports.message_meta = function (msg) {
22 var tmp = h('div')
23 var el
24 var pre
25 return h('input', {
26 type: 'checkbox',
27 title: 'View Data',
28 onclick: function () {
29 var msgEl = this.parentNode.parentNode.parentNode
30 var msgContentEl = msgEl.querySelector('.message_content')
31 if (this.checked) {
32 // move away the content
33 while (el = msgContentEl.firstChild)
34 tmp.appendChild(el)
35 // show the raw stuff
36 if (!pre) pre = h('pre', linkify(JSON.stringify({
37 key: msg.key,
38 value: msg.value
39 }, 0, 2)))
40 msgContentEl.appendChild(pre)
41 } else {
42 // hide the raw stuff
43 msgContentEl.removeChild(pre)
44 // put back the content
45 while (el = tmp.firstChild)
46 msgContentEl.appendChild(el)
47 }
48 }
49 })
50}
51
52
53

Built with git-ssb-web