javascript function toggle(..) to hide/show text or activities

javascript function toggle(..) to hide/show text or activities

על ידי Ingo Baumann בתאריך
מספר תגובות: 4
Hi,

I tried to implement the javascipt function toggle(..) in my new module. In order to test this function, I tried to hide/show div-tags in mynewmod/view.php but this way it's not working:


echo "<script language='javascript'>
function toggle(targetId) {
target = document.all(targetId);
if (target.style.display == 'none'){
target.style.display='';
} else {
target.style.display='none';
}
}
//-->
</script>";

echo "<a href='javascript:toggle(\"Link1\")'>Link 1 </a>
<div id='Link1' style='display: none'>
<div align='justify'>Here is the text you would like to show for Link 1.</font></div>
</div>";

Would be nice if anybody can tell me how to fix this.

My idea is to implement a new course format where I toggle the visibility of activity modules. Does anybody has a solution with YUI for my problem??

Thx for any advice
Ingo




ממוצע דרוגים: -
בתגובה ל: Ingo Baumann

Re: javascript function toggle(..) to hide/show text or activities

על ידי Tim Hunt בתאריך
תמונה של Core developers תמונה של Documentation writers תמונה של Particularly helpful Moodlers תמונה של Peer reviewers תמונה של Plugin developers
document.all is IE only. javascript: URLs are evil.

Development:JavaScript_guidelines tries to explain the right way to do it.
בתגובה ל: Tim Hunt

Re: javascript function toggle(..) to hide/show text or activities

על ידי James Lloyd בתאריך

Hi Tim - I am trying to do the same thing.

Rather than discussing the moralities of coding, I wonder if there is documentation of the functions available in javascript-static.js?

I am thinking that perhaps there is already a show/hide <div> function available - and perhaps a YUI or jQuery call rather than an inline href?

I just learned about YUI and jQuery about 7 minutes ago.

Then the trick becomes training your content providers to not delete ur <div>s!

thanks moodle community!

בתגובה ל: James Lloyd

Re: javascript function toggle(..) to hide/show text or activities

על ידי James Lloyd בתאריך

Replying to myself - trying to track down how to use the function "elementToggleHide" in javascript-statis.js

I can only find a very few examples and nothing I'd consider documentation.

Been trying to make this example work (from URS and it's returned in several places by googling):

<div class="hide-show"><a href="#" onclick="elementToggleHide(this, true,
function(el) {return findParentNode(el, 'DIV', 'sideblock'); } ); return
false;"><img src="http://moodle.eb-zuerich.ch/pix/spacer.gif" alt="" class="hide-show-image"></a></div>Hauptmenü</div></div>

Oh, and it's using an inline javascript!

From this page:
http://www.nabble.com/Component-Template-td4661021.html