git ssb

16+

Dominic / patchbay



Tree: 4cda013d06b86a002895df3cbed747f6baf1085c

Files: 4cda013d06b86a002895df3cbed747f6baf1085c / modules_extra / raw.js

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

Built with git-ssb-web