Sorry for my unclear explanation, the following is all my JavaScript
code,

// script01.js //

obj = new Object();
obj.f1 = eventHandler;
window.onload = obj.f1;
window.onunload = function(){};

function eventHandler(){
        postUpdater();
        dynamicEdit();
        deleteAlert();
        var loc = document.getElementById("newLocation");
        loc.selectedIndex = 0;
    loc.onchange = jumpPage;
}

function postUpdater() {
        var myAjax = new Ajax.PeriodicalUpdater(
                "recentPost",
                "recentPost.php",
                {
                        method: 'get',
                        frequency: 50
                });
}

function dynamicEdit() {
        for(var j=0;;j++){
                if($('theTitle'+j) && $('postid'+j)){
                   new Ajax.InPlaceEditor(
                          'theTitle'+j,
                          
'answer.php?ident=Title&postid='+$('postid'+j).value+'&content='+$
('content'+j).value+'&author='+$('userId').value,
                          {
                                 formId: 'whatever',
                                 okText: 'Edit !',
                                 cancelText: 'Cancel'
                          }
                   );
           }

           if($('theCont'+j) && $('postid'+j)){
                   new Ajax.InPlaceEditor(
                          'theCont'+j,
                          'answer.php?ident=Content&postid='+ 
$('postid'+j).value+'&title='+
$('title'+j).value+'&author='+$('userId').value,
                          {
                                 formId: 'whatever',
                                 okText: 'Edit!',
                                 cancelText: 'Cancel',
                                 rows:10,
                                 cols: 45
                          }
                   );
           }
           if(!$('theTitle'+j) && !$('theCont'+j)){ break;}
        }
}

function deleteAlert(){
        var formid = document.getElementsByName("deleteid");
        for(var k=0;k<formid.length;k++){
                formid[k].onclick=function(){
                        return confirm("Are you sure to delete this post?");
                }
        }
}

function jumpPage(){
        var newLoc = document.getElementById("newLocation");
        var newPage = newLoc.options[newLoc.selectedIndex].value;
                if(newPage != ""){window.location = newPage;}
}


------------------------------------------End of
script01.js----------------------------------------------

//prev.js code//

 var ci;
 var xPos,yPos;

Event.observe(window,'load',function(){
        var elms = document.getElementsByClassName("toplink");
        Event.observe(elms[0],'mouseover',function(ev){gotopreview(ev,
0);});
        Event.observe(elms[1],'mouseover',function(ev){gotopreview(ev,1);});
        Event.observe(elms[2],'mouseover',function(ev){gotopreview(ev,2);});
        Event.observe(elms[3],'mouseover',function(ev){gotopreview(ev,3);});
});

 function gotopreview(event,ci){
    alert(ci);
        xPos = Event.pointerX(event);
        yPos = Event.pointerY(event);
        var getpostid=document.getElementsByName("targetpid");
        var getsid = document.getElementsByName("stdid");
        var url = "getOnePost.php";
        var pars = "stdid="+getsid[ci].value + "&targetpid=" + getpostid
[ci].value;

        var myajax = new Ajax.Request(url,{
                method:'get',
            parameters: pars,
                asynchronous: true,
                onSuccess: function(transport){
                        $('previewWin').update(transport.responseText);
                        $('previewWin').style.top = parseInt(yPos) + 2 + "px";
                        $('previewWin').style.left = parseInt(xPos) + 2 + "px";
                        $('previewWin').style.visibility = "visible";
                        $('previewWin').onmouseout =function(){ $
('previewWin').style.visibility = "hidden";}

                }
        });
}

-------------------------End of
prev.js--------------------------------------

// Yahoo UI paginator yuifunction.js //

// YUI Paginator
YAHOO.util.Event.onDOMReady(function () {
        // Set up the application under the YAHOO.example namespace
        var Ex = YAHOO.namespace('example');
        Ex.content    = YAHOO.util.Dom.get('yuicontent');
        Ex.handlePagination = function (state) {
            // Show the appropriate content for the requested page
            Ex.content.className = 'page' + state.page;
            // Update the Paginator's state, confirming change
            Ex.paginator.setState(state);
        };
        // Create the Paginator widget and subscribe to its changeRequest
event
        Ex.paginator = new YAHOO.widget.Paginator({
            rowsPerPage : 3,
            totalRecords : Ex.content.getElementsByTagName('div').length,
            containers : 'paging'
        });
        Ex.paginator.subscribe('changeRequest', Ex.handlePagination);
        // Render the Paginator into the configured container(s)
        Ex.paginator.render();
});

-------------------End of
yuifunction.js---------------------------------

// my php code is: //

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
<html xmlns="http://www.w3.org/1999/xhtml";>

<head>
  <title>XXX</title>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" /
>
        <!--*** YAHOO YUI Library ***-->
         <link rel="stylesheet" type="text/css" href="http://
yui.yahooapis.com/2.7.0/build/fonts/fonts-min.css" />
        <link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/
2.7.0/build/paginator/assets/skins/sam/paginator.css" />
        <script type="text/javascript" src="http://yui.yahooapis.com/2.7.0/
build/yahoo-dom-event/yahoo-dom-event.js"></script>
        <script type="text/javascript" src="http://yui.yahooapis.com/2.7.0/
build/element/element-min.js"></script>
        <script type="text/javascript" src="http://yui.yahooapis.com/2.7.0/
build/paginator/paginator-min.js"></script>
        <!-- **** stylesheet **** -->
        <link rel="stylesheet" type="text/css" href="style.css" />
        <!-- *** javascript ***-->
        <script type="text/javascript" src="js/yuifunction.js"></script>
        <script type="text/javascript"src="javascript/prototype.js"></script>
        <script type="text/javascript"src="javascript/scriptaculous.js?
load=effects,controls"></script>
        <script type="text/javascript" src="js/script01.js"></script>
        <script type="text/javascript" src="js/prev.js"></script>

</head>

<body>
  <div id="main">
    <div id="logo"></div>
    <div id="menubar">
      <ul id="menu">
        <li><a class="current" href="index.php" title="Welcome">Home</
a></li>
        <li><a href="crblog.php" title="Create post">Create post</a></
li>
      </ul>
    </div>

        <div id="site_content">
      <div class="sidebar">
                <?php include ("sidebar.php");?>
      </div>
          <div id="previewWin"></div>

      <div id="content_container" class="yui-skin-sam">
        <!-- rounded corners - top **** -->
        <div class="rtop"><div class="r1"></div><div class="r2"></
div><div class="r3"></div><div class="r4"></div></div>

        <div id="bcontent">
                <?php
                        $currentUser=file_get_contents("http://
studentid:passw...@www.myschool.edu/CS/getUser.py");
                        echo '<label for="id"><input type="hidden" id="userId" 
value="'.
$currentUser.'"'.' /></label>';
                        echo '<b><h1>Welceome!  '.$currentUser.'</h1></b>';
                        
$var=file_get_contents("http://studentid:passw...@www.myschool.edu/
getPost.py?author=".$currentUser."&type=html");
                        $var=explode("</li>", $var);

                        $varLen = count($var);

                        $yuij=1;

                        $counter = 1;
                        echo '<div id="paging"></div>'."\n\t";
                        #<!--Yahoo YUI div class page1 and yuicontent-->
                        echo '<div id="yuicontent" class="page1">'."\n\t";

                        #length - 2; because <ul> is counted;
                        for($i = $varLen-2; $i>=0;$i--){
                                echo "<div class=\"page$yuij\">"."\n\t";
                                echo '<fieldset>'."\n\t";

                                #finding title:
                                if(preg_match("/Title:/",$var[$i])){
                                        $tlen =strpos($var[$i],'Title:')+11;
                                        $clen = strpos($var[$i],'Content:')-10;
                                        $tname = 
substr($var[$i],$tlen,($clen-$tlen));

                                        echo '<legend 
id="theTitle'.$i.'">'.$tname.'</legend>'."\n\t";
                                        echo '<label for="id"><input 
type="hidden" id="title'.$i.'"
value="'.$tname.'"'.' /></label>'."\n\t";
                                        echo '<p></p>';
                            }

                                #finding Content:
                                if(preg_match("/Content:/",$var[$i])){
                                        $ctlen = strpos($var[$i],'Content:')+13;
                                        $ctlast = strripos($var[$i],'<br />');
                                        $cont = 
substr($var[$i],$ctlen,($ctlast-$ctlen));

                                        $cont = html_entity_decode($cont);
                                        echo '<p name="Content" 
id="theCont'.$i.'">'.$cont.'</p>';
                                        echo '<label for="id"><input 
type="hidden" id="content'.$i.'"
value="'.$cont.'"'.' /></label>'."\n\t";
                            }

                                #finding Updated:
                                if(preg_match("/Updated:/",$var[$i])){
                                        $uppos =strpos($var[$i],'Updated:')+13;
                                        $uplen = strpos($var[$i],'Title:')-4;

                                        #date
                                        $up = 
substr($var[$i],$uppos,($uplen-$uppos));
                                        $upfinal = 
substr($up,0,(strpos($up,'T')));

                                        #time
                                        $upT = strpos($up,'T');
                                        $upDot = strripos($up,'.');
                                        $uptime = 
substr($up,$upT+1,($upDot-1)-$upT);

                                        echo 'updated on'.$upfinal.' '.$uptime;
                                        echo '<p></p>';
                            }

                                if(preg_match("/Id:/",$var[$i])){
                                        $idpos = strpos($var[$i],'Id:')+9;
                                        $idlast = strpos($var[$i],'Updated')-10;
                                        $idis = 
substr($var[$i],$idpos,($idlast-$idpos));
                            }

                                echo '<label for="id"><input type="hidden" 
id="postid'.$i.'"
value="'.$idis.'"'.' /></label>'."\n\t";
                                echo '<a 
href="http://www.myschool.edu/deletePost.py?id='.$idis.'"
name="deleteid">Delete</a>'."\n\t";

                                echo '</fieldset>'."\n\t";
                                echo '<hr width="100%" size="1" />'."\n\t";
                                echo '<p></p>'."\n\t";
                                #yahoo yui div end
                                echo '</div>'."\n\t";
                                if($counter%3 == 0){
                                        $yuij++;

                                }
                                $counter++;
                        }
                        echo '</div>'."\n\t";
                ?>
   </div>
                <p>&nbsp;</p>

        <!-- rounded corners - bottom **** -->
        <div class="rbottom"></div>
      </div>
    </div>

  <div id="footer"> My teammate and i...@my school Computer Science
Department</div>
  </div>

</body>
</html>

---------------------------End of my index.php
code.----------------------------------------------

Purpose:  What I want to do is making prev.js compatible with
script01.js, and make it work.
My problem now is that when I include script01.js or prev.js
separately, it works well.  But if I include both of them, prev.js
will not work.

My code maybe tedious,ugly and not user-friendly, sorry about that.  I
am new to Ajax and could some one give me reference How to write a
clear program?
And How to solve the above problem.  Thanks.


On Mar 9, 5:39 pm, ColinFine <colin.f...@pace.com> wrote:
> On Mar 6, 5:30 pm, SamuelXiao <foolsmart2...@gmail.com> wrote:> Hi, David, it 
> seems that periodicalupdater send request first,
> > breaking down the preview code
> > setting new Ajax.Request.  And the object is no longer refering to the
> > gotopreview function.
> > Because the firebug console returns the link that the
> > periodicalupdater request sever to update something,
> > just after that I move over any of the four elements (toplink), it
> > doesn't work.
>
> I'm sorry, I don't understand what you say is happening. There should
> be no relationship between the PeriodicalUpdater and the other
> Request. What do you mean when you say it 'breaks down' the preview
> code - what actually happens?
> You say 'the object is no longer referring to the gotopreview
> function', but I don't know which object you mean.
>
> Colin
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to