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
Goto page 1, 2  Next

Refresh on display?

Author Message
JohnnyBender



Joined: 19 Apr 2005
Posts: 17
Location: Toronto, Canada

Posted: Sat Apr 23, 2005 - 4:30 pm    Post subject: Refresh on display? Reply with quote

How do I make a widget refresh itself every time dashboard is activated?
View user's profile Send private message Send e-mail Visit poster's website Widgets
iremembercliford



Joined: 27 Mar 2005
Posts: 32

Posted: Sat Apr 23, 2005 - 11:05 pm    Post subject: Reply with quote

refresh how? completely reload, or just reload data from a websource. If it's the second, it already does this.
View user's profile Send private message Send e-mail Widgets
ebustaman



Joined: 22 Apr 2005
Posts: 8

Posted: Sun Apr 24, 2005 - 7:38 am    Post subject: Reply with quote

Most likely you will want to look at the "widget.onshow()" function. This allows you to setup some routine to run whenever the widget is shown. The definition of "show" here means if someone launches your widget the first time, or if he leaves dashboard and re-enters.
View user's profile Send private message Send e-mail Widgets
JohnnyBender



Joined: 19 Apr 2005
Posts: 17
Location: Toronto, Canada

Posted: Sun Apr 24, 2005 - 11:09 am    Post subject: Reply with quote

ebustaman wrote:
Most likely you will want to look at the "widget.onshow()" function. This allows you to setup some routine to run whenever the widget is shown. The definition of "show" here means if someone launches your widget the first time, or if he leaves dashboard and re-enters.


Yes, that's exactly what I want. I don't have access to the developers kit, can you tell me how I would do this? Or point me to a widget that does this already?
View user's profile Send private message Send e-mail Visit poster's website Widgets
ebustaman



Joined: 22 Apr 2005
Posts: 8

Posted: Sun Apr 24, 2005 - 12:05 pm    Post subject: Reply with quote

JohnnyBender wrote:
Yes, that's exactly what I want. I don't have access to the developers kit, can you tell me how I would do this? Or point me to a widget that does this already?


Code:

if (window.widget) {
    widget.onhide = onhide;
    widget.onshow = onshow;
}

function onshow() {
    <routine when the widget is displayed>
}

function onhide() {
   <routine when the widget is hidden>
}
View user's profile Send private message Send e-mail Widgets
JohnnyBender



Joined: 19 Apr 2005
Posts: 17
Location: Toronto, Canada

Posted: Sun Apr 24, 2005 - 12:17 pm    Post subject: Reply with quote

ebustaman wrote:
Code:

if (window.widget) {
    widget.onhide = onhide;
    widget.onshow = onshow;
}

function onshow() {
    <routine when the widget is displayed>
}

function onhide() {
   <routine when the widget is hidden>
}


Hmm, that's what I tried. The code snippet below appears in my HTML where the im age should be.

Code:
         <SCRIPT LANGUAGE="JavaScript">
         function onshow() {
         document.writeln('<IMG SRC="http://www.creaturesinmyhead.com/creatures/'+creatures[choice]+'" WIDTH=250 TITLE=Creatures ALT=Creatures BORDER=0 onClick="window.location.reload();" onError="window.location.reload();" >');
         }
         </SCRIPT>


And the document.writeIn never happens. If I take the document.writeIn line outside of the onshow function, then it works.

Any ideas?
View user's profile Send private message Send e-mail Visit poster's website Widgets
JohnnyBender



Joined: 19 Apr 2005
Posts: 17
Location: Toronto, Canada

Posted: Sun Apr 24, 2005 - 12:18 pm    Post subject: Reply with quote

iremembercliford wrote:
refresh how? completely reload, or just reload data from a websource. If it's the second, it already does this.


I'm calling a random image. I need it to be random every time Dashboard is shown.
View user's profile Send private message Send e-mail Visit poster's website Widgets
Lutz



Joined: 18 Apr 2005
Posts: 19
Location: Sweden

Posted: Sun Apr 24, 2005 - 1:24 pm    Post subject: Re: Refresh on display? Reply with quote

JohnnyBender wrote:
How do I make a widget refresh itself every time dashboard is activated?


I'm struggeling with the same problem, it seems widgets can't reload in dashboard, an alternative is innerHTML but I can't get that to work either... both refresh scripts and innerHTML works in safari for me, just not in dashboard.

but someone said that innerHTML should work, and that should be enough for you random pic function.
View user's profile Send private message Send e-mail Visit poster's website AIM Address ICQ NumberWidgets
ebustaman



Joined: 22 Apr 2005
Posts: 8

Posted: Sun Apr 24, 2005 - 3:11 pm    Post subject: Reply with quote

Somewhere in the body tag of your HTML document, place a <div> tag like so:

Code:

<div id="main">
</div>


Then, your onShow() function could do something like this
Code:

function onshow() {
     document.getElementById("main").innerHTML = '<IMG SRC="http://www.creaturesinmyhead.com/creatures/'+creatures[choice]+'" WIDTH=250 TITLE=Creatures ALT=Creatures BORDER=0 onClick="window.location.reload();" onError="window.location.reload();" >';
}


The document.getElementById() function will be your friend when dynamically updating stuff in your widget. If you notice, the <div> tag has the attribute id='main'. Thus, the document.getElementById("main") grabs that element, and the .innerHTML lets you overwrite the HTML content of the <div>.

Give this a try and let me know how it comes out.
View user's profile Send private message Send e-mail Widgets
Lutz



Joined: 18 Apr 2005
Posts: 19
Location: Sweden

Posted: Sun Apr 24, 2005 - 3:51 pm    Post subject: Reply with quote

ebustaman wrote:


Give this a try and let me know how it comes out.


Thanks! it worked for me now Smile
View user's profile Send private message Send e-mail Visit poster's website AIM Address ICQ NumberWidgets
JohnnyBender



Joined: 19 Apr 2005
Posts: 17
Location: Toronto, Canada

Posted: Sun Apr 24, 2005 - 3:52 pm    Post subject: Reply with quote

ebustaman wrote:
Give this a try and let me know how it comes out.


No dice. It still doesn't load.
View user's profile Send private message Send e-mail Visit poster's website Widgets
catchersmitt0



Joined: 10 Aug 2006
Posts: 2

Posted: Fri Aug 11, 2006 - 5:51 am    Post subject: Reply with quote

I see the answers died after the last (above) posting. No one knows...?
View user's profile Send private message Send e-mail Widgets
3n



Joined: 07 Nov 2006
Posts: 4

Posted: Tue Nov 07, 2006 - 1:29 pm    Post subject: Reply with quote

I simply can't get widget.onshow to activate upon dashboard activation. I have this code:
Code:

if (window.widget) {
    alert("WINDOW.WIDGET ACTIVATED");
    widget.onshow = xxxxx();

}

Not only does my "xxxxx" function never get called, but the alert is never printed to the console. If I put the "widget.onshow = xxxxx();" line outside of any function (global), and put an alert inside my xxxxx function, once again the alert is not seen in the console.

Basically, widget.onshow doesn't work in my case. Nor does if (window.widget).

Any advice? Something need to be added to the plist?

Thanks all.
View user's profile Send private message Send e-mail Widgets
3n



Joined: 07 Nov 2006
Posts: 4

Posted: Tue Nov 07, 2006 - 2:25 pm    Post subject: Reply with quote

Looks like I solved my own problem. If I change the form of my update function call from "xxxx():" to "xxxx;", it works - weird. I'm no javascript expert, so I'll just assume I'm being an idiot.
View user's profile Send private message Send e-mail Widgets
joemcmahon



Joined: 24 Nov 2006
Posts: 1
Location: Palo Alto, CA

Posted: Fri Nov 24, 2006 - 3:43 pm    Post subject: Reply with quote

3n wrote:
Looks like I solved my own problem. If I change the form of my update function call from "xxxx():" to "xxxx;", it works - weird. I'm no javascript expert, so I'll just assume I'm being an idiot.

No, you're not being an idiot at all. "widget.onshow = xxxx();" says "call this function now and put its answer into widget.onshow", while "widget.onshow = xxxx" says "this is a reference to the function xxxx for when you want to call it; put that into widget,onshow". Since the second one is what widget.onshow needs - a reference to a function to call - it works.

A very subtle syntactical difference, and just something you have to remember.
View user's profile Send private message Send e-mail Visit poster's website Widgets
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.

 
Goto page 1, 2  Next
Powered by phpBB © 2001, 2002 phpBB Group