-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.html
More file actions
96 lines (95 loc) · 2.31 KB
/
index.html
File metadata and controls
96 lines (95 loc) · 2.31 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<!doctype html>
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.1.10/vue.min.js"></script>
<style>
.folder, .file{
position:relative;
padding: 3px 12px;
cursor: pointer;
}
.folder:before{
content:'';
display:block;
border: 5px solid black;
border-color: transparent transparent transparent #000;
position:absolute;
left:0;
top:0%;
width:0;
transition: all .2s ease;
transform: translateY(75%);
}
.folder.active:before{
border-color:#000 transparent transparent transparent;
}
.folder > .tree{
padding: 0;
}
</style>
</head>
<body>
<div id='app'>
<tree></tree>
</div>
<script type='x-template' id='tree'>
<div class='tree'>
<div v-for="file in files">
<folder v-if="file.tag == 'folder'" :file='file'></folder>
<div v-else class='file'>
{{file.name}}
</div>
</div>
</div>
</script>
<script type="x-template" id='folder'>
<div class='folder' v-bind:class="{ active: isOpen }">
<div v-on:click="toggleExpand()">
{{file.name}}/
<small v-if="isOpen && !file.files">(empty)</small>
</div>
<tree v-if='isOpen && file.files' :children='file.files'></tree>
</div>
</script>
<script>
let files = [
{tag: 'folder', name: 'dir1', files: [
{tag: 'file', name: 'fileA'},
{tag: 'file', name: 'fileB'},
{tag: 'folder', name: 'dir1a', files: [
{tag: 'file', name: 'fileAA'},
{tag: 'file', name: 'fileBB'}
]}
]},
{tag: 'folder', name: 'dir2'},
{tag: 'file', name: 'file1'}
]
Vue.component('tree',{
template: '#tree',
props: ['children'],
data(){
return {
files: this.children || files
}
}
})
Vue.component('folder',{
template: '#folder',
props: ['file'],
methods: {
toggleExpand: function(){
this.isOpen = !this.isOpen
}
},
data: function(){
return {
isOpen: false
}
}
})
new Vue({
el: '#app'
})
</script>
</body>
</html>