Re: Making xajax bookmarkable - a little advice needed

BigBrownChunx wrote:

yep, we were talking about that in my last post smile

Ahh yes, that would be not reading things correctly smile Sorry bout that smile BTW Thanks for the very responsive post!
AJ

Re: Making xajax bookmarkable - a little advice needed

I'm trying to do this functionality but using a session class that keeps a cookie with the parameters the user has entered and where, please send me your comments about this please...

Re: Making xajax bookmarkable - a little advice needed

leoz, that sounds really good smile
a few other frameworks (such as the Plesk domain management program) use this very same approach in a non-ajax way.  i'd be really keen to see any examples you end up making smile
one of the things that bugged me with Plesk however, was that you couldn't have two copies of the same window open and use the back button in one and have it not affected by the other page since the cookie was set across the whole domain and both pages were using it.

actually, i better ask, is your cookie idea for the back button or for bookmarking the page?

Re: Making xajax bookmarkable - a little advice needed

I just stumbled over Brad Neuberg's "The Really Simple History (RSH) framework".
Beside the big? drawback that it does not work for IE <6 and Safari (yet?) it looks quite good.

It addresses History, Bookmarking and even some kind of caching of session information.
See http://codinginparadise.org/projects/dh … EADME.html for the complete story.

Re: Making xajax bookmarkable - a little advice needed

Yeah, its probably easier to leave it up to someone else to do it eh?

I'll probably put RSH into v0.5 as a plugin, instead of reinventing the wheel.


But until 0.5 comes out, here's an extension for xajaxResponse that you can use.

class xajaxResponseWaypoint extends xajaxResponse {
    function addWaypoint($sWaypointName, $sHistoryData)
    {
        return $this->addScriptCall('dhtmlHistory.add', $sWaypointName, $sHistoryData);
    }
    
    function initRSH($sPathToRSHJavascript, $sWaypointFunctionName)
    {
        $this->addIncludeScript($sPathToRSHJavascript);
        $this->addScript("dhtmlHistory.initialize(); dhtmlHistory.addListener(".$sWaypointFunctionName.");");
        //deal with the current waypoint setting (for bookmarks)
        return $this->addScript($sWaypointFunctionName."(dhtmlHistory.getCurrentLocation(),null);");
    }
}

So start things off by initialiasing the RSH script:

$objResponse->initRSH('js/dhtmlHistory.js', 'xajax_waypoint_handler');

You pass in the location of the javascript file and the function that's going to handle the waypoints.
Then you can add waypoints using

$objResponse->addWaypoint('waypointName', 'someDataToStore');

and you could deal with waypoints using

xajax->registerFunction('waypoint_handler');
function waypoint_handler($waypointName, $waypointData)
{
    $objResponse = new xajaxResponse();
    $objResponse->addAssign('data','innerHTML',$waypointData);
    return $objResponse;
}

31 (edited by ralf 2006-06-20 10:56:54 AM)

Re: Making xajax bookmarkable - a little advice needed

Yeah, its probably easier to leave it up to someone else to do it eh?

Hope you don't blame me to prey the community.

But until 0.5 comes out, here's an extension for xajaxResponse that you can use.

That's great! Did you just write that from scratch or do you have some secret drawer with code like that?;)
I just added it to my app and the first tests with IE6 and FF1.5 were fine!:)

There is one thing I have changed.
It did not work out for me to include the dhtmlHistory.js using addIncludeScript() (err: window.dhtmlHistory has no properties) so I included it right away in my html head.

Re: Making xajax bookmarkable - a little advice needed

ralf wrote:

That's great! Did you just write that from scratch or do you have some secret drawer with code like that?

I wish I had a drawer like that smile  No, I wrote it from scratch.

ralf wrote:

It did not work out for me to include the dhtmlHistory.js using addIncludeScript()

Thats not good sad It'll make it more difficult to make a plugin for it.
I have a good look at the dhtml source to see what about it would stop it from loading properly.

Thanks for the feedback big_smile

Re: Making xajax bookmarkable - a little advice needed

Hi!

It's nice to hear that 0.5 will come with bookmark support... It would be sooo gooood...

But, for me the code above doesn't work...

I've got only an empty array in the waypoint_handler function without any data...

what can be the problem??

Thanks!

Re: Making xajax bookmarkable - a little advice needed

It seems that the "waypoint_handler" function is called everytime twice (at the second time with empty data input), when I click on a bookmark able link.

I missed something?

<?php
require("../../libs/xajax/xajax.inc.php");

//-----------------------------WayPoint handling-------------------------------------//

class xajaxResponseWaypoint extends xajaxResponse {
    
    function addWaypoint($sWaypointName, $sHistoryData)
    {
        return $this->addScriptCall('dhtmlHistory.add', $sWaypointName, $sHistoryData);
    }
    
    function initRSH($sPathToRSHJavascript, $sWaypointFunctionName)
    {
        //$this->addIncludeScript($sPathToRSHJavascript);
        $this->addScript("dhtmlHistory.initialize(); dhtmlHistory.addListener(".$sWaypointFunctionName.");");
        //deal with the current waypoint setting (for bookmarks)
        return $this->addScript($sWaypointFunctionName."(dhtmlHistory.getCurrentLocation(),null);");
    }
    
}

function waypoint_handler($waypointName, $waypointData)
{
    $objResponse = new xajaxResponse();

// Without this statement the content area contains an "array" string...

// the array is empy:
// $waypointData = var_export($waypointData, true);

    if (!empty($waypointData)) {
        $objResponse->addAssign("content", "innerHTML", "<h1>$waypointData</h1>");
    }
    
    return $objResponse;
}

//-----------------------------WayPoint handling-------------------------------------//

function top_menu($menu) {
    switch ($menu) {
        case "menupont1":
            $html = "Menupont1";
            break;
        case "menupont2":
            $html = "Menupont2";
            break;
        case "menupont3":
            $html = "Menupont3";
            break;
        case "menupont4":
            $html = "Menupont4";
            break;
        case "menupont5":
            $html = "Menupont5";
            break;
        case "menupont6":
            $html = "Menupont6";
            break;
    }
    
    $objResponse = new xajaxResponseWaypoint();
    $objResponse->addAssign("content", "innerHTML", "<h1>$html</h1>");
    $objResponse->initRSH('../../libs/xajax/plugins/dhtmlHistory.js', 'xajax_waypoint_handler');
    $objResponse->addWaypoint($menu, $html);
    return $objResponse->getXML();
}

$xajax = new xajax();
$xajax->registerFunction("top_menu");
$xajax->registerFunction("waypoint_handler");
$xajax->processRequests();

?>

<!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">
...
<script type="text/javascript">
    <?php echo file_get_contents("../../libs/xajax/plugins/dhtmlHistory.js"); ?>
</script>
...
<ul id="top_menu">
            <li>
                <a href="" onclick="xajax_top_menu('menupont1'); return false;">menupont1</a>
            </li>
            <li>
                <a href="" onclick="xajax_top_menu('menupont2'); return false;">menupont2</a>
            </li>
            <li>
                <a href="" onclick="xajax_top_menu('menupont3'); return false;">menupont3</a>
            </li>
            <li>
                <a href="" onclick="xajax_top_menu('menupont4'); return false;">menupont4</a>
            </li>
            <li>
                <a href="" onclick="xajax_top_menu('menupont5'); return false;">menupont5</a>
            </li>
            <li>
                <a href="" onclick="xajax_top_menu('menupont6'); return false;">menupont6</a>
            </li>
        </ul>
        <div id="content">
            <!-- AJAX Content goes here -->
        </div>
...

Thanks!

Re: Making xajax bookmarkable - a little advice needed

The $objResponse->initRSH() function should only be called once, not every time in the function.  It was a cludgy way of putting it in there, but it needed to be somewhere and that was the easiest.  Things like this will be a little easier with v0.5 for doing init functions.

Re: Making xajax bookmarkable - a little advice needed

Hi!

First of all... Thank you, for your reply. It helped.

With a lot of work I've made my ajax example project fully "history-able". It's working fine with Firefox, but not working with IE at all...

So I've tested it with the modified simple example above, and with IE it's still not working.

Please help me out... I can't imagine what's the problem..

Thanks a lot:
Andras Nemeseri

Re: Making xajax bookmarkable - a little advice needed

Please, please, please

I'm still searching for the answer...

Re: Making xajax bookmarkable - a little advice needed

IE is a really tricky one to get working, since it doesn't tell you if window.location.hash changes.  Aparently some kind of 'security feature'.  Can you post your code here so that we can help a little better?

Re: Making xajax bookmarkable - a little advice needed

:-)

This is the example page which isn't working with IE. It's fine with FF and Opera...

<?php
require("../../libs/xajax/xajax.inc.php");

//-----------------------------WayPoint handling-------------------------------------//

class xajaxResponseWaypoint extends xajaxResponse {
    
    function addWaypoint($sWaypointName, $sHistoryData)
    {
        return $this->addScriptCall('dhtmlHistory.add', $sWaypointName, $sHistoryData);
    }
    
    function initRSH($sPathToRSHJavascript, $sWaypointFunctionName)
    {
        $this->addScript("dhtmlHistory.initialize(); dhtmlHistory.addListener(".$sWaypointFunctionName.");");
        return $this->addScript($sWaypointFunctionName."(dhtmlHistory.getCurrentLocation(),null);");
    }
    
}

function waypoint_handler($waypointName, $waypointData)
{
    $objResponse = new xajaxResponse();
    
    $objResponse->addAssign("content", "innerHTML", "<h1>$waypointData</h1>");
    
    return $objResponse;
}

function waypoint_init() {
     $objResponse = new xajaxResponseWaypoint();
     $objResponse->initRSH('../../libs/xajax/plugins/dhtmlHistory.js', 'xajax_waypoint_handler');
     return $objResponse;
}

//-----------------------------WayPoint handling-------------------------------------//

function top_menu($menu) {
    switch ($menu) {
        case "menu1":
            $html = "Menu1";
            break;
        case "menu2":
            $html = "Menu2";
            break;
        case "menu3":
            $html = "Menu3";
            break;
        case "menu4":
            $html = "Menu4";
            break;
        case "menu5":
            $html = "Menu5";
            break;
        case "menu6":
            $html = "Menu6";
            break;
        default:
            $html = "Menu1";
    }
    
    $objResponse = new xajaxResponseWaypoint();
    $objResponse->addAssign("content", "innerHTML", "<h1>$html</h1>");
    $objResponse->addWaypoint($menu, $html);
    return $objResponse->getXML();
}

$xajax = new xajax();
$xajax->registerFunction("top_menu");
$xajax->registerFunction("waypoint_handler");
$xajax->registerFunction("waypoint_init");
$xajax->processRequests();

?>
<!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>Waypoint Example</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <link rel="stylesheet" href="index.css" type="text/css" media="screen" />
        <?php $xajax->printJavascript("../../libs/xajax/"); ?>
        <script type="text/javascript">
        <?php echo file_get_contents("../../libs/xajax/plugins/dhtmlHistory.js"); ?>
        </script>
        
        <script type="text/javascript">
            function bookm () {
                xajax_waypoint_init();
            }
        </script>
        
    </head>
    <body onload="bookm()">
        <ul id="top_menu">
            <li>
                <a href="" onclick="xajax_top_menu('menu1'); return false;">menu1</a>
            </li>
            <li>
                <a href="" onclick="xajax_top_menu('menu2'); return false;">menu2</a>
            </li>
            <li>
                <a href="" onclick="xajax_top_menu('menu3'); return false;">menu3</a>
            </li>
            <li>
                <a href="" onclick="xajax_top_menu('menu4'); return false;">menu4</a>
            </li>
            <li>
                <a href="" onclick="xajax_top_menu('menu5'); return false;">menu5</a>
            </li>
            <li>
                <a href="" onclick="xajax_top_menu('menu6'); return false;">menu6</a>
            </li>
        </ul>
        <div id="content">
            <!-- AJAX Content goes here -->
        </div>
    </body>
</html>

Thank you soo much!

Re: Making xajax bookmarkable - a little advice needed

Don't you forget to put the "blank.html" in your root directory ?

This file is used to put an invisible iframe wich permit to use RSH in IE.

It work well for me, look at http://beta.burncrewconcept.net/ to see it work.

Re: Making xajax bookmarkable - a little advice needed

I can confirm Anthor's solution. After simply adding "blank.html" to nemesa's example it works also in IE.

Re: Making xajax bookmarkable - a little advice needed

Thank you so much!
It's working with the example, now I have to find out what's wrong with my real page.

Thanks a lot!

Re: Making xajax bookmarkable - a little advice needed

Wow, If you use RSH, your links don't have to be in the :

<a href="#" onclick="yourfunction...">...</a>

They could be in this form :

<a href="#links-1-2">Links</a>

When you click on them the listening function of RSH launch your xajax function, this help google a lot to index your website...

Re: Making xajax bookmarkable - a little advice needed

Anthor wrote:

this help google a lot to index your website.

I'm not sure if googlebot has any capability of 'following links' with #, since googlebot isn't running javascript (correct me if i'm wrong here)

45 (edited by Anthor 2006-09-07 7:37:19 PM)

Re: Making xajax bookmarkable - a little advice needed

not following them but index them more easilly than a link who don't have any href. I think ?

Sorry for my english ^^

Re: Making xajax bookmarkable - a little advice needed

Did anyone made an plugin out of it already for xajax 0.5?

47 (edited by statiic 2006-10-12 10:18:29 AM)

Re: Making xajax bookmarkable - a little advice needed

I got some strange error in FF.

www.heldermarketing.nl

have an look. It loads the page and the reloads somehow and only displays array.

BTW in IE it doesnt work at all. It doesnt reload the previous pages when I hit back.

48 (edited by wojewsky 2006-11-08 9:27:19 AM)

Re: Making xajax bookmarkable - a little advice needed

Hi,

whats about the plugin for xajax 0.5?
Anyone did the job?

i need it...

Thanks alot

Sascha

49 (edited by mickey9801 2006-11-08 1:19:50 PM)

Re: Making xajax bookmarkable - a little advice needed

I have tried to implement RSH into my project which is using Xajax 0.2.4. It works well in FF but some problem in IE. Although IE can set and retrieve waypoints within the site, once the user left the site and try to come back to my site using Back button, all previous waypoints will get lost in IE. FF won't have such problem. Especially when using IE7, when user try to come back, the content within the site will disappear for a while once the mouse move (about 30 sec.).

Because I have loaded several JS libraries such as script.aculo.us together in the page. I am wondering there are any conflict between them and tried to take away them but the problem still there. Hope anyone can give me some idea to solve this problem. Thank you.

My project : http://dev.i-gamer.com.hk

Fedora Cord 3 / Apache 2.0.53 / PHP 4.3.11 / MySQL 4.1.13

50 (edited by ralf 2006-11-11 1:47:32 PM)

Re: Making xajax bookmarkable - a little advice needed

I prepared a rsh plugin "tested" with the 0.5 code from the trunk.

It is useable, but there are still some issues:
1 - There is a timeout used when dynamically loading the javascript sources. This should be avoided.
     One could load the js static, but I like the dynamic way with the plugin-idea much more.
2 - At least with IE7 (not tested with IE6 yet) it breaks when hitting F5 with a hash value in the url.
3 - Maybe more...

You can check it and load some demo code from here: http://www.goldenzazu.de/code/