+
{{#if !$initialized}}
{{/if}}
@@ -55,11 +60,19 @@
import { database } from '../../_database/database'
import { initializeTimeline, fetchTimelineItemsOnScrollToBottom, setupTimeline } from '../../_actions/timeline'
import LoadingPage from '../LoadingPage.html'
+ import { focusWithCapture, blurWithCapture } from '../../_utils/events'
export default {
- async oncreate() {
+ oncreate() {
console.log('timeline oncreate()')
setupTimeline()
+ if (this.store.get('initialized')) {
+ console.log('initialized!!!!')
+ this.restoreFocus()
+ }
+ },
+ ondestroy() {
+ console.log('ondestroy')
},
data: () => ({
StatusVirtualListItem,
@@ -109,6 +122,10 @@
PseudoVirtualList,
LoadingPage
},
+ events: {
+ focusWithCapture,
+ blurWithCapture
+ },
methods: {
initialize() {
if (this.store.get('initialized') || !this.store.get('timelineItemIds')) {
@@ -124,7 +141,46 @@
return
}
fetchTimelineItemsOnScrollToBottom()
- }
+ },
+ saveFocus(e) {
+ let instanceName = this.store.get('currentInstance')
+ let timelineName = this.get('timeline')
+ let lastFocusedElementSelector
+ let activeElement = e.target
+ if (activeElement) {
+ let focusKey = activeElement.getAttribute('focus-key')
+ if (focusKey) {
+ lastFocusedElementSelector = `[focus-key=${focusKey}]`
+ }
+ }
+ console.log('saving focus to ', lastFocusedElementSelector)
+ this.store.setForTimeline(instanceName, timelineName, {
+ lastFocusedElementSelector
+ })
+ },
+ clearFocus() {
+ /*console.log('clearing focus')
+ let instanceName = this.store.get('currentInstance')
+ let timelineName = this.get('timeline')
+ this.store.setForTimeline(instanceName, timelineName, {
+ lastFocusedElementSelector: null
+ })*/
+ },
+ restoreFocus() {
+ let lastFocusedElementSelector = this.store.get('lastFocusedElementSelector')
+ console.log('lastFocused', lastFocusedElementSelector)
+ if (lastFocusedElementSelector) {
+ requestAnimationFrame(() => {
+ requestAnimationFrame(() => {
+ let element = document.querySelector(lastFocusedElementSelector)
+ console.log('el', element)
+ if (element) {
+ element.focus()
+ }
+ })
+ })
+ }
+ },
}
}
\ No newline at end of file
diff --git a/routes/_store/timelineComputations.js b/routes/_store/timelineComputations.js
index 2cfc2c23..dbff7cfe 100644
--- a/routes/_store/timelineComputations.js
+++ b/routes/_store/timelineComputations.js
@@ -1,11 +1,19 @@
+
+function computeForTimeline(store, key) {
+ store.compute(key, ['currentTimelineData'], (currentTimelineData) => currentTimelineData[key])
+}
+
+
export function timelineComputations (store) {
store.compute('currentTimelineData', ['currentInstance', 'currentTimeline', 'timelines'],
(currentInstance, currentTimeline, timelines) => {
return ((timelines && timelines[currentInstance]) || {})[currentTimeline] || {}
})
- store.compute('timelineItemIds', ['currentTimelineData'], (currentTimelineData) => currentTimelineData.timelineItemIds)
- store.compute('runningUpdate', ['currentTimelineData'], (currentTimelineData) => currentTimelineData.runningUpdate)
- store.compute('initialized', ['currentTimelineData'], (currentTimelineData) => currentTimelineData.initialized)
+ computeForTimeline(store, 'timelineItemIds')
+ computeForTimeline(store, 'runningUpdate')
+ computeForTimeline(store, 'initialized')
+ computeForTimeline(store, 'lastFocusedElementSelector')
+
store.compute('lastTimelineItemId', ['timelineItemIds'], (timelineItemIds) => timelineItemIds && timelineItemIds.length && timelineItemIds[timelineItemIds.length - 1])
}
diff --git a/routes/_utils/events.js b/routes/_utils/events.js
index fc9b144f..1b02ba53 100644
--- a/routes/_utils/events.js
+++ b/routes/_utils/events.js
@@ -34,3 +34,21 @@ export function mouseover (node, callback) {
}
}
}
+
+export function focusWithCapture (node, callback) {
+ node.addEventListener('focus', callback, true)
+ return {
+ teardown () {
+ node.removeEventListener('focus', callback, true)
+ }
+ }
+}
+
+export function blurWithCapture (node, callback) {
+ node.addEventListener('blur', callback, true)
+ return {
+ teardown () {
+ node.removeEventListener('blur', callback, true)
+ }
+ }
+}
\ No newline at end of file