git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Commit 60000ec734ec84dab4b2b19eb518cb6689764bfc

extract link preview out of main-window to app/link-preview

Matt McKegg committed on 10/18/2017, 2:15:19 AM
Parent: 47f88c71eec1667f35848253793375e28d250237

Files changed

main-window.jschanged
modules/app/link-preview.jsadded
main-window.jsView
@@ -1,14 +1,12 @@
11 var combine = require('depject')
22 var entry = require('depject/entry')
33 var electron = require('electron')
44 var h = require('mutant/h')
5-var Value = require('mutant/value')
65 var when = require('mutant/when')
76 var onceTrue = require('mutant/once-true')
87 var computed = require('mutant/computed')
98 var catchLinks = require('./lib/catch-links')
10-var ObserveLinkHover = require('./lib/observe-link-hover')
119 var insertCss = require('insert-css')
1210 var nest = require('depnest')
1311 var LatestUpdate = require('./lib/latest-update')
1412 var ref = require('ssb-ref')
@@ -40,11 +38,12 @@
4038 'app.html.progressNotifier': 'first',
4139 'profile.sheet.edit': 'first',
4240 'profile.html.preview': 'first',
4341 'app.navigate': 'first',
42+ 'app.linkPreview': 'first',
4443 'channel.obs.subscribed': 'first',
4544 'settings.obs.get': 'first',
46- 'intl.sync.i18n': 'first',
45+ 'intl.sync.i18n': 'first'
4746 }))
4847
4948 setupContextMenuAndSpellCheck(api.config.sync.load())
5049
@@ -127,61 +126,10 @@
127126 ),
128127 views.html
129128 ])
130129
131- var currentHover = ObserveLinkHover(container, 500)
132- var previewElement = Value()
133- previewElement(currentHover.active.set)
130+ var previewElement = api.app.linkPreview(container, 500)
134131
135- currentHover(element => {
136- var href = element && element.getAttribute('href')
137- var preview = null
138-
139- if (href) {
140- if (ref.isFeed(href)) {
141- preview = api.profile.html.preview(href)
142- } else if (href.includes('://')) {
143- preview = h('ProfilePreview', [
144- h('section', [
145- h('strong', [i18n('External Link'), ' ๐ŸŒ']), h('br'),
146- h('code', href)
147- ])
148- ])
149- }
150- }
151-
152- if (preview) {
153- var rect = element.getBoundingClientRect()
154- var width = 510
155- var maxLeft = window.innerWidth - width
156- var maxTop = window.innerHeight - 100
157- var distanceFromRight = window.innerWidth - rect.right
158- var shouldDisplayBeside = rect.bottom > maxTop || rect.left < 50 || distanceFromRight < 50
159-
160- if (shouldDisplayBeside && rect.bottom > 50) {
161- if (rect.right > maxLeft && (rect.left - width) < 0) {
162- // no room, just give up!
163- previewElement.set(null)
164- return
165- } else {
166- preview.style.top = `${Math.min(rect.top, maxTop)}px`
167- if (rect.right > maxLeft) {
168- preview.style.left = `${rect.left - width}px`
169- } else {
170- preview.style.left = `${rect.right + 5}px`
171- }
172- }
173- } else {
174- preview.style.top = `${rect.bottom + 5}px`
175- preview.style.left = `${Math.min(rect.left, maxLeft)}px`
176- }
177-
178- previewElement.set(preview)
179- } else if (element !== false) {
180- previewElement.set(null)
181- }
182- })
183-
184132 catchLinks(container, (href, external, anchor) => {
185133 if (external) {
186134 electron.shell.openExternal(href)
187135 } else if (ref.isBlob(href)) {
modules/app/link-preview.jsView
@@ -1,0 +1,72 @@

Built with git-ssb-web