side_menu/src/SideMenu.vue

128 lines
4.2 KiB
Vue
Raw Normal View History

2020-03-29 13:47:07 +02:00
<!--
@license GNU AGPL version 3 or any later version
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
2020-03-28 17:40:53 +01:00
<template>
<div id="side-menu">
<div class="side-menu-header">
<button class="side-menu-opener"></button>
<div v-if="logo" class="side-menu-logo">
<img v-bind:src="logo">
</div>
</div>
<ul class="side-menu-apps-list">
2020-04-11 11:17:29 +02:00
<li v-for="app in apps" v-bind:class="{'side-menu-app': true, 'active': app.active}">
2020-05-12 09:25:43 +02:00
<a v-bind:href="app.href" v-bind:title="app.name">
<span class="side-menu-app-icon" v-html="app.icon"></span>
<span class="side-menu-app-text" v-html="app.name"></span>
</a>
</li>
</ul>
</div>
2020-03-28 17:40:53 +01:00
</template>
<script>
2020-05-12 09:25:43 +02:00
import trim from 'trim'
2020-03-28 17:40:53 +01:00
export default {
name: 'SideMenu',
data() {
return {
apps: [],
2020-05-09 14:30:24 +02:00
logo: null,
2020-05-09 16:37:17 +02:00
forceLightIcon: false,
}
},
methods: {
retrieveApps() {
2020-05-09 16:37:17 +02:00
this.apps = []
2020-04-26 21:36:54 +02:00
const links = document.querySelectorAll('#appmenu a')
for (let element of links) {
let href = element.getAttribute('href')
var parent = element.parentNode
if (!parent) {
continue
}
var dataId = parent.getAttribute('data-id')
dataId = dataId !== null ? dataId : ''
if (this.ignoreExternalSites && dataId.indexOf('external_index') !== -1) {
continue
2020-05-09 16:37:17 +02:00
}
if (href !== '#') {
2020-04-25 16:29:52 +02:00
let svg = element.querySelector('svg').outerHTML
svg = svg
2020-05-09 16:37:17 +02:00
.replace(/(height|width)="20"/, '')
.replace('id="invertMenuMain', 'id="invertSideMenu')
.replace('url(#invertMenuMain', 'url(#invertSideMenu')
2020-05-09 16:37:17 +02:00
if (this.forceLightIcon) {
svg = svg.replace(/filter="url[^"]+"/, '')
}
2020-05-09 14:30:24 +02:00
this.apps.push({
href: href,
2020-05-12 09:25:43 +02:00
name: trim(element.querySelector('span').innerHTML),
icon: svg,
active: element.classList.contains('active')
});
}
}
2020-04-26 21:36:54 +02:00
2020-05-09 16:37:17 +02:00
(function(apps) {
window.setTimeout(function() {
jQuery('body').trigger('side-menu.apps', [apps])
}, 1000)
})(this.apps)
},
retrieveLogo() {
2020-04-25 16:29:52 +02:00
const ncLogo = document.querySelector('#nextcloud .logo')
2020-04-09 14:19:10 +02:00
2020-04-25 16:29:52 +02:00
if (ncLogo) {
const url = window.getComputedStyle(ncLogo, null)
.getPropertyValue('background-image')
.replace('url("', '')
.replace('")', '')
2020-04-16 12:36:30 +02:00
2020-04-25 16:29:52 +02:00
if (url && url !== 'none') {
this.logo = url
}
}
},
},
2020-05-09 14:30:24 +02:00
mounted() {
this.retrieveApps()
this.retrieveLogo()
2020-05-09 16:37:17 +02:00
this.forceLightIcon = document.querySelector('#side-menu-container').getAttribute('data-forcelighticon') == 1;
this.ignoreExternalSites = document.querySelector('#side-menu-container').getAttribute('data-externalsitesintopmenu') == 1;
const menu = document.querySelector('#appmenu')
2020-04-25 16:04:54 +02:00
2020-04-25 16:29:52 +02:00
if (menu) {
2020-05-09 14:30:24 +02:00
const config = {attributes: true, childList: true, subtree: true}
const observer = new MutationObserver(this.retrieveApps)
observer.observe(menu, config)
2020-04-25 16:29:52 +02:00
}
}
2020-03-28 17:40:53 +01:00
}
</script>