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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
<!--
Matomo - free/libre analytics platform
@link https://matomo.org
@license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
-->
<template>
<div
ref="root"
class="menuDropdown"
v-focus-anywhere-but-here="{ blur: lostFocus }"
>
<span
class="title"
@click="showItems = !showItems"
:title="tooltip"
>
<span v-html="$sanitize(this.actualMenuTitle)" />
<span class="icon-arrow-bottom" />
</span>
<div
class="items"
v-show="showItems"
>
<div
class="search"
v-if="showSearch && showItems"
>
<input
type="text"
v-model="searchTerm"
@keydown="onSearchTermKeydown($event)"
:placeholder="translate('General_Search')"
/>
<img
v-show="!searchTerm"
class="search_ico"
src="plugins/Morpheus/images/search_ico.png"
:title="translate('General_Search')"
/>
<img
v-show="searchTerm"
v-on:click="searchTerm = '';searchItems('')"
class="reset"
src="plugins/CoreHome/images/reset_search.png"
:title="translate('General_Clear')"
/>
</div>
<div v-on:click="selectItem($event)">
<slot />
</div>
</div>
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import FocusAnywhereButHere from '../FocusAnywhereButHere/FocusAnywhereButHere';
import FocusIf from '../FocusIf/FocusIf';
const { $ } = window;
export default defineComponent({
props: {
menuTitle: String,
tooltip: String,
showSearch: Boolean,
menuTitleChangeOnClick: String,
},
directives: {
FocusAnywhereButHere,
FocusIf,
},
emits: ['afterSelect'],
watch: {
menuTitle() {
this.actualMenuTitle = this.menuTitle;
},
},
data() {
return {
showItems: false,
searchTerm: '',
actualMenuTitle: this.menuTitle,
};
},
methods: {
lostFocus() {
this.showItems = false;
},
selectItem(event: MouseEvent) {
const targetClasses = (event.target as HTMLElement).classList;
if (!targetClasses.contains('item')
|| targetClasses.contains('disabled')
|| targetClasses.contains('separator')
) {
return;
}
if (this.menuTitleChangeOnClick !== false) {
this.actualMenuTitle = (event.target as HTMLElement).textContent
.replace(/[\u0000-\u2666]/g, (c) => `&#${c.charCodeAt(0)};`); // eslint-disable-line
}
this.showItems = false;
$(this.$slots.default()).find('.item').removeClass('active');
targetClasses.add('active');
this.$emit('afterSelect');
},
onSearchTermKeydown() {
setTimeout(() => {
this.searchItems(this.searchTerm);
});
},
searchItems(unprocessedSearchTerm: string) {
const searchTerm = unprocessedSearchTerm.toLowerCase();
$(this.$refs.root).find('.item').each((index: number, node: HTMLElement) => {
const $node = $(node);
if ($node.text().toLowerCase().indexOf(searchTerm) === -1) {
$node.hide();
} else {
$node.show();
}
});
},
},
});
</script>
|