diff --git a/js/notice_manager_panel.js b/js/notice_manager_panel.js index b08cb50..d2eee9d 100644 --- a/js/notice_manager_panel.js +++ b/js/notice_manager_panel.js @@ -110,7 +110,7 @@ var NoticeManager = (function ($, document) { /** * auto-open notices panel */ - if (button.length) { + if (button.length && ! options.distraction_free) { panel.toggle() button.addClass("screen-meta-active") 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 no error messages */ - if (options.auto_collapse) { + if (options.auto_collapse && ! options.distraction_free) { wait(4000).then(() => { if (haveClosed && NoticeManager.getNoticesTopPriority() != 'error') { screenMeta.close(panel, button) @@ -129,6 +129,11 @@ var NoticeManager = (function ($, document) { } }) } + + if (options.distraction_free) { + NoticeManager.addCounterWhenClosed() + } + }) // end document.on.ready // prevent jumpy scrollRestoration on reload page @@ -158,6 +163,19 @@ var NoticeManager = (function ($, document) { 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. * 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( + $("").text(notices.length).attr({ + class: "plugin-count", + }).addClass(NoticeManager.getNoticesTopPriorityWhenClosed()) + ) + } + }, + removeCounter: () => { button.children(".plugin-count").remove() }, diff --git a/notice-manager.php b/notice-manager.php index 763e178..4171bc7 100644 --- a/notice-manager.php +++ b/notice-manager.php @@ -62,6 +62,12 @@ new PluginCore( '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.', ], + [ + 'id' => 'distraction_free', + 'title' => 'Distraction Free', + 'type' => 'checkbox', + 'description' => 'Notice Panel is closed on page load. Requires auto_collect.' + ], ] ] ]