-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvuetify.js
45 lines (37 loc) · 1.15 KB
/
vuetify.js
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
function vuetify(x) {
return isDirective(x) ? vuetifyDirective(x) : vuetifyFunction(x)
}
function isDirective(x) {
return getFirstParameter(x).startsWith('el')
}
function vuetifyDirective(fn) {
function shortened(fn) {
function directive(el, binding, node) {
try {
if (binding.value) {
fn(el, binding.value)
}
}
catch(e) {
console.log('error @ directive', e)
console.log(binding)
}
}
return directive
}
function create(fn) {
return test(/^.*?binding/, fn.toString()) ? fn : shortened(fn)
}
const name = fn.name.replace(/^v/, '')
Vue.directive(name, {inserted: create(fn), update: create(fn)})
}
function vuetifyFunction(fn) {
const payload = isClass(fn) ? new fn() : fn
let name = test(/^\$?(?:to|is|has|get|set|asdf)/, fn.name) ? fn.name : fn.name.toLowerCase()
if (!name.startsWith('$')) name = '$' + name
if (isClass(fn)) {
name = '$' + abbreviate(payload.constructor.name)
}
console.log(name)
Vue.prototype[name] = payload
}