option: distraction_free

This commit is contained in:
abuyoyo 2023-01-14 15:46:00 +02:00
parent bc1a864dd1
commit 2bdd4b24b7
2 changed files with 39 additions and 2 deletions

View File

@ -110,7 +110,7 @@ var NoticeManager = (function ($, document) {
/** /**
* auto-open notices panel * auto-open notices panel
*/ */
if (button.length) { if (button.length && ! options.distraction_free) {
panel.toggle() panel.toggle()
button.addClass("screen-meta-active") button.addClass("screen-meta-active")
screenMeta.open(panel, button) screenMeta.open(panel, button)
@ -121,7 +121,7 @@ var NoticeManager = (function ($, document) {
* only auto-close if we have collected notices previously * only auto-close if we have collected notices previously
* only auto-close if no error messages * only auto-close if no error messages
*/ */
if (options.auto_collapse) { if (options.auto_collapse && ! options.distraction_free) {
wait(4000).then(() => { wait(4000).then(() => {
if (haveClosed && NoticeManager.getNoticesTopPriority() != 'error') { if (haveClosed && NoticeManager.getNoticesTopPriority() != 'error') {
screenMeta.close(panel, button) screenMeta.close(panel, button)
@ -129,6 +129,11 @@ var NoticeManager = (function ($, document) {
} }
}) })
} }
if (options.distraction_free) {
NoticeManager.addCounterWhenClosed()
}
}) // end document.on.ready }) // end document.on.ready
// prevent jumpy scrollRestoration on reload page // prevent jumpy scrollRestoration on reload page
@ -158,6 +163,19 @@ var NoticeManager = (function ($, document) {
return 'notice' return 'notice'
}, },
/**
* .filter(":visible") unreliable when closed
*
* @returns {string} top priority
*/
getNoticesTopPriorityWhenClosed: () => {
if (notices.filter(selectors_error.join(", ")).length)
return 'error'
if (notices.filter(selectors_warning.join(", ")).length)
return 'warning'
return 'notice'
},
/** /**
* Collect notices into panel. * Collect notices into panel.
* Remove dismiss-notices button. * Remove dismiss-notices button.
@ -194,6 +212,19 @@ var NoticeManager = (function ($, document) {
} }
}, },
/**
* cannot rely on filter(:visible)
*/
addCounterWhenClosed: () => {
if (!button.children('.plugin-count').length){
button.append(
$("<span/>").text(notices.length).attr({
class: "plugin-count",
}).addClass(NoticeManager.getNoticesTopPriorityWhenClosed())
)
}
},
removeCounter: () => { removeCounter: () => {
button.children(".plugin-count").remove() button.children(".plugin-count").remove()
}, },

View File

@ -62,6 +62,12 @@ new PluginCore(
'type' => 'checkbox', 'type' => 'checkbox',
'description' => 'If auto-collect is enabled - Notices panel will stay open for a few seconds on page load, and then close automatically. Panel will not auto-collapse if it contains `error` level notices.', 'description' => 'If auto-collect is enabled - Notices panel will stay open for a few seconds on page load, and then close automatically. Panel will not auto-collapse if it contains `error` level notices.',
], ],
[
'id' => 'distraction_free',
'title' => 'Distraction Free',
'type' => 'checkbox',
'description' => 'Notice Panel is closed on page load. Requires auto_collect.'
],
] ]
] ]
] ]