main-window.jsView |
---|
1 | 1 | var combine = require('depject') |
2 | 2 | var entry = require('depject/entry') |
3 | 3 | var electron = require('electron') |
4 | 4 | var h = require('mutant/h') |
5 | | -var Value = require('mutant/value') |
6 | 5 | var when = require('mutant/when') |
7 | 6 | var onceTrue = require('mutant/once-true') |
8 | 7 | var computed = require('mutant/computed') |
9 | 8 | var catchLinks = require('./lib/catch-links') |
10 | | -var ObserveLinkHover = require('./lib/observe-link-hover') |
11 | 9 | var insertCss = require('insert-css') |
12 | 10 | var nest = require('depnest') |
13 | 11 | var LatestUpdate = require('./lib/latest-update') |
14 | 12 | var ref = require('ssb-ref') |
40 | 38 | 'app.html.progressNotifier': 'first', |
41 | 39 | 'profile.sheet.edit': 'first', |
42 | 40 | 'profile.html.preview': 'first', |
43 | 41 | 'app.navigate': 'first', |
| 42 | + 'app.linkPreview': 'first', |
44 | 43 | 'channel.obs.subscribed': 'first', |
45 | 44 | 'settings.obs.get': 'first', |
46 | | - 'intl.sync.i18n': 'first', |
| 45 | + 'intl.sync.i18n': 'first' |
47 | 46 | })) |
48 | 47 | |
49 | 48 | setupContextMenuAndSpellCheck(api.config.sync.load()) |
50 | 49 | |
127 | 126 | ), |
128 | 127 | views.html |
129 | 128 | ]) |
130 | 129 | |
131 | | - var currentHover = ObserveLinkHover(container, 500) |
132 | | - var previewElement = Value() |
133 | | - previewElement(currentHover.active.set) |
| 130 | + var previewElement = api.app.linkPreview(container, 500) |
134 | 131 | |
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 | | - |
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 | | - |
184 | 132 | catchLinks(container, (href, external, anchor) => { |
185 | 133 | if (external) { |
186 | 134 | electron.shell.openExternal(href) |
187 | 135 | } else if (ref.isBlob(href)) { |