Hi Thomas,
There was no real reason to do it in javascript
The source site had this coded in javascript so i thought this could be relatively Copy
and Paste ;-(
I do believe it would be much easier in velocity...
Op 1 apr 2011, om 11:46 heeft Thomas Mortagne het volgende geschreven:
On Fri, Apr 1, 2011 at 11:45, Thomas Mortagne
<thomas.mortagne(a)xwiki.com> wrote:
On Fri, Apr 1, 2011 at 11:31, Gerritjan Koekkoek
<gerritjankoekkoek(a)gmail.com> wrote:
Hi,
My use case;
Each time a document is opened display a random image from a index of 25
The images are located on a external website
I've tried the following
step 0:
I've a document Sandbox.Try
step 1:
I've added a object of type XWiki.JavaScriptExtension to the page
in name: random-header.js
in Code:
// JavaScript Document
images = new Array(25);
images[0] = '<img
src="http://www.cdlsusa.org/images/interiors/1.jpg"
>'
images[1] = '<img
src="http://www.cdlsusa.org/images/interiors/2.jpg"
>'
images[2] = '<img
src="http://www.cdlsusa.org/images/interiors/3.jpg"
>'
images[3] = '<img
src="http://www.cdlsusa.org/images/interiors/4.jpg"
>'
images[4] = '<img
src="http://www.cdlsusa.org/images/interiors/5.jpg"
>'
images[5] = '<img
src="http://www.cdlsusa.org/images/interiors/6.jpg"
>'
images[6] = '<img
src="http://www.cdlsusa.org/images/interiors/7.jpg"
>'
images[7] = '<img
src="http://www.cdlsusa.org/images/interiors/8.jpg"
>'
images[8] = '<img
src="http://www.cdlsusa.org/images/interiors/9.jpg"
>'
images[9] = '<img
src="http://www.cdlsusa.org/images/interiors/10.jpg"
>'
images[10] = '<img
src="http://www.cdlsusa.org/images/interiors/11.jpg"
>'
images[11] = '<img
src="http://www.cdlsusa.org/images/interiors/12.jpg"
>'
images[12] = '<img
src="http://www.cdlsusa.org/images/interiors/13.jpg"
>'
images[13] = '<img
src="http://www.cdlsusa.org/images/interiors/14.jpg"
>'
images[14] = '<img
src="http://www.cdlsusa.org/images/interiors/15.jpg"
>'
images[15] = '<img
src="http://www.cdlsusa.org/images/interiors/16.jpg"
>'
images[16] = '<img
src="http://www.cdlsusa.org/images/interiors/17.jpg"
>'
images[17] = '<img
src="http://www.cdlsusa.org/images/interiors/18.jpg"
>'
images[18] = '<img
src="http://www.cdlsusa.org/images/interiors/19.jpg"
>'
images[19] = '<img
src="http://www.cdlsusa.org/images/interiors/20.jpg"
>'
images[20] = '<img
src="http://www.cdlsusa.org/images/interiors/21.jpg"
>'
images[21] = '<img
src="http://www.cdlsusa.org/images/interiors/22.jpg"
>'
images[22] = '<img
src="http://www.cdlsusa.org/images/interiors/23.jpg"
>'
images[23] = '<img
src="http://www.cdlsusa.org/images/interiors/24.jpg"
>'
images[24] = '<img
src="http://www.cdlsusa.org/images/interiors/25.jpg"
>'
images[25] = '<img
src="http://www.cdlsusa.org/images/interiors/26.jpg"
>'
index = Math.floor(Math.random() * images.length);
in use this extension: on demand
parse content: no
caching policy: long
step 2
In the page i've added the following
{{velocity}}
$xwiki.jsx.use('Sandbox.Try')
{{/velocity}}
{{html wiki="false"}}<!-- start main image div & javascript for home
page -->
<div id="interior-pg-main-img">
<div style="float: left;">
<script type="text/javascript">
document.write(images[index]);
</script>
</div>
</div>
<!-- end main image div & javascript for home page -->
{{/html}}
step 3:
Empty page ;-(
Any suggestions how to approach this more effective
Gerritjan
_______________________________________________
users mailing list
users(a)xwiki.org
http://lists.xwiki.org/mailman/listinfo/users
If you need to pick a random image when the document is loaded I don't
understand why you are doing that using javascript. Would be much
easier to do it server side.
Now it's maybe not that easy to do random number generation in
velocity,looks like there is no $randomtool by default.
Actually there is one in $mathtool.
Do you know how I would use the $mathtool; is
it build in by default
--
Thomas Mortagne
--
Thomas Mortagne
_______________________________________________
users mailing list
users(a)xwiki.org
http://lists.xwiki.org/mailman/listinfo/users