diff --git a/css/admin_notices.css b/css/admin_notices.css new file mode 100644 index 0000000..20d367b --- /dev/null +++ b/css/admin_notices.css @@ -0,0 +1,59 @@ +:not(.wrap) ~ div.updated, +:not(.wrap) ~ div.error, +:not(.wrap) ~ div.notice, +:not(.wrap) ~ div.update-nag{ + margin: 5px 20px 15px 2px; +} + + + +#meta-link-notices-wrap { + margin: 0; + /* padding: 8px 20px 12px; */ + position: relative; +} + +#meta-link-notices-wrap > button.notice-dismiss { + position: relative; + display: flex; +} + +.notice_container{ + padding: 9px 0px 1px 0px; + background-color: gainsboro; +} + +.notice_container.empty{ + padding: 0; +} + +.notice_container > div.updated, +.notice_container > div.error, +.notice_container > div.notice, +.notice_container > div.update-nag{ + margin: 5px 12px 15px 12px; +} + + +/* ngfb update-nag override */ +div.ngfb-notice.update-nag { + display: none !important; /* not working - need to remove with js */ + /* restore normal formatting */ + /* margin-top: 25px; */ + border: 0px; + /* border-left: 4px solid #ffba00; */ + border-left: 4px solid #00a0d2; +} + +.ngfb-notice.update-nag .notice-message { + max-width: 100%; + padding: 0; +} + +.ngfb-notice.update-nag p, .ngfb-notice.update-nag ul, .ngfb-notice.update-nag ol { + text-align: left !important; + font-size: 13px !important; + line-height: 1.5; + margin: 1em 0 !important; + opacity: 0.5; +} \ No newline at end of file diff --git a/js/move_notices.js b/js/move_notices.js new file mode 100644 index 0000000..a18a35b --- /dev/null +++ b/js/move_notices.js @@ -0,0 +1,21 @@ +/** + * Move all notices "above the fold" + * + * Used for plugins that print their notices after 'admin_notice' + */ + +(function ($,document){ + $(document).ready(function(){ + //alert ('move_notices.js'); + //$( 'div.updated, div.error, div.notice' ).not( '.inline, .below-h2' ).insertAfter( $headerEnd ); + + //alert('plugin move notices'); + $( 'div.updated, div.error, div.notice, div.update-nag' ).not( '.inline, .below-h2' ).insertBefore('.wrap:first'); //alert('plugin move notices'); + + // $( 'div.updated, div.error, div.notice, div.update-nag' ).not( '.inline, .below-h2' ).each(function(){ + // $(this).insertBefore('.wrap'); //alert('plugin move notices'); + // }); + + }); +}(jQuery, document)) + diff --git a/js/notice_manager_panel.js b/js/notice_manager_panel.js new file mode 100644 index 0000000..f48ac46 --- /dev/null +++ b/js/notice_manager_panel.js @@ -0,0 +1,59 @@ +(function($,document){ + var button = $( '#meta-link-notices' ), + panel = $( '#meta-link-notices-wrap' ), + haveClosed = false, + haveDismissed = false; + + //auto-open notice-panel for quick dismiss + $(document).ready(function(){ + if (button.length){ + panel.toggle(); + button.addClass( 'screen-meta-active' ); + + screenMeta.open(panel,button); + } + }); + + var dismiss = $( '#meta-link-notices-wrap button' ); + dismiss.on('click',function(){ + screenMeta.close(panel,button); + $( 'div.updated, div.error, div.notice, div.update-nag' ).not( '.inline, .below-h2' ).appendTo('.notice_container').eq(0); + $('.notice_container').removeClass('empty'); + dismiss.hide(); + haveDismissed = true; + }); + + //original wp focus on click function + /* button.on( 'focus.scroll-into-view', function(e){ + if ( e.target.scrollIntoView ) + e.target.scrollIntoView(false); + }); */ + + //scroll page to top when closing notice panel + button.on('click',function(){ + haveClosed = true; + if ( $(this).hasClass('screen-meta-active') ){ + $(window).scrollTop(true); + }else{ + wait (500).then(function(){ //still jumpy sometimes - but scrolls to correct position 400 ~ 600 + $(window).scrollTop(true); + }); + } + + }); + + + wait = window.wait || function(ms){ + var dfd = $.Deferred(); + setTimeout(dfd.resolve, ms); //callback, timeout till callback + return dfd.promise(); + }; + + // auto-close notices panel after short delay + // only auto-close if we have not interacted (opened/closed) with panel previously + wait(20000).then(function(){ + if ( ! haveClosed ) + screenMeta.close(panel,button); + }); + +}(jQuery,document) ) \ No newline at end of file diff --git a/notice-manager.php b/notice-manager.php new file mode 100644 index 0000000..3a4764e --- /dev/null +++ b/notice-manager.php @@ -0,0 +1,82 @@ + 'meta-link-notices-wrap' ], // $attributes - Additional attributes for the link tag. + [ $this , 'print_notice_manager_panel' ] // $panel callback - cb echoes its output + ); + + wp_enqueue_script( 'notice_manager_panel', plugin_dir_url( __FILE__ ) . 'js/notice_manager_panel.js' , null, false , true ); + } + + /* not JSON-safe - unescaped quotes */ + function print_notice_manager_panel(){ + + // NOTE: + // button is a copy of is-dismissible button - for styling purposes only + // js functionality and listener - js/notice_manager_meta_panel.js + echo '
'; + echo '' ; + } + + function remove_update_notifications($value) { + + if ( isset( $value ) && is_object( $value ) ) { + unset( $value->response[ plugin_basename(__FILE__) ] ); + } + + return $value; + } + +} + + +global $notice_manager; +$notice_manager = new NoticeManager(); + + +add_filter( 'wds_required_plugins', function($required){ + $req_array = [ + 'screen-meta-links/screen-meta-links.php', + ]; + return array_merge( $required, $req_array ); +});