Hi,

> Is there a work around to force Prototype to leave JavaScript source
> files inclusions after Ajax updates?

Nothing built into Prototype.  If you search through Lighthouse[1] or
this group (I forget which) there was a discussion about possibly
adding that at some stage.  In the meantime, I see two options:

One is that you can use Ajax.Request rather than Ajax.Updater and
process the result yourself.  At its core, Ajax.Updater just processes
a successful result by calling Element#update[2], which uses
String#evalScripts[3] to execute the inline scripts (but not the ones
referencing external files).  You could replace it with Ajax.Request,
look for the script tags referencing external files, and process them
yourself.

String#evalScripts uses String#extractScripts[4], which uses this
regex repeatedly to build an array of the contents of script tags:
'<script[^>]*>([\\S\\s]*?)<\/script>'  As you can see, the only
capture group there is for the content between the script tags, and so
the array String#extractScripts builds is only for inline scripts.
You'd have to use a modified form to search for tags for external
scripts.

Once you have the external scripts, you can load them dynamically;
some tips on doing that here[5] on the unofficial wiki.

The second approach, which may be simpler, only works if you're in
control of what comes back (e.g., you're not calling some third-party
code you don't have control over).  If you are in control of it, you
could change it to use inline script to load external scripts, rather
than script tags.  E.g., instead of having the result contain:

<script src='somescriptfile.js'></script>

you could have it do this:

<script>loadExternalScript('somescriptfile.js');</script>

...where loadExternalScript is defined on the main page and (again)
uses techniques like those suggested[5] on the unofficial wiki.

[1] http://prototype.lighthouseapp.com/projects/8886-prototype/overview
[2] http://prototypejs.org/api/element/update
[3] http://prototypejs.org/api/string/evalScripts
[4] http://prototypejs.org/api/string/extractScripts
[5] http://proto-scripty.wikidot.com/prototype:how-to-load-scripts-dynamically

HTH,
--
T.J. Crowder
tj / crowder software / com
Independent Software Engineer, consulting services available

On May 6, 9:30 am, almeidap <almei...@gmail.com> wrote:
> Hi,
>
> Our application has been enhanced with an asynchronous circuit (based
> over the Prototype's Ajax class) that is able to load and navigate
> through usecases in a modal window.
>
> When calling an usecase action in a asynchronous way, the circuit
> returns only the needed HTML content (and not a full web page with the
> HTML or HEAD tags) that may contain JavaScript source file inclusions,
> like:
>
> <script type="text/javascript" src="/MyUsecase/MyAction.js" />"></
> script>
>
> When performing a such update (using Ajax.Updater(container,
> actionUrl, {evalJS : true, evalScripts : true})), scripts are
> correctly evaluated and removed from output. But script tags that
> reference a source file are also removed and the contents of the
> Javascript file will never be interpreted!
>
> Is there a work around to force Prototype to leave JavaScript source
> files inclusions after Ajax updates?
>
> Thanks
--~--~---------~--~----~------------~-------~--~----~
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