Close notices

#7 · closed · 5 comments

View on GitHub ↗

xdaniel2063

Hello Torsten, It's the first time I write to github, please excuse if it's the wrong way. I really like the idea behind Dobby and want to suggest a little feature. I didn't find a way to close the notices when I once opened them? Best wishes from LEV, Daniel

Comments

tfrommen

Hi Daniel, thanks for the issue. Dobby simply _captures_ any rendered notices, and _reveals_ them again, if you wish. But you are right, there is currently no way to _close_ the notices again. In order to be able to do so, you would need some sort of UI, for example, as simple as a button. I am thinking about implementing this via a filter - I will **not** add any settings UI or even a separate settings page for Dobby, so a filter is as far as I would go here. This filter would be used to switch between two different kinds of behavior: 1. just like it is now: Dobby hides the notices, and on click, he reveals them and removes his own notice; 1. the _Reveal_ button would act as a toggle switch, meaning you can show hidden notices, and once displayed, you can hide them again. The latter means that Dobby's notice would always stay. Is this something that you find useful? Cheers, Thorsten

xdaniel2063

Hello Thorsten, thanks a lot for your reply and engagement. I'm not a friend of code snippets, because I'm running a multisite for older volunteers and don't want to open these possibilities. But for a lot users this could be a solution. But, your plugin is good as it is too ;-) Best, Daniel

webfolkcreative

I updated the JS so that the button toggles the notifications. May be a quick & easy alternative to creating a filter. ``` /* global dobbySettings, jQuery */ (function( $ ) { 'use strict'; const closet = $( '.dobby-closet' ); const dobby = $( '#dobby' ); const notices = closet.find( 'div.error,div.notice,div.updated' ); function reveal() { closet.replaceWith( closet.html() ); //dobby.remove(); } function getClass() { if ( closet.find( 'div.error,div.notice-error' ).length ) { return 'notice-error'; } if ( closet.find( 'div.notice-warning' ).length ) { return 'notice-warning'; } return 'notice-info'; } if ( notices.length < dobbySettings.threshold ) { reveal(); return; } notices.addClass( 'inline' ); dobby.addClass( getClass() ).removeClass( 'hide-if-js' ); $( '.dobby-button' ).click( function() { closet.appendTo( dobby ); var $this = $(this); $this.toggleClass('dobby-button'); if($this.hasClass('dobby-button')){ $this.text('Reveal'); } else { $this.text('Hide'); } $( '.dobby-closet' ).toggle(); //reveal(); } ); })( jQuery );

xdaniel2063

Hello Thorsten, how can I test this? I didn't receive an update notification about wordpress.org? Best, Daniel

tfrommen

Hi @webfolkcreative, thanks for the suggestion, but this is nothing that I will implement; not like this, at least. Dobby started out [toggling](https://github.com/tfrommen/Dobby/blob/cc18368722c2a8a1f7658a7c7490086fcb8b1193/dobby.php#L78) the notices, but then I decided to reveal them once, and make Dobby's notice itself disappear. Following the need of @xdaniel2063, I was _thinking out loud_ about maybe implementing a filter to make Dobby toggle again. But as the only voice asking for something like this (i.e., @xdaniel2063, of course) didn't want to use a filter, Dobby will stay as it is. ---- Hi @xdaniel2063, there hasn't been any new release, so you don't see it. ;) ---- Thanks for all your interest. Cheers, Thorsten