forked from quasarframework/quasar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpage-utils.js
More file actions
58 lines (48 loc) · 1.29 KB
/
page-utils.js
File metadata and controls
58 lines (48 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { Notify } from 'quasar'
export function copyToClipboard (text) {
const textArea = document.createElement('textarea')
textArea.className = 'fixed-top'
textArea.value = text
document.body.appendChild(textArea)
textArea.focus()
textArea.select()
document.execCommand('copy')
document.body.removeChild(textArea)
}
export function copyHeading (id) {
const text = window.location.origin + window.location.pathname + '#' + id
const el = document.getElementById(id)
if (el) {
el.id = ''
}
if ('replaceState' in history) {
history.replaceState(history.state, '', `${location.pathname}#${id}`)
}
else {
window.location.hash = '#' + id
}
if (el) {
setTimeout(() => {
el.id = id
}, 300)
}
copyToClipboard(text)
Notify.create({
message: 'Anchor has been copied to clipboard.',
position: 'top',
actions: [{ icon: 'cancel', color: 'white', dense: true, round: true }],
timeout: 2000
})
}
// eslint-disable-next-line
const specialRE = /[\s·/_\\,:;\.\(\)\[\]]+/g
const andRE = /&/g
const nonWordRE = /[^\w-]+/g
const multipleDashRE = /--+/g
export function slugify (str) {
return String(str).toLowerCase()
.replace(specialRE, '-')
.replace(andRE, '-and-')
.replace(nonWordRE, '')
.replace(multipleDashRE, '-')
}