Visualizzazione dei risultati da 1 a 6 su 6
  1. #1
    Utente di HTML.it
    Registrato dal
    May 2003
    Messaggi
    186

    reinizializzare funzione js

    Salve a tutti:

    ho questa funzione js che mi calcola la dimensione delle custom scrollbars di un div scrollabile:

    <script type="text/javascript">

    //We wrap all the code in an object so that it doesn't interfere with any other code
    var scroller = {
    init: function() {

    //collect the variables
    scroller.docH = document.getElementById("content").offsetHeight;
    scroller.contH = document.getElementById("container").offsetHeight;
    scroller.scrollAreaH = document.getElementById("scrollArea").offsetHeight ;

    //calculate height of scroller and resize the scroller div
    //(however, we make sure that it isn't to small for long pages)
    scroller.scrollH = (scroller.contH * scroller.scrollAreaH) / scroller.docH;
    //if(scroller.scrollH < 15) scroller.scrollH = 15;
    document.getElementById("scroller").style.height = Math.round(scroller.scrollH) + "px";

    //what is the effective scroll distance once the scoller's height has been taken into account
    scroller.scrollDist = Math.round(scroller.scrollAreaH-scroller.scrollH);

    //make the scroller div draggable
    Drag.init(document.getElementById("scroller"),null ,0,0,-1,scroller.scrollDist);

    //add ondrag function
    document.getElementById("scroller").onDrag = function (x,y) {
    var scrollY = parseInt(document.getElementById("scroller").style .top);
    var docY = 0 - (scrollY * (scroller.docH - scroller.contH) / scroller.scrollDist);
    document.getElementById("content").style.top = docY + "px";
    }
    }
    }

    onload = scroller.init;
    </script>

    Problema: quando all'interno non ho un semplice testo ma delle faq mostra/nascondi (codice in php) non mi viene ricalcolata la nuova area; per cui vorrei aggiungere nello stesso codice in php una stringa che mi re-inizializzi la funzione in js.

    -----------------------------------------------------------------------------

    Questo è il codice php della faq mostra/nascondi:

    <?php
    /**
    * moshide 1.5
    * - moshide v0.14 has been updated to work with Joomla! 1.5.x by Fraser Doerksen, http://fraserjohn.ca
    *
    * (C) Martin Larsen 2005-2007
    * Usage:
    * Put {moshide [hidden] <title when hidden>|<title when shown>}{/moshide} around blocks of text you want to be foldable
    * If you supply the "hidden" parameter, the block will be hidden from the start.
    *
    * Examples:
    * {moshide show block|hide block}
    * This block can be shown and hidden by choice
    * {/moshide}
    *
    * {moshide hidden show block|hide block}
    * This block is hidden from the start
    * {/moshide}
    *
    * Moshide blocks can be nested using a special syntax:
    * {moshide.name [hidden] <title when hidden>|<title when shown>}{/moshide.name}
    * For example:
    * {moshide.block1 Show block 1|Hide block 1}
    * some text here for block 1
    * {moshide.block2 Show block 2|Hide block 2}
    * some text here for block 2
    * {/moshide.block2}
    * more text for block 1
    * {/moshide.block1}
    *
    * If you only supply one caption, Moshide will use the caption for both views:
    * {moshide Here is an example:}Example here {/moshide}
    *
    * If one of the captions is a space character, there will be no caption for the view lacking the caption:
    * {moshide hidden Show block| }
    * When you show this block you cannot make it go away again, since this is no "Hide block" caption!
    * {/moshide}
    *
    * Finally, if you don't provide a caption at all, the block will never be visible - even if you don't provide the "hidden" option.
    * But as Moshide does not hide printed content, it will still appear on print. This is useful in case you have some text you only
    * want to include when printed, like a page header or footer etc.
    * {moshide}This will only appear on print{/moshide}
    *
    * For live examples and full syntax of Moshide as well as some cool (and advanced!) uses not covered here,
    * see www.kreacom.dk/mambot/
    **/

    defined( '_JEXEC' ) or die( 'Direct Access to this location is not allowed.' );
    $mainframe->registerEvent( 'onPrepareContent', 'moshide' );

    function moshide( &$row, &$params, $page ) {
    global $appendix, $printmode;
    $printmode = $_GET["pop"] || $_GET["do_pdf"] || ($_GET["moshide"]=="0");
    $appendix = "";
    $regex = "#{moshide((?:\.\S*)?) (hidden)?([^}]*)?}(.*?){/moshide\\1}#is";
    global $moshide_matchfound;
    do { // Get all nested moshide
    $moshide_matchfound=false;
    $row->text = preg_replace_callback($regex, "moshide_callback", $row->text);
    } while ($moshide_matchfound) ;
    $regex = "#{moshidetag (\d+ )?(hidden )?([^\s}]+)(.*?)}#i";
    $row->text = preg_replace_callback($regex, "moshidetag_callback", $row->text);
    $row->text .= $appendix;
    return true;
    }

    function escape_text($s) {
    return str_replace(array("'", "&#39;", "\r", "\n"), array("\\'", "\\'", "\\r", "\\n"), $s);
    };

    function moshide_callback(&$matches){
    global $moshide_count, $moshide_matchfound, $printmode;

    $moshide_matchfound=true;
    $moshide_count += 1;
    $caption = explode("|",$matches[3]);
    if($caption[1]=="") $caption[1]=$caption[0];
    $state = $matches[2] ? 0 : 1;
    if(!$matches[3]) $state=0; // Hide if no captions given
    if($printmode) $state=1;
    $show = $state ? 'block' : 'none';
    $tempstr = "<a class='moshide' style='cursor: pointer' ";
    $tempstr .= "onclick=\"o=document.getElementById('moshide$mosh ide_count').style;this.innerHTML= o.display!='none' ? '" .escape_text($caption[0]). "' : '"

    .escape_text($caption[1]). "';";

    $tempstr .= "o.display = o.display!='none' ? 'none' : 'block';\">";
    $tempstr .= ($state ? $caption[1] : $caption[0]) . "</a>";
    $tempstr .= "<div style='display: $show' class='moshide' ";
    $tempstr .= " id='moshide$moshide_count'>$matches[4]</div>";





    return $tempstr;
    };

    function moshidetag_callback(&$matches){
    global $appendix, $printmode;
    $limit=trim($matches[1]);
    if($limit<=0)$limit=99999;
    $tag=$matches[3];
    $tag=explode(".", $tag);
    $classname=$tag[1];
    $tag=$tag[0];
    $caption = explode("|",$matches[4]);
    if($caption[1]=="") $caption[1]=$caption[0];
    $state = $matches[2] ? 0 : 1;
    if($printmode) return "<a class='moshidetag'>".($state ? $caption[1] : $caption[0])."</a>"; // Don't process moshidetags in printmode
    if($tag[0]=="#"){
    $tag=substr($tag,1);
    $appendix .= $state ? "" : "<script>shID(0,'$tag')</script>";
    $tempstr = "<script>";
    $tempstr .= "function shID(a,ID,cap1,cap2){";
    $tempstr .= " e = document.getElementById(ID);";
    $tempstr .= " e.style.display = e.style.display=='none' ? '' : 'none';";
    $tempstr .= " a.innerHTML = e.style.display=='' ? cap1 : cap2;";
    $tempstr .= "}";
    $tempstr .= "</script>";
    if($caption[0]!=""){
    $tempstr .= "<a class='moshidetag'";
    $tempstr .= " style='cursor: pointer'";
    $tempstr .= " onclick=\"shID(this,'$tag', '$caption[1]', '$caption[0]')\">";
    $tempstr .= $state ? $caption[1] : $caption[0];
    $tempstr .= "</a>";
    }
    }
    else {
    $appendix .= $state ? "" : "<script>sh(0,'$tag','$classname', '', '', $limit)</script>";
    $tempstr = "<script>";
    $tempstr .= "function sh(a,tag,classname,cap1,cap2,limit){";
    $tempstr .= " e = document.getElementsByTagName(tag);";
    $tempstr .= " for(var i=0; i<e.length; i++)";
    $tempstr .= " if(e[i].className==classname) {";
    $tempstr .= " e[i].style.display = e[i].style.display=='none' ? '' : 'none';";
    $tempstr .= " a.innerHTML = e[i].style.display=='' ? cap1 : cap2;";
    $tempstr .= " if(--limit==0) break;";
    $tempstr .= " }";
    $tempstr .= "}";
    $tempstr .= "</script>";
    if($caption[0]!=""){
    $tempstr .= "<a class='moshidetag'";
    $tempstr .= " style='cursor: pointer'";
    $tempstr .= " onclick=\"sh(this,'$tag','$classname', '$caption[1]', '$caption[0]', $limit)\">";
    $tempstr .= $state ? $caption[1] : $caption[0];
    $tempstr .= "</a>";
    }
    }
    return $tempstr;
    }
    ?>


    ------------------------------------------
    Avete qualche idea? Grazie.

  2. #2
    Utente di HTML.it
    Registrato dal
    May 2003
    Messaggi
    186
    :master:

  3. #3
    Utente di HTML.it
    Registrato dal
    May 2003
    Messaggi
    186
    Allora, come posso fare in modo che da php il browser ricalcoli l'altezza del content una volta aperta la faq?

  4. #4
    Utente di HTML.it L'avatar di strae
    Registrato dal
    Apr 2008
    Messaggi
    407
    Originariamente inviato da wimkieft
    Allora, come posso fare in modo che da php il browser ricalcoli l'altezza del content una volta aperta la faq?
    Da php non puoi, è lato server, il suo lavoro finisce nel momento che visualizzi la pagina.

    Prova nella sezione javascript..

    qualcosa del genere potrebbe funzionare:

    Codice PHP:
    var height document.getElementById('id_del_div_con_le_faq').offsetHeight;
    scroller.init
    però ci sarebbe da analizzare il codice js a modo
    You HAVE to assume your visitor is a maniac serial killer, out to destroy your application. And you have to prevent it.
    I can accept failure, everyone fails at something - But I can't accept not trying.

  5. #5
    Utente di HTML.it
    Registrato dal
    May 2003
    Messaggi
    186
    Quindi non posso neanche sfruttare l'event onClick?

    ...
    $tempstr = "<a class='moshide' style='cursor: pointer' ";
    $tempstr .= "onclick=\"o=document.getElementById('moshide$moshide_coun t').style;this.innerHTML= o.display!='none' ? '" .escape_text($caption[0]). "' : '"

    .escape_text($caption[1]). "';";

    $tempstr .= "o.display = o.display!='none' ? 'none' : 'block'; ...magari da aggiungere qui in coda...? \">";
    $tempstr .= ($state ? $caption[1] : $caption[0]) . "</a>";

  6. #6
    Utente di HTML.it L'avatar di strae
    Registrato dal
    Apr 2008
    Messaggi
    407
    Originariamente inviato da wimkieft
    Quindi non posso neanche sfruttare l'event onClick?

    ...
    $tempstr = "<a class='moshide' style='cursor: pointer' ";
    $tempstr .= "onclick=\"o=document.getElementById('moshide$moshide_coun t').style;this.innerHTML= o.display!='none' ? '" .escape_text($caption[0]). "' : '"

    .escape_text($caption[1]). "';";

    $tempstr .= "o.display = o.display!='none' ? 'none' : 'block'; ...magari da aggiungere qui in coda...? \">";
    $tempstr .= ($state ? $caption[1] : $caption[0]) . "</a>";
    Onclick è javascript ma viene eseguito dopo la stampa del codice html da parte di php...
    Leggiti bene cosa è javascript e cosa è php, ti stai affogando in un bicchiere d'acqua
    You HAVE to assume your visitor is a maniac serial killer, out to destroy your application. And you have to prevent it.
    I can accept failure, everyone fails at something - But I can't accept not trying.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.