Files: aced9005d3a8be64c8d93decc047283d941c6d5e / modules / raw.js
1376 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 | var 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 |
11 | var refRegex = /((?:@|%|&)[A-Za-z0-9\/+]{43}=\.[\w\d]+)/g |
12 | |
13 | function linkify(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 | |
21 | exports.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', 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