Jump to content

Dojo tabs breaking on Prototype Ajax.Updater execution


MDWeezer

Recommended Posts

I'm trying to utilize the excellent tabbing capabilities of Dojo at the moment.  I have a standalone page which dynamically populates a nice set of tabs and fills them with content based on a variable passed in the URL.  This page works flawlessly.

I'm currently using Prototype to do a bunch of AJAX calls to update different parts of the page.  Everything works great except for my Ajax.updater call with Prototype to pass a variable to the page containing the Dojo tabs and putting that in a DIV placeholder.  What ends up happing is that the content of each of my tabs gets placed but it seems all the JavaScript is being ignored and I get an error message saying "'Dojo' is undefined".  I've messed with Firebug but I can't come up with anything. 

I'm also using the EvalScripts parameter on my call but that doesn't do the trick.  Is there a special way I should be including the Dojo javascript files?

Like I said, this page works great on its own but when I try to call it to another page I just get the content and no tabs.

Some code:

[code]function getLRUData(selected_value){
var url = 'getlrudata.cfm';
var pars = 'lru='+selected_value;
var target = 'lruSpace';
var myAjax = new Ajax.Updater(target, url, {method: 'get', parameters: pars, evalScripts: true});
}[/code]

Dojo includes on getlrudata.cfm:

[code]<script type="text/javascript">
var djConfig = { isDebug: true };
</script>
<script type="text/javascript" src="include/dojo/dojo.js"></script>
<script type="text/javascript">
dojo.require("dojo.widget.TabContainer");
dojo.require("dojo.widget.LinkPane");
dojo.require("dojo.widget.ContentPane");
dojo.require("dojo.widget.LayoutContainer");
dojo.require("dojo.widget.Checkbox");
</script>[/code]

I'm guessing I have some scope issues or some quirky JavaScript syntax wrong.  But I'm out of ideas…

Thanks!
Link to comment
Share on other sites

I can tell you that prototype only evaluates js files without a src="" attribute( inline js).  As well prototype does not allow you to mix js and html as the return value.  It has to be all one js file, or all html, or an xml file.

I've done it before with non prototype ajax and maybe you could adapt it to prototype.  Have prototype stick the return of ajax into just a regular js var(don't know if you can do that) and then search the var for a script /script tag.  Use this regular expression which I extracted from the prototype.js code itself(works great):
[code]scriptregexp = /(?:<script.*?>)(?:(\n|\r|.)*?)(?:<\/script>)/im;[/code]

use code like this:
[code]var curscript = ajaxreturnvalue.match(scriptregexp);

if (curscript) { // script tag found!
    // the 2 statements below are necessary if the code uses
    // document.write - I redirect to a function which will write it to a var
    var savewrite = document.write;
    document.write = mywrite; // mywrite is a function defined below
    writtenstring = ''; // reset document.write var

    // the curscript[1] var below is only the part between the script tags
    // not including the script tags, do not use the actual script tags in eval()
    eval(curscript[1]);

    // restore the document.write event below
    // if any document.write statements were executed
    // the result will be in the global var 'writtenstring'
    document.write = savewrite;

  // delete the script from the code returned
  ajaxreturnvalue = ajaxreturnvalue.replace(scriptregexp, '');
  // or replace with redirected output of document.write
  ajaxreturnvalue = ajaxreturnvalue.replace(scriptregexp, writtenstring);
}[/code]

and you'll need this function and global var
[code]var writtenstring = ''; // initialize

function mywrite(writevalue) {
    writtenstring += writevalue; //add to end of string
}[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.