constructor(elem) {
this.container = elem;
- this.menu = elem.querySelector('ul, [dropdown-menu]');
+ this.menu = elem.querySelector('.dropdown-menu, [dropdown-menu]');
+ this.moveMenu = elem.hasAttribute('dropdown-move-menu');
this.toggle = elem.querySelector('[dropdown-toggle]');
+ this.body = document.body;
this.setupListeners();
}
- show() {
+ show(event) {
+ this.hide();
+
this.menu.style.display = 'block';
this.menu.classList.add('anim', 'menuIn');
- this.container.addEventListener('mouseleave', this.hide.bind(this));
+
+ if (this.moveMenu) {
+ // Move to body to prevent being trapped within scrollable sections
+ this.rect = this.menu.getBoundingClientRect();
+ this.body.appendChild(this.menu);
+ this.menu.style.position = 'fixed';
+ this.menu.style.left = `${this.rect.left}px`;
+ this.menu.style.top = `${this.rect.top}px`;
+ this.menu.style.width = `${this.rect.width}px`;
+ }
+
+ // Set listener to hide on mouse leave or window click
+ this.menu.addEventListener('mouseleave', this.hide.bind(this));
+ window.addEventListener('click', event => {
+ if (!this.menu.contains(event.target)) {
+ this.hide();
+ }
+ });
// Focus on first input if existing
let input = this.menu.querySelector('input');
if (input !== null) input.focus();
+
+ event.stopPropagation();
}
hide() {
this.menu.style.display = 'none';
this.menu.classList.remove('anim', 'menuIn');
+ if (this.moveMenu) {
+ this.menu.style.position = '';
+ this.menu.style.left = '';
+ this.menu.style.top = '';
+ this.menu.style.width = '';
+ this.container.appendChild(this.menu);
+ }
}
setupListeners() {
constructor(elem) {
this.elem = elem;
+ this.menu = elem.querySelector('ul');
this.sortInput = elem.querySelector('[name="sort"]');
this.orderInput = elem.querySelector('[name="order"]');
this.form = elem.querySelector('form');
- this.elem.addEventListener('click', event => {
+ this.menu.addEventListener('click', event => {
if (event.target.closest('[data-sort-value]') !== null) {
this.sortOptionClick(event);
}
+ });
+
+ this.elem.addEventListener('click', event => {
if (event.target.closest('[data-sort-dir]') !== null) {
this.sortDirectionClick(event);
}
- })
-
+ });
}
sortOptionClick(event) {
position: relative;
}
-.dropdown-container ul {
+.dropdown-menu {
display: none;
position: absolute;
z-index: 999;
}
}
-@include smaller-than($l) {
+@include smaller-than($m) {
.page-edit-toolbar {
overflow-x: scroll;
overflow-y: visible;
}
}
-@include smaller-than($l) {
+@include smaller-than($m) {
.page-edit-toolbar #save-button {
position: fixed;
z-index: 30;
- background-color: #FFF;
border-radius: 50%;
- width: 42px;
- height: 42px;
- font-size: 16px;
+ width: 56px;
+ height: 56px;
+ font-size: 24px;
right: $-m;
- bottom: $-xs;
- box-shadow: $bs-med;
+ bottom: $-s;
+ box-shadow: $bs-hover;
+ background-color: currentColor;
+ svg {
+ fill: #FFF;
+ }
span {
display: none;
}
<span>@icon('export')</span>
<span>{{ trans('entities.export') }}</span>
</div>
- <ul class="wide">
+ <ul class="wide dropdown-menu">
<li><a href="{{ $book->getUrl('/export/html') }}" target="_blank">{{ trans('entities.export_html') }} <span class="text-muted float right">.html</span></a></li>
<li><a href="{{ $book->getUrl('/export/pdf') }}" target="_blank">{{ trans('entities.export_pdf') }} <span class="text-muted float right">.pdf</span></a></li>
<li><a href="{{ $book->getUrl('/export/plaintext') }}" target="_blank">{{ trans('entities.export_text') }} <span class="text-muted float right">.txt</span></a></li>
<span>@icon('export')</span>
<span>{{ trans('entities.export') }}</span>
</div>
- <ul class="wide">
+ <ul class="wide dropdown-menu">
<li><a href="{{ $chapter->getUrl('/export/html') }}" target="_blank">{{ trans('entities.export_html') }} <span class="text-muted float right">.html</span></a></li>
<li><a href="{{ $chapter->getUrl('/export/pdf') }}" target="_blank">{{ trans('entities.export_pdf') }} <span class="text-muted float right">.pdf</span></a></li>
<li><a href="{{ $chapter->getUrl('/export/plaintext') }}" target="_blank">{{ trans('entities.export_text') }} <span class="text-muted float right">.txt</span></a></li>
@if(userCan('comment-delete', $comment))
<div dropdown class="dropdown-container">
<button type="button" dropdown-toggle class="text-button" title="{{ trans('common.delete') }}">@icon('delete')</button>
- <ul>
+ <ul class="dropdown-menu">
<li class="px-m text-small text-muted pb-s">{{trans('entities.comment_delete_confirm')}}</li>
<li><a action="delete" class="text-button text-neg" >@icon('delete'){{ trans('common.delete') }}</a></li>
</ul>
<img class="avatar" src="{{$currentUser->getAvatar(30)}}" alt="{{ $currentUser->name }}">
<span class="name">{{ $currentUser->getShortName(9) }}</span> @icon('caret-down')
</span>
- <ul>
+ <ul class="dropdown-menu">
<li>
<a href="{{ baseUrl("/user/{$currentUser->id}") }}">@icon('user'){{ trans('common.view_profile') }}</a>
</li>
</div>
<div class="text-center px-m py-xs">
- <div v-show="draftsEnabled" dropdown class="dropdown-container draft-display text">
- <a dropdown-toggle class="text-primary text-button"><span class="faded-text" v-text="draftText"></span> @icon('more')</a>
+ <div v-show="draftsEnabled" dropdown dropdown-move-menu class="dropdown-container draft-display text">
+ <a dropdown-toggle class="text-primary text-button"><span class="faded-text" v-text="draftText"></span> @icon('more')</a>
@icon('check-circle', ['class' => 'text-pos draft-notification svg-icon', ':class' => '{visible: draftUpdated}'])
- <ul>
+ <ul class="dropdown-menu">
<li>
<a @click="saveDraft()" class="text-pos">@icon('save'){{ trans('entities.pages_edit_save_draft') }}</a>
</li>
</div>
<div class="action-buttons px-m py-xs" v-cloak>
- <div dropdown class="dropdown-container">
+ <div dropdown dropdown-move-menu class="dropdown-container">
<a dropdown-toggle class="text-primary text-button">@icon('edit') <span v-text="changeSummaryShort"></span></a>
- <ul class="wide">
+ <ul class="wide dropdown-menu">
<li class="px-l py-m">
<p class="text-muted pb-s">{{ trans('entities.pages_edit_enter_changelog_desc') }}</p>
<input name="summary" id="summary-input" type="text" placeholder="{{ trans('entities.pages_edit_enter_changelog') }}" v-model="changeSummary" />
</li>
</ul>
+ <span>{{-- Prevents button jumping on menu show --}}</span>
</div>
<button type="submit" id="save-button" class="float-left text-primary text-button text-pos-hover">@icon('save')<span>{{ trans('entities.pages_save') }}</span></button>
<a href="{{ $revision->getUrl('restore') }}"></a>
<div dropdown class="dropdown-container">
<a dropdown-toggle>{{ trans('entities.pages_revisions_restore') }}</a>
- <ul>
+ <ul class="dropdown-menu">
<li class="px-m py-s"><small class="text-muted">{{trans('entities.revision_restore_confirm')}}</small></li>
<li>
<form action="{{ $revision->getUrl('/restore') }}" method="POST">
<span class="text-muted"> | </span>
<div dropdown class="dropdown-container">
<a dropdown-toggle>{{ trans('common.delete') }}</a>
- <ul>
+ <ul class="dropdown-menu">
<li class="px-m py-s"><small class="text-muted">{{trans('entities.revision_delete_confirm')}}</small></li>
<li>
<form action="{{ $revision->getUrl('/delete/') }}" method="POST">
<span>@icon('export')</span>
<span>{{ trans('entities.export') }}</span>
</div>
- <ul class="wide">
+ <ul class="dropdown-menu wide">
<li><a href="{{ $page->getUrl('/export/html') }}" target="_blank">{{ trans('entities.export_html') }} <span class="text-muted float right">.html</span></a></li>
<li><a href="{{ $page->getUrl('/export/pdf') }}" target="_blank">{{ trans('entities.export_pdf') }} <span class="text-muted float right">.pdf</span></a></li>
<li><a href="{{ $page->getUrl('/export/plaintext') }}" target="_blank">{{ trans('entities.export_text') }} <span class="text-muted float right">.txt</span></a></li>
<div class="list-sort">
<div class="list-sort-type dropdown-container" dropdown>
<div dropdown-toggle>{{ $options[$selectedSort] }}</div>
- <ul>
+ <ul class="dropdown-menu">
@foreach($options as $key => $label)
<li @if($key === $selectedSort) class="active" @endif><a href="#" data-sort-value="{{$key}}">{{ $label }}</a></li>
@endforeach
</ul>
</div>
<div class="list-sort-dir" data-sort-dir>
- @if($order === 'desc')
- @icon('sort-up')
- @else
- @icon('sort-down')
- @endif
+ @icon($order === 'desc' ? 'sort-up' : 'sort-down')
</div>
</div>
</form>