X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/524adce6547a32b0aa19762e3302461c3d1b3452..e2409a5fab3e38e1753adb51ff432b6104c7572b:/resources/js/components/shelf-sort.js diff --git a/resources/js/components/shelf-sort.js b/resources/js/components/shelf-sort.js index e4aefc591..01ca11a33 100644 --- a/resources/js/components/shelf-sort.js +++ b/resources/js/components/shelf-sort.js @@ -1,17 +1,17 @@ -import Sortable from "sortablejs"; -import {Component} from "./component"; +import Sortable from 'sortablejs'; +import {Component} from './component'; /** * @type {Object} */ 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,11 +62,11 @@ export class ShelfSort extends Component { } }); - this.bookSearchInput.addEventListener('input', event => { + this.bookSearchInput.addEventListener('input', () => { this.filterBooksByName(this.bookSearchInput.value); }); - this.sortButtonContainer.addEventListener('click' , event => { + this.sortButtonContainer.addEventListener('click', event => { const button = event.target.closest('button[data-sort]'); if (button) { this.sortShelfBooks(button.dataset.sort); @@ -78,11 +78,10 @@ export class ShelfSort extends Component { * @param {String} filterVal */ filterBooksByName(filterVal) { - // Set height on first search, if not already set, to prevent the distraction // of the list height jumping around if (!this.allBookList.style.height) { - this.allBookList.style.height = this.allBookList.getBoundingClientRect().height + 'px'; + this.allBookList.style.height = `${this.allBookList.getBoundingClientRect().height}px`; } const books = this.allBookList.children; @@ -100,7 +99,7 @@ export class ShelfSort extends Component { */ sortItemActionClick(sortItemAction) { const sortItem = sortItemAction.closest('.scroll-box-item'); - const action = sortItemAction.dataset.action; + const {action} = sortItemAction.dataset; const actionFunction = itemActions[action]; actionFunction(sortItem, this.shelfBookList, this.allBookList); @@ -122,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) { @@ -136,4 +135,4 @@ export class ShelfSort extends Component { this.onChange(); } -} \ No newline at end of file +}