Compare commits
No commits in common. "master" and "0.25" have entirely different histories.
17
CHANGELOG.md
17
CHANGELOG.md
@ -1,22 +1,5 @@
|
|||||||
# Notice Manager Changelog
|
# Notice Manager Changelog
|
||||||
|
|
||||||
## 0.27
|
|
||||||
|
|
||||||
Release date: Sep 7 2024
|
|
||||||
|
|
||||||
### Dependencies
|
|
||||||
- Composer config: `prepend-autoloader: false` - Give precedence to other composer installations if present.
|
|
||||||
|
|
||||||
## 0.26
|
|
||||||
|
|
||||||
Release date: Sep 1 2024
|
|
||||||
|
|
||||||
### Changed
|
|
||||||
- Use Mutation Observer instead of deprecated `DOMNodeRemoved` event.
|
|
||||||
|
|
||||||
### Added
|
|
||||||
- Add method `NoticeManager.bootstrap()` to initialize Notice manager.
|
|
||||||
|
|
||||||
## 0.25
|
## 0.25
|
||||||
|
|
||||||
Release date: Feb 18 2024
|
Release date: Feb 18 2024
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
"name": "abuyoyo/notice-manager",
|
"name": "abuyoyo/notice-manager",
|
||||||
"description": "Manage notices on WordPress admin pages. Adds 'Notices' screen-meta-link.",
|
"description": "Manage notices on WordPress admin pages. Adds 'Notices' screen-meta-link.",
|
||||||
"type": "wordpress-plugin",
|
"type": "wordpress-plugin",
|
||||||
"version": "0.27",
|
"version": "0.25",
|
||||||
"repositories": [
|
"repositories": [
|
||||||
{
|
{
|
||||||
"type": "vcs",
|
"type": "vcs",
|
||||||
@ -13,8 +13,5 @@
|
|||||||
"abuyoyo/screen-meta-links": "~0.13",
|
"abuyoyo/screen-meta-links": "~0.13",
|
||||||
"abuyoyo/plugincore": "~0.27",
|
"abuyoyo/plugincore": "~0.27",
|
||||||
"abuyoyo/adminmenupage": "~0.29"
|
"abuyoyo/adminmenupage": "~0.29"
|
||||||
},
|
|
||||||
"config": {
|
|
||||||
"prepend-autoloader": false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2,26 +2,27 @@
|
|||||||
* NoticeManager class/module
|
* NoticeManager class/module
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
const NoticeManager = function ($) {
|
var NoticeManager = (function ($, document) {
|
||||||
|
let options = window.notice_manager_options
|
||||||
|
|
||||||
const selectors_notice = [
|
let selectors_notice = [
|
||||||
"div.notice",
|
"div.notice",
|
||||||
"div.updated",
|
"div.updated",
|
||||||
]
|
]
|
||||||
|
|
||||||
const selectors_warning = [
|
let selectors_warning = [
|
||||||
"div.notice-warning",
|
"div.notice-warning",
|
||||||
"div.update-nag",
|
"div.update-nag",
|
||||||
]
|
]
|
||||||
|
|
||||||
const selectors_error = [
|
let selectors_error = [
|
||||||
"div.error",
|
"div.error",
|
||||||
"div.notice-error",
|
"div.notice-error",
|
||||||
]
|
]
|
||||||
|
|
||||||
const selectors_all = selectors_notice.concat(selectors_warning, selectors_error)
|
let selectors_all = selectors_notice.concat(selectors_warning, selectors_error)
|
||||||
|
|
||||||
const selectors_skip = [
|
let selectors_skip = [
|
||||||
".inline",
|
".inline",
|
||||||
".below-h2",
|
".below-h2",
|
||||||
".theme-info .notice",
|
".theme-info .notice",
|
||||||
@ -29,40 +30,25 @@ const NoticeManager = function ($) {
|
|||||||
]
|
]
|
||||||
|
|
||||||
// wait function used with autoCollapse
|
// wait function used with autoCollapse
|
||||||
const wait = function (ms) {
|
let wait = function (ms) {
|
||||||
var dfd = $.Deferred()
|
var dfd = $.Deferred()
|
||||||
setTimeout(dfd.resolve, ms) //callback, timeout till callback
|
setTimeout(dfd.resolve, ms) //callback, timeout till callback
|
||||||
return dfd.promise()
|
return dfd.promise()
|
||||||
}
|
}
|
||||||
|
|
||||||
const options = window.notice_manager_options
|
|
||||||
|
|
||||||
let notices
|
let notices
|
||||||
|
|
||||||
let button
|
let button
|
||||||
let panel
|
let panel
|
||||||
|
let haveClosed // set to true on first close/collect
|
||||||
let dismissNoticesButton
|
let dismissNoticesButton
|
||||||
|
|
||||||
let haveClosed // set to true on first close/collect
|
// bootstrap
|
||||||
let panelObserver
|
// some of these need to run BEFORE document.ready - don't know why really
|
||||||
|
|
||||||
return {
|
|
||||||
bootstrap: () => {
|
|
||||||
|
|
||||||
// Init selectors
|
|
||||||
button = $("#meta-link-notices")
|
button = $("#meta-link-notices")
|
||||||
panel = $("#meta-link-notices-wrap")
|
panel = $("#meta-link-notices-wrap")
|
||||||
dismissNoticesButton = $("#meta-link-notices-wrap button.notice-dismiss")
|
|
||||||
|
|
||||||
// bootstrap notices
|
|
||||||
// get all notices that are not explicitly marked as `.inline` or `.below-h2`
|
|
||||||
// we add .update-nag.inline for WordPress Update notice
|
|
||||||
notices = $(selectors_all.join(', '))
|
|
||||||
.not(selectors_skip.join(', '))
|
|
||||||
.add("div.update-nag")
|
|
||||||
|
|
||||||
// Set state
|
|
||||||
haveClosed = false
|
haveClosed = false
|
||||||
|
dismissNoticesButton = $("#meta-link-notices-wrap button.notice-dismiss")
|
||||||
|
|
||||||
dismissNoticesButton.on("click", () => {
|
dismissNoticesButton.on("click", () => {
|
||||||
screenMeta.close(panel, button)
|
screenMeta.close(panel, button)
|
||||||
@ -97,20 +83,21 @@ const NoticeManager = function ($) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// prevent jumpy scrollRestoration on reload page
|
|
||||||
// fixed below on 'beforeunload'
|
|
||||||
// if (history.scrollRestoration) {
|
|
||||||
// history.scrollRestoration = 'manual'
|
|
||||||
//}
|
|
||||||
/**
|
/**
|
||||||
* Set history.scrollTop to prevent jump on page refresh when scrollRestoration = auto
|
* document.on.ready
|
||||||
*/
|
*/
|
||||||
$(window).on('beforeunload', () => history.pushState(
|
$(() => {
|
||||||
{ scrollTop: document.body.scrollTop },
|
|
||||||
document.title,
|
console.log("NoticeManager.on.ready")
|
||||||
document.location.pathname
|
console.log("options")
|
||||||
)
|
console.log(options)
|
||||||
)
|
|
||||||
|
// bootstrap notices
|
||||||
|
// get all notices that are not explicitly marked as `.inline` or `.below-h2`
|
||||||
|
// we add .update-nag.inline for WordPress Update notice
|
||||||
|
notices = $( selectors_all.join(', ') )
|
||||||
|
.not(selectors_skip.join(', '))
|
||||||
|
.add("div.update-nag")
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove panel if there are no notices on this page
|
* Remove panel if there are no notices on this page
|
||||||
@ -154,8 +141,25 @@ const NoticeManager = function ($) {
|
|||||||
NoticeManager.addCounterWhenClosed()
|
NoticeManager.addCounterWhenClosed()
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
}) // end document.on.ready
|
||||||
|
|
||||||
|
// prevent jumpy scrollRestoration on reload page
|
||||||
|
// fixed below on 'beforeunload'
|
||||||
|
// if (history.scrollRestoration) {
|
||||||
|
// history.scrollRestoration = 'manual'
|
||||||
|
//}
|
||||||
|
/**
|
||||||
|
* Set history.scrollTop to prevent jump on page refresh when scrollRestoration = auto
|
||||||
|
*/
|
||||||
|
$(window).on("beforeunload", () => {
|
||||||
|
history.pushState(
|
||||||
|
{ scrollTop: document.body.scrollTop },
|
||||||
|
document.title,
|
||||||
|
document.location.pathname
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
return {
|
||||||
getNotices: () => notices,
|
getNotices: () => notices,
|
||||||
|
|
||||||
getNoticesTopPriority: () => {
|
getNoticesTopPriority: () => {
|
||||||
@ -193,14 +197,16 @@ const NoticeManager = function ($) {
|
|||||||
* When dismissible notices are dismissed, check if any notices are left on page.
|
* When dismissible notices are dismissed, check if any notices are left on page.
|
||||||
* If no notices are left - remove Notice Panel entirely
|
* If no notices are left - remove Notice Panel entirely
|
||||||
*/
|
*/
|
||||||
panelObserver = new MutationObserver(() => {
|
$(document).on(
|
||||||
|
"DOMNodeRemoved",
|
||||||
|
"#meta-link-notices-wrap div.notice",
|
||||||
|
() => {
|
||||||
notices = panel
|
notices = panel
|
||||||
.find(selectors_all.join(", "))
|
.find(selectors_all.join(", "))
|
||||||
.filter(":visible")
|
.filter(":visible")
|
||||||
NoticeManager.maybeRemoveNoticesPanel()
|
NoticeManager.maybeRemoveNoticesPanel()
|
||||||
});
|
}
|
||||||
panelObserver.observe(panel.get(0), { childList: true, subtree: true }); // only run once
|
)
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
addCounter: () => {
|
addCounter: () => {
|
||||||
@ -256,6 +262,4 @@ const NoticeManager = function ($) {
|
|||||||
notices.insertBefore(".wrap:first")
|
notices.insertBefore(".wrap:first")
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}(jQuery);
|
}(jQuery,document) )
|
||||||
|
|
||||||
jQuery(NoticeManager.bootstrap);
|
|
||||||
@ -2,7 +2,7 @@
|
|||||||
/**
|
/**
|
||||||
* Plugin Name: Notice Manager
|
* Plugin Name: Notice Manager
|
||||||
* Description: Manage notices on WordPress admin pages. Adds 'Notices' screen-meta-link panel to collect notices from page.
|
* Description: Manage notices on WordPress admin pages. Adds 'Notices' screen-meta-link panel to collect notices from page.
|
||||||
* Version: 0.27
|
* Version: 0.25
|
||||||
* Author: abuyoyo
|
* Author: abuyoyo
|
||||||
* Author URI: https://github.com/abuyoyo/
|
* Author URI: https://github.com/abuyoyo/
|
||||||
* Plugin URI: https://github.com/abuyoyo/notice-manager
|
* Plugin URI: https://github.com/abuyoyo/notice-manager
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user