1
0
mirror of https://github.com/php/web-php.git synced 2026-03-31 19:52:29 +02:00
Files
archived-web-php/userprefs.js
Gabor Hojtsy 8fe303bc05 Use divs to present the TOC items on manual
pages on the left side of the window

Add images according to php.net rules to these
two styles (toca, toci) depending on what mirror
they are used on

Also rewrite the TOC generator code a bit, so it
identifies items properly when their title and titleabbrev
differ [was a bug on many pages]

Also wrap too long function names, so we have the
same amount of content and nav area on pages with
long function names in the TOC [eg. xml functions]

The new div based approach means that we have *much*
less HTML to output, and the layout of the menu is better
than before, as the box images are aligned to the text.
Tested with Mozilla and Konqueror. Apart from pages with
long function names in the TOC, this should look very similar
to the display of the TOC before
2003-06-14 18:28:56 +00:00

101 lines
3.4 KiB
JavaScript

// Get a value of one cookie set by it's name
// Impmentation from the JS 1.3 Client Guide by Netscape
function getCookie(Name)
{
var search = Name + "=";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search);
if (offset != -1) {
offset += search.length;
end = document.cookie.indexOf(";", offset);
if (end == -1) { end = document.cookie.length; }
return unescape(document.cookie.substring(offset, end));
}
}
return null;
}
// Make events in the user's country bold
function boldEvents()
{
// Get cookie if possible
country = getCookie("COUNTRY");
if (typeof(country) == "string") {
// Get country code from cookie
country = country.substring(0, 3);
// If DOM is supported, get <span>s
if (document.getElementsByTagName) {
spans = document.getElementsByTagName("span");
// Style every span bold which is for this country
for (var i = 0; i < spans.length; i++) {
if (spans[i].className == "event_" + country) {
spans[i].style.fontWeight = "bold";
}
}
}
}
}
// Restore the last search as stored in a cookie
function searchHistory()
{
// Something is already typed in, do not try to overwrite it
if (document.forms["topsearch"].pattern.value.length > 0) {
return;
}
// Try to get the lastsearch cookie
lastSearch = getCookie("LAST_SEARCH");
if (typeof(lastSearch) == "string") {
// Get pattern and show information from cookie
option = lastSearch.substr(0, lastSearch.indexOf(","));
pattern = lastSearch.substr(lastSearch.indexOf(",") + 1);
// Set pattern in form
document.forms["topsearch"].pattern.value = pattern;
// Set the last selected search method in the dropdown
with (document.forms["topsearch"]) {
for (var i = 0; i < show.length; i++) {
if (show[i].value == option) {
show[i].selected = true;
break;
}
}
}
}
}
// Make images appear by the side of TOC items on the manual pages
// This is not a user based function, but a mirror based one. Only
// php.net has images on a different server. But for performance
// reasons, the code is implemented to run on the client side.
function tocImages()
{
// If DOM is supported, get the <div>s
if (document.getElementsByTagName) {
divs = document.getElementsByTagName("div");
// Check if we are on the master site or not
staticContent = (location.hostname == "www.php.net" ||
location.hostname == "php.net") ?
"http://static.php.net/www.php.net/" : "/";
// Change the style of every div tag which is in
// the "toci" or "toca" class, modifying the class
// according to the hostname
for (var i = 0; i < divs.length; i++) {
if (divs[i].className == "toci") {
divs[i].style.backgroundImage = "url(" + staticContent + "images/box-0.gif)";
} else if(divs[i].className == "toca") {
divs[i].style.backgroundImage = "url(" + staticContent + "images/box-1.gif)";
}
}
}
}