Files: 9746cd345f014701f5911b233fe5aec3e3c52edb / modules_extra / raw.js
1492 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 | exports.gives = 'message_meta' |
14 | |
15 | function 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 | |
23 | exports.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