How to add script

If you have questions about using mojoPortal, you can post them here.

You may want to first review our site administration documentation to see if your question is answered there.

This thread is closed to new posts. You must sign in to post in the forums.
11/20/2009 3:24:08 PM
Gravatar
Total Posts 123
/Mats Lillnor

How to add script

I wish to add some external scripts to my mojoPortal site. Only om a few selected pages, so I think it would be unnessecary to add it into the layout.master page.

In this case I want to add a sticky note on my first page using this script from dynamic drive. Of course I want help with this particular issue, but the question is general, there are a lot of other situations where similar things could be done. Very shortly it is christmas and it would be nice to have some snow flakes all over the site for instance. This is very easy on a static html-site, but how do I integrate it with mojoportal?

 

/Mats

11/21/2009 8:45:05 AM
Gravatar
Total Posts 18439

Re: How to add script

Hi Matz,

To me adding scripts is more a developer thing than a site administration thing. Some scripts and widgets can be used directly by putting the script in the html source of the editor but not all scripts can work this way.

One can make a custom feature and register the scripts using .NET code from inside the UserControl with code similar to this:

Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "oomph", "\n<script src=\"" + Page.ResolveUrl("~/ClientScript/oomph/oomph.min.js") + "\" type=\"text/javascript\" ></script>");

Hope it helps,

Joe

11/21/2009 10:19:49 AM
Gravatar
Total Posts 123
/Mats Lillnor

Re: How to add script

The thing is that I am not a developer Smile, however I do know how to copy and paste.

(I got the script working by the way by copying a large chunk of code into layout.master and a few lines in a html-content on the page, see http://www.haningebudoklubb.se, but I think this is an ugly implementation.)

In this case there where some code that must be within the <head> </head> section.

Since the head-section is within the layout.master-page I had to put it there, but this is not very good since it makes it not skinnable. If I change the skin (which contain layout.master) the script breaks.

In the layout.master there is this line of code:

<portal:ScriptLoader id="ScriptLoader1" runat="server" />

If this is a script-loader function that already is included in all skins and it refers to an external file in the site outside of the skin it should just be to put the script into this file, but I can't find any documentation obout it, hence my question. Where is all the script code for the jQuery scripts and other stuf located?

 

/Mats

11/21/2009 12:07:34 PM
Gravatar
Total Posts 18439

Re: How to add script

Hi Matz,

No ScriptLoader only adds scripts I have coded it to add and handles dependency logic for the included jquery and YUI features and various other features built into mojoPortal. It is not designed to add arbitrary scripts.

The ASP.NET ScriptManager can add scripts but it is no different in that you have to declare them in layout.master, and adding them with ScriptManager does not put them in the head, so if it really needs to go there you should put it there manually.

<asp:ScriptManager ID="ScriptManager1" EnablePageMethods="true" runat="server">

<Scripts>

<asp:ScriptReference Path="~/pathtopyourscript.js" />

</Scripts>

</asp:ScriptManager>

Best,

Joe

1/25/2010 1:18:41 PM
Gravatar
Total Posts 67

Re: How to add script

Nice tip Joe. I didn't know about the asp script manager, that's really useful. I always wondered why master pages re-wrote paths depending on current directory for css links, but not javascript references. I was always struggling with paths between local and production environments. Thanks! learn something new every day, I guess.

You must sign in to post in the forums. This thread is closed to new posts.