@@ -11,7 +11,6 @@ var self = this,
1111 } ,
1212 log = console . log . bind ( console ) ;
1313
14-
1514function include ( path )
1615{
1716 Services . scriptloader . loadSubScript ( addon . getResourceURI ( path ) . spec , self ) ;
@@ -147,12 +146,12 @@ function main(window)
147146
148147function disableAll ( obj , r , s )
149148{
149+ if ( obj . hasAttribute && obj . hasAttribute ( "autoSLM" ) )
150+ return true ;
151+
150152 if ( ! s && obj . hasAttribute && obj . hasAttribute ( "autoSLM" ) )
151153 s = true ;
152154
153- if ( obj . tagName == "button" || ( obj . hasAttribute && obj . hasAttribute ( "autoSLM" ) ) )
154- return true ;
155-
156155 if ( s || typeof ( r ) == "undefined" )
157156 {
158157 if ( "disabled" in obj && ! ( "___autoSLM_disabled" in obj ) )
@@ -318,7 +317,7 @@ function fixpref(window, r, s)
318317 {
319318 function addElement ( el , parent , type )
320319 {
321- el . setAttribute ( "autoSLM" , "" ) ;
320+ el . setAttribute ( "autoSLM" , '' ) ;
322321 type = type || "appendChild" ;
323322
324323 if ( type == "insertBefore" )
@@ -331,10 +330,25 @@ function fixpref(window, r, s)
331330 el . parentNode . removeChild ( el ) ;
332331 } ) , false ) ;
333332 }
334- function prefChange ( )
333+
334+ function prefChange ( e , val )
335335 {
336- disableAll ( startBox . parentNode . parentNode , pref . getIntPref ( "sel" ) ? true : false ) ;
336+ if ( e && ( e . target . id != "autoSLM" || e . attrName != "value" ) )
337+ return ;
338+
339+ if ( e && "newValue" in e )
340+ val = ~ ~ e . newValue ;
341+ else
342+ val = pref . getIntPref ( "sel" ) ;
343+
344+ disableAll ( startBox . parentNode . parentNode , val ? true : false ) ;
345+ try
346+ {
347+ doc . getElementById ( "autoSLM_checkbox" ) . disabled = ! val ;
348+ }
349+ catch ( e ) { }
337350 }
351+
338352 if ( ! r && ! doc . getElementById ( "autoSLM_box" ) )
339353 {
340354 let h = startBox . parentNode . parentNode . clientHeight ,
@@ -343,14 +357,13 @@ function fixpref(window, r, s)
343357 menupopup = doc . createXULElement ( "menupopup" ) ,
344358 menulist = doc . createXULElement ( "menulist" ) ,
345359 box = doc . createXULElement ( "hbox" ) ,
346- menuitem = doc . createXULElement ( "menuitem" ) ,
347- p = doc . createXULElement ( "preference" ) ;
360+ menuitem = doc . createXULElement ( "menuitem" ) ;
348361
349362 menulist . id = "autoSLM" ;
350363 menulist . setAttribute ( "label" , "Select first unread message only" ) ;
351364 menulist . setAttribute ( "preference" , PREF_BRANCH + "sel" ) ;
352- menulist . addEventListener ( "command " , prefChange , true ) ;
353- menulist . setAttribute ( "onsyncfrompreference" , "prefChange(event) ") ;
365+ menulist . addEventListener ( "DOMAttrModified " , prefChange , false ) ;
366+ menulist . value = pref . getIntPref ( "sel ") ;
354367 box . setAttribute ( "flex" , false ) ;
355368 box . id = "autoSLM_box" ;
356369 menuitem . setAttribute ( "value" , 0 ) ;
@@ -367,44 +380,15 @@ function fixpref(window, r, s)
367380 menulist . appendChild ( menupopup ) ;
368381 box . appendChild ( menulist ) ;
369382
370- addElement ( box , startBox . parentNode , "insertBefore" ) ;
371-
372383 checkbox . id = "autoSLM_checkbox" ;
373384 checkbox . setAttribute ( "label" , "Auto focus on messages list" ) ;
374385 checkbox . setAttribute ( "preference" , PREF_BRANCH + "focus" ) ;
375- addElement ( checkbox , box ) ;
376-
377- let ps = doc . getElementsByTagName ( "preferences" ) ;
378- if ( ps . length )
379- {
380- ps = ps [ 0 ] ;
381- }
382- else
383- {
384- ps = doc . createXULElement ( "prefrences" ) ;
385- startBox . appendChild ( ps ) ;
386- }
387- addElement ( p , ps ) ;
388-
389- p . id = PREF_BRANCH + "sel" ;
390- p . setAttribute ( "type" , "int" ) ;
391- p . setAttribute ( "name" , p . id ) ;
392- addElement ( p , ps ) ;
386+ box . appendChild ( checkbox ) ;
393387
394- p = doc . createXULElement ( "preference" ) ;
395- p . id = PREF_BRANCH + "focus" ;
396- p . setAttribute ( "type" , "bool" ) ;
397- p . setAttribute ( "name" , p . id ) ;
398- addElement ( p , ps ) ;
388+ addElement ( box , startBox . parentNode , "insertBefore" ) ;
399389
400390 width = startBox . parentNode . parentNode . clientWidth - w ;
401391 height = startBox . parentNode . parentNode . clientHeight - h ;
402- // window.resizeBy(width, height);
403- try
404- {
405- doc . getElementById ( "MailPreferences" ) . showPane ( doc . getElementById ( "MailPreferences" ) . currentPane ) ;
406- }
407- catch ( e ) { }
408392 try
409393 {
410394 let p = [
@@ -425,7 +409,6 @@ function fixpref(window, r, s)
425409 listen ( window , window , "unload" , unload ( function ( )
426410 {
427411 disableAll ( startBox . parentNode . parentNode ) ;
428- // window.resizeBy(-width, -height);
429412 } ) , false ) ;
430413 }
431414 else if ( ! s && doc . getElementById ( "paneGeneral" ) )
0 commit comments