Recent Widgets


Register for DashboardWidgets

Recent Forums Posts

Partners


iCompositions

MacDesktops.net

RSS Showcase
RSS Comments
RSS Forums

This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies. Posted in: Widget Development

Resize Widget window

Author Message
Mbars



Joined: 20 Nov 2007
Posts: 3

Posted: Tue Nov 20, 2007 - 11:56 am    Post subject: Resize Widget window Reply with quote

I know this should be simple, but I'm stuck since a few days.

My widget has an <img> element that I use to load and display an image from the Web, setting its .src property with an image URL.

Image is displayed OK, but I am not able to resize accordingly the Widget window and/or the frontImg. Apparently I am not able to retrieve both .width and .height from the img element. Should I use the onLoad event to be sure the image is loaded? Is there something trivial I am missing?

Any help will be greatly appreciated.
View user's profile Send private message Send e-mail Widgets
Mbars



Joined: 20 Nov 2007
Posts: 3

Posted: Sun Nov 25, 2007 - 12:40 pm    Post subject: Reply with quote

Ok, nobody is answering so let me add more details: I am loading a new picture by simply setting src with a valid image URL
Code:
document.mainfrm.comic_pic.src = pic_url;

This works because the image is loaded. Then, I would like to access the new dimensions of comic_pic element (it's a simpe <img>), and I've tried tons of variations of the following:

Code:
   new_width = document.mainfrm.comic_pic.style.width
   new_heigth = document.mainfrm.comic_pic.style.height

But i never retrieve the values, it's always Null.
Please help, I am feeling a complete dummy.
View user's profile Send private message Send e-mail Widgets
Greenie



Joined: 08 Jun 2005
Posts: 81

Posted: Tue Nov 27, 2007 - 7:37 am    Post subject: Reply with quote

There is a problem with your approach, as far as I can tell:

You try to read a property that doesn't get updated automagically just because you change the src-attribute. In other words: If you didn't set a height via css you can't read one (because there is none set).

And even if you set the height via css before, all you would get would be the original value but not the actual one.

What you could try is to use "getComputedStyle" like this:

Code:
var myPic = document.mainfrm.comic_pic

myWidth = parseInt(document.defaultView.getComputedStyle(myPic, '').getPropertyValue("width"));
myHeight = parseInt(document.defaultView.getComputedStyle(myPic, '').getPropertyValue("height"));


Theoretically you should get the actual dimensions of the displayed image.
View user's profile Send private message Send e-mail AIM Address ICQ NumberWidgets
Mbars



Joined: 20 Nov 2007
Posts: 3

Posted: Thu Nov 29, 2007 - 8:58 am    Post subject: Reply with quote

Thanks for your help, I'm finally getting closer to my goal.
Now I have to find a way to preload the image..
View user's profile Send private message Send e-mail Widgets
Greenie



Joined: 08 Jun 2005
Posts: 81

Posted: Thu Nov 29, 2007 - 9:47 am    Post subject: Reply with quote

Not sure what you mean by "preloading". If you mean: "Display the widget only after the image has been loaded", I'd say the "onload"-handler should do the trick. One other approach might be to set the images' initial dimensions to 1x1 and then check periodically if the actual dimensions have changed (which should only happen if the new image is loaded).
View user's profile Send private message Send e-mail AIM Address ICQ NumberWidgets
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.

 
Powered by phpBB © 2001, 2002 phpBB Group