Files: 8dc25143a3f37f1618f7a92b3c46dec512b43bfd / modules / raw.js
1329 bytesRaw
1 | var h = require('hyperscript') |
2 | var u = require('../util') |
3 | var pull = require('pull-stream') |
4 | var Scroller = require('pull-scroll') |
5 | |
6 | // from ssb-ref |
7 | var refRegex = /((?:@|%|&)[A-Za-z0-9\/+]{43}=\.[\w\d]+)/g |
8 | |
9 | exports.gives = 'message_meta' |
10 | |
11 | function 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 | |
19 | exports.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 | var msgEl = this.parentNode.parentNode.parentNode |
29 | var msgContentEl = msgEl.querySelector('.message_content') |
30 | if (this.checked) { |
31 | // move away the content |
32 | while (el = msgContentEl.firstChild) |
33 | tmp.appendChild(el) |
34 | // show the raw stuff |
35 | if (!pre) pre = h('pre', linkify(JSON.stringify({ |
36 | key: msg.key, |
37 | value: msg.value |
38 | }, 0, 2))) |
39 | msgContentEl.appendChild(pre) |
40 | } else { |
41 | // hide the raw stuff |
42 | msgContentEl.removeChild(pre) |
43 | // put back the content |
44 | while (el = tmp.firstChild) |
45 | msgContentEl.appendChild(el) |
46 | } |
47 | } |
48 | }) |
49 | } |
50 | } |
51 | |
52 |
Built with git-ssb-web