git ssb

16+

Dominic / patchbay



Tree: 0831215dc5165e22aefa788b8249903f50b9de23

Files: 0831215dc5165e22aefa788b8249903f50b9de23 / modules_extra / raw.js

1544 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 // HACK (mw) yo we need a better way to replace the content
33 var msgEl = this.parentNode.parentNode
34 var msgContentEl = msgEl.querySelector('.\\.content')
35 if (this.checked) {
36 // move away the content
37 while (el = msgContentEl.firstChild)
38 tmp.appendChild(el)
39 // show the raw stuff
40 if (!pre) pre = h('pre', linkify(JSON.stringify({
41 key: msg.key,
42 value: msg.value
43 }, 0, 2)))
44 msgContentEl.appendChild(pre)
45 } else {
46 // hide the raw stuff
47 msgContentEl.removeChild(pre)
48 // put back the content
49 while (el = tmp.firstChild)
50 msgContentEl.appendChild(el)
51 }
52 }
53 })
54 }
55}
56
57

Built with git-ssb-web