JavaScript: Request for body's onload event:

flyingdutchieflyingdutchie Registered Users Posts: 1,286 Major grins
edited September 19, 2005 in SmugMug Support
(I copied - i can not move it - this thread from customization... i think i belongs better here)

Hi smugmug,

In my customization i use the <body onload=""> event to execute code after the page finished loading (it creates a menu).

However, your 'slideshow' page overrides it because it contains javascript that forcefully overwrites the onload event-handler ==> My menu does not load. I got around it by doing some javascript hacking, but i'd prefer a proper solution :):

Here is a snippet of the javascript from smugmug on the 'slideshow' page that overwrites it:
[b]onload = onStart;[/b]
	captionTopHidden = true;
	captionBottomHidden = true;
	 ...

Maybe your smugmug.js scripting file could contain this piece of code:
var g_onLoadFncs = new Array(); 
function RegisterFunction(pFunction, pParameter)
{
	this.funct	 = pFunction;
	this.parameter = pParameter;
}
 
function executeOnLoad()
{
	for (var i = 0; i < g_onLoadFncs.length; i++)
	{
		var fnc = g_onLoadFncs[i];
		fnc.funct(fnc.parameter);
	}
}
 
function registerOnLoad(pFunc, pParameter)
{
	var curIndex = g_onLoadFncs.length;
	g_onLoadFncs.length++;
	g_onLoadFncs[curIndex] = new RegisterFunction(pFunc, pParameter);
}

The body tag must then look like this:
<body onload="executeOnLoad();">

And when some function needs to execute after the page has loaded, the registerOnLoad must be called:
function myfunction(pParm) 
{ ... }
[b]registerOnLoad(myfunction, "hello");[/b]
 
function myotherfunction() 
{ ... }
[b]registerOnLoad(myotherfunction);[/b]

Thank you very much.
-- Anton.
I can't grasp the notion of time.

When I hear the earth will melt into the sun,
in two billion years,
all I can think is:
    "Will that be on a Monday?"
==========================
http://www.streetsofboston.com
http://blog.antonspaans.com

Comments

  • {JT}{JT} Registered Users Posts: 1,016 Major grins
    edited September 18, 2005
    We will solve this the same way that we solved adding classes to a custmized body tag: we will look for an onload and either add or append the function to launch the show.

    JT
  • flyingdutchieflyingdutchie Registered Users Posts: 1,286 Major grins
    edited September 18, 2005
    {JT} wrote:
    We will solve this the same way that we solved adding classes to a custmized body tag: we will look for an onload and either add or append the function to launch the show.

    JT
    Kewl! So, i can add my own <body onload="myfunction()"> event: Your slideshow code will detect that and chain myfunction() (so that it will be called as well)?
    Please, notify me when you guys make that change, so that i can remove that hack from my scripting (otherwise the slideshow code will be launched twice).

    Thanks!<img src="https://us.v-cdn.net/6029383/emoji/thumb.gif&quot; border="0" alt="" >
    -- Anton.
    I can't grasp the notion of time.

    When I hear the earth will melt into the sun,
    in two billion years,
    all I can think is:
        "Will that be on a Monday?"
    ==========================
    http://www.streetsofboston.com
    http://blog.antonspaans.com
  • {JT}{JT} Registered Users Posts: 1,016 Major grins
    edited September 19, 2005
    Here is how it will work; you have:
    <body onload="myfunction();">

    On the slideshow page (or any other page we want to use javascript); you will end up with:
    <body onload="slideshow(); myfunction();">

    We have the same thing for classes and the body tag, if we detect you already have a class we automatically add ours.
    Kewl! So, i can add my own <body onload="myfunction()"> event: Your slideshow code will detect that and chain myfunction() (so that it will be called as well)?
    Please, notify me when you guys make that change, so that i can remove that hack from my scripting (otherwise the slideshow code will be launched twice).

    Thanks!<img src="https://us.v-cdn.net/6029383/emoji/thumb.gif&quot; border="0" alt="" >
    -- Anton.
  • flyingdutchieflyingdutchie Registered Users Posts: 1,286 Major grins
    edited September 19, 2005
    {JT} wrote:
    Here is how it will work; you have:
    <body onload="myfunction();">

    On the slideshow page (or any other page we want to use javascript); you will end up with:
    <body onload="slideshow(); myfunction();">

    We have the same thing for classes and the body tag, if we detect you already have a class we automatically add ours.
    Thanks for the update,
    however instead of this:

    <body onload="slideshow(); myfunction();">

    could you change it to this:

    <body onload="myfunction(); slideshow();">

    (myfunction() establishes my page (menu/logo/etc). I'd like to see that happening first, before the slideshow starts).

    Thanks!
    I can't grasp the notion of time.

    When I hear the earth will melt into the sun,
    in two billion years,
    all I can think is:
        "Will that be on a Monday?"
    ==========================
    http://www.streetsofboston.com
    http://blog.antonspaans.com
Sign In or Register to comment.