This repository was archived by the owner on Jan 4, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy paththeme-header.vue
101 lines (71 loc) · 1.73 KB
/
theme-header.vue
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
97
98
99
100
101
<template>
<header id="masthead" class="site-header" role="banner">
<div class="row">
<div class="column large-10 medium-10 small-10">
<router-link :to="{ name: 'home'}" class="site-name"> {{ site_name }} </router-link>
</div>
<div class="column large-2 medium-2 small-2 end">
<a id="nav-icon1" v-on:click="toggleMenu" v-bind:class="{open: isActive}">
<div></div>
<div></div>
<div></div>
</a>
<nav id="site-navigation" v-bind:class="{open: isActive}">
<ul>
<li v-for="item in menus" v-if="item.type != 'custom'">
<router-link :to="{ name: getRouteType(item.object), params: { name: getUrlName( item.url ) }}"> {{ item.title }} </router-link>
</li>
</ul>
</nav>
</div>
</div>
</header>
</template>
<script>
export default {
mounted: function() {
//console.log( wp.api.collections );
this.getMenu();
},
data() {
return {
menus: [],
site_name: rtwp.site_name,
isActive: false
};
},
methods: {
getMenu: function() {
const vm = this;
vm.$http.get( 'wp-api-menus/v2/menu-locations/primary-menu' )
.then( ( res ) => {
vm.menus = res.data;
} )
.catch( ( res ) => {
//console.log( `Something went wrong : ${ res }` );
} );
},
getUrlName: function( url ) {
const array = url.split( '/' );
return array[ array.length - 2 ];
},
getRouteType: function( object ) {
let type = 'page'
if (object === 'category') {
type = 'cat'
} else if (object === 'post') {
type = 'post'
} else if (object === 'tag') {
type = 'tag'
}
return type
},
toggleMenu: function() {
//console.log("Clicked" + this.isActive);
this.isActive = ! this.isActive;
}
}
};
</script>
<style>
</style>