@@ -171,6 +171,40 @@ function wireup()
171171 } ) ;
172172 // End settings wireup
173173
174+ //wireup the notification-settings switches
175+ $ ( '.enum#notification' ) . on ( 'click' , 'li:not(.sel)' , function ( )
176+ {
177+ var enabled = $ ( this ) . data ( 'notification' ) ;
178+ log ( "Turning notifications " + enabled ? 'on' : 'off' ) ;
179+ save ( 'notifications' , enabled ) ;
180+
181+ if ( notif ( ) && 'Notification' in window )
182+ {
183+ if ( Notification . permission !== 'denied' )
184+ {
185+ Notification . requestPermission ( function ( per )
186+ {
187+ if ( ! ( 'permission' in Notification ) )
188+ {
189+ Notification . permission = per ;
190+ }
191+ } ) ;
192+ }
193+ else
194+ log ( "Permission denied to show desktop notification" ) ;
195+ }
196+
197+ setNotifUI ( )
198+ } ) ;
199+
200+ $ ( '.enum#notification-level' ) . on ( 'click' , 'li:not(.sel)' , function ( )
201+ {
202+ var level = $ ( this ) . data ( 'notification-level' ) ;
203+ convey . notificationLevel = level ;
204+ save ( 'notification-level' , level ) ;
205+ } ) ;
206+ // End notification-settings
207+
174208 convey . layout . header = $ ( 'header' ) . first ( ) ;
175209 convey . layout . frame = $ ( '.frame' ) . first ( ) ;
176210 convey . layout . footer = $ ( 'footer' ) . last ( ) ;
@@ -222,23 +256,7 @@ function wireup()
222256
223257 $ ( '#toggle-notif' ) . click ( function ( )
224258 {
225- log ( "Turning notifications " + ( notif ( ) ? "off" : "on" ) ) ;
226- $ ( this ) . toggleClass ( "fa-bell-o fa-bell " + convey . layout . selClass ) ;
227- save ( 'notifications' , ! notif ( ) ) ;
228-
229- if ( notif ( ) && 'Notification' in window )
230- {
231- if ( Notification . permission !== 'denied' )
232- {
233- Notification . requestPermission ( function ( per )
234- {
235- if ( ! ( 'permission' in Notification ) )
236- Notification . permission = per ;
237- } ) ;
238- }
239- else
240- log ( "Permission denied to show desktop notification" ) ;
241- }
259+ toggle ( $ ( '.settings-notification' ) , $ ( this ) ) ;
242260 } ) ;
243261
244262 $ ( '#show-history' ) . click ( function ( )
@@ -248,7 +266,7 @@ function wireup()
248266
249267 $ ( '#show-settings' ) . click ( function ( )
250268 {
251- toggle ( $ ( '.settings' ) , $ ( this ) ) ;
269+ toggle ( $ ( '.settings-general ' ) , $ ( this ) ) ;
252270 } ) ;
253271
254272 $ ( '#show-gen' ) . click ( function ( ) {
@@ -394,12 +412,13 @@ function wireup()
394412 $ ( window ) . resize ( reframe ) ;
395413}
396414
397- function setTooltips ( ) {
415+ function setTooltips ( )
416+ {
398417 var tips = {
399418 '#path' : { delayIn : 500 } ,
400419 '#logo' : { gravity : 'w' } ,
401420 '.controls li, .pkg-cover-name' : { live : false } ,
402- 'footer .replay' :{ live : false , gravity : 'e' } ,
421+ 'footer .replay' : { live : false , gravity : 'e' } ,
403422 '.ignore' : { live : false , gravity : $ . fn . tipsy . autoNS } ,
404423 '.disabled' : { live : false , gravity : $ . fn . tipsy . autoNS }
405424 } ;
@@ -414,6 +433,12 @@ function setTooltips(){
414433 }
415434}
416435
436+ function setNotifUI ( )
437+ {
438+ var $toggleNotif = $ ( '#toggle-notif' ) . addClass ( notif ( ) ? "fa-bell" : "fa-bell-o" ) ;
439+ $toggleNotif . removeClass ( ! notif ( ) ? "fa-bell" : "fa-bell-o" ) ;
440+ }
441+
417442function expandAll ( )
418443{
419444 $ ( '.story-pkg' ) . each ( function ( ) { expandPackage ( $ ( this ) . data ( 'pkg' ) ) ; } ) ;
@@ -491,8 +516,16 @@ function loadSettingsFromStorage()
491516 convey . uiEffects = uiEffects === "true" ;
492517 enumSel ( "ui-effects" , uiEffects ) ;
493518
494- if ( notif ( ) )
495- $ ( '#toggle-notif' ) . toggleClass ( "fa-bell-o fa-bell " + convey . layout . selClass ) ;
519+ enumSel ( "notification" , "" + notif ( ) ) ;
520+ var notifLevel = get ( "notification-level" ) ;
521+ if ( notifLevel === null )
522+ {
523+ notifLevel = '.*' ;
524+ }
525+ convey . notificationLevel = notifLevel ;
526+ enumSel ( "notification-level" , notifLevel ) ;
527+
528+ setNotifUI ( ) ;
496529}
497530
498531
@@ -783,7 +816,8 @@ function process(data, status, jqxhr)
783816 convey . intervalFuncs . momentjs ( ) ;
784817
785818 // Show notification, if enabled
786- if ( notif ( ) )
819+ var levelRegex = new RegExp ( "(" + convey . notificationLevel + ")" , "i" ) ;
820+ if ( notif ( ) && current ( ) . overall . status . class . match ( levelRegex ) )
787821 {
788822 log ( "Showing notification" ) ;
789823 if ( convey . notif )
@@ -792,7 +826,7 @@ function process(data, status, jqxhr)
792826 convey . notif . close ( ) ;
793827 }
794828
795- var notifText = notifSummary ( current ( ) )
829+ var notifText = notifSummary ( current ( ) ) ;
796830
797831 convey . notif = new Notification ( notifText . title , {
798832 body : notifText . body ,
0 commit comments