[3.0.11] prosilver on[un]load_functions arrays

For support and discussion related to templates, themes, and imagesets in phpBB 3.0.
Scam Warning
Locked
User avatar
8680
Registered User
Posts: 1
Joined: Sun Dec 23, 2012 2:15 am

[3.0.11] prosilver on[un]load_functions arrays

Post by 8680 »

In overall_header.html/simple_header.html, two arrays, onload_functions and onunload_functions, are created in the inline <script>.

Code: Select all

var onload_functions = new Array();
var onunload_functions = new Array();
Then, in login_body.html, mcp_topic.html, posting_editor.html, quickreply_editor.html, search_body.html, styleswitcher.js, and ucp_register.html, strings of JavaScript are pushed to these arrays.

Code: Select all

// styleswitcher.js
onload_functions.push('load_cookie()');
onunload_functions.push('unload_cookie()');

// search_body.html
onload_functions.push('document.getElementById("keywords").focus();');
Then, on load and unload, the arrays are iterated through and eval is called on each string.

Code: Select all

// overall_header.html
window.onload = function()
{
	for (var i = 0; i < onload_functions.length; i++)
	{
		eval(onload_functions[i]);
	}
};
Why push and eval strings? Why not push and call functions?

Code: Select all

// styleswitcher.js
onload_functions.push(load_cookie);
onunload_functions.push(unload_cookie);

// search_body.html
onload_functions.push(function() {
	document.getElementById("keywords").focus();
});

// overall_header.html
window.onload = function()
{
	for (var i = 0; i !== onload_functions.length; ++i)
	{
		onload_functions[i]();
	}
};
Locked

Return to “[3.0.x] Styles Support & Discussion”