Added ability for dropdown menu to be bottom of dom body

- Used when a dropdown is within a scrollable section such as editor
toolbar on mobile.
- Also made mobile page save button more obvious by increasing size and
inverting color.
This commit is contained in:
Dan Brown
2019-05-05 14:43:26 +01:00
parent ad542f0407
commit adc866cb3d
12 changed files with 66 additions and 33 deletions

View File

@ -6,24 +6,54 @@ class DropDown {
constructor(elem) { constructor(elem) {
this.container = 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.toggle = elem.querySelector('[dropdown-toggle]');
this.body = document.body;
this.setupListeners(); this.setupListeners();
} }
show() { show(event) {
this.hide();
this.menu.style.display = 'block'; this.menu.style.display = 'block';
this.menu.classList.add('anim', 'menuIn'); 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 // Focus on first input if existing
let input = this.menu.querySelector('input'); let input = this.menu.querySelector('input');
if (input !== null) input.focus(); if (input !== null) input.focus();
event.stopPropagation();
} }
hide() { hide() {
this.menu.style.display = 'none'; this.menu.style.display = 'none';
this.menu.classList.remove('anim', 'menuIn'); 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() { setupListeners() {

View File

@ -6,20 +6,23 @@ class ListSortControl {
constructor(elem) { constructor(elem) {
this.elem = elem; this.elem = elem;
this.menu = elem.querySelector('ul');
this.sortInput = elem.querySelector('[name="sort"]'); this.sortInput = elem.querySelector('[name="sort"]');
this.orderInput = elem.querySelector('[name="order"]'); this.orderInput = elem.querySelector('[name="order"]');
this.form = elem.querySelector('form'); this.form = elem.querySelector('form');
this.elem.addEventListener('click', event => { this.menu.addEventListener('click', event => {
if (event.target.closest('[data-sort-value]') !== null) { if (event.target.closest('[data-sort-value]') !== null) {
this.sortOptionClick(event); this.sortOptionClick(event);
} }
});
this.elem.addEventListener('click', event => {
if (event.target.closest('[data-sort-dir]') !== null) { if (event.target.closest('[data-sort-dir]') !== null) {
this.sortDirectionClick(event); this.sortDirectionClick(event);
} }
}) });
} }
sortOptionClick(event) { sortOptionClick(event) {

View File

@ -510,7 +510,7 @@ ul.pagination {
position: relative; position: relative;
} }
.dropdown-container ul { .dropdown-menu {
display: none; display: none;
position: absolute; position: absolute;
z-index: 999; z-index: 999;

View File

@ -20,7 +20,7 @@
} }
} }
@include smaller-than($l) { @include smaller-than($m) {
.page-edit-toolbar { .page-edit-toolbar {
overflow-x: scroll; overflow-x: scroll;
overflow-y: visible; overflow-y: visible;
@ -35,18 +35,21 @@
} }
} }
@include smaller-than($l) { @include smaller-than($m) {
.page-edit-toolbar #save-button { .page-edit-toolbar #save-button {
position: fixed; position: fixed;
z-index: 30; z-index: 30;
background-color: #FFF;
border-radius: 50%; border-radius: 50%;
width: 42px; width: 56px;
height: 42px; height: 56px;
font-size: 16px; font-size: 24px;
right: $-m; right: $-m;
bottom: $-xs; bottom: $-s;
box-shadow: $bs-med; box-shadow: $bs-hover;
background-color: currentColor;
svg {
fill: #FFF;
}
span { span {
display: none; display: none;
} }

View File

@ -126,7 +126,7 @@
<span>@icon('export')</span> <span>@icon('export')</span>
<span>{{ trans('entities.export') }}</span> <span>{{ trans('entities.export') }}</span>
</div> </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/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/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> <li><a href="{{ $book->getUrl('/export/plaintext') }}" target="_blank">{{ trans('entities.export_text') }} <span class="text-muted float right">.txt</span></a></li>

View File

@ -128,7 +128,7 @@
<span>@icon('export')</span> <span>@icon('export')</span>
<span>{{ trans('entities.export') }}</span> <span>{{ trans('entities.export') }}</span>
</div> </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/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/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> <li><a href="{{ $chapter->getUrl('/export/plaintext') }}" target="_blank">{{ trans('entities.export_text') }} <span class="text-muted float right">.txt</span></a></li>

View File

@ -29,7 +29,7 @@
@if(userCan('comment-delete', $comment)) @if(userCan('comment-delete', $comment))
<div dropdown class="dropdown-container"> <div dropdown class="dropdown-container">
<button type="button" dropdown-toggle class="text-button" title="{{ trans('common.delete') }}">@icon('delete')</button> <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 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> <li><a action="delete" class="text-button text-neg" >@icon('delete'){{ trans('common.delete') }}</a></li>
</ul> </ul>

View File

@ -53,7 +53,7 @@
<img class="avatar" src="{{$currentUser->getAvatar(30)}}" alt="{{ $currentUser->name }}"> <img class="avatar" src="{{$currentUser->getAvatar(30)}}" alt="{{ $currentUser->name }}">
<span class="name">{{ $currentUser->getShortName(9) }}</span> @icon('caret-down') <span class="name">{{ $currentUser->getShortName(9) }}</span> @icon('caret-down')
</span> </span>
<ul> <ul class="dropdown-menu">
<li> <li>
<a href="{{ baseUrl("/user/{$currentUser->id}") }}">@icon('user'){{ trans('common.view_profile') }}</a> <a href="{{ baseUrl("/user/{$currentUser->id}") }}">@icon('user'){{ trans('common.view_profile') }}</a>
</li> </li>

View File

@ -20,10 +20,10 @@
</div> </div>
<div class="text-center px-m py-xs"> <div class="text-center px-m py-xs">
<div v-show="draftsEnabled" dropdown class="dropdown-container draft-display text"> <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>&nbsp; @icon('more')</a> <a dropdown-toggle class="text-primary text-button"><span class="faded-text" v-text="draftText"></span>&nbsp; @icon('more')</a>
@icon('check-circle', ['class' => 'text-pos draft-notification svg-icon', ':class' => '{visible: draftUpdated}']) @icon('check-circle', ['class' => 'text-pos draft-notification svg-icon', ':class' => '{visible: draftUpdated}'])
<ul> <ul class="dropdown-menu">
<li> <li>
<a @click="saveDraft()" class="text-pos">@icon('save'){{ trans('entities.pages_edit_save_draft') }}</a> <a @click="saveDraft()" class="text-pos">@icon('save'){{ trans('entities.pages_edit_save_draft') }}</a>
</li> </li>
@ -38,14 +38,15 @@
</div> </div>
<div class="action-buttons px-m py-xs" v-cloak> <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> <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"> <li class="px-l py-m">
<p class="text-muted pb-s">{{ trans('entities.pages_edit_enter_changelog_desc') }}</p> <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" /> <input name="summary" id="summary-input" type="text" placeholder="{{ trans('entities.pages_edit_enter_changelog') }}" v-model="changeSummary" />
</li> </li>
</ul> </ul>
<span>{{-- Prevents button jumping on menu show --}}</span>
</div> </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> <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>

View File

@ -53,7 +53,7 @@
<a href="{{ $revision->getUrl('restore') }}"></a> <a href="{{ $revision->getUrl('restore') }}"></a>
<div dropdown class="dropdown-container"> <div dropdown class="dropdown-container">
<a dropdown-toggle>{{ trans('entities.pages_revisions_restore') }}</a> <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 class="px-m py-s"><small class="text-muted">{{trans('entities.revision_restore_confirm')}}</small></li>
<li> <li>
<form action="{{ $revision->getUrl('/restore') }}" method="POST"> <form action="{{ $revision->getUrl('/restore') }}" method="POST">
@ -67,7 +67,7 @@
<span class="text-muted">&nbsp;|&nbsp;</span> <span class="text-muted">&nbsp;|&nbsp;</span>
<div dropdown class="dropdown-container"> <div dropdown class="dropdown-container">
<a dropdown-toggle>{{ trans('common.delete') }}</a> <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 class="px-m py-s"><small class="text-muted">{{trans('entities.revision_delete_confirm')}}</small></li>
<li> <li>
<form action="{{ $revision->getUrl('/delete/') }}" method="POST"> <form action="{{ $revision->getUrl('/delete/') }}" method="POST">

View File

@ -171,7 +171,7 @@
<span>@icon('export')</span> <span>@icon('export')</span>
<span>{{ trans('entities.export') }}</span> <span>{{ trans('entities.export') }}</span>
</div> </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/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/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> <li><a href="{{ $page->getUrl('/export/plaintext') }}" target="_blank">{{ trans('entities.export_text') }} <span class="text-muted float right">.txt</span></a></li>

View File

@ -14,18 +14,14 @@
<div class="list-sort"> <div class="list-sort">
<div class="list-sort-type dropdown-container" dropdown> <div class="list-sort-type dropdown-container" dropdown>
<div dropdown-toggle>{{ $options[$selectedSort] }}</div> <div dropdown-toggle>{{ $options[$selectedSort] }}</div>
<ul> <ul class="dropdown-menu">
@foreach($options as $key => $label) @foreach($options as $key => $label)
<li @if($key === $selectedSort) class="active" @endif><a href="#" data-sort-value="{{$key}}">{{ $label }}</a></li> <li @if($key === $selectedSort) class="active" @endif><a href="#" data-sort-value="{{$key}}">{{ $label }}</a></li>
@endforeach @endforeach
</ul> </ul>
</div> </div>
<div class="list-sort-dir" data-sort-dir> <div class="list-sort-dir" data-sort-dir>
@if($order === 'desc') @icon($order === 'desc' ? 'sort-up' : 'sort-down')
@icon('sort-up')
@else
@icon('sort-down')
@endif
</div> </div>
</div> </div>
</form> </form>