git ssb

16+

Dominic / patchbay



Tree: 98875334dade3d82e196503d21dae241058b2a35

Files: 98875334dade3d82e196503d21dae241058b2a35 / modules / raw.js

1395 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
13exports.linkify = function (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', exports.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