Skip to content

Commit 70a9452

Browse files
re-fortkazupon
authored andcommitted
fix why vue video closing immediately after open (vuejs#574)
* fix fuzzy matching when match already exists ref: vuejs/v2.vuejs.org@85329db * fix why vue video closing immediately after open
1 parent 4f10c51 commit 70a9452

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

themes/vue/source/js/common.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,24 +43,23 @@
4343
}
4444
}
4545

46-
function escapeCharacters (hash) {
46+
function parseRawHash (hash) {
4747
// Remove leading hash
4848
if (hash.charAt(0) === '#') {
4949
hash = hash.substr(1)
5050
}
5151

52-
return '#' + CSS.escape(hash)
52+
// Escape characters
53+
try {
54+
hash = decodeURIComponent(hash)
55+
} catch (e) {}
56+
return CSS.escape(hash)
5357
}
5458

5559
function initLocationHashFuzzyMatching () {
5660
var rawHash = window.location.hash
5761
if (!rawHash) return
58-
var hash
59-
try {
60-
hash = escapeCharacters(decodeURIComponent(rawHash))
61-
} catch(e) {
62-
hash = escapeCharacters(rawHash)
63-
}
62+
var hash = parseRawHash(rawHash)
6463
var hashTarget = document.getElementById(hash)
6564
if (!hashTarget) {
6665
var normalizedHash = normalizeHash(hash)
@@ -73,7 +72,7 @@
7372
if (distanceA > distanceB) return 1
7473
return 0
7574
})
76-
window.location.hash = encodeURIComponent(possibleHashes[0])
75+
window.location.hash = '#' + possibleHashes[0]
7776
}
7877

7978
function normalizeHash (rawHash) {
@@ -155,7 +154,8 @@
155154
overlay.className = 'overlay'
156155

157156

158-
modalButton.addEventListener('click', function() {
157+
modalButton.addEventListener('click', function(event) {
158+
event.stopPropagation()
159159
videoModal.classList.toggle('open')
160160
document.body.classList.toggle('stop-scroll')
161161
document.body.appendChild(overlay)

0 commit comments

Comments
 (0)