git ssb

0+

ev / minbase



Tree: f1cc08ac986f18880000b780dae6fb2043e76948

Files: f1cc08ac986f18880000b780dae6fb2043e76948 / modules / avatar-edit.js

1595 bytesRaw
1'use strict'
2var dataurl = require('dataurl-')
3var hyperfile = require('hyperfile')
4var hypercrop = require('hypercrop')
5var hyperlightbox = require('hyperlightbox')
6var h = require('hyperscript')
7var pull = require('pull-stream')
8var id = require('../keys').id
9var addblob = require('./scuttlebot').blobs_add
10
11var avatar = require('./avatar')
12
13exports.needs = {
14 message_confirm: 'first'
15}
16
17exports.gives = 'avatar_edit'
18
19exports.create = function (api) {
20 return function () {
21 var img = h('div.avatar--profile', avatar.image(id, 'profile'))
22
23 var selected = null, selected_data = null
24
25 return h('div.row.profile',
26 img,
27 h('div',
28 h('strong', name),
29 hyperfile.asDataURL(function (data) {
30 if(data) {
31 img.src = data
32 var _data = dataurl.parse(data)
33 pull(
34 pull.once(_data.data),
35 addblob(function (err, hash) {
36 if(err) return alert(err.stack)
37 selected = {
38 link: hash,
39 size: _data.data.length,
40 type: _data.mimetype,
41 width: 512,
42 height: 512
43 }
44 })
45 )
46 }
47 }),
48 h('br'),
49 h('button.btn.btn-primary', 'Preview Image', {onclick: function() {
50 if(selected) {
51 api.message_confirm({
52 type: 'about',
53 about: id,
54 image: selected
55 })
56 } else { alert('select an image before hitting preview')}
57 }})
58 )
59 )
60 }
61}
62

Built with git-ssb-web