Getting javascript to run.

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
alumwell
Forum Members
Forum Members
Posts: 12
Joined: Thu Oct 16, 2008 8:53 am

Getting javascript to run.

Post by alumwell »

Hello.

I'm trying to run this piece of javascript on a page:

Code: Select all

{literal}
<__script__ type="text/javascript"><!--
//new fadeshow(IMAGES_ARRAY_NAME, slideshow_width, slideshow_height, borderwidth, delay, pause (0=no, 1=yes), optionalRandomOrder)
//new fadeshow(fadeimages, 140, 225, 0, 3000, 1, "R")
new fadeshow(fadeimages2, 140, 225, 0, 3000, 0)
// --></__script>
{/literal}
Although i cannot get it to run. I have the other needed files in the correct place. Any suggestions why?
Dee
Power Poster
Power Poster
Posts: 1197
Joined: Sun Mar 19, 2006 8:46 pm
Location: the Netherlands

Re: Getting javascript to run.

Post by Dee »

The script will be run this way (surrounded with {literal}{/literal} tags). It creates a new fadeshow object, it's hard to tell why it doesn't work without the source of the js file containing the class definition and without knowing how you've included that.

Regards,
D
alumwell
Forum Members
Forum Members
Posts: 12
Joined: Thu Oct 16, 2008 8:53 am

Re: Getting javascript to run.

Post by alumwell »

hexdj
Power Poster
Power Poster
Posts: 415
Joined: Sat Mar 24, 2007 8:28 am

Re: Getting javascript to run.

Post by hexdj »

Well, did you add the code from Step 1 on that link that you posted?
alumwell
Forum Members
Forum Members
Posts: 12
Joined: Thu Oct 16, 2008 8:53 am

Re: Getting javascript to run.

Post by alumwell »

yep. I put it in a .js file and put it in the main template in the head like:

Code: Select all

{literal}	
<__script__ type="text/javascript" src="lib/slideshow.js" ></__script>
 {/literal}

And when i view source it says:

Code: Select all

<head>

	
<__script__ type="text/javascript" src="lib/slideshow.js" ></__script>
 

<title>A....etc
Any suggestions?

Thanks
alumwell
Forum Members
Forum Members
Posts: 12
Joined: Thu Oct 16, 2008 8:53 am

Re: Getting javascript to run.

Post by alumwell »

Also it seems to automatically seems to put '<!--' into the code when i apply, am i correct in saying this comments it out? If so could that be why it's not working?

Thanks.
NaN

Re: Getting javascript to run.

Post by NaN »

Is your js file really located in the lib folder of cmsms?
Are there sufficient permissions to directly access js files?
Where are the comment tags placed in the source?
What seems to be commented out?
User avatar
kittymcooper
Forum Members
Forum Members
Posts: 44
Joined: Sat Aug 02, 2008 4:40 am
Location: Fort Collins, CO

Re: Getting javascript to run.

Post by kittymcooper »

I had the same problem when adding some javascript to a page and had to remove the comments normally put in after and before to hide it from old browsers  because the html editor loses the line breaks. Perhaps there is a better solution but removing the comments works.

So

becomes
some javascript code
and now it works
Kitty Munson Cooper, web designer, programmer
alumwell
Forum Members
Forum Members
Posts: 12
Joined: Thu Oct 16, 2008 8:53 am

Re: Getting javascript to run.

Post by alumwell »

Hello.

1. Yes, the js is in the lib folder.
2. i don't believe there is any permissions problem
3. It automatically seems to put the comment in:

Code: Select all

{literal}
<__script__ type="text/javascript">
//new fadeshow(IMAGES_ARRAY_NAME, slideshow_width, slideshow_height, borderwidth, delay, pause (0=no, 1=yes), optionalRandomOrder)
//new fadeshow(fadeimages, 140, 225, 0, 3000, 1, "R")
new fadeshow(fadeimages2, 140, 225, 0, 3000, 0)
</__script>
{/literal}
Turns to this when you update:

Code: Select all

literal}
<__script__ type="text/javascript"><!--
//new fadeshow(IMAGES_ARRAY_NAME, slideshow_width, slideshow_height, borderwidth, delay, pause (0=no, 1=yes), optionalRandomOrder)
//new fadeshow(fadeimages, 140, 225, 0, 3000, 1, "R")
new fadeshow(fadeimages2, 140, 225, 0, 3000, 0)
// --></__script>
{/literal}
User avatar
duclet
Forum Members
Forum Members
Posts: 187
Joined: Fri Jun 23, 2006 12:55 pm

Re: Getting javascript to run.

Post by duclet »

Try adding a semicolon at the end.
alumwell
Forum Members
Forum Members
Posts: 12
Joined: Thu Oct 16, 2008 8:53 am

Re: Getting javascript to run.

Post by alumwell »

just tried. Still puts the around the javascript.

Any other ideas?

thanks.
NaN

Re: Getting javascript to run.

Post by NaN »

The comment tags are just to avoid that the script will be displayed as text in old browsers that cannot handle javascript.
It has nothing to do with the functionality of the script.

But why are these two lines commented out?

//new fadeshow(IMAGES_ARRAY_NAME, slideshow_width, slideshow_height, borderwidth, delay, pause (0=no, 1=yes), optionalRandomOrder)
//new fadeshow(fadeimages, 140, 225, 0, 3000, 1, "R")
alumwell
Forum Members
Forum Members
Posts: 12
Joined: Thu Oct 16, 2008 8:53 am

Re: Getting javascript to run.

Post by alumwell »

NaN wrote:
The comment tags are just to avoid that the script will be displayed as text in old browsers that cannot handle javascript.
It has nothing to do with the functionality of the script.

But why are these two lines commented out?

//new fadeshow(IMAGES_ARRAY_NAME, slideshow_width, slideshow_height, borderwidth, delay, pause (0=no, 1=yes), optionalRandomOrder)
//new fadeshow(fadeimages, 140, 225, 0, 3000, 1, "R")

They are not needed. I've already removed those to lines to try and get it to work. Any other ideas?

Thanks.
hexdj
Power Poster
Power Poster
Posts: 415
Joined: Sat Mar 24, 2007 8:28 am

Re: Getting javascript to run.

Post by hexdj »

Are you sure JS is turned on?
User avatar
kittymcooper
Forum Members
Forum Members
Posts: 44
Joined: Sat Aug 02, 2008 4:40 am
Location: Fort Collins, CO

Re: Getting javascript to run.

Post by kittymcooper »

The comment tags will disappear the js code in all browsers, if they do not have line breaks after them (\n) -

I was able to remove the comments by using the html editor from the icon in the wsyiwyg editor that comes with CMSMS which did not add the comments and did solve this issue for me.
Kitty Munson Cooper, web designer, programmer
Post Reply

Return to “Developers Discussion”