Thursday 5 June 2008

[Fun] searching google in a shell like

A funny web site allowing to request Google from a shell : http://goosh.org/


Thursday 14 February 2008

Generating doc on javascript a la javadoc

Javascript is a very fine language but contrary to Java there isn't any native documentation engine.
Some open source projects offer you ways to generate doc from javadoc like comment in your code :
  • JsDoc : It is a good perl generator for javascript doc but it impose upon user tgto follow a given way to write javascript because it tries to interpret some javascript instruction to generate documentation :
                      /**
                       * Shape is an abstract base class. It is defined simply
                       * to have something to inherit from for geometric 
                       * subclasses
                       * @constructor
                       */
                       function Shape(color){
                         this.color = color;
                       }
    
                       // Bind the Shape_getColor method to the Shape class
                       Shape.prototype.getColor = Shape_getColor;
                        
                       /**
                        * Get the name of the color for this shape
                        * @returns A color string for this shape
                        */
                       function Shape_getColor(){
                         return this.color;
                       }
                        
                       /**
                        * Circle is a subclass of Shape
                        */
                       function Circle(radius){
                         this.radius = radius;
                       }
                        
                       /**
                        * A very rough value for pi
                        */
                       Circle.PI = 3.14;
                       
                       /**
                        * Get the radius of this circle 
                        * @returns The radius of this circle
                        */
                       function Circle_getRadius(){
                         return this.radius;
                       }
                      
                       // Circle is a subclass of Shape
                       Circle.prototype = new Shape(null);
    
  • JGrouse : It is much better when you want to use frameworks, because it allows documenting of Javascript classes, regardless which approach or framework is being used for it - be it Prototype, Dojo, Dean Edward's Base, jGrouse or any other. And it is fully integrated as ant Task :
    exemple using dojo
                      dojo.provide("net.demay.geometry.Shape");
                      /**
                       * Shape is an abstract base class. It is defined simply
                       * to have something to inherit from for geometric 
                       * subclassesl
                       * @class net.demay.geometry.Shape
                       * @author Vincent Demay
                       */
                      dojo.declare("net.demay.geometry.Shape", null, {
    
                       /**
                        * Color of the shape
                        * @variable {net.demay.color.Color} color
                       color : null,
                       
                       /**
                        * @constructor Shape
                        * @param {net.demay.color.Color} color
                        */
                       constructor: function(color){
                         this.color = color;
                       },
                        
                       /**
                        * Get the name of the color for this shape
                        * @function {net.demay.color.Color} return a color string for this shape
                        */
                       getColor: function(){
                         return this.color;
                       }
                     }
    
    
    
                      dojo.provide("net.demay.geometry.Circle");
                      /**
                       * A circle is a specific {@link net.demay.geometry.Shape
                       * @class net.demay.geometry.Circle
                       * @author Vincent Demay
                       * @extends net.demay.geometry.Shape
                       */
                      dojo.declare("net.demay.geometry.Circle", [net.demay.geometry.Shape], {            
    
                       /**
                        * Circle radius
                        * @variable {Float} radius
                        */
                       radius :  null,
    
                       //private no doc
                       PI : 3.14,
    
                       /**
                        * @constructor Circle
                        * @param {Float} radius
                        */
                       constructor: function(radius){
                         this.radius = radius;
                       },
                       
                       /**
                        * Get the radius of this circle 
                        * @function {Float} getRadius
                        */
                       getRadius : function(){
                         return this.radius;
                       }
                     }		

Wednesday 30 May 2007

VI and javascript

No, this post is not about writing javascript in vi.

Actually, this post is about a vi editor written with javascript. Amazing! but also useless ;). but it is good fun!


see it in action.

Monday 16 April 2007

A scriptless day for the summer

As a css naked day, This day aim is to demonstrate how javascript is became mandatory on user interface feeling during last years. During this day some websites will remove all javascript on their pages. The scriptless day is also a good idea to show that well developped website can also work without any script ;). Come on board and try to remove your javascript for the july 07.

Friday 13 April 2007

A very light an easy-to-use javascript librairy

Effects in webpages are more and more used, but often packaged in a big librairy such as Dojo, Scriptaculous, etc... Animator.js is a single little js allowing to make advanced effect very easly :
ex15 = new Animator().addSubject(new CSSStyleSubject(
    $('ex15Button'),
    "width: 10em; background-color: rgb(256, 256, 256); font-style: normal",
    "width: 40em; background-color: #F39; font-style: italic"));
// note how you can use any unit, not just 'px'.
This simple code will make a fade between first styles attributes and second one.

Congratulation to the author for this very good library!

Tuesday 6 February 2007

Playing sounds in javascripts

Ajax and Javascripts allow developpers to make more and more awasone things in a web browser.
The last I found "exciting" is playing sound with very goog javascript APIs?. Take a look at Sound Manager 2 (Using backgrounded flash player to play sound) - Project Home page - , it is crazy what we now can do with Javascript

You can see also:

Sunday 10 December 2006

Comment voir les propriétés d'un objet javascript

il n'est pas toujours facile de connaitre les propriétés d'un objet javascript car il n'y a souvent aucune documentation sur les classes javascript. Voici un petit bout de code permettant de lister les propriétés d'un objet avec leurs valeurs:
function getProperties(/*Object*/ obj){
    var msg = "";
    for (prop in obj){
        msg += "property : " + prop + "\t\t value : " + obj[prop] + "\n";
    }
    alert(msg);
}

Thursday 2 November 2006

La "javadoc" de javascript

J'en revais depuis longtemps, je l'ai trouvé : la javadoc pour javascript.
Pour les habitués de la trés fameuse javadoc, il existe la même chose pour javascript : http://krook.org/jsdom/

Wednesday 25 October 2006

Dojo 0.4 est sorti

Au menu de cette nouvelle version
  • Plus de possibilité graphique avec GFX
  • Gestion de l'i18n
  • Plus de fonctions Drag'n'Drop
  • Plein de nouveau widgets dont l'horloge ;)
Plus d'info sur http://dojo.jot.com/WikiHome/Release0Point4

Monday 26 June 2006

Les cookies en javascript

Voici un petit tutorial pour faire de la gestion de cookies en Javascript
cookie est en fait une propriété de l'objet document. Il s'agit donc de bien le manipuler : La syntaxe générale est la suivante :
document.cookie="liste-des-attributs-du-cookie"

Et voici la liste des attribute d'un cookie
  • Un nom et une valeur (nom=valeur): Le nom permet d'identifier le cookie. Sa valeur est un texte qui constitue le contenu du cookie.
  • Une date d'expiration (expires=date-au-format-GMT): Au format GMT (ex: Tue, 31-Dec-2002 08:00:00 GMT), elle est facultative. Si elle est omise, le cookie "meurt" à la fin de la session en cours du navigateur. Si elle est spécifiée on parle d'un "cookie persistant".
  • Un chemin d'accès (path=chemin-d-accès): Il indique la partie de l'URL pour laquelle le cookie est valable. Une page HTML pourra lire les cookies de ses sur-répertoires jusqu'à la racine du site: ex: http://www.domaine.com/repertoire/index.htm lira les cookies des répertoires http://www.domaine.com/ et http://www.domaine.com/repertoire/ En revanche, elle ne pourra pas lire les cookies de ses sous-répertoires: ex: http://www.domaine.com/index.php ne pourra pas lire les cookies du répertoire http://www.domaine.com/repertoire/ Pour qu'un cookie soit accessible depuis tous les répertoires d'un site, il faudra donc spécifier path="/". Enfin, si le chemin d'accès est omis, il prendra la valeur par défaut du chemin de la page HTML qui écrit le cookie, ce qui est dans bien des cas suffisant.
  • Un domaine de validité (domain=domaine-de-validité): Il indique le serveur pour lequel le cookie est valable (ex: www.domaine.com). S'il n'est pas spécifié il prend la valeur par défaut du domaine de la page HTML qui écrit le cookie, ce qui est, dans la grande majorité des cas, l'effet recherché. Pour des raisons de sécurité, il ne semble cependant pas possible (on a essayé), qu'un site web place des cookies qui seront relus par un autre site.
  • Un attribut de sécurité (secure): S'il existe, le cookie ne sera transmis que si la connexion vers le serveur est sécurisée (protocole HTTPS et non HTTP).

Fonction d'Ecriture

<script type="text/javascript" language="JavaScript">
<!--
function EcrireCookie(nom, valeur)
{
var argv=EcrireCookie.arguments;
var argc=EcrireCookie.arguments.length;
var expires=(argc > 2) ? argv[2] : null;
var path=(argc > 3) ? argv[3] : null;
var domain=(argc > 4) ? argv[4] : null;
var secure=(argc > 5) ? argv[5] : false;
document.cookie=nom+"="+escape(valeur)+
((expires==null) ? "" : ("; expires="+expires.toGMTString()))+
((path==null) ? "" : ("; path="+path))+
((domain==null) ? "" : ("; domain="+domain))+
((secure==true) ? "; secure" : "");
}
//-->
</script>

Fonction de Lecture

<script type="text/javascript" language="JavaScript">
<!--
function getCookieVal(offset)
{
var endstr=document.cookie.indexOf (";", offset);
if (endstr==-1) endstr=document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
function LireCookie(nom)
{
var arg=nom+"=";
var alen=arg.length;
var clen=document.cookie.length;
var i=0;
while (i<clen)
{
var j=i+alen;
if (document.cookie.substring(i, j)==arg) return getCookieVal(j);
i=document.cookie.indexOf(" ",i)+1;
if (i==0) break;

}
return null;
}
//-->
</script>

Fonction de Suppression

<script type="text/javascript" language="JavaScript">
<!--
function EffaceCookie(nom)
{
date=new Date;
date.setFullYear(date.getFullYear()-1);
EcrireCookie(nom,null,date);
}
//-->
</script>