It's late and I really don't know what I'm doing

Talk about add-ons and extension development.
User avatar
diesel_travis
Posts: 133
Joined: September 16th, 2003, 11:31 pm
Location: Rochester, NY
Contact:

It's late and I really don't know what I'm doing

Post by diesel_travis »

:?: I've never written an extension before, but I'm attempting to write one that adds 2 options to the context menu when images are right-clicked on: Zoom In, Zoom Out. Zoom In doubles the dimensions of the image, and Zoom Out halves them. I used the source from the Next/Prev Image extension as a basis, but I really am not sure what I'm doing.

Here is my source:
http://travis.servebeer.com/imagezoomer/

I've done some brief googling to no avail, but does a tutorial exist for extension writing?

I think I probably compressed the Jar and Xpi incorrectly as well. (I used winrar for the Jar and winzip for the Xpi)

Thanks in advance and I apologize for being such a n00b.
User avatar
Pike
Posts: 2293
Joined: August 10th, 2003, 12:12 pm
Location: UK
Contact:

Post by Pike »

Compress both the JAR and XPI as zips (you may want to play about with the compression settings on each to find the optimum size, i.e. zero compression on JAR, maximum on XPI, etc.), then rename them. PowerArchiver couldn't open your JAR so I doubt Mozilla can either.
User avatar
diesel_travis
Posts: 133
Joined: September 16th, 2003, 11:31 pm
Location: Rochester, NY
Contact:

yay

Post by diesel_travis »

Ok, after using winzip for both files and correcting an error in my install.js, my extension appeared to install successfully. (Thanx Pike)

Now I have this big red error in my status bar:

Code: Select all

label="&zoominimage:label;"
-------------------^


My extension doesn't work. What is the best way to debug this error?

Thanks
User avatar
diesel_travis
Posts: 133
Joined: September 16th, 2003, 11:31 pm
Location: Rochester, NY
Contact:

Post by diesel_travis »

whoop! there were some mislabeled items in my dtd.
User avatar
diesel_travis
Posts: 133
Joined: September 16th, 2003, 11:31 pm
Location: Rochester, NY
Contact:

Post by diesel_travis »

OK, now my extension installs fine, and the items show up in the context menu.

I thought there might be a bug in my javascript, but I made a test page: http://travis.servebeer.com/imagezoomer/imageZoomer.html and it seems to work fine.

I'm guessing that there's something wrong with the following code in imageZoomerOverlay.js:

Code: Select all

var imageZ = null; 

function imageZoomerContext()
{
    imageZ = getImage(self._content.location.toString());
    var disable = (imageZ == null);
    // show all or none
    disableElement("context-sep-imagezoomer", disable);
    disableElement("context-zoominimage", disable);
    disableElement("context-zoomoutimage", disable);
}

here's some other methods called for reference:

Code: Select all

function getImage(urlstr)
{
    if (!urlstr) return null;

    var file = getFile(urlstr);
    if(isImage(file)) return file;
    return null;
}

function getFile(urlstr)
{
    // copied from utilityOverlay.js
    var lastSlash = urlstr.slice(urlstr.lastIndexOf( "/" )+1);
    if (lastSlash)
    {
        var nameIndex = lastSlash.lastIndexOf( "filename=" );
        if (nameIndex != -1) {
            return (lastSlash.slice(nameIndex+9));
        }
        else {
            return lastSlash;
        }
    }
    return null;
}

function isImage(file)
{
    var imageRegExp = /(\.jpe?g$)|(\.gif$)|(\.png$)/i
    return imageRegExp.test(file);
}

function disableElement(ele, disabled)
{
    document.getElementById(ele).setAttribute("disabled", disabled);
}



(as you can see most of this code was copied from the Next/Prev Image extension)

Anyone have any ideas?
Also, can anyone suggest a better install.js template?

Thanks!
clav
Posts: 1974
Joined: November 5th, 2002, 3:25 am
Location: Lancaster, UK
Contact:

Post by clav »

diesel_jackass wrote:Also, can anyone suggest a better install.js template?


what's the problem with the current one?

if you want profile install support you could grab a more recent version of that script from the ToolbarExt source here


i'm planning on updating the script soon to detect if the extension has already been installed to the profile before, and if so disallow installing globally (because the profile version seems to take precedence, which will confuse the user)
User avatar
diesel_travis
Posts: 133
Joined: September 16th, 2003, 11:31 pm
Location: Rochester, NY
Contact:

Post by diesel_travis »

clav wrote:what's the problem with the current one?

No problems, I was just looking for profile support. The ToolbarExt one looks like it'll work fine. The profile checking support sounds pretty sweet, I think I've seen it before, but I don't remember which extension used it.
thanks.
clav
Posts: 1974
Joined: November 5th, 2002, 3:25 am
Location: Lancaster, UK
Contact:

Post by clav »

it's very likely you've seen this install.js before. it's a descendant of one I first wrote for my Cards extension, and have used in all others since. and many other authors seem to have used it too
jedbro
Posts: 1899
Joined: November 10th, 2002, 12:35 pm
Location: Mexico / Boulder Co.
Contact:

Post by jedbro »

clav wrote:i'm planning on updating the script soon to detect if the extension has already been installed to the profile before, and if so disallow installing globally (because the profile version seems to take precedence, which will confuse the user)


I've made an installer script that does what you are saying for quicknote <a href="http://www.mozdev.org/source/browse/quicknote/src/install.js?rev=1.13&content-type=text/x-cvsweb-markup">here</a>.
I think it's actually one of Clav's first install scripts modded up a bit ;)

Feel free to use it ;)

Basically it first checks to see if the extension already exists either in the Profile or Globar dir's
If not, you get asked. If it does already exists, then it does not ask you and defaults to where it is currently located.
clav
Posts: 1974
Joined: November 5th, 2002, 3:25 am
Location: Lancaster, UK
Contact:

Post by clav »

it's missing support for locale packages. is QuickNote using hard coded strings ?
User avatar
diesel_travis
Posts: 133
Joined: September 16th, 2003, 11:31 pm
Location: Rochester, NY
Contact:

Post by diesel_travis »

jedbro wrote:Feel free to use it ;)

Thanks, don't mind if I do.

I've altered the source somewhat, but my extension still doesn't work correctly.
Problem #1: the options show up in the menu all the time instead of just on images (i've tried code from Next/Prev Image and Copy Image extensions)
Problem #2: I am most certainly incorrectly assuming that "self" references the image that last had its context menu activated. How would I go about accessing this? self._content.location ?
Last edited by diesel_travis on September 17th, 2003, 1:30 pm, edited 1 time in total.
User avatar
diesel_travis
Posts: 133
Joined: September 16th, 2003, 11:31 pm
Location: Rochester, NY
Contact:

Post by diesel_travis »

clav wrote:it's missing support for locale packages. is QuickNote using hard coded strings ?


As far as locales go how hard is it to support multiple locales?

Is it this easy:

Code: Select all

const APP_LOCALE_FOLDER1  = "locale/en-US/";
const APP_LOCALE_FOLDER2  = "locale/en/";
const APP_LOCALE_FOLDER3  = "locale/eo/";

registerChrome(localeFlag, folder, APP_LOCALE_FOLDER1);
registerChrome(localeFlag, folder, APP_LOCALE_FOLDER2);
registerChrome(localeFlag, folder, APP_LOCALE_FOLDER3);

... or am I oversimplifying it?
ant1832
Posts: 98
Joined: February 5th, 2003, 10:08 am
Contact:

Post by ant1832 »

this sounds like a cool extension. I can't wait to test it out
dkDesignCo.com--Professional designs for all your web needs.
User avatar
diesel_travis
Posts: 133
Joined: September 16th, 2003, 11:31 pm
Location: Rochester, NY
Contact:

Post by diesel_travis »

ant1832 wrote:this sounds like a cool extension. I can't wait to test it out

hehe, well I can't wait to get it working. :-)
There used to be an old hack for IE 5.0 that kinda did this, but I forget the name of the program. I figured it would be simple enough for me to attempt as my first extension.
clav
Posts: 1974
Joined: November 5th, 2002, 3:25 am
Location: Lancaster, UK
Contact:

Post by clav »

self would reference the current window or frame I think.

the node for which the current context menu or other popup has been created can be accessed from document.popupNode, in XUL at least. might be different when you want a node inside the html document, but it might just be window._content.document.popupNode

I really ought to know this, since I must have used it when i wrote GoTo... :(
Post Reply