Combine 2 FFtoolbar toggle buttons into one

May 18, 2010 at 02:17:18
Specs: Windows XP, 2.0 GHz, 512MB
I would like to be able to toggle two Firefox about:config preferences at the same time. I created a button to toggle each preference by modifying the code from a toggle popup blocker button. For the combined button I would use the same images as I did for the "Toggle Favicon Firefox" button.

My two buttons are:

"Toggle Favicon Firefox"

var popups_enabled_img = "data:image/x-icon;base64,AAABAAEAEBAQAAEABAAoAQAAFgAAACgAAAAQAAAAIAAAAAEABAAAAAAAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/AP//AABCRfAAhYriAEFF8ACbod0AAAAAAAAAfwAAAL8AAAA/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABEQAAAAAAAAERAAAAAAAAAREAAAAAAAABEQAAAAAAAAERAAAAAAAAAREREQAAAAABERERAAAAAAEREREAAAAAAREAAAAAAAABEQAAAAAAAAEREREQAAAAARERERAAAAABEREREAAAAAAAAAAAAAAAAAAAAAAAD//wAA8f8AAPH/AADx/wAA8f8AAPH/AADwHwAA8B8AAPAfAADx/wAA8f8AAPAPAADwDwAA8A8AAP//AAD//wAA";

var popups_disabled_img = "data:image/x-icon;base64,AAABAAEAEBAQAAEABAAoAQAAFgAAACgAAAAQAAAAIAAAAAEABAAAAAAAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/AP//AABCRfAAhYriAEFF8ACbod0AAAAAAAAAfwAAAL8AAAA/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABEQAAAAAAAAERAAAAAAAAAREAAAAAAAABEQAAAAAAAAERAAAAAAAAAREREQAAAAABERERAAAAAAEREREAAAAAAREAAAAAAAABEQAAAAAAAAEREREQAAAAARERERAAAAABEREREAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";

var preF = 'browser.chrome.site_icons';
var on = false;
var off = true;
this.pref = preF;

this.setState = function(){
  var state = this.PS.getBoolPref(this.pref);
  if (state == off) {
    this.checkedval = false;
    this.image = popups_disabled_img;
    this.tooltipText = "Favicon Firefox are currently enabled, click to disable them.";
  } else {
    this.checkedval = true;
    this.image = popups_enabled_img;
    this.tooltipText = "Favicon Firefox are currently disabled, click to enable them.";
  }
}


// TOGGLE FUNCTION FOR CHECK/UNCHECK
this.leftclick = function(evt){
  var prefValue = custombuttons.getPrefs(preF);
  if (prefValue == off) { 
    custombuttons.setPrefs(preF,on); 
    this.checkedval = false; 
    this.image = popups_enabled_img;
    this.tooltipText = "Favicon Firefox are currently disabled, click to enable them.";
  }
  else { 
    custombuttons.setPrefs(preF,off); 
    this.checkedval = true; 
    this.image = popups_disabled_img;
    this.tooltipText = "Favicon Firefox are currently enabled, click to disable them.";
  }
}

this.setAttribute('onclick', 'gQuot( event, this )'); // Calls the Global MouseClick handler gQuot



// OBSERVES STATE OF PREFERENCE
this.PS = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
this.ob = {};
this.ob.observe = this.setState.bind(this);
this.PS.addObserver(this.pref,this.ob,false);
this.setState();
this.setAttribute('preference',preF);



// BUTTON ATTRIBUTES
this.setAttribute("author", 'rawny, nicholas');							                       // Stores Author.
this.setAttribute("version", '2 (2009-02-22)');                                                 	                       // Stores Version.
this.setAttribute('homepage', 'http://custombuttons2.com/forum/buttons/buttons-database/toggle-pop-blocker.html');      // Stores Homepage.
this.setAttribute("dependency", 'FF 2.0.*,CB 2.0.*');						                       // Stores Dependency.
this.setAttribute("status", 'Complete');							                       // Stores Devstatus.
this.setAttribute("public", true);								                       // Stores Public.


and:

"Toggle Favicon Pages"

var popups_enabled_img = "data:image/x-icon;base64,AAABAAEAEBAQAAEABAAoAQAAFgAAACgAAAAQAAAAIAAAAAEABAAAAAAAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/AP//AABCRfAAhYriAEFF8ACbod0AAAAAAAAAfwAAAL8AAAA/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABEQAAAAAAAAERAAAAAAAAAREAAAAAAAABEQAAAAAAAAEREREAAAAAARERERAAAAABEREREQAAAAERAAERAAAAAREAAREAAAABEQABEQAAAAERERERAAAAARERERAAAAABERERAAAAAAAAAAAAAAAAAAAAAAAAD//wAA8f8AAPH/AADx/wAA8f8AAPAfAADwDwAA8AcAAPHHAADxxwAA8ccAAPAHAADwDwAA8B8AAP//AAD//wAA";

var popups_disabled_img = "data:image/x-icon;base64,AAABAAEAEBAQAAEABAAoAQAAFgAAACgAAAAQAAAAIAAAAAEABAAAAAAAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/AP//AABCRfAAhYriAEFF8ACbod0AAAAAAAAAfwAAAL8AAAA/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABEQAAAAAAAAERAAAAAAAAAREAAAAAAAABEQAAAAAAAAEREREAAAAAARERERAAAAABEREREQAAAAERAAERAAAAAREAAREAAAABEQABEQAAAAERERERAAAAARERERAAAAABERERAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";

var preF = 'browser.chrome.favicons';
var on = false;
var off = true;
this.pref = preF;

this.setState = function(){
  var state = this.PS.getBoolPref(this.pref);
  if (state == off) {
    this.checkedval = false;
    this.image = popups_disabled_img;
    this.tooltipText = "Favicon Pages are currently enabled, click to disable them.";
  } else {
    this.checkedval = true;
    this.image = popups_enabled_img;
    this.tooltipText = "Favicon Pages are currently disabled, click to enable them.";
  }
}


// TOGGLE FUNCTION FOR CHECK/UNCHECK
this.leftclick = function(evt){
  var prefValue = custombuttons.getPrefs(preF);
  if (prefValue == off) { 
    custombuttons.setPrefs(preF,on); 
    this.checkedval = false; 
    this.image = popups_enabled_img;
    this.tooltipText = "Favicon Pages are currently disabled, click to enable them.";
  }
  else { 
    custombuttons.setPrefs(preF,off); 
    this.checkedval = true; 
    this.image = popups_disabled_img;
    this.tooltipText = "Favicon Pages are currently enabled, click to disable them.";
  }
}

this.setAttribute('onclick', 'gQuot( event, this )'); // Calls the Global MouseClick handler gQuot



// OBSERVES STATE OF PREFERENCE
this.PS = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
this.ob = {};
this.ob.observe = this.setState.bind(this);
this.PS.addObserver(this.pref,this.ob,false);
this.setState();
this.setAttribute('preference',preF);



// BUTTON ATTRIBUTES
this.setAttribute("author", 'rawny, nicholas');							                       // Stores Author.
this.setAttribute("version", '2 (2009-02-22)');                                                 	                       // Stores Version.
this.setAttribute('homepage', 'http://custombuttons2.com/forum/buttons/buttons-database/toggle-pop-blocker.html');      // Stores Homepage.
this.setAttribute("dependency", 'FF 2.0.*,CB 2.0.*');						                       // Stores Dependency.
this.setAttribute("status", 'Complete');							                       // Stores Devstatus.
this.setAttribute("public", true);								                       // Stores Public.


I have no knowledge of Java and would appreciate any help I could get.

Thanks


See More: Combine 2 FFtoolbar toggle buttons into one

Report •


#1
May 18, 2010 at 06:53:55
You're better off asking on the MozillaZine Forums. Personally, I'm casually waiting for a better, faster browser. Too much so to learn the script model in question.

Report •

#2
May 18, 2010 at 08:02:54
I took your advice and posted on that forum as well.
Thanks for the suggestion.

Report •

#3
May 19, 2010 at 09:27:04
I still hope for some replies here. Nobody has viewed my MozineForum posr.

Report •

Related Solutions


Ask Question