mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-07-28 17:02:04 +03:00
ESLINT: Addressed remaining detected issues
This commit is contained in:
@ -20,7 +20,7 @@ export class AjaxDeleteRow extends Component {
|
||||
window.$events.emit('success', resp.data.message);
|
||||
}
|
||||
this.row.remove();
|
||||
}).catch(err => {
|
||||
}).catch(() => {
|
||||
this.row.style.opacity = null;
|
||||
this.row.style.pointerEvents = null;
|
||||
});
|
||||
|
@ -27,7 +27,7 @@ export class Attachments extends Component {
|
||||
this.startEdit(event.detail.id);
|
||||
});
|
||||
|
||||
this.container.addEventListener('event-emit-select-edit-back', event => {
|
||||
this.container.addEventListener('event-emit-select-edit-back', () => {
|
||||
this.stopEdit();
|
||||
});
|
||||
|
||||
|
@ -25,7 +25,7 @@ export class AutoSuggest extends Component {
|
||||
setupListeners() {
|
||||
const navHandler = new KeyboardNavigationHandler(
|
||||
this.list,
|
||||
event => {
|
||||
() => {
|
||||
this.input.focus();
|
||||
setTimeout(() => this.hideSuggestions(), 1);
|
||||
},
|
||||
@ -104,7 +104,8 @@ export class AutoSuggest extends Component {
|
||||
*/
|
||||
displaySuggestions(suggestions) {
|
||||
if (suggestions.length === 0) {
|
||||
return this.hideSuggestions();
|
||||
this.hideSuggestions();
|
||||
return;
|
||||
}
|
||||
|
||||
// This used to use <button>s but was changed to div elements since Safari would not focus on buttons
|
||||
|
@ -45,19 +45,19 @@ const sortOperations = {
|
||||
*/
|
||||
const moveActions = {
|
||||
up: {
|
||||
active(elem, parent, book) {
|
||||
active(elem, parent) {
|
||||
return !(elem.previousElementSibling === null && !parent);
|
||||
},
|
||||
run(elem, parent, book) {
|
||||
run(elem, parent) {
|
||||
const newSibling = elem.previousElementSibling || parent;
|
||||
newSibling.insertAdjacentElement('beforebegin', elem);
|
||||
},
|
||||
},
|
||||
down: {
|
||||
active(elem, parent, book) {
|
||||
active(elem, parent) {
|
||||
return !(elem.nextElementSibling === null && !parent);
|
||||
},
|
||||
run(elem, parent, book) {
|
||||
run(elem, parent) {
|
||||
const newSibling = elem.nextElementSibling || parent;
|
||||
newSibling.insertAdjacentElement('afterend', elem);
|
||||
},
|
||||
@ -81,10 +81,10 @@ const moveActions = {
|
||||
},
|
||||
},
|
||||
next_chapter: {
|
||||
active(elem, parent, book) {
|
||||
active(elem, parent) {
|
||||
return elem.dataset.type === 'page' && this.getNextChapter(elem, parent);
|
||||
},
|
||||
run(elem, parent, book) {
|
||||
run(elem, parent) {
|
||||
const nextChapter = this.getNextChapter(elem, parent);
|
||||
nextChapter.querySelector('ul').prepend(elem);
|
||||
},
|
||||
@ -92,14 +92,14 @@ const moveActions = {
|
||||
const topLevel = (parent || elem);
|
||||
const topItems = Array.from(topLevel.parentElement.children);
|
||||
const index = topItems.indexOf(topLevel);
|
||||
return topItems.slice(index + 1).find(elem => elem.dataset.type === 'chapter');
|
||||
return topItems.slice(index + 1).find(item => item.dataset.type === 'chapter');
|
||||
},
|
||||
},
|
||||
prev_chapter: {
|
||||
active(elem, parent, book) {
|
||||
active(elem, parent) {
|
||||
return elem.dataset.type === 'page' && this.getPrevChapter(elem, parent);
|
||||
},
|
||||
run(elem, parent, book) {
|
||||
run(elem, parent) {
|
||||
const prevChapter = this.getPrevChapter(elem, parent);
|
||||
prevChapter.querySelector('ul').append(elem);
|
||||
},
|
||||
@ -107,11 +107,11 @@ const moveActions = {
|
||||
const topLevel = (parent || elem);
|
||||
const topItems = Array.from(topLevel.parentElement.children);
|
||||
const index = topItems.indexOf(topLevel);
|
||||
return topItems.slice(0, index).reverse().find(elem => elem.dataset.type === 'chapter');
|
||||
return topItems.slice(0, index).reverse().find(item => item.dataset.type === 'chapter');
|
||||
},
|
||||
},
|
||||
book_end: {
|
||||
active(elem, parent, book) {
|
||||
active(elem, parent) {
|
||||
return parent || (parent === null && elem.nextElementSibling);
|
||||
},
|
||||
run(elem, parent, book) {
|
||||
@ -119,7 +119,7 @@ const moveActions = {
|
||||
},
|
||||
},
|
||||
book_start: {
|
||||
active(elem, parent, book) {
|
||||
active(elem, parent) {
|
||||
return parent || (parent === null && elem.previousElementSibling);
|
||||
},
|
||||
run(elem, parent, book) {
|
||||
@ -127,18 +127,18 @@ const moveActions = {
|
||||
},
|
||||
},
|
||||
before_chapter: {
|
||||
active(elem, parent, book) {
|
||||
active(elem, parent) {
|
||||
return parent;
|
||||
},
|
||||
run(elem, parent, book) {
|
||||
run(elem, parent) {
|
||||
parent.insertAdjacentElement('beforebegin', elem);
|
||||
},
|
||||
},
|
||||
after_chapter: {
|
||||
active(elem, parent, book) {
|
||||
active(elem, parent) {
|
||||
return parent;
|
||||
},
|
||||
run(elem, parent, book) {
|
||||
run(elem, parent) {
|
||||
parent.insertAdjacentElement('afterend', elem);
|
||||
},
|
||||
},
|
||||
@ -196,7 +196,7 @@ export class BookSort extends Component {
|
||||
reverse = (lastSort === sort) ? !reverse : false;
|
||||
let sortFunction = sortOperations[sort];
|
||||
if (reverse && reversibleTypes.includes(sort)) {
|
||||
sortFunction = function(a, b) {
|
||||
sortFunction = function reverseSortOperation(a, b) {
|
||||
return 0 - sortOperations[sort](a, b);
|
||||
};
|
||||
}
|
||||
@ -260,7 +260,7 @@ export class BookSort extends Component {
|
||||
animation: 150,
|
||||
fallbackOnBody: true,
|
||||
swapThreshold: 0.65,
|
||||
onSort: event => {
|
||||
onSort: () => {
|
||||
this.ensureNoNestedChapters();
|
||||
this.updateMapInput();
|
||||
this.updateMoveActionStateForAll();
|
||||
|
@ -27,7 +27,11 @@ export class ChapterContents extends Component {
|
||||
|
||||
click(event) {
|
||||
event.preventDefault();
|
||||
this.isOpen ? this.close() : this.open();
|
||||
if (this.isOpen) {
|
||||
this.close();
|
||||
} else {
|
||||
this.open();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -43,9 +43,9 @@ export class CodeEditor extends Component {
|
||||
this.languageInputChange(language);
|
||||
});
|
||||
|
||||
onEnterPress(this.languageInput, e => this.save());
|
||||
this.languageInput.addEventListener('input', e => this.languageInputChange(this.languageInput.value));
|
||||
onSelect(this.saveButton, e => this.save());
|
||||
onEnterPress(this.languageInput, () => this.save());
|
||||
this.languageInput.addEventListener('input', () => this.languageInputChange(this.languageInput.value));
|
||||
onSelect(this.saveButton, () => this.save());
|
||||
|
||||
onChildEvent(this.historyList, 'button', 'click', (event, elem) => {
|
||||
event.preventDefault();
|
||||
@ -74,7 +74,8 @@ export class CodeEditor extends Component {
|
||||
|
||||
onChildEvent(button.parentElement, '.lang-option-favorite-toggle', 'click', () => {
|
||||
isFavorite = !isFavorite;
|
||||
isFavorite ? this.favourites.add(language) : this.favourites.delete(language);
|
||||
const action = isFavorite ? this.favourites.add : this.favourites.delete;
|
||||
action(language);
|
||||
button.setAttribute('data-favourite', isFavorite ? 'true' : 'false');
|
||||
|
||||
window.$http.patch('/preferences/update-code-language-favourite', {
|
||||
@ -173,7 +174,7 @@ export class CodeEditor extends Component {
|
||||
const historyKeys = Object.keys(this.history).reverse();
|
||||
this.historyDropDown.classList.toggle('hidden', historyKeys.length === 0);
|
||||
this.historyList.innerHTML = historyKeys.map(key => {
|
||||
const localTime = (new Date(parseInt(key))).toLocaleTimeString();
|
||||
const localTime = (new Date(parseInt(key, 10))).toLocaleTimeString();
|
||||
return `<li><button type="button" data-time="${key}" class="text-item">${localTime}</button></li>`;
|
||||
}).join('');
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ export class ConfirmDialog extends Component {
|
||||
this.sendResult(false);
|
||||
});
|
||||
|
||||
return new Promise((res, rej) => {
|
||||
return new Promise(res => {
|
||||
this.res = res;
|
||||
});
|
||||
}
|
||||
|
@ -41,7 +41,11 @@ export class Dropdown extends Component {
|
||||
this.menu.style.position = 'fixed';
|
||||
this.menu.style.width = `${menuOriginalRect.width}px`;
|
||||
this.menu.style.left = `${menuOriginalRect.left}px`;
|
||||
heightOffset = dropUpwards ? (window.innerHeight - menuOriginalRect.top - toggleHeight / 2) : menuOriginalRect.top;
|
||||
if (dropUpwards) {
|
||||
heightOffset = (window.innerHeight - menuOriginalRect.top - toggleHeight / 2);
|
||||
} else {
|
||||
heightOffset = menuOriginalRect.top;
|
||||
}
|
||||
}
|
||||
|
||||
// Adjust menu to display upwards if near the bottom of the screen
|
||||
@ -55,8 +59,8 @@ export class Dropdown extends Component {
|
||||
|
||||
// Set listener to hide on mouse leave or window click
|
||||
this.menu.addEventListener('mouseleave', this.hide);
|
||||
window.addEventListener('click', event => {
|
||||
if (!this.menu.contains(event.target)) {
|
||||
window.addEventListener('click', clickEvent => {
|
||||
if (!this.menu.contains(clickEvent.target)) {
|
||||
this.hide();
|
||||
}
|
||||
});
|
||||
|
@ -13,7 +13,7 @@ export class Dropzone extends Component {
|
||||
this.uploadLimitMessage = this.$opts.uploadLimitMessage;
|
||||
this.timeoutMessage = this.$opts.timeoutMessage;
|
||||
|
||||
const _this = this;
|
||||
const component = this;
|
||||
this.dz = new DropZoneLib(this.container, {
|
||||
addRemoveLinks: true,
|
||||
dictRemoveFile: this.removeMessage,
|
||||
@ -23,9 +23,9 @@ export class Dropzone extends Component {
|
||||
withCredentials: true,
|
||||
init() {
|
||||
this.dz = this;
|
||||
this.dz.on('sending', _this.onSending.bind(_this));
|
||||
this.dz.on('success', _this.onSuccess.bind(_this));
|
||||
this.dz.on('error', _this.onError.bind(_this));
|
||||
this.dz.on('sending', component.onSending.bind(component));
|
||||
this.dz.on('success', component.onSuccess.bind(component));
|
||||
this.dz.on('error', component.onError.bind(component));
|
||||
},
|
||||
});
|
||||
}
|
||||
@ -34,7 +34,7 @@ export class Dropzone extends Component {
|
||||
const token = window.document.querySelector('meta[name=token]').getAttribute('content');
|
||||
data.append('_token', token);
|
||||
|
||||
xhr.ontimeout = e => {
|
||||
xhr.ontimeout = () => {
|
||||
this.dz.emit('complete', file);
|
||||
this.dz.emit('error', file, this.timeoutMessage);
|
||||
};
|
||||
|
@ -34,7 +34,7 @@ export class EntityPermissions extends Component {
|
||||
});
|
||||
|
||||
// Role select change
|
||||
this.roleSelect.addEventListener('change', event => {
|
||||
this.roleSelect.addEventListener('change', () => {
|
||||
const roleId = this.roleSelect.value;
|
||||
if (roleId) {
|
||||
this.addRoleRow(roleId);
|
||||
|
@ -31,7 +31,8 @@ export class EntitySearch extends Component {
|
||||
runSearch() {
|
||||
const term = this.searchInput.value.trim();
|
||||
if (term.length === 0) {
|
||||
return this.clearSearch();
|
||||
this.clearSearch();
|
||||
return;
|
||||
}
|
||||
|
||||
this.searchView.classList.remove('hidden');
|
||||
|
@ -29,7 +29,7 @@ export class EntitySelector extends Component {
|
||||
this.elem.addEventListener('click', this.onClick.bind(this));
|
||||
|
||||
let lastSearch = 0;
|
||||
this.searchInput.addEventListener('input', event => {
|
||||
this.searchInput.addEventListener('input', () => {
|
||||
lastSearch = Date.now();
|
||||
this.showLoading();
|
||||
setTimeout(() => {
|
||||
@ -43,26 +43,26 @@ export class EntitySelector extends Component {
|
||||
});
|
||||
|
||||
// Keyboard navigation
|
||||
onChildEvent(this.$el, '[data-entity-type]', 'keydown', (e, el) => {
|
||||
if (e.ctrlKey && e.code === 'Enter') {
|
||||
onChildEvent(this.$el, '[data-entity-type]', 'keydown', event => {
|
||||
if (event.ctrlKey && event.code === 'Enter') {
|
||||
const form = this.$el.closest('form');
|
||||
if (form) {
|
||||
form.submit();
|
||||
e.preventDefault();
|
||||
event.preventDefault();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (e.code === 'ArrowDown') {
|
||||
if (event.code === 'ArrowDown') {
|
||||
this.focusAdjacent(true);
|
||||
}
|
||||
if (e.code === 'ArrowUp') {
|
||||
if (event.code === 'ArrowUp') {
|
||||
this.focusAdjacent(false);
|
||||
}
|
||||
});
|
||||
|
||||
this.searchInput.addEventListener('keydown', e => {
|
||||
if (e.code === 'ArrowDown') {
|
||||
this.searchInput.addEventListener('keydown', event => {
|
||||
if (event.code === 'ArrowDown') {
|
||||
this.focusAdjacent(true);
|
||||
}
|
||||
});
|
||||
|
@ -3,7 +3,7 @@ import {Component} from './component';
|
||||
|
||||
export class ExpandToggle extends Component {
|
||||
|
||||
setup(elem) {
|
||||
setup() {
|
||||
this.targetSelector = this.$opts.targetSelector;
|
||||
this.isOpen = this.$opts.isOpen === 'true';
|
||||
this.updateEndpoint = this.$opts.updateEndpoint;
|
||||
@ -25,7 +25,8 @@ export class ExpandToggle extends Component {
|
||||
|
||||
const matchingElems = document.querySelectorAll(this.targetSelector);
|
||||
for (const match of matchingElems) {
|
||||
this.isOpen ? this.close(match) : this.open(match);
|
||||
const action = this.isOpen ? this.close : this.open;
|
||||
action(match);
|
||||
}
|
||||
|
||||
this.isOpen = !this.isOpen;
|
||||
|
@ -50,20 +50,20 @@ export class ImageManager extends Component {
|
||||
event.preventDefault();
|
||||
});
|
||||
|
||||
onSelect(this.cancelSearch, event => {
|
||||
onSelect(this.cancelSearch, () => {
|
||||
this.resetListView();
|
||||
this.resetSearchView();
|
||||
this.loadGallery();
|
||||
this.cancelSearch.classList.remove('active');
|
||||
});
|
||||
|
||||
this.searchInput.addEventListener('input', event => {
|
||||
this.searchInput.addEventListener('input', () => {
|
||||
this.cancelSearch.classList.toggle('active', this.searchInput.value.trim());
|
||||
});
|
||||
|
||||
onChildEvent(this.listContainer, '.load-more', 'click', async event => {
|
||||
showLoading(event.target);
|
||||
this.page++;
|
||||
this.page += 1;
|
||||
await this.loadGallery();
|
||||
event.target.remove();
|
||||
});
|
||||
@ -71,7 +71,7 @@ export class ImageManager extends Component {
|
||||
this.listContainer.addEventListener('event-emit-select-image', this.onImageSelectEvent.bind(this));
|
||||
|
||||
this.listContainer.addEventListener('error', event => {
|
||||
event.target.src = baseUrl('loading_error.png');
|
||||
event.target.src = window.baseUrl('loading_error.png');
|
||||
}, true);
|
||||
|
||||
onSelect(this.selectButton, () => {
|
||||
@ -81,7 +81,7 @@ export class ImageManager extends Component {
|
||||
this.hide();
|
||||
});
|
||||
|
||||
onChildEvent(this.formContainer, '#image-manager-delete', 'click', event => {
|
||||
onChildEvent(this.formContainer, '#image-manager-delete', 'click', () => {
|
||||
if (this.lastSelected) {
|
||||
this.loadImageEditForm(this.lastSelected.id, true);
|
||||
}
|
||||
|
@ -1,59 +1,59 @@
|
||||
export {AddRemoveRows} from './add-remove-rows.js';
|
||||
export {AjaxDeleteRow} from './ajax-delete-row.js';
|
||||
export {AjaxForm} from './ajax-form.js';
|
||||
export {Attachments} from './attachments.js';
|
||||
export {AttachmentsList} from './attachments-list.js';
|
||||
export {AutoSuggest} from './auto-suggest.js';
|
||||
export {AutoSubmit} from './auto-submit.js';
|
||||
export {BackToTop} from './back-to-top.js';
|
||||
export {BookSort} from './book-sort.js';
|
||||
export {ChapterContents} from './chapter-contents.js';
|
||||
export {CodeEditor} from './code-editor.js';
|
||||
export {CodeHighlighter} from './code-highlighter.js';
|
||||
export {CodeTextarea} from './code-textarea.js';
|
||||
export {Collapsible} from './collapsible.js';
|
||||
export {AddRemoveRows} from './add-remove-rows';
|
||||
export {AjaxDeleteRow} from './ajax-delete-row';
|
||||
export {AjaxForm} from './ajax-form';
|
||||
export {Attachments} from './attachments';
|
||||
export {AttachmentsList} from './attachments-list';
|
||||
export {AutoSuggest} from './auto-suggest';
|
||||
export {AutoSubmit} from './auto-submit';
|
||||
export {BackToTop} from './back-to-top';
|
||||
export {BookSort} from './book-sort';
|
||||
export {ChapterContents} from './chapter-contents';
|
||||
export {CodeEditor} from './code-editor';
|
||||
export {CodeHighlighter} from './code-highlighter';
|
||||
export {CodeTextarea} from './code-textarea';
|
||||
export {Collapsible} from './collapsible';
|
||||
export {ConfirmDialog} from './confirm-dialog';
|
||||
export {CustomCheckbox} from './custom-checkbox.js';
|
||||
export {DetailsHighlighter} from './details-highlighter.js';
|
||||
export {Dropdown} from './dropdown.js';
|
||||
export {DropdownSearch} from './dropdown-search.js';
|
||||
export {Dropzone} from './dropzone.js';
|
||||
export {EditorToolbox} from './editor-toolbox.js';
|
||||
export {CustomCheckbox} from './custom-checkbox';
|
||||
export {DetailsHighlighter} from './details-highlighter';
|
||||
export {Dropdown} from './dropdown';
|
||||
export {DropdownSearch} from './dropdown-search';
|
||||
export {Dropzone} from './dropzone';
|
||||
export {EditorToolbox} from './editor-toolbox';
|
||||
export {EntityPermissions} from './entity-permissions';
|
||||
export {EntitySearch} from './entity-search.js';
|
||||
export {EntitySelector} from './entity-selector.js';
|
||||
export {EntitySelectorPopup} from './entity-selector-popup.js';
|
||||
export {EventEmitSelect} from './event-emit-select.js';
|
||||
export {ExpandToggle} from './expand-toggle.js';
|
||||
export {GlobalSearch} from './global-search.js';
|
||||
export {HeaderMobileToggle} from './header-mobile-toggle.js';
|
||||
export {ImageManager} from './image-manager.js';
|
||||
export {ImagePicker} from './image-picker.js';
|
||||
export {ListSortControl} from './list-sort-control.js';
|
||||
export {MarkdownEditor} from './markdown-editor.js';
|
||||
export {NewUserPassword} from './new-user-password.js';
|
||||
export {Notification} from './notification.js';
|
||||
export {OptionalInput} from './optional-input.js';
|
||||
export {PageComments} from './page-comments.js';
|
||||
export {PageDisplay} from './page-display.js';
|
||||
export {PageEditor} from './page-editor.js';
|
||||
export {PagePicker} from './page-picker.js';
|
||||
export {PermissionsTable} from './permissions-table.js';
|
||||
export {Pointer} from './pointer.js';
|
||||
export {Popup} from './popup.js';
|
||||
export {SettingAppColorScheme} from './setting-app-color-scheme.js';
|
||||
export {SettingColorPicker} from './setting-color-picker.js';
|
||||
export {SettingHomepageControl} from './setting-homepage-control.js';
|
||||
export {ShelfSort} from './shelf-sort.js';
|
||||
export {EntitySearch} from './entity-search';
|
||||
export {EntitySelector} from './entity-selector';
|
||||
export {EntitySelectorPopup} from './entity-selector-popup';
|
||||
export {EventEmitSelect} from './event-emit-select';
|
||||
export {ExpandToggle} from './expand-toggle';
|
||||
export {GlobalSearch} from './global-search';
|
||||
export {HeaderMobileToggle} from './header-mobile-toggle';
|
||||
export {ImageManager} from './image-manager';
|
||||
export {ImagePicker} from './image-picker';
|
||||
export {ListSortControl} from './list-sort-control';
|
||||
export {MarkdownEditor} from './markdown-editor';
|
||||
export {NewUserPassword} from './new-user-password';
|
||||
export {Notification} from './notification';
|
||||
export {OptionalInput} from './optional-input';
|
||||
export {PageComments} from './page-comments';
|
||||
export {PageDisplay} from './page-display';
|
||||
export {PageEditor} from './page-editor';
|
||||
export {PagePicker} from './page-picker';
|
||||
export {PermissionsTable} from './permissions-table';
|
||||
export {Pointer} from './pointer';
|
||||
export {Popup} from './popup';
|
||||
export {SettingAppColorScheme} from './setting-app-color-scheme';
|
||||
export {SettingColorPicker} from './setting-color-picker';
|
||||
export {SettingHomepageControl} from './setting-homepage-control';
|
||||
export {ShelfSort} from './shelf-sort';
|
||||
export {Shortcuts} from './shortcuts';
|
||||
export {ShortcutInput} from './shortcut-input';
|
||||
export {SortableList} from './sortable-list.js';
|
||||
export {SubmitOnChange} from './submit-on-change.js';
|
||||
export {Tabs} from './tabs.js';
|
||||
export {TagManager} from './tag-manager.js';
|
||||
export {TemplateManager} from './template-manager.js';
|
||||
export {ToggleSwitch} from './toggle-switch.js';
|
||||
export {TriLayout} from './tri-layout.js';
|
||||
export {UserSelect} from './user-select.js';
|
||||
export {SortableList} from './sortable-list';
|
||||
export {SubmitOnChange} from './submit-on-change';
|
||||
export {Tabs} from './tabs';
|
||||
export {TagManager} from './tag-manager';
|
||||
export {TemplateManager} from './template-manager';
|
||||
export {ToggleSwitch} from './toggle-switch';
|
||||
export {TriLayout} from './tri-layout';
|
||||
export {UserSelect} from './user-select';
|
||||
export {WebhookEvents} from './webhook-events';
|
||||
export {WysiwygEditor} from './wysiwyg-editor.js';
|
||||
export {WysiwygEditor} from './wysiwyg-editor';
|
||||
|
@ -82,7 +82,7 @@ export class MarkdownEditor extends Component {
|
||||
}
|
||||
|
||||
handleDividerDrag() {
|
||||
this.divider.addEventListener('pointerdown', event => {
|
||||
this.divider.addEventListener('pointerdown', () => {
|
||||
const wrapRect = this.elem.getBoundingClientRect();
|
||||
const moveListener = event => {
|
||||
const xRel = event.pageX - wrapRect.left;
|
||||
@ -90,7 +90,7 @@ export class MarkdownEditor extends Component {
|
||||
this.displayWrap.style.flexBasis = `${100 - xPct}%`;
|
||||
this.editor.settings.set('editorWidth', xPct);
|
||||
};
|
||||
const upListener = event => {
|
||||
const upListener = () => {
|
||||
window.removeEventListener('pointermove', moveListener);
|
||||
window.removeEventListener('pointerup', upListener);
|
||||
this.display.style.pointerEvents = null;
|
||||
|
@ -100,7 +100,7 @@ export class PageComments extends Component {
|
||||
deleteComment(commentElem) {
|
||||
const id = commentElem.getAttribute('comment');
|
||||
this.showLoading(commentElem.querySelector('[comment-content]'));
|
||||
window.$http.delete(`/comment/${id}`).then(resp => {
|
||||
window.$http.delete(`/comment/${id}`).then(() => {
|
||||
commentElem.parentNode.removeChild(commentElem);
|
||||
window.$events.success(this.deletedText);
|
||||
this.updateCount();
|
||||
|
@ -2,6 +2,33 @@ import * as DOM from '../services/dom';
|
||||
import {scrollAndHighlightElement} from '../services/util';
|
||||
import {Component} from './component';
|
||||
|
||||
function toggleAnchorHighlighting(elementId, shouldHighlight) {
|
||||
DOM.forEach(`a[href="#${elementId}"]`, anchor => {
|
||||
anchor.closest('li').classList.toggle('current-heading', shouldHighlight);
|
||||
});
|
||||
}
|
||||
|
||||
function headingVisibilityChange(entries) {
|
||||
for (const entry of entries) {
|
||||
const isVisible = (entry.intersectionRatio === 1);
|
||||
toggleAnchorHighlighting(entry.target.id, isVisible);
|
||||
}
|
||||
}
|
||||
|
||||
function addNavObserver(headings) {
|
||||
// Setup the intersection observer.
|
||||
const intersectOpts = {
|
||||
rootMargin: '0px 0px 0px 0px',
|
||||
threshold: 1.0,
|
||||
};
|
||||
const pageNavObserver = new IntersectionObserver(headingVisibilityChange, intersectOpts);
|
||||
|
||||
// observe each heading
|
||||
for (const heading of headings) {
|
||||
pageNavObserver.observe(heading);
|
||||
}
|
||||
}
|
||||
|
||||
export class PageDisplay extends Component {
|
||||
|
||||
setup() {
|
||||
@ -58,33 +85,6 @@ export class PageDisplay extends Component {
|
||||
if (headings.length > 0 && pageNav !== null) {
|
||||
addNavObserver(headings);
|
||||
}
|
||||
|
||||
function addNavObserver(headings) {
|
||||
// Setup the intersection observer.
|
||||
const intersectOpts = {
|
||||
rootMargin: '0px 0px 0px 0px',
|
||||
threshold: 1.0,
|
||||
};
|
||||
const pageNavObserver = new IntersectionObserver(headingVisibilityChange, intersectOpts);
|
||||
|
||||
// observe each heading
|
||||
for (const heading of headings) {
|
||||
pageNavObserver.observe(heading);
|
||||
}
|
||||
}
|
||||
|
||||
function headingVisibilityChange(entries, observer) {
|
||||
for (const entry of entries) {
|
||||
const isVisible = (entry.intersectionRatio === 1);
|
||||
toggleAnchorHighlighting(entry.target.id, isVisible);
|
||||
}
|
||||
}
|
||||
|
||||
function toggleAnchorHighlighting(elementId, shouldHighlight) {
|
||||
DOM.forEach(`a[href="#${elementId}"]`, anchor => {
|
||||
anchor.closest('li').classList.toggle('current-heading', shouldHighlight);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
setupDetailsCodeBlockRefresh() {
|
||||
|
@ -59,7 +59,9 @@ export class PageEditor extends Component {
|
||||
window.$events.listen('editor-save-page', this.savePage.bind(this));
|
||||
|
||||
// Listen to content changes from the editor
|
||||
const onContentChange = () => this.autoSave.pendingChange = true;
|
||||
const onContentChange = () => {
|
||||
this.autoSave.pendingChange = true;
|
||||
};
|
||||
window.$events.listen('editor-html-change', onContentChange);
|
||||
window.$events.listen('editor-markdown-change', onContentChange);
|
||||
|
||||
@ -80,7 +82,8 @@ export class PageEditor extends Component {
|
||||
|
||||
setInitialFocus() {
|
||||
if (this.hasDefaultTitle) {
|
||||
return this.titleElem.select();
|
||||
this.titleElem.select();
|
||||
return;
|
||||
}
|
||||
|
||||
window.setTimeout(() => {
|
||||
@ -133,7 +136,9 @@ export class PageEditor extends Component {
|
||||
try {
|
||||
const saveKey = `draft-save-fail-${(new Date()).toISOString()}`;
|
||||
window.localStorage.setItem(saveKey, JSON.stringify(data));
|
||||
} catch (err) {}
|
||||
} catch (lsErr) {
|
||||
console.error(lsErr);
|
||||
}
|
||||
|
||||
window.$events.emit('error', this.autosaveFailText);
|
||||
}
|
||||
@ -154,7 +159,8 @@ export class PageEditor extends Component {
|
||||
try {
|
||||
response = await window.$http.get(`/ajax/page/${this.pageId}`);
|
||||
} catch (e) {
|
||||
return console.error(e);
|
||||
console.error(e);
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.autoSave.interval) {
|
||||
|
@ -1,5 +1,9 @@
|
||||
import {Component} from './component';
|
||||
|
||||
function toggleElem(elem, show) {
|
||||
elem.style.display = show ? null : 'none';
|
||||
}
|
||||
|
||||
export class PagePicker extends Component {
|
||||
|
||||
setup() {
|
||||
@ -18,7 +22,7 @@ export class PagePicker extends Component {
|
||||
this.selectButton.addEventListener('click', this.showPopup.bind(this));
|
||||
this.display.parentElement.addEventListener('click', this.showPopup.bind(this));
|
||||
|
||||
this.resetButton.addEventListener('click', event => {
|
||||
this.resetButton.addEventListener('click', () => {
|
||||
this.setValue('', '');
|
||||
});
|
||||
}
|
||||
@ -55,7 +59,3 @@ export class PagePicker extends Component {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function toggleElem(elem, show) {
|
||||
elem.style.display = show ? null : 'none';
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ export class Pointer extends Component {
|
||||
|
||||
setupListeners() {
|
||||
// Copy on copy button click
|
||||
this.button.addEventListener('click', event => {
|
||||
this.button.addEventListener('click', () => {
|
||||
copyTextToClipboard(this.input.value);
|
||||
});
|
||||
|
||||
@ -46,7 +46,7 @@ export class Pointer extends Component {
|
||||
});
|
||||
|
||||
// Hide pointer when clicking away
|
||||
DOM.onEvents(document.body, ['click', 'focus'], event => {
|
||||
DOM.onEvents(document.body, ['click', 'focus'], () => {
|
||||
if (!this.showing || this.isSelection) return;
|
||||
this.hidePointer();
|
||||
});
|
||||
|
@ -26,11 +26,11 @@ export class Popup extends Component {
|
||||
|
||||
this.container.addEventListener('click', event => {
|
||||
if (event.target === this.container && lastMouseDownTarget === this.container) {
|
||||
return this.hide();
|
||||
this.hide();
|
||||
}
|
||||
});
|
||||
|
||||
onSelect(this.hideButtons, e => this.hide());
|
||||
onSelect(this.hideButtons, () => this.hide());
|
||||
}
|
||||
|
||||
hide(onComplete = null) {
|
||||
|
@ -59,7 +59,6 @@ export class SettingAppColorScheme extends Component {
|
||||
const rgb = this.hexToRgb(hexVal);
|
||||
const rgbLightVal = `rgba(${[rgb.r, rgb.g, rgb.b, '0.15'].join(',')})`;
|
||||
|
||||
console.log(input.name, lightName, hexVal, rgbLightVal);
|
||||
const lightColorInput = this.container.querySelector(`input[name="${lightName}"][type="hidden"]`);
|
||||
lightColorInput.value = rgbLightVal;
|
||||
}
|
||||
|
@ -5,13 +5,13 @@ import {Component} from './component';
|
||||
* @type {Object<string, function(HTMLElement, HTMLElement, HTMLElement)>}
|
||||
*/
|
||||
const itemActions = {
|
||||
move_up(item, shelfBooksList, allBooksList) {
|
||||
move_up(item) {
|
||||
const list = item.parentNode;
|
||||
const index = Array.from(list.children).indexOf(item);
|
||||
const newIndex = Math.max(index - 1, 0);
|
||||
list.insertBefore(item, list.children[newIndex] || null);
|
||||
},
|
||||
move_down(item, shelfBooksList, allBooksList) {
|
||||
move_down(item) {
|
||||
const list = item.parentNode;
|
||||
const index = Array.from(list.children).indexOf(item);
|
||||
const newIndex = Math.min(index + 2, list.children.length);
|
||||
@ -20,7 +20,7 @@ const itemActions = {
|
||||
remove(item, shelfBooksList, allBooksList) {
|
||||
allBooksList.appendChild(item);
|
||||
},
|
||||
add(item, shelfBooksList, allBooksList) {
|
||||
add(item, shelfBooksList) {
|
||||
shelfBooksList.appendChild(item);
|
||||
},
|
||||
};
|
||||
@ -62,7 +62,7 @@ export class ShelfSort extends Component {
|
||||
}
|
||||
});
|
||||
|
||||
this.bookSearchInput.addEventListener('input', event => {
|
||||
this.bookSearchInput.addEventListener('input', () => {
|
||||
this.filterBooksByName(this.bookSearchInput.value);
|
||||
});
|
||||
|
||||
@ -121,10 +121,10 @@ export class ShelfSort extends Component {
|
||||
const bProp = bookB.dataset[sortProperty].toLowerCase();
|
||||
|
||||
if (reverse) {
|
||||
return aProp < bProp ? (aProp === bProp ? 0 : 1) : -1;
|
||||
return bProp.localeCompare(aProp);
|
||||
}
|
||||
|
||||
return aProp < bProp ? (aProp === bProp ? 0 : -1) : 1;
|
||||
return aProp.localeCompare(bProp);
|
||||
});
|
||||
|
||||
for (const book of books) {
|
||||
|
@ -33,7 +33,8 @@ export class Shortcuts extends Component {
|
||||
|
||||
window.addEventListener('keydown', event => {
|
||||
if (event.key === '?') {
|
||||
this.hintsShowing ? this.hideHints() : this.showHints();
|
||||
const action = this.hintsShowing ? this.hideHints : this.showHints;
|
||||
action();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -36,10 +36,10 @@ export class TemplateManager extends Component {
|
||||
});
|
||||
|
||||
// Search submit button press
|
||||
this.searchButton.addEventListener('click', event => this.performSearch());
|
||||
this.searchButton.addEventListener('click', () => this.performSearch());
|
||||
|
||||
// Search cancel button press
|
||||
this.searchCancel.addEventListener('click', event => {
|
||||
this.searchCancel.addEventListener('click', () => {
|
||||
this.searchInput.value = '';
|
||||
this.performSearch();
|
||||
});
|
||||
|
@ -19,7 +19,7 @@ export class TriLayout extends Component {
|
||||
|
||||
// Watch layout changes
|
||||
this.updateLayout();
|
||||
window.addEventListener('resize', event => {
|
||||
window.addEventListener('resize', () => {
|
||||
this.updateLayout();
|
||||
}, {passive: true});
|
||||
}
|
||||
|
Reference in New Issue
Block a user