Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Template Questions /

[SOLVED] Why does calling Requirements::javascript include other core javascript files?


Reply


7 Posts   2280 Views

Avatar
Ryno in Stereo

Community Member, 8 Posts

24 January 2009 at 11:45am

Edited: 24/01/2009 5:07pm

Environment: Windows XP SP3 XAMPP, PHP 5.2.8, Apache 2.2.11
SilverStripe version: /branches/2.3

In my customised version of mysite/code/Page.php in the init() method, whenever I make a call to Requirements::javascript, the following always end up being included in the outputted HTML.

<script type="text/javascript" src="http://development.surferscentury.com.au/jsparty/behaviour.js?m=1231497686"></script>
<script type="text/javascript" src="http://development.surferscentury.com.au/jsparty/prototype.js?m=1231381869"></script>
<script type="text/javascript" src="http://development.surferscentury.com.au/sapphire/javascript/i18n.js?m=1231381787"></script>
<script type="text/javascript" src="http://development.surferscentury.com.au/sapphire/javascript/lang/en_US.js?m=1231381787"></script>
<script type="text/javascript" src="http://development.surferscentury.com.au/themes/surferscentury/js/jquery-1.3.1.min.js?m=1232688508"></script><script type="text/javascript" src="http://development.surferscentury.com.au/themes/surferscentury/js/swfobject.js?m=1232617897"></script><script type="text/javascript" src="http://development.surferscentury.com.au/jsparty/behaviour.js?m=1231497686"></script><script type="text/javascript" src="http://development.surferscentury.com.au/jsparty/prototype.js?m=1231381869"></script><script type="text/javascript" src="http://development.surferscentury.com.au/sapphire/javascript/i18n.js?m=1231381787"></script><script type="text/javascript" src="http://development.surferscentury.com.au/sapphire/javascript/lang/en_US.js?m=1231381787"></script><script type="text/javascript">//<![CDATA[
            Behaviour.register({
               '#switchView a' : {
                  onclick : function() {
                     var w = window.open(this.href,windowName(this.target));
                     w.focus();
                     return false;
                  }
               }
            });

            function windowName(suffix) {
               var base = document.getElementsByTagName('base')[0].href.replace('http://','').replace(/\//g,'_').replace(/\./g,'_');
               return base + suffix;
            }
            window.name = windowName('site');

//]]></script>

Why is this?

Calling Requirements::clear() doesn't work because as soon as I include any javascript via the Requirements:javascript() method, I cannot stop the above output?

How can I stop this happening as I want control over what JavaScript files do and do not display.

Avatar
Nivanka

Community Member, 400 Posts

24 January 2009 at 3:11pm

Do you mean that the <script></script> tags are visible on the screen?

Check whether they are in side the <head></head> section

Avatar
ajshort

Community Member, 244 Posts

24 January 2009 at 4:33pm

Nivanka - I think you misunderstood the question.

Ryno: These JS files are included in order to enable javascript translation. However, if you don't need any of this, you can manually block each javascript file in your Page_Controller->init() method. Just add something like this to block a javascript file:

Requirements::block('jsparty/behaviour.js');

and so on for each file you don't need.

Avatar
Ryno in Stereo

Community Member, 8 Posts

24 January 2009 at 5:06pm

Thanks ajshort, that's exactly what I needed to know!

Avatar
Nivanka

Community Member, 400 Posts

24 January 2009 at 8:20pm

Ah yes Ajshort, I thought something else.

Avatar
Hamish

Community Member, 712 Posts

27 January 2009 at 3:39pm

I posted on the developer forum about this - I'm not a fan. Even if there is no translatable content on the page, prototype and i18n are included. We should not have to explicitly block javascript files from loading if we're not using them.

It also adds another upgrade step, more baggage to the root page type and so on.

Hamish

Avatar
Ingo

Forum Moderator, 801 Posts

3 March 2009 at 11:54am

Regarding the javascript i18n issue, there's some news here: http://open.silverstripe.com/ticket/3643