|
@@ -28,7 +28,7 @@
|
|
|
tabindex="0"
|
|
|
aria-description="Close"
|
|
|
type="button"
|
|
|
- @click="ariaSettings.isMagnifying = !ariaSettings.isMagnifying"
|
|
|
+ @click="onClickMagnifier"
|
|
|
>
|
|
|
<img
|
|
|
:src="assetUrls.closeMagnifyArea"
|
|
@@ -476,8 +476,11 @@ export default {
|
|
|
viewportAreaNum: null,
|
|
|
interactionAreaNum: null,
|
|
|
|
|
|
- focusedNode: null,
|
|
|
- focudedNodeTimeoutId: null,
|
|
|
+ // 为了避免朗读竞争
|
|
|
+ isJustMouseDown: false,
|
|
|
+ domChangeLastTime: null,
|
|
|
+ mutationObserver: null,
|
|
|
+ requestReadLastTime: null,
|
|
|
}
|
|
|
},
|
|
|
watch: {
|
|
@@ -625,10 +628,20 @@ export default {
|
|
|
document.addEventListener('focusin', this.onFocusIn, {
|
|
|
passive: true,
|
|
|
})
|
|
|
+ document.addEventListener('mousedown', this.onMouseDown, {
|
|
|
+ passive: true,
|
|
|
+ })
|
|
|
+ document.addEventListener('mouseover', this.onMouseOver, {
|
|
|
+ passive: true,
|
|
|
+ })
|
|
|
+ document.addEventListener("visibilitychange", this.onPageVisibilityChange, {
|
|
|
+ passive: true
|
|
|
+ })
|
|
|
|
|
|
this.$eventBus.$on('request-read', (text) => {
|
|
|
console.log('无障碍组件收到request-read消息:', text);
|
|
|
if (this.ariaSettings.isCompActive) {
|
|
|
+ this.requestReadLastTime = Date.now()
|
|
|
this.planToPlayAudio('', text)
|
|
|
}
|
|
|
})
|
|
@@ -653,6 +666,13 @@ export default {
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
+
|
|
|
+ const config = { attributes: true, childList: true, subtree: true };
|
|
|
+ const callback = (mutationsList, observer) => {
|
|
|
+ this.domChangeLastTime = Date.now()
|
|
|
+ };
|
|
|
+ this.mutationObserver = new MutationObserver(callback);
|
|
|
+ this.mutationObserver.observe(document.body, config);
|
|
|
},
|
|
|
mounted() {
|
|
|
},
|
|
@@ -666,19 +686,39 @@ export default {
|
|
|
document.removeEventListener('focusin', this.onFocusIn, {
|
|
|
passive: true,
|
|
|
})
|
|
|
-
|
|
|
- this.$eventBus.$off('request-read')
|
|
|
- this.$eventBus.$off('request-magnify')
|
|
|
- this.$eventBus.$off('request-process-text-element')
|
|
|
-
|
|
|
document.removeEventListener('mouseover', this.onMouseOverForContinueRead, {
|
|
|
passive: true,
|
|
|
})
|
|
|
document.removeEventListener('mouseover', this.onMouseOverForPointRead, {
|
|
|
passive: true,
|
|
|
})
|
|
|
+ document.removeEventListener('mousedown', this.onMouseDown, {
|
|
|
+ passive: true,
|
|
|
+ })
|
|
|
+ document.removeEventListener("visibilitychange", this.onPageVisibilityChange, {
|
|
|
+ passive: true
|
|
|
+ })
|
|
|
+
|
|
|
+ this.$eventBus.$off('request-read')
|
|
|
+ this.$eventBus.$off('request-magnify')
|
|
|
+ this.$eventBus.$off('request-process-text-element')
|
|
|
+
|
|
|
+ this.mutationObserver.disconnect();
|
|
|
},
|
|
|
methods: {
|
|
|
+ onPageVisibilityChange() {
|
|
|
+ if (document.visibilityState === 'hidden') {
|
|
|
+ if (this.audioPlayer && !this.audioPlayer.ended) {
|
|
|
+ this.audioPlayer.pause()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ onMouseDown() {
|
|
|
+ this.isJustMouseDown = true
|
|
|
+ setTimeout(() => {
|
|
|
+ this.isJustMouseDown = false
|
|
|
+ }, 0);
|
|
|
+ },
|
|
|
planToPlayAudio(taskId, text = '') {
|
|
|
let XHR = new XMLHttpRequest()
|
|
|
const that = this
|
|
@@ -834,23 +874,36 @@ export default {
|
|
|
if (!this.ariaSettings.isCompActive) {
|
|
|
return
|
|
|
}
|
|
|
+ const curTime = Date.now()
|
|
|
+ if (curTime - this.domChangeLastTime <= 500 + 100) {
|
|
|
+ console.log('DOM刚改变,忽略hover。');
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (curTime - this.requestReadLastTime <= 500 + 100) {
|
|
|
+ console.log('刚被要求朗读,忽略hover。');
|
|
|
+ return
|
|
|
+ }
|
|
|
const extractedText = utils.extractTextForMagnify(e)
|
|
|
if (extractedText) {
|
|
|
this.elemType = extractedText.elemType
|
|
|
this.elemDisc = extractedText.elemDisc
|
|
|
|
|
|
- if (extractedText.ariaNode === this.focusedNode) {
|
|
|
- console.log('已经由于(可能是点击导致的)focus而朗读了,不用再因为hover而朗读了');
|
|
|
- return
|
|
|
- } else {
|
|
|
- this.planToPlayAudio()
|
|
|
- }
|
|
|
+ this.planToPlayAudio()
|
|
|
}
|
|
|
}, 500),
|
|
|
onMouseOverForContinueRead(e) {
|
|
|
if (!this.ariaSettings.isCompActive) {
|
|
|
return
|
|
|
}
|
|
|
+ const curTime = Date.now()
|
|
|
+ if (curTime - this.domChangeLastTime <= 100) {
|
|
|
+ console.log('DOM刚改变,忽略hover。');
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (curTime - this.requestReadLastTime <= 100) {
|
|
|
+ console.log('刚被要求朗读,忽略hover。');
|
|
|
+ return
|
|
|
+ }
|
|
|
const extractedText = utils.extractTextForMagnify(e)
|
|
|
if (extractedText) {
|
|
|
this.elemType = extractedText.elemType
|
|
@@ -863,7 +916,7 @@ export default {
|
|
|
}
|
|
|
const continueReadTaskId = (new Date).getTime()
|
|
|
this.continueReadTaskId = continueReadTaskId
|
|
|
- utils.iterateOnFocusableNode(e.path[0], (node) => {
|
|
|
+ utils.iterateOnFocusableNode(e.target, (node) => {
|
|
|
return new Promise((resolve, reject) => {
|
|
|
this.continueReadIteratorStoper = reject
|
|
|
this.$once('audio-end', (taskId) => {
|
|
@@ -890,18 +943,23 @@ export default {
|
|
|
if (!this.ariaSettings.isCompActive) {
|
|
|
return
|
|
|
}
|
|
|
+ // 如果是点击鼠标引起的focus
|
|
|
+ if (this.isJustMouseDown) {
|
|
|
+ if (
|
|
|
+ document.activeElement.dataset.ariaNavigationArea !== undefined ||
|
|
|
+ document.activeElement.dataset.ariaViewportArea !== undefined ||
|
|
|
+ document.activeElement.dataset.ariaInteractionArea !== undefined
|
|
|
+ ) {
|
|
|
+ document.activeElement.blur()
|
|
|
+ }
|
|
|
+ console.log('刚按下鼠标,忽略focus。');
|
|
|
+ return
|
|
|
+ }
|
|
|
const extractedText = utils.extractTextForMagnify(e, true)
|
|
|
if (extractedText) {
|
|
|
this.elemType = extractedText.elemType
|
|
|
this.elemDisc = extractedText.elemDisc
|
|
|
|
|
|
- this.focusedNode = extractedText.ariaNode
|
|
|
- clearTimeout(this.focusedNodeTimeoutId)
|
|
|
- this.focusedNodeTimeoutId = setTimeout(() => {
|
|
|
- this.focusedNode = null
|
|
|
- this.focudedNodeTimeoutId = null
|
|
|
- }, 1000);
|
|
|
-
|
|
|
this.planToPlayAudio(this.continueReadTaskId)
|
|
|
}
|
|
|
},
|
|
@@ -911,15 +969,15 @@ export default {
|
|
|
this.ariaSettings = copy
|
|
|
},
|
|
|
onClickReset() {
|
|
|
- this.planToPlayAudio('', "You've reset the feature settings")
|
|
|
+ this.$eventBus.$emit('request-read', "You've reset the feature settings")
|
|
|
this.reset()
|
|
|
},
|
|
|
onClickMute() {
|
|
|
this.ariaSettings.isMuted = !this.ariaSettings.isMuted
|
|
|
if (this.ariaSettings.isMuted) {
|
|
|
- // this.planToPlayAudio('', 'Sound off')
|
|
|
+ // this.$eventBus.$emit('request-read', "Sound off")
|
|
|
} else {
|
|
|
- this.planToPlayAudio('', 'Sound on')
|
|
|
+ this.$eventBus.$emit('request-read', "Sound on")
|
|
|
}
|
|
|
if (this.audioPlayer) {
|
|
|
this.audioPlayer.muted = this.ariaSettings.isMuted
|
|
@@ -931,11 +989,11 @@ export default {
|
|
|
this.ariaSettings.speechRateLevel = 0
|
|
|
}
|
|
|
if (this.ariaSettings.speechRateLevel === 0) {
|
|
|
- this.planToPlayAudio('', 'Speak slowly')
|
|
|
+ this.$eventBus.$emit('request-read', "Speak slowly")
|
|
|
} else if (this.ariaSettings.speechRateLevel === 1) {
|
|
|
- this.planToPlayAudio('', 'Speak normally')
|
|
|
+ this.$eventBus.$emit('request-read', "Speak normally")
|
|
|
} else if (this.ariaSettings.speechRateLevel === 2) {
|
|
|
- this.planToPlayAudio('', 'Speak fast')
|
|
|
+ this.$eventBus.$emit('request-read', "Speak fast")
|
|
|
}
|
|
|
if (this.audioPlayer) {
|
|
|
this.audioPlayer.playbackRate = speechRateFactors[this.ariaSettings.speechRateLevel]
|
|
@@ -943,10 +1001,10 @@ export default {
|
|
|
},
|
|
|
onClickScreenReaderMode() {
|
|
|
if (this.ariaSettings.readMode === 'point') {
|
|
|
- this.planToPlayAudio('', "You've enabled continuous reading mode.Please move the mouse over on the text you need to read,it'll start reading the screen in 1 second. When reading the link, tap the Enter key to enter the corresponding page.")
|
|
|
+ this.$eventBus.$emit('request-read', "You've enabled continuous reading mode.Please move the mouse over on the text you need to read,it'll start reading the screen in 1 second. When reading the link, tap the Enter key to enter the corresponding page.")
|
|
|
this.ariaSettings.readMode = 'continue'
|
|
|
} else if (this.ariaSettings.readMode === 'continue') {
|
|
|
- this.planToPlayAudio('', "You've enabled read-only mode.Please move the mouse over on the text you need to read,Blind users can operate the keyboard directly.")
|
|
|
+ this.$eventBus.$emit('request-read', "You've enabled read-only mode.Please move the mouse over on the text you need to read,Blind users can operate the keyboard directly.")
|
|
|
this.ariaSettings.readMode = 'point'
|
|
|
}
|
|
|
},
|
|
@@ -956,68 +1014,68 @@ export default {
|
|
|
this.ariaSettings.themeIdx = 0
|
|
|
}
|
|
|
if (this.ariaSettings.themeIdx === 0) {
|
|
|
- this.planToPlayAudio('', "Ajust to standard color.")
|
|
|
+ this.$eventBus.$emit('request-read', "Ajust to standard color.")
|
|
|
} else if (this.ariaSettings.themeIdx === 1) {
|
|
|
- this.planToPlayAudio('', "Adjust to black lettering on white background.")
|
|
|
+ this.$eventBus.$emit('request-read', "Adjust to black lettering on white background.")
|
|
|
} else if (this.ariaSettings.themeIdx === 2) {
|
|
|
- this.planToPlayAudio('', "Adjust to yellow lettering on blue background.")
|
|
|
+ this.$eventBus.$emit('request-read', "Adjust to yellow lettering on blue background.")
|
|
|
} else if (this.ariaSettings.themeIdx === 3) {
|
|
|
- this.planToPlayAudio('', "Adjust to black lettering on yellow background.")
|
|
|
+ this.$eventBus.$emit('request-read', "Adjust to black lettering on yellow background.")
|
|
|
} else if (this.ariaSettings.themeIdx === 4) {
|
|
|
- this.planToPlayAudio('', "Adjust to yellow lettering on black background.")
|
|
|
+ this.$eventBus.$emit('request-read', "Adjust to yellow lettering on black background.")
|
|
|
}
|
|
|
},
|
|
|
onClickZoomIn() {
|
|
|
if (this.ariaSettings.zoomLevel === zoomFactors.length - 1) {
|
|
|
return
|
|
|
}
|
|
|
- this.planToPlayAudio('', "Zooming in on page")
|
|
|
+ this.$eventBus.$emit('request-read', "Zooming in on page")
|
|
|
this.ariaSettings.zoomLevel++
|
|
|
},
|
|
|
onClickZoomOut() {
|
|
|
if (this.ariaSettings.zoomLevel === 0) {
|
|
|
return
|
|
|
}
|
|
|
- this.planToPlayAudio('', "Zooming out on page")
|
|
|
+ this.$eventBus.$emit('request-read', "Zooming out on page")
|
|
|
this.ariaSettings.zoomLevel--
|
|
|
},
|
|
|
onClickCursorStyle() {
|
|
|
this.ariaSettings.isBigCursor = !this.ariaSettings.isBigCursor
|
|
|
if (this.ariaSettings.isBigCursor) {
|
|
|
- this.planToPlayAudio('', "You've enabled the large cursor")
|
|
|
+ this.$eventBus.$emit('request-read', "You've enabled the large cursor")
|
|
|
} else {
|
|
|
- this.planToPlayAudio('', "You've disabled the large cursor")
|
|
|
+ this.$eventBus.$emit('request-read', "You've disabled the large cursor")
|
|
|
}
|
|
|
},
|
|
|
onClickCrossCursor() {
|
|
|
this.ariaSettings.isCursorCrosshair = !this.ariaSettings.isCursorCrosshair
|
|
|
if (this.ariaSettings.isCursorCrosshair) {
|
|
|
- this.planToPlayAudio('', "You've enabled the cross cursor")
|
|
|
+ this.$eventBus.$emit('request-read', "You've enabled the cross cursor")
|
|
|
} else {
|
|
|
- this.planToPlayAudio('', "You've disabled the cross cursor")
|
|
|
+ this.$eventBus.$emit('request-read', "You've disabled the cross cursor")
|
|
|
}
|
|
|
},
|
|
|
onClickMagnifier() {
|
|
|
this.ariaSettings.isMagnifying = !this.ariaSettings.isMagnifying
|
|
|
if (this.ariaSettings.isMagnifying) {
|
|
|
- this.planToPlayAudio('', "You've enabled the magnifier")
|
|
|
+ this.$eventBus.$emit('request-read', "You've enabled the magnifier")
|
|
|
} else {
|
|
|
- this.planToPlayAudio('', "You've disabled the magnifier")
|
|
|
+ this.$eventBus.$emit('request-read', "You've disabled the magnifier")
|
|
|
}
|
|
|
},
|
|
|
onClickHelp() {
|
|
|
window.open(config.publicPath + 'help.html')
|
|
|
},
|
|
|
onClickDownloadShortcut() {
|
|
|
- this.planToPlayAudio('', "You are downloading the shortcut. Double click the shortcut to reach the website.")
|
|
|
+ this.$eventBus.$emit('request-read', "You are downloading the shortcut. Double click the shortcut to reach the website.")
|
|
|
},
|
|
|
onClickElderlyServicesAreaEntry() {
|
|
|
this.ariaSettings.menuMode = 'old'
|
|
|
- this.planToPlayAudio('', "You've switched to the elderly services mode.")
|
|
|
+ this.$eventBus.$emit('request-read', "You've switched to the elderly services mode.")
|
|
|
},
|
|
|
onClickScreenReaderAreaEntry() {
|
|
|
this.ariaSettings.menuMode = 'blind'
|
|
|
- this.planToPlayAudio('', "You've switched to screen the reading accessibility mode.")
|
|
|
+ this.$eventBus.$emit('request-read', "You've switched to screen the reading accessibility mode.")
|
|
|
},
|
|
|
onMouseDownNavigationArea(e) {
|
|
|
e.preventDefault()
|
|
@@ -1122,6 +1180,7 @@ a {
|
|
|
flex: 1 0 auto;
|
|
|
overflow: auto;
|
|
|
text-align: center;
|
|
|
+ white-space: break-spaces;
|
|
|
p {
|
|
|
vertical-align: middle;
|
|
|
display: inline-block;
|