From 9368c27990b5fc90d48376df0cd4c659bb93bc84 Mon Sep 17 00:00:00 2001 From: Rob Garrison Date: Fri, 30 Nov 2018 21:56:26 -0600 Subject: [PATCH] Cleanup updateDate code --- manage/manage-actions.js | 25 +------------------------ manage/manage-ui.js | 23 +++++++++++++++++------ 2 files changed, 18 insertions(+), 30 deletions(-) diff --git a/manage/manage-actions.js b/manage/manage-actions.js index 2776a5cd..fb5b67ef 100644 --- a/manage/manage-actions.js +++ b/manage/manage-actions.js @@ -66,9 +66,6 @@ function initGlobalEvents() { btn.onclick = btn.onclick || (() => openURL({url: URLS.configureCommands})); $$('#header a[href^="http"]').forEach(a => (a.onclick = handleEvent.external)); - // show date installed & last update on hover - installed.addEventListener('mouseover', handleEvent.lazyAddEntryTitle); - installed.addEventListener('mouseout', handleEvent.lazyAddEntryTitle); document.addEventListener('visibilitychange', onVisibilityChange); @@ -272,28 +269,8 @@ Object.assign(handleEvent, { config(event, {styleMeta}) { event.preventDefault(); configDialog(styleMeta); - }, - - lazyAddEntryTitle({type, target}) { - const cell = target.closest('h2.style-name'); - if (cell) { - const link = $('.style-name-link', cell); - if (type === 'mouseover' && !link.title) { - debounce(handleEvent.addEntryTitle, 50, link); - } else { - debounce.unregister(handleEvent.addEntryTitle); - } - } - }, - - addEntryTitle(link) { - const entry = link.closest('.entry'); - link.title = [ - {prop: 'installDate', name: 'dateInstalled'}, - {prop: 'updateDate', name: 'dateUpdated'}, - ].map(({prop, name}) => - t(name) + ': ' + (formatDate(entry.styleMeta[prop]) || '—')).join('\n'); } + }); function handleUpdate(style, {reason, method} = {}) { diff --git a/manage/manage-ui.js b/manage/manage-ui.js index d233b4b7..5a62b479 100644 --- a/manage/manage-ui.js +++ b/manage/manage-ui.js @@ -1,6 +1,7 @@ /* -global prefs $ $$ $create template tWordBreak -installed sorter filterAndAppend +global prefs t $ $$ $create template tWordBreak +installed sorter filterAndAppend handleEvent +animateElement scrollElementIntoView formatDate */ 'use strict'; @@ -158,10 +159,13 @@ const UI = { $('.entry-version', entry).textContent = style.usercssData && style.usercssData.version || ''; - let lastUpdate = style.updateDate ? new Date(style.updateDate) : ''; - lastUpdate = lastUpdate instanceof Date && isFinite(lastUpdate) ? lastUpdate.toISOString() : ''; - $('.entry-last-update', entry).textContent = lastUpdate.split('T')[0].replace(/-/g, '.'); - $('.entry-last-update', entry).title = lastUpdate; + const lastUpdate = $('.entry-last-update', entry); + lastUpdate.textContent = UI.getDateString(style.updateDate); + // Show install & last update in title + lastUpdate.title = [ + {prop: 'installDate', name: 'dateInstalled'}, + {prop: 'updateDate', name: 'dateUpdated'}, + ].map(({prop, name}) => t(name) + ': ' + (formatDate(entry.styleMeta[prop]) || '—')).join('\n'); UI.createStyleTargetsElement({entry, style}); UI.addLabels(entry); @@ -169,6 +173,13 @@ const UI = { return entry; }, + getDateString: date => { + const newDate = new Date(date); + return newDate instanceof Date && isFinite(newDate) + ? newDate.toISOString().split('T')[0].replace(/-/g, '.') + : ''; + }, + createStyleTargetsElement: ({entry, style}) => { const parts = UI._parts;