From d800f072f9d198596bef1f04ffccb6ad99f6094d Mon Sep 17 00:00:00 2001 From: Rob Garrison Date: Sat, 23 Dec 2017 22:45:20 -0600 Subject: [PATCH] Clean up sort function & variable names --- manage/filters.js | 2 +- manage/manage.js | 6 +++--- manage/sort.js | 36 ++++++++++++++++++------------------ manage/updater-ui.js | 2 +- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/manage/filters.js b/manage/filters.js index 6b934a4a..82f1dcfe 100644 --- a/manage/filters.js +++ b/manage/filters.js @@ -155,7 +155,7 @@ function filterOnChange({target: el, forceRefilter}) { }); if (installed) { reapplyFilter(); - sorter().updateSort(); + sorter().update(); } } diff --git a/manage/manage.js b/manage/manage.js index 2a3d7940..6a51c22b 100644 --- a/manage/manage.js +++ b/manage/manage.js @@ -85,7 +85,7 @@ function initGlobalEvents() { // N.B. triggers existing onchange listeners setupLivePrefs(); - sorter().sortInit(); + sorter().init(); $$('[id^="manage.newUI"]') .forEach(el => (el.oninput = (el.onchange = switchUI))); @@ -108,7 +108,7 @@ function initGlobalEvents() { function showStyles(styles = []) { - const sorted = sorter().sortStyles({ + const sorted = sorter().sort({ parser: 'style', styles: styles.map(style => ({ style, @@ -459,7 +459,7 @@ function handleUpdate(style, {reason, method} = {}) { handleUpdateInstalled(entry, reason); } filterAndAppend({entry}); - sorter().updateSort(); + sorter().update(); if (!entry.matches('.hidden') && reason !== 'import') { animateElement(entry); scrollElementIntoView(entry); diff --git a/manage/sort.js b/manage/sort.js index df56a00f..fb47962d 100644 --- a/manage/sort.js +++ b/manage/sort.js @@ -27,7 +27,7 @@ const sorter = (() => { sorter: sorterType.number }, disabled: { - text: '', // added as either "enabled" or "disabled" by the addSortOptions function + text: '', // added as either "enabled" or "disabled" by the addOptions function parse: { style: ({style}) => (style.enabled ? 1 : 0), entry: entry => (entry.classList.contains('enabled') ? 1 : 0) @@ -54,7 +54,7 @@ const sorter = (() => { // Adding (assumed) most commonly used ('title,asc' should always be first) // whitespace before & after the comma is ignored - const sortSelectOptions = [ + const selectOptions = [ '{groupAsc}', 'title,asc', 'dateInstalled,desc, title,asc', @@ -74,9 +74,9 @@ const sorter = (() => { 'disabled,desc, usercss,asc, title,desc' ]; - const sortByRegex = /\s*,\s*/; + const splitRegex = /\s*,\s*/; - function addSortOptions() { + function addOptions() { let container; const select = $('#sort-select'); const renderBin = document.createDocumentFragment(); @@ -92,7 +92,7 @@ const sorter = (() => { groupDesc: t('sortLabelTitleDesc') }; const optgroupRegex = /\{\w+\}/; - sortSelectOptions.forEach(sort => { + selectOptions.forEach(sort => { if (optgroupRegex.test(sort)) { if (container) { renderBin.appendChild(container); @@ -103,7 +103,7 @@ const sorter = (() => { } let lastTag = ''; const opt = option.cloneNode(); - opt.textContent = sort.split(sortByRegex).reduce((acc, val) => { + opt.textContent = sort.split(splitRegex).reduce((acc, val) => { if (tagData[val]) { lastTag = val; return acc + (acc !== '' ? ' + ' : '') + tagData[val].text; @@ -120,14 +120,14 @@ const sorter = (() => { select.value = prefs.get('manage.newUI.sort'); } - function sortStyles({styles, parser}) { + function sort({styles, parser}) { if (!styles) { styles = [...installed.children]; parser = 'entry'; } else { parser = 'style'; } - const sortBy = prefs.get('manage.newUI.sort').split(sortByRegex); // 'title,asc' + const sortBy = prefs.get('manage.newUI.sort').split(splitRegex); // 'title,asc' const len = sortBy.length; return styles.sort((a, b) => { let types, direction; @@ -143,10 +143,10 @@ const sorter = (() => { }); } - function updateSort() { + function update() { if (!installed) return; const current = [...installed.children]; - const sorted = sortStyles({ + const sorted = sort({ styles: current.map(entry => ({ entry, name: entry.styleNameLowerCase, @@ -163,13 +163,13 @@ const sorter = (() => { } } - function manageSort(event) { + function manageChange(event) { event.preventDefault(); prefs.set('manage.newUI.sort', this.value); - updateSort(); + update(); } - function showSortHelp(event) { + function showHelp(event) { event.preventDefault(); messageBox({ className: 'help-text', @@ -182,10 +182,10 @@ const sorter = (() => { }); } - function sortInit() { - $('#sort-select').addEventListener('change', manageSort); - $('#sorter-help').onclick = showSortHelp; - addSortOptions(); + function init() { + $('#sort-select').addEventListener('change', manageChange); + $('#sorter-help').onclick = showHelp; + addOptions(); } function updateStripes() { @@ -199,5 +199,5 @@ const sorter = (() => { }); } - return {sortInit, updateSort, sortStyles, updateStripes}; + return {init, update, sort, updateStripes}; }); diff --git a/manage/updater-ui.js b/manage/updater-ui.js index 6e88ed31..2117d901 100644 --- a/manage/updater-ui.js +++ b/manage/updater-ui.js @@ -144,7 +144,7 @@ function reportUpdateState(state, style, details) { } if (filtersSelector.hide) { filterAndAppend({entry}); - sorter().updateSort(); + sorter().update(); } }