Jump to:

5554 Posts in 1742 Topics by 1227 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Adding external JavaScript

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 2134 Views
  • Victor
    Avatar
    Community Member
    128 Posts

    Adding external JavaScript Link to this post

    jsMath javascript suite is very useful for displaying math
    On normal pages produced with this script in mind it is enough to add <script type="text/javascript" src="jsMath/jsMath.js">
    How one can load some js on SilverStripe pages?

    Thank you in advance. Victor

  • Victor
    Avatar
    Community Member
    128 Posts

    Re: Adding external JavaScript Link to this post

    So, what is the way to add external javascript to CustomPage?

    Thank you in advance

    Victor

  • t|m
    Avatar
    Community Member
    19 Posts

    Re: Adding external JavaScript Link to this post

    how about

    Requirements::javascript("filejs");

  • Victor
    Avatar
    Community Member
    128 Posts

    Re: Adding external JavaScript Link to this post

    Well, I know this (and it should be enclosed into

    public function init()
    {

    }

    However it does not work in some particular case:

    Compare

    http://weyl.math.toronto.edu:8888/devsite/x.html

    which shows properly parsed mathematical expression

    with

    http://weyl.math.toronto.edu:8888/devsite/test/?stage=Live

  • banal
    Avatar
    Community Member
    901 Posts

    Re: Adding external JavaScript Link to this post

    Hi Victor

    On the page where it works you have the following javascript statement: jsMath.Process();
    Whereas on the SilverStripe site it's completely lacking...
    You should probably add

    Requirements::customScript('jsMath.Process();');

    to your init method.
    Some other file seems to be missing on the SilverStripe site as well. I get the following error in firebug:
    uncaught exception: jsMath can't load the file 'http://weyl.math.toronto.edu:8888/devsite/test/jsMath-fallback-symbols.js' Error status: 404

  • Victor
    Avatar
    Community Member
    128 Posts

    Re: Adding external JavaScript Link to this post

    Well, it did not work this way but your post suggested me a different solution: instead of paste htm source in (html) in Content allowing to TinyMCE to handicap it, I created new HTMLText field and pasted html snippet with reference to javascript there

    http://weyl.math.toronto.edu:8888/devsite/test/?stage=Live

    PS Still I left reference to jsMath in .php, I suspect it is needed

    Thanks! Victor

  • BenWu
    Avatar
    Community Member
    90 Posts

    Re: Adding external JavaScript Link to this post

    how about

    LeftAndMain::require_javascript('mysite/javascript/initGoogleMaps.js')

    2134 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.