[Companion] Oops

Brian mozdev at bkennelly.net
Wed Sep 15 01:02:53 EDT 2004


I broke the "Show Icons Only" menu item in the last JAR.  It was a 
simple oversight, and I can send a fixed jar file if anyone wants it, 
otherwise I will send it out when I have more changes.

Until then, here is the fixed class_MenuItem.js file.



-------------- next part --------------
//
// MenuItem
//
// The MenuItem is just a thing that appears in a menu list.
// getTitle() - return the title or label for this item.
// getImage() - return the image for this item.
// getLink() - return the correct url for this button
// isRefresh() - return boolean whether this is the Refresh Toolbar item.
// isUninstall() - return boolean whether this is the Uninstall Companion item
//
// $Id: class_MenuItem.js,v 1.4 2004/01/27 17:03:48 burgner Exp $

function MenuItem(raw)
{
    this.raw = raw;
    this.menuText="";
    this.menuLink="";
    this.menuType = "";
    this.parse(this.raw);
}

// USES LOCALIZATION - CHANGE TO POSITION!!!
// E.g. 6th MenuItem of 1st Menu is "About Yahoo! Companion".
MenuItem.prototype.getTitle = function()
{
    if(this.menuText == "About Yahoo! Toolbar" )
        return "About Yahoo! Companion (Mozilla)";
    if(this.menuText == "Über Yahoo! Assistent")
        return "Über Yahoo! Companion (Mozilla)";
    else
        return this.menuText;
}
MenuItem.prototype.getLink = function()
{
    if(this.getTitle() == "About Yahoo! (Mozilla) Companion")
        return "http://companion.mozdev.org/";
    if(this.getTitle() == "Über Yahoo! Companion (Mozilla)")
        return "http://companion.mozdev.org/";
    else
        return this.menuLink;
}
MenuItem.prototype.isRefresh = function()
{
      return (this.menutype == 6);
//    var tmp = this.getTitle();
//    if(tmp == "Refresh Toolbar")
//        return true;
//    if(tmp == "Aktualisieren")
//        return true;
//    else
//        return false;
}
MenuItem.prototype.isAbout = function()
{
      return (this.menutype == 7);
//    var tmp = this.getTitle();
//    if(tmp == "About Yahoo! Companion" || tmp == "About Yahoo! Companion (Mozilla)")
//        return true;
//    else
//        return false;
}
MenuItem.prototype.isIconOnlyToggle = function()
{
      return (this.menutype == 14);
//    var tmp = this.getTitle();
//    if(tmp == "Show Icons Only")
//        return true;
//    if(tmp == "Nur Symbole")
//        return true;
//    if(tmp == "Show Icons and Names")
//        return true;
//    if(tmp == "Symbole und Namen")
//        return true;     
//    else
//        return false;
}
MenuItem.prototype.isUninstall = function()
{
      return (this.menutype == 8);
//    if(this.getTitle() == "Uninstall")
//        return true;
//    if(this.getTitle() == "Yahoo! Assistent deinstallieren")
//        return true;
//    else
//        return false;
}

MenuItem.prototype.isSwitch = function()
{
      return (this.menutype == 9);
}

MenuItem.prototype.isAddBookmark = function()
{
      return (this.menutype == 1);
//    if(this.getTitle().substr(0,12) == "Add Bookmark")
//        return true;
//    if(this.getTitle() == "Neues Bookmark")
//        return true;
//    else
//        return false;
}

MenuItem.prototype.isSeparator = function()
{
    if(this.menuText == "-")
        return true;
    else
        return false;
}

MenuItem.prototype.parse = function(txt)
{
    var txtEnd = txt.indexOf('\x18');
    //alert("Finding Text String (to char "+ txtEnd+") out of this line\n"+txt);
    this.menuText = txt.substr(0,txtEnd);
    var linkRaw = txt.substr(txtEnd+1);
    this.menuLink = this.extractLink(linkRaw);
}

MenuItem.prototype.extractLink = function(txt)
{
    var link = "";
    // in rare cases (like Alerts from a MenuItem) the http:// starts the text...
    // so look for that first
    if(txt.substr(0,4) == "http")
    {
        var idx = txt.indexOf('\x18\x18');
        if(idx != -1)
        {
            // we need to subtract 1 to leave a ^X at the end.
            // this is removed later in this function.
            link = txt.substr(0,idx+1);
            //alert("I think the link should be " + link2 + "\nidx: " + idx + "\norig: " + txt);
        }
        else
        {
            link = txt;
        }
    }
    else
    {
        // often there is a string of ^A that represent a link.
        // -A- -A- -A-
        // after 3rd \x01 is $, then link is after 4th \x01, but need to replace % with $VAR
        // VAR could be ESRV
        // after 3rd \x01 is %, then remove %, and return link.
        // Note, could be empty... not always link in there!
        //alert('find link in: ' + txt);
        
        //if(this.isAddBookmark())
        if (txt.charAt(0) == '\x01')
        {
           var re = /^\x01([0-9]*)/;            
           var type = re.exec(txt);
           this.menutype = type[1];

	   switch (type[1])
           {
	      case "1":        // Add Bookmark
                //alert("Building bookmark link from '"+txt+"'");
                // the bookmark should look like:
	        // \x011\x01
                // \x011\x01N\x19
	        // in the first case, the Folder is empty.
	        // in the second, the N is the folder id
	        // so we're gonna skip ahead 3 spaces, then get the next char
	        var buffer = txt.substr(3);
	        if(buffer == null)
	            return link;
            
                // now we look for the next \x01
                var l = buffer.indexOf('\x19');
                     
	        link = buffer.substr(0,l);
                //alert('Orig buffer: '+buffer+' -- New buffer is: ' + link + '\nloc is: ' + l);
	        return link;
                break;
              case "9":        // Switch toolbar
                re = /\x01.*\x01(\d*)\x19/;
                var tb = re.exec(txt);
                if (tb[1] == "3")           // Currently 'My Toolbar'
                   link = "http://edit.companion.yahoo.com/config/slv4_changedefault?.commit=y&.dflt=2";
                else
                   link = "http://edit.companion.yahoo.com/config/slv4_changedefault?.commit=y&.dflt=3";
                return link;
                break;
              case "4":        // Action item
              case "14":       // Toggle Icons only 
                 re = /\x01.*?\x01.*?\x01?(\$ESRV)?\x01%(.*?)[\x18|\x19]/;  // Get string starting with 3rd ^A
                 var links = re.exec(txt);
                 if (links[1] == "$ESRV") 
                   link = "http://edit.companion.yahoo.com";
                 link += links[2];
                 return link;
                 break;            
              default:
                 break;
           }
        }
        
    }
    // shorten by 1 since there's a control char at the end
    var len = link.length;
    link = link.substr(0,(len-1));
    return link;
}



More information about the Companion mailing list