i want it to be transparent hence the syncronous request ... so the function 
that calls the dependencies waits to continue untill the scripts that it 
requires are loaded ....
I have it inserting a script into the dom properly but if i try to call the 
function in the test script it doesnt work

-- Code
 loadDependency : function(e) {
   var req=new Ajax.Request(e, {
              evalScripts: true,
                method: 'post',
            asynchronous:false,
        onComplete : function(res) {
             var scriptTag = document.createElement("script");
             scriptTag.setAttribute("type", "text/javascript");
             scriptTag.setAttribute("src", e);
                 
document.getElementsByTagName("head")[0].appendChild(scriptTag);
             $(scriptTag).update(res.responseText);
    }


    });
 },
lazyLoader : function(type,files) {
  var url=new String(document.location);
  if (url.charAt(url.length - 1) == "/") //remove trailing slash
   {
      url = url.substring(0, url.length - 1);
   }

  // url now holds the domain name // this is all because IE and ff differ 
on echoing sources

  var loaded    = new Array();
  var toLoad    = new Array();
  var dependenciesArray = new Array();
  var f=files.length;

  for(i=0;i<f;i++) {
   toLoad.push(url+files[i]);
  }



  $$('script').each(function(e) {
   if($(e).readAttribute('src')) {
    if($(e).readAttribute('src').indexOf("http") < 0) {
     //alert($(e).readAttribute('src'));
     loaded.push(url+$(e).readAttribute('src'));
      } else {
     loaded.push($(e).readAttribute('src')); // now the shit has the fuckin 
URL in it
    }
   }
  });


    var needsLoading=array_diff(toLoad,loaded); // array diff works fine
    alert(needsLoading.length);
         for(m=0;m<needsLoading.length;m++) {


      alert(needsLoading[m]);
     loadDependency(needsLoading[m]);

     }

  helpMe(); // this is in the loaded script (which has 3 lines in it!!) and 
doesn't work


 },


Above is the 2 parts to the script ...
As you can see the 1st one gathers all the scripts in the DOM and appends 
them with the current URL (because Firefox and Inernet Explorer get the 
sources differently - Firefox adds the domain to the start of some of the 
scripts even though i havent put that as the source, only the relative path 
... this fixes everything to add with a domain path)

It takes the things that need to be loaded as an array -- Here
var files = [ 
'/resources/includes/client/effects.js','/resources/includes/client/scriptaculous.js','/resources/includes/client/f2.js'];
lazyLoader('script',files);

and adds domain to the path preceeding so i can match whats what in the 2 
arrays and not potentially load something thats already there...

array_diff then returns me an array of what is missing from what is loaded 
and a loop on the array carries out supposedly `syncronous` ajax requests to 
load them into the head of the document ...

It loads them fine and i can see the script source get added in firebug but 
when i goto call the function from f2.js (which is loaded properly) it 
returns "helpMe() is not defined" as a firebug error even though i can see 
it exists in the DOM ....

So my theory is that if the request is synchronous then helpMe cannot be 
executed untill it is placed in the DOM...

perhaps synchronous requests are removed from the latest prototype build

Thanks

Alex


----- Original Message ----- 
From: "T.J. Crowder" <[EMAIL PROTECTED]>
To: "Prototype & script.aculo.us" <[email protected]>
Sent: Thursday, November 06, 2008 2:41 PM
Subject: [Proto-Scripty] Re: Building a lazy Loader



Hi Alex,

Can you post the offending code?

Ideally, though, it makes for a more responsive UI if you allow the
request to be asynchronous and handle the remainder of your logic in
the onSuccess callback.  Synchronous requests basically lock up the UI
of the browser.
--
T.J. Crowder
tj / crowder software / com

On Nov 6, 2:33 pm, Jeztah <[EMAIL PROTECTED]> wrote:
> Hi guys and gals ... today i am building a lazyLoader based on
> prototype
> ....
>
> Its already working except i assumed i could do a synchronous request
> so
> nothing further in the javascript function is executed untill the
> request
> has finished ... it seems that asynchronous : false; is not wokring
> as i
> expected in the Ajax options .. am i expecting to much from the
> response to
> hijack my function untill it has finished its XHR then let my script
> continue what it was doing ?
>
> I asumed this was a good idea as it would workout into a nice
> dependency
> module for certain scripts ...
>
> Any ideas ?
>
> ta
>
> Alex



--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to