git ssb

16+

Dominic / patchbay



Commit 95947f0ca5c8eebaaa8fa01239dc409edfa01d95

copy in improvements from patch-profile

mix irving committed on 9/20/2017, 3:41:43 AM
Parent: 9cfd9544eab2af7e70d57a32b331156893817f51

Files changed

about/html/edit.jschanged
about/html/edit.mcsschanged
app/html/external-confirm.mcsschanged
app/styles/mcss/lightbox.mcsschanged
app/styles/mcss/button.mcssadded
app/styles/mixins.jschanged
about/html/edit.jsView
@@ -67,9 +67,9 @@
6767 })
6868 )
6969 var names = dictToCollection(namesRecord)
7070
71- var lb = hyperlightbox()
71 + var lightbox = hyperlightbox()
7272
7373 var isPossibleUpdate = computed([name.new, avatar.new], (name, avatar) => {
7474 return name || avatar.link
7575 })
@@ -98,9 +98,9 @@
9898 });
9999 })
100100
101101 return h('AboutEditor', [
102- h('Lightbox', lb),
102 + lightbox,
103103 h('section.avatar', [
104104 h('section', [
105105 h('img', { src: avatarSrc })
106106 ]),
@@ -143,29 +143,63 @@
143143 ])
144144 ])
145145
146146 function dataUrlCallback (data) {
147- var el = crop(data, (err, data) => {
147 + const cropCallback = (err, cropData) => {
148148 if (err) throw err
149 + if (!cropData) return lightbox.close()
149150
150- if (data) {
151- var _data = dataurl.parse(data)
151 + var _data = dataurl.parse(cropData)
152 + api.sbot.async.addBlob(pull.once(_data.data), (err, hash) => {
153 + if (err) throw err // TODO check if this is safely caught by error catcher
152154
153- api.sbot.async.addBlob(pull.once(_data.data), (err, hash) => {
154- if (err) throw err // TODO check if this is safely caught by error catcher
155 + avatar.new.set({
156 + link: hash,
157 + size: _data.data.length,
158 + type: _data.mimetype,
159 + width: 512,
160 + height: 512
161 + })
162 + })
163 + lightbox.close()
164 + }
155165
156- avatar.new.set({
157- link: hash,
158- size: _data.data.length,
159- type: _data.mimetype,
160- width: 512,
161- height: 512
162- })
163- })
166 + const cropEl = Crop(data, cropCallback)
167 + lightbox.show(cropEl)
168 + }
169 +
170 + function Crop (data, cb) {
171 + var img = h('img', {src: data})
172 +
173 + var crop = h('div')
174 +
175 + waitForImg()
176 +
177 + return h('div.cropper', [
178 + crop,
179 + h('div.background')
180 + ])
181 +
182 + function waitForImg () {
183 + // WEIRDNESS - if you invoke hypecrop before img is ready,
184 + // the canvas instantiates and draws nothing
185 +
186 + if (!img.height && !img.width) {
187 + return window.setTimeout(waitForImg, 100)
164188 }
165- lb.close()
166- })
167- lb.show(el)
189 +
190 + var canvas = hypercrop(img)
191 + crop = (
192 + h('PatchProfileCrop', [
193 + h('header', 'click and drag to crop your image'),
194 + canvas,
195 + h('section.actions', [
196 + h('Button', { 'ev-click': () => cb() }, 'Cancel'),
197 + h('Button -primary', { 'ev-click': () => cb(null, canvas.selection.toDataURL()) }, 'Okay')
198 + ])
199 + ])
200 + )
201 + }
168202 }
169203
170204 function clearNewSelections () {
171205 name.new.set(null)
@@ -194,17 +228,4 @@
194228 }
195229 }
196230 }
197231
198-function crop (d, cb) {
199- var canvas = hypercrop(h('img', {src: d}))
200-
201- return h('AboutImageEditor', [
202- h('header', 'Click and drag to crop your avatar.'),
203- canvas,
204- // canvas.selection,
205- h('section.actions', [
206- h('button.cancel', { 'ev-click': () => cb(new Error('canceled')) }, 'cancel'),
207- h('button.okay', { 'ev-click': () => cb(null, canvas.selection.toDataURL()) }, 'okay')
208- ])
209- ])
210-}
about/html/edit.mcssView
@@ -1,40 +1,29 @@
1-AboutImageEditor {
2- header {
3- font-weight: 600
4- margin-bottom: .5rem
5- }
1 +AboutEditor {
2 + position: relative
63
7- canvas {
8- margin: 0 auto
9- width: 100%
10- }
4 + margin-bottom: 2rem
115
12- section.actions {
13- display: flex
14- justify-content: flex-end
15-
16- button.cancel {
17-
18- }
19-
20- button.okay {
21- margin-right: 0
22-
23- }
24- }
25-}
26-
27-AboutEditor {
286 display: flex
297 flex-wrap: wrap
308 justify-content: space-between
319
32- margin-bottom: 2rem
10 + div.lightbox {
11 + div.lightbox__content {
12 + div.cropper {
13 + div.PatchProfileCrop {}
14 + div.background {
15 + position: fixed
16 + z-index: 98
17 + top: 0
18 + left: 0
3319
34- section.Lightbox {
35- position: absolute
36- z-index: 40
20 + width: 100%
21 + height: 100%
22 + background-color: rgba(0, 0, 0, 0.5)
23 + }
24 + }
25 + }
3726 }
3827
3928 section.avatar {
4029 margin-right: 1rem
@@ -192,4 +181,41 @@
192181 }
193182 }
194183 }
195184 }
185 +
186 +PatchProfileCrop {
187 + background: #f5f5f5
188 +
189 + z-index: 99
190 + position: absolute
191 + top: 0
192 + left: 0
193 + right: 0
194 +
195 +
196 + overflow: auto
197 + max-width: 100%
198 + padding: 1rem
199 + border: 1px solid #eee
200 + border-radius: .2em
201 +
202 + display: flex
203 + flex-direction: column
204 +
205 + header {
206 + font-weight: 600
207 + margin-bottom: .5rem
208 + }
209 +
210 + canvas {
211 + margin: 0 auto 1rem auto
212 + max-height: 80vh
213 + max-width: 100%
214 + }
215 +
216 + section.actions {
217 + display: flex
218 + justify-content: space-between
219 + }
220 +}
221 +
app/html/external-confirm.mcssView
@@ -13,9 +13,13 @@
1313
1414 }
1515
1616 pre.link {
17-
17 + background-color: #f5f5f5
18 + color: #c121dc
19 + padding: .3rem
20 + white-space: pre-wrap
21 + word-wrap: break-word
1822 }
1923 }
2024
2125 section.actions {
app/styles/mcss/lightbox.mcssView
@@ -1,7 +1,8 @@
1-/* lightbox - used in message-confirm */
1 +/* used in app.html.externalConfirm */
2 +/* used in message.html.confirm */
23
3-Lightbox {
4 +body {
45 div.lightbox {
56 position: fixed
67 left: 0px
78 right: 0px
app/styles/mcss/button.mcssView
@@ -1,0 +1,37 @@
1 +Button {
2 + font-family: arial
3 + text-align: center
4 +
5 + cursor: pointer
6 +
7 + padding: .2rem 2rem
8 + min-width: 4rem
9 + border: 1px #b9b9b9 solid
10 +
11 + -subtle {
12 + color: #b9b9b9
13 + :hover {
14 + color: #222
15 + }
16 + }
17 + -primary {
18 + $colorPrimary
19 +
20 + :hover {
21 + opacity: .9
22 + }
23 +
24 + border: 1px solid #3dc8c3
25 + }
26 +
27 + -showMore {
28 + width: 100%
29 +
30 + padding: .2rem 0
31 +
32 + border-left: none
33 + border-right: none
34 + border-bottom: none
35 + }
36 +}
37 +
app/styles/mixins.jsView
@@ -21,8 +21,17 @@
2121 $textSubtle {
2222 color: gray
2323 }
2424
25 +$colorPrimary {
26 + color: white
27 + background-color: #3dc8c3
28 +
29 + (a) {
30 + color: #5c6bc0
31 + }
32 +}
33 +
2534 $backgroundPrimary {
2635 background-color: #50aadf
2736 }
2837

Built with git-ssb-web