[TYPO3-core] RFC: Load javascript libraries

Oliver Hader oh at inpublica.de
Wed Sep 19 19:18:58 CEST 2007


Hi Benni,

Benjamin Mack schrieb:
> Oliver Hader wrote:
>> Having a function that holds information about which JavaScript library
>> was integrated is absolutely required. But I wouldn't put this to
>> template.php but more to t3lib_div. The libs could also be used for
>> front-end disposal - so putting this to template.php has no effect in
>> that case.
> Yeah, but since t3lib_div is a class with a lot of static functions, we
> cannot find out if a library is loaded already (at least not in an easy
> way ;-)). t3lib_div would need to know which document is used right now,
> if it is used for the backend /  frontend etc. I think we need two
> functions:
> * One in template.php for the BE
> * One in pi_base or in lib/div for the FE plugins

Of course t3lib_div is static, I knew that before... ;-)
I though about a $GLOBAL[..] approach, but this might not be the best
solution. But I don't like the idea of having two methods doing exactly
the same but at different places (FE/BE).

Maybe there should be two methods:
* isJavaScriptLibraryLoaded(...)
* getJavaScriptLibraryCode(...)

Furthermore I'm not sure if it's good, that the loadJavaScriptLibrary()
puts the code (<script type=".." src=".."></script>) to one(!) class
variable in FE/BE. Maybe it's required that the developer decides were
to load the library, but with the information if a library was already
loaded before, e.g. like this:

  // Get the script tag loading prototype.js if not done yet:
$this->JSsomething.= getJavaScriptLibraryCode('prototype.js');

Furthermore this could/should also be used for TypoScript, e.g.
page.config.includeJS.prototype = typo3/contrib/prototype/prototype.js
An extension could call the getJavaScriptLibraryCode() function and put
this to $TSFE->additionalHeaderData.

>> With an approach storing the filepath, all files would be integrated
>> together. A better one would be to extract and store only the filename,
>> e.g. 'prototype.js', of the library to be loaded.
> Anyway, your concern could be fixed with a "basename($libname)" solution
> to only get "prototype.js" in the array key. What do you think?

Yeah, that's exactly what I wrote and would like to have... ;-)
As you can see, I also don't have THE solution for this issue, but I
think we're on the right way. I'm looking forward to more comments and
ideas.


olly
-- 
Oliver Hader
http://inpublica.de/


More information about the TYPO3-team-core mailing list