4images Forum & Community

General / Allgemeines => Programming => Topic started by: x23piracy on October 20, 2010, 04:31:41 AM

Title: Fontsize changing (js) by id (html tag) will not work proper help needed
Post by: x23piracy on October 20, 2010, 04:31:41 AM
Hi,

i have this js (put in root/js/fontsize.js):

Code: [Select]
//<!-- Textgroesse anfang -->
var faktor = 0.05;
var start_groesse = 1.0;
var anz = 0;
function fontsizer(inc, reset) {
if ((anz + inc >= 0) && (anz + inc <= 2)) {
anz += inc;
neue_groesse = anz * faktor + start_groesse;
artikel_text = document.getElementById('container');
artikel_text.style.fontSize = neue_groesse + "em";
}
switch (anz) {
case 0:
document.getElementById("fsminus").src = "templates/Iceberg/images/fontsize_down_inactive.png";
break;
case 2:
document.getElementById("fsplus").src = "templates/Iceberg/images/fontsize_up_inactive.png";
break;
default:
document.getElementById("fsplus").src = "templates/Iceberg/images/fontsize_up.png";
document.getElementById("fsminus").src = "templates/Iceberg/images/fontsize_down.png";
break;
}
}
//<!-- Textgroesse ende -->


in header.html:

Code: [Select]
<script language="javascript" src="./js/fontsize.js"></script>
in any template.html:

Code: [Select]
<a href="javascript:void(0)" onmousedown="fontsizer(-1, false)" onfocus="blur()"><img src="{template_url}/images/fontsize_down.png" id="fsminus" border="0"></a>
<img src="{template_url}/images/fontsize_font.png" id="fsminus" border="0"></a>
<a href="javascript:void(0)" onmousedown="fontsizer(1, false)" onfocus="blur()"><img src="{template_url}/images/fontsize_up.png" id="fsplus" border="0"></a>

I've set the id to change the fontsize to "container" this is my main div for the hole galery...
But only some custom text in the footer changes his fontsize... (not the copyright text)

I thought the main div inherits to sub divs?

If not how to handle this with the js? is there an easy way without set an individual id to any tag
i like to change the fontsize?


Greetz X23
Title: Re: Fontsize changing (js) by id (html tag) will not work proper help needed
Post by: V@no on October 20, 2010, 04:42:29 AM
I thought the main div inherits to sub divs?
It does unless overridden by it's own style.
Try DOM Inspector or FireBug firefox extensions to see what HTML element has what style and via what style class.
Title: Re: Fontsize changing (js) by id (html tag) will not work proper help needed
Post by: x23piracy on October 22, 2010, 10:50:13 PM
I thought the main div inherits to sub divs?
It does unless overridden by it's own style.
Try DOM Inspector or FireBug firefox extensions to see what HTML element has what style and via what style class.

Hi v@no,

is it possible to get all the available style classes names and override there fontsize style
settings with my existing script?

getelementbyclass don't exists?

Sorry im very bad with js...

EDIT:

I found this code on the web that should find all tags that have an id and save them
into var "element", can you help with biulding a working js im to dump for doing that alone.

the code:

Code: [Select]
var element=new Array()

for (var i=0;i<document.getElementsByTagName('*').length;i++)
{
if (document.getElementsByTagName('*')[i].id)

{element[document.getElementsByTagName('*')[i].id]=document.getElementsByTagName('*')[i]}
}


Here is my idea:

Code: [Select]
//<!-- Textgroesse anfang -->
var faktor = 0.05;
var start_groesse = 1.0;
var anz = 0;
var element=new Array()

for (var i=0;i<document.getElementsByTagName('*').length;i++)
{
if (document.getElementsByTagName('*')[i].id)

{element[document.getElementsByTagName('*')[i].id]=document.getElementsByTagName('*')[i]}
}
 
function fontsizer(inc, reset) {
if ((anz + inc >= 0) && (anz + inc <= 2)) {
anz += inc;
neue_groesse = anz * faktor + start_groesse;

HERE THE LOOP SHOULD START

artikel_text = document.getElementById('container');
artikel_text.style.fontSize = neue_groesse + "em";

HERE THE LOOP SHOULD STOP

}
switch (anz) {
case 0:
document.getElementById("fsminus").src = "templates/Iceberg/images/fontsize_down_inactive.png";
break;
case 2:
document.getElementById("fsplus").src = "templates/Iceberg/images/fontsize_up_inactive.png";
break;
default:
document.getElementById("fsplus").src = "templates/Iceberg/images/fontsize_up.png";
document.getElementById("fsminus").src = "templates/Iceberg/images/fontsize_down.png";
break;
}
}
//<!-- Textgroesse ende -->

If that is delphi i should write:

Code: [Select]
var
  I : Integer;
for I := 0 to length(element) do
begin
  artikel_text = document.getElementById(element[I]);
  artikel_text.style.fontSize = neue_groesse + "em";
end;


Greetz X23