RSS
 

Archive for the ‘Javascript’ Category

GWT- How to reference the body in your java code

10 juin

I was confronted with this problem. How to retrieve Element references the body. As GWT API doesn’t provide this service directly you need to use an other way.

You can add for example an id to the body in the HTML description of the page
<html> <head> <meta name='gwt:module' content='fr.improve.testGWT.gwt.Application'> </head> <body id='bodyId'> <script language="javascript" src="gwt.js"></script> </body> </html>

In your java application you just have to use the following code:

import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Element;

Element body= DOM.getElementById(« bodyId »);

Another solution is to use the JSNI with the following method:

public static native Element getBody() /*-{ return $doc.body; }-*/;

The body element is retrieve with this call:

Element body = getBody();

And you don’t need to change the HTML page of your application.
It is a little bit strange that base element like the body can’t be directly accessible

 

Visited link … by CSS

22 avr

I read this article this weekend and I was really fooled by the simplicity and the efficiency of the proposed script. The author explains how he can find visited sites by using only the CSS property visited of a hypertext link.
How does it work?
In fact in the page the author « hidde » a list link of the sites he wants to test.

<a href="http://urlToTest/">MySite.com</a> ....

He also has defines a particular css property for the visited links
a:visited { .. height:100px; ... }

Then your browser makes the rest by marking the links you have already visited. It remains to go through these links and to test their offsetHeight property.

var items = document.getElementsByTagName('a'); for (var i=0,i<items.length; i++) { if (items[i].offsetHeight == 100) { //Site already visited .....

Simple and effective ….

 
 

Release V0.9 of Rialto

19 avr

A new version of Rialto is available in the download section of the site corresponding to the 0.9 release:

What’s new:

* bug corection
* the tabFolder has a new parameter call orientation that allow to set the orientation of the tabitem with `t’ for top, `l’ for left, `r’ for right and `b’ for bottom position.
* integration of firebug lite for debug. If you have the firebug plugin in FF then all the messages will be display in. Else (IE or FF without firebug) an emulation of the console appear in a floating frame in your page. I already talk about it here
* the grid become skinable

Notice that the next version will be the V1. We plan to release it in september.

 
 

XML/Javascript UI development

06 avr

In following my previous news on GUI conception, the Jonathan Allen’s news ask the question a new time, talking about Javascript approach and presenting the new Firefox 3.0 approach with Gran Paradiso.

 

Box model and Quirks mode

05 avr

One difficultie in the design of javascript components results from differences of interpretation from the browsers. To make simple, the W3C specifies that the width or the height of an element has to reflect its actual contents. That is that the dimensions of padding, border and margins have to be to add to the specified dimensions. Regrettably, Microsoft in the first versions of his browser (up to internet explorer 5) use another model, that is than the size of an element correspond to its global size (including borders, set the margins).

You will say « Ok but they fixed it since version 6 « .
Yes but not because of the Quirks mode (by opposition to the standard mode) which allows the browse to insure a retro compatibility by preserving the former mode of renderer.

And when can you say that you are in Quirks mode (among others)?

By using an HTML page without DOCTYPE in other words in the majority of the cases

To observe the phenomenon just test the following code in a HTML page.

<html>
<head>
	<title></title>
</head>
<script>
function init(){
var div=document.getElementById('div1');
div.style.width="200px";
div.style.height="100px";
div.style.border="5px solid red";
div.style.backgroundColor="blue";

var iw=document.getElementById('width');
var ih=document.getElementById('height');
var iow=document.getElementById('offwidth');
var ioh=document.getElementById('offheigth');

div.onmouseover=function(){
iw.value=this.style.width;
ih.value=this.style.height;
iow.value=this.offsetWidth;
ioh.value=this.offsetHeight;
}

div.onmouseout=function(){
iw.value="";
ih.value="";
iow.value="";
ioh.value="";
}

}
</script>
<body onload="init();">
<div id='div1'></div>
Width :<input type='text' id='width'/>
Height :<input type='text' id='height'/>
OffsetWidth :<input type='text' id='offwidth'/>
OffsetHeight :<input type='text' id='offheigth'/>
</body>
</html>

You will observe according to browsers the difference beetween the fixed size (width and height) and the real occupied size (offsetWidth and offsetHeight) by passing the mouse on the div.

Then what are the solutions

  • Insert in your page the following doctype.
  • <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/DTD/strict.dtd">
  • Use browser detection and at the need re-size elements

Most of the ajax frameworks use the 2nd solution because they can’t be sure of the pages in which they are executed.

You should not forget to test the mode of renderer to affect or not the new sizes. Just test the property document.compatMode

  • if the value is « CSS1Compat then you are in standart mod and you don’t need to change the size
  • if the value is « BackCompat » you are in quirks mode and you have to set the size

Here is a squeleton of function that change the width of an object

function(oHtml){
	if (window.event && document.compatMode== "BackCompat") {
	//Get border,margins and padding size
	var delta=......;
	//IE and Quirks mode so we increase the size
	oHtml.style.width =  parseInt(oHtml.style.width) + delta +"px";
	}
}

This probleme can seem harmless but the construction of complex components require the assembly of a large number of HTML element and size are very rigorous. A gap of 1 or 2px have naturally consequences on the coherence of the component.

And so, all this work for this old bug…..

 
 

Util link…

02 avr

It has been a long time since I want to honour the quirksMode site.
For those who want to use javascript and dom api this site must be in
your bookmarks. It was really helpful for us when we made the first
implementation of what will become Rialto (and i still get
information in).

So don’t hesitate to visit this site.

 
 

Firebug Lite

16 mar

Firebug became a necessary tool for the development of javascript « rich » components. Regrettably its use is limited to firefox. To offer a reduced service with the other browsers the team of firebug released Firebug Lite, a competition of the famous console. I have just tested its integration in Rialto. The first report is that the script is very simple and that the offered features are well thought. You can use 4 kind of messages (log, info, warm and error) but also some more as console.time and console.timeEnd which allow to measure the execution time of a block of script. You can also display all the properties of an object with the function console.dir or the contents of a node with the function console.dirxml.

An input text also allows to evaluate any javascript expression. Usefull to check the properties of your objects.

firebug

 
1 Comment

Posted in Javascript

 

E4X : xml manipulation

10 mar

Rahul Kumar Gupta :
« E4X provides a more intuitive, familiar, and natural way for JavaScript developers to deal with XML. E4X code is easier to read, write, and maintain than standard XML in programming models such as XSLT, XQuery, and the DOM »

E4X Adds Direct XML Support to JavaScript