LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 08-21-2010, 11:14 AM   #1
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948
Need help modifying Firefox custombutton javascript


I've been using this custombuttons2 button in Firefox for a while now. It functions by popping up the contents of a hidden toolbar whenever the button is pressed. It's great for keeping less-commonly-used buttons at hand without taking up a ton of toolbar space. However it seems to me that it would be even better if the toolbar dropped down vertically, allowing for smoother and faster mouse access than with the current horizontal pop-up.

I've been playing around and so far I've gotten it to almost work by inserting popupToolbar.setAttribute("orient", "vertical"); into the first if statement near the beginning. This makes it drop down the way I want it to, but only by applying the vertical orientation globally. That is, if the visibility of the toolbar itself is toggled, such as when I open up the toolbar customize dialog, I get a fat toolbar with vertically-aligned buttons. Not good.

What I need, I guess, is for it to apply the vertical alignment only when the button is active, and to remove it again when it closes. but I don't understand javascript well enough to figure out where to modify it. I've tried inserting setAttribute and removeAttribute in various places with no success. Could someone help me out here?

I'm re-posting the button code here for convenience.
Code:
/*Initialization code*/
 
var popupToolbarName = "";
var popupToolbarId = "";
var popupId = "";
var contextPopupId = "popuptoolbar-contextpopup";
 
this.type = "menu";
this._init = function() {
  popupToolbarName = this.label;
  popupToolbarId = "__customToolbar_" + popupToolbarName.replace(" ", "_");
  popupId = popupToolbarName.replace(" ", "").toLowerCase() + "-" + this.type + "popup";
 
  var popupToolbar = document.getElementById(popupToolbarId);
  if (popupToolbar) {
    popupToolbar.setAttribute("collapsed", "true");
    document.persist(popupToolbarId, "collapsed");
  }
 
  var popup = document.getElementById(popupId);
  if (popup) {
    popup.hidePopup();
    popup.parentNode.removeChild(popup);
  }
 
  popup = document.getElementById("mainPopupSet").appendChild(document.createElement("menupopup"));
  popup.setAttribute("id", popupId);
  popup.setAttribute("position", "after_start");
 
  if (this.type == "menu") {
    while (this.firstChild && this.firstChild.localName == "menupopup") {
      this.firstChild.hidePopup();
      this.removeChild(this.firstChild);
    }
    this.appendChild(popup);
    popup.setAttribute("onpopupshowing", 'this.parentNode.setPopup(event);');
  }
  else {
    popup.setAttribute("onpopupshowing", 'document.popupNode.setPopup(event);');
  }
 
  popup.setAttribute("onpopupshown", '{\
    window.addEventListener("popuphidden", function(e) {\
      var popup = document.getElementById(popupId);\
      if (e.target == popup) {\
        window.removeEventListener("popuphidden", arguments.callee, false);\
        return;\
      }\
      var popupNode = document.popupNode;\
      while (popupNode && popupNode != popup) popupNode = popupNode.parentNode;\
      if (popupNode == popup) popup.hidePopup();\
    }, false);\
  }'.replace("popupId", '"' + popupId + '"'));
 
  popup.setAttribute("onpopuphidden", '{\
    var popup = event.target;\
    if (popup.firstChild && popup.firstChild.localName == "toolbar") {\
      var popupToolbar = popup.firstChild;\
      popupToolbar.removeAttribute("style");\
      popupToolbar.setAttribute("collapsed", "true");\
      document.persist(popupToolbar.id, "collapsed");\
      var navbox = document.getElementById("navigator-toolbox");\
      var nextElement = navbox.firstChild;\
      while (nextElement && nextElement.localName != "toolbarset") {\
        if (Number(nextElement.getAttribute("customindex")) > Number(popupToolbar.getAttribute("customindex")))\
          break;\
        nextElement = nextElement.nextSibling;\
      }\
      navbox.insertBefore(popupToolbar, nextElement);\
      popupToolbar.firstPermanentChild = null;\
      popupToolbar.lastPermanentChild = null;\
      popupToolbar.currentSet = popupToolbar.getAttribute("currentset");\
    }\
    while (popup.lastChild && popup.lastChild.localName == "menuitem")\
      popup.removeChild(popup.lastChild);\
  }');
 
  var contextPopup = document.getElementById(contextPopupId);
  if (contextPopup) {
    contextPopup.hidePopup();
    contextPopup.parentNode.removeChild(contextPopup);
  }
 
  contextPopup = document.getElementById("mainPopupSet").appendChild(document.createElement("menupopup"));
  contextPopup.setAttribute("id", contextPopupId);
  contextPopup.setAttribute("position", "at_pointer");
  contextPopup.setAttribute("onpopupshowing", 'document.popupNode.setContextPopup(event);');
 
  var menuitem = document.createElement("menuitem");
  menuitem.setAttribute("label", "Show Context Menu With Toolbar");
  menuitem.setAttribute("type", "checkbox");
  menuitem.setAttribute("checked", this.getBoolPref('showContextWithToolbar'));
  menuitem.setAttribute("oncommand", "document.popupNode.setBoolPref('showContextWithToolbar', this.getAttribute('checked') == 'true');");
  contextPopup.appendChild(menuitem);
  contextPopup.appendChild(document.createElement("menuseparator"));
 
  this.tooltipText = this.label;
}
 
this.setBoolPref = function(name, value) {
  var prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
  prefs.setBoolPref("custombuttons.popuptoolbar." + name, value);
}
 
this.getBoolPref = function(name) {
  var prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
  return prefs.getPrefType("custombuttons.popuptoolbar." + name)
        && prefs.getBoolPref("custombuttons.popuptoolbar." + name);
}
 
this.setPopup = function(event) {
  if (this.getBoolPref('showContextWithToolbar')) {
    document.popupNode = this;
    this.setContextPopup(event);
  }
 
  var popup = event.target;
  var popupToolbar = document.getElementById(popupToolbarId);
  if (popupToolbar && popupToolbar.parentNode != popup && this.parentNode != popupToolbar) {
    popup.insertBefore(popupToolbar, popup.firstChild);
    popupToolbar.setAttribute("collapsed", "false");
    if (!this.getBoolPref('showContextWithToolbar'))
      popupToolbar.setAttribute("style", "border: none !important;");
  }
 
  if (!popup.firstChild) {
    document.popupNode = this;
    this.setContextPopup(event);
  }
}
 
this.setContextPopup = function(event) {
  var contextPopup = event.target;
  while (contextPopup.lastChild && contextPopup.lastChild.localName == "menuitem")
    contextPopup.removeChild(contextPopup.lastChild);
 
  var toolbars = document.getElementById("navigator-toolbox").getElementsByTagName("toolbar");
  for (var i=0; i<toolbars.length; i++) {
    var toolbarname = toolbars[i].getAttribute("toolbarname");
    var toolbarid = toolbars[i].getAttribute("id");
    var menuitem = contextPopup.appendChild(document.createElement("menuitem"));
    menuitem.setAttribute("label", toolbarname);
    menuitem.setAttribute("type", "radio");
    menuitem.setAttribute("name", "toolbars-radio");
    menuitem.setAttribute("checked", (this.label == toolbarname));
    menuitem.setAttribute("disabled", ("__customToolbar_" + toolbarname.replace(" ", "_") != toolbarid) || (this.parentNode == toolbars[i]));
    menuitem.setAttribute("oncommand", "document.popupNode.setToolbar(this.label.toString());");
  }
}
 
this.setToolbar = function(toolbarname) {
  var toolbar = document.getElementById("__customToolbar_" + toolbarname.replace(" ", "_"));
  if (toolbar && toolbar != this.parentNode) {
    this.label = toolbarname;
    if (toolbar.firstChild && toolbar.firstChild.image)
      this.image = toolbar.firstChild.image;
 
    this._init();
  }
}
 
var that = this;
this.hideDropMarker = function() {
  var dropMarker = document.getAnonymousElementByAttribute(that, "class", "toolbarbutton-menu-dropmarker");
  if (dropMarker) {
    dropMarker.setAttribute("hidden", "true");
  } else {
    setTimeout(that.hideDropMarker, 10);
  }
}
 
this.showPopup = function(event) {
  document.popupNode = this;
  document.getElementById(popupId).showPopup(this, -1, -1, "popup", "bottomleft", "topleft");
}
 
this.showContextPopup = function(event) {
  document.popupNode = this;
  document.getElementById(contextPopupId).showPopup(this, event.screenX, event.screenY, "context", "none", "none");
}
 
this.leftclick = this.showPopup;
this.rightclick = this.showContextPopup;
 
if (this.type == "menu") {
  this.leftclick = this.hideDropMarker;
  this.hideDropMarker();
}
 
this._init();
 
this.setAttribute('onclick', 'if (event.target == event.currentTarget) gQuot(event, this);');
 
this.setAttribute('author','ithinc');
this.setAttribute('version','20080322.05');
this.setAttribute('homepage', 'http://custombuttons2.com/forum/buttons/buttons-database/popup-toolbar.html');
this.setAttribute('dependency','FF2.0*, CB2 2.0.5*');
this.setAttribute('status','Development');
this.setAttribute('public',true);
 
  


Reply

Tags
firefox, javascript, toolbar


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
JavaScript and Firefox JonBL Linux - Newbie 4 11-17-2007 02:49 AM
Ubuntu Edgy/Firefox 2/Javascript - Firefox closes accessing websites with Javascript Interdictor Ubuntu 8 11-02-2006 11:58 AM
javascript in firefox jackdoll Fedora 1 11-19-2005 02:18 AM
modifying cookies in firefox pepisfree Linux - Software 2 08-25-2004 05:35 AM
javascript for firefox? mohapi Fedora 4 06-20-2004 03:22 PM


All times are GMT -5. The time now is 09:11 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration