[aida] Javascripts

Dirk Verleysen dirk.verleysen at roots.be
Tue Oct 2 21:37:33 CEST 2007


Janko,

Your examples work perfectly. I've added the onLoad: and onUnload: to WebPage and it does what I want.

Thanks.. (you to Nicolas).

Dirk

-----Oorspronkelijk bericht-----
Van: aida-bounces op aidaweb.si [mailto:aida-bounces op aidaweb.si] Namens Janko Mivšek
Verzonden: dinsdag 2 oktober 2007 18:24
Aan: AIDA/Web general discussion list
Onderwerp: Re: [aida] Javascripts

Hi Dirk,

Dirk Verleysen wrote:

> I want to display a googlemap. I need some javascript in my code.

> The first line is this one:
> 
> <script type="text/javascript" 
> src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=myKeyxxxx"></script>

yourApp addLinkToJavascript:
   'http://maps.google.com/maps?file=api&amp;v=2&amp;key=myKeyxxxx'

See this and similar methods in WebPage header elements. WebPage is 
superclass of WebApplipaction.

> Then there is this javascript code that I need in the html file. I tried 
> putting it in an external file but this didn’t work.

As every WebElement can have a script before and after itself, the same 
goes with WebPage as a sublclass of WebElement too. So, try this and 
look in a generated html if it is ok:

1. put that script as a text in a method, say #onLoadScript . Note that 
you need to  change Javascript's $' with two '' so that Smalltalk parser 
will accept it.

YourApp>>onLoadScript

^'
  //<![CDATA[

  function load() { ...}
'

2. in yourApp:

	self scriptBefore: self onLoadStript
	self onLoad: 'load()'; onUnload='GUnload()'

3. There is no onLoad: and onUnload: methods yet in WebPage, but that is 
simple to add - just follow the pattern from, say, WebElement onClick:

WebPage>>onLoad: aJavascriptCode   (in events)

	self attributesAt: #onLoad add: aJavascriptCode


I hope this help. Let me know the result to add this in next version of 
Aida.

Best regards
Janko


>   <script>
> 
> //<![CDATA[
> 
> function load() {
> 
> if (GBrowserIsCompatible()) {
> 
> var map = new GMap2(document.getElementById("map"));
> 
> var geocoder = null;
> 
> var trafficInfo = new GTrafficOverlay();
> 
> map.setCenter(new GLatLng(50.968580,4.073543,0), 15);
> 
> map.addControl(new GSmallMapControl());
> 
> map.addControl(new GMapTypeControl());
> 
> geoCode = new GClientGeocoder();
> 
> var encodedPolyline = new GPolyline.fromEncoded({
> 
>     color: "#09E466",
> 
>     weight: 10,
> 
>     points: "gxavHgvzW{GiItCwElAbD_ op h@lC`Eq op tC",
> 
>     levels: "BBBBBBB",
> 
>     zoomFactor: 32,
> 
>     numLevels: 4
> 
> });
> 
> map.addOverlay(encodedPolyline);
> 
> } }
> 
> function showAddress(address) {
> 
> geocoder.getLatLng(
> 
> address,
> 
> function(point) {
> 
> if (!point) {
> 
> alert(address + " not found");
> 
> } else {
> 
> map.setCenter(point, 13);
> 
> var marker = new GMarker(point);
> 
> map.addOverlay(marker);
> 
> marker.openInfoWindowHtml(address);
> 
> }
> 
> }
> 
> );
> 
> }
> 
> //]]>
> 
> </script>
> 
>  
> 
> The <body> tag also needs the onLoad=”load()” onUnload=”GUnload()”. 
> 
>  
> 
> What’s the best way to deal with this ?
> 
>  
> 
> Dirk
> 
>  
> 
>  
> 
>  
> 
>  
> 
>  
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Aida mailing list
> Aida op aidaweb.si
> http://lists.aidaweb.si/mailman/listinfo/aida

-- 
Janko Mivšek
AIDA/Web
Smalltalk Web Application Server
http://www.aidaweb.si
_______________________________________________
Aida mailing list
Aida op aidaweb.si
http://lists.aidaweb.si/mailman/listinfo/aida


More information about the Aida mailing list