git ssb

16+

Dominic / patchbay



Tree: 7478b5388306a177f85de2b6a0c3bcedf8635c87

Files: 7478b5388306a177f85de2b6a0c3bcedf8635c87 / modules_extra / raw.js

1381 bytesRaw
1var h = require('hyperscript')
2var u = require('../util')
3var pull = require('pull-stream')
4var Scroller = require('pull-scroll')
5
6// from ssb-ref
7var refRegex = /((?:@|%|&)[A-Za-z0-9\/+]{43}=\.[\w\d]+)/g
8
9exports.gives = 'message_meta'
10
11function linkify (text) {
12 var arr = text.split(refRegex)
13 for (var i = 1; i < arr.length; i += 2) {
14 arr[i] = h('a', {href: '#' + arr[i]}, arr[i])
15 }
16 return arr
17}
18
19exports.create = function (api) {
20 return function (msg) {
21 var tmp = h('div')
22 var el
23 var pre
24 return h('input', {
25 type: 'checkbox',
26 title: 'View Data',
27 onclick: function () {
28 // HACK (mw) yo we need a better way to replace the content
29 var msgEl = this.parentNode.parentNode
30 var msgContentEl = msgEl.querySelector('.\\.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