Files: f11783d11c708f64970a272ab558eb7e3ad1820b / modules_extra / raw.js
1544 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 | // 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