Trainer for SkillsMatter

January 7th, 2009

I am really proud to be a member of SkillsMatter to deliver courses about:

  • JavaScript, JSON & DOM
  • Ajax Enterprise Web Development

The first 5-day session will start in London on February 2th. I will do this session with my friend Tobie Langel itself. More sessions are coming for 2009 in London (UK), Paris (France) and Aarhus (Danmark).

I will post dates as soon as I know them.

I hope to see some of you there :)

Introduction

May be some of you knows about service I launched more than one year now called who-s-web. Its server-side cluster algorithm is at the origin of a new service launched few weeks ago: Mapeed.

But this site has also an address form when you register with a great feature: you can check your address on a little google map before submitting it, you can even move marker if it’s not correct. This “widget” is something you need when you let someone enter a location like a user’s address or a place’s location for a real better user experience.

After having seeing this same kind of form on Google Local Business Center, I decided to make a Javascript component to bring this behavior with only a couple of lines of code and Mapeed.AddressChooser is born :).

Features

  • Javascript framework-agnostic. You can use it as is or with any great frameworks like Prototype, JQuery …
  • Mapping system independent. The current implementation is based on Google Map using a Google Map proxy object.
  • Interactive map display location while you arex typing an address.
  • Center map on user location (based on its IP) if mapping system allows it.
  • Fully customizable.
  • Fully documented with pdoc.
  • Works on Safari, Firefox, IE 6/7, Chrome and Opera.
  • ...

Download

This component is free, open-source and available on github here: http://github.com/mapeed/addresschooser.

You can also get a zip file or directly download Javascript file, checkout official website.

Enjoy!

Introduction

I did this framework first of all for personal use. I could not find what I needed in script.aculo.us and honestly, I do not see any activity in script.aculo.us or scripty2 (alpha version of script.aculo.us 2)

I like also jQuery when I need to just have animation. But as I use a lot Prototype to build complex web applications, I needed something based on this powerfull JS Framework.

So ProtoFX is born :)

It’s a light weight animation framework (base version is less than 7Ko packed) with great features. I decided to use music semantic for class names. Running effects is like playing a song isn’t it?. The object in charge of time synchronization is called Metronome. The “queue” system (I will describe it later, but it’s more powerfull than a classical queue system) is called Score.

Actions are like music player actions: play/stop/reverse/rewind…

But let’s talk about ProtoFX features.

Features

Easy to use

I tryed to make an API really easy to use. You just need to chain methods on an effect object. For example to fade an element, just do:

   1  new FX.Element(element).animate({opacity: 0}).play();

If you need to set some options like duration just call setOptions function in chained methods.

   1  new FX.Element(element).setOptions({duration: 2000}).animate({opacity: 0}).play();

Pretty simple!

Actions

As I said before, actions are like using a music player. You can do:

  • play
  • stop
  • reverse (even if the effect is running, call reverse and your animation will run backward)
  • rewind. Next time you call play it will play from the beginning

Delta

Sometimes you do not know exactly where is your element in the page, you just want to move it of XX pixels to the left. You can use operand +=, -=, /= and *= to specify delta like this

   1  new FX.Element(element).animate({left: "+=100px"}).play();

“Cloneable”

One great feature is to be able to create an effect without specifying an element. Consider that like just specifying effect parameters. To be able to play it on a element, just clone the effect and call play.

This is very usefull for UI widget for instance. UI is usually created dynamically. In this case it’s pretty hard to give an effect as UI option because you do not know the element to apply the effect when you create your UI component.

With ProtoFX, you can have an effect parameter on your widget. The widget will clone it when it needs to play animation.

   1  var fx = new FX.Element().animate({opacity: 0});
   2  ...
   3  ...
   4  fx.cloneFor(element1).play();
   5  fx.cloneFor(element2).reverse().play();

Event notifications and callbacks

As a lot of prototype add-ons, ProtoFX fire events on different actions like ‘fx:started”, “fx:stopped” ... You just need to observe those events if need be, as usual.

But sometimes, I think it needs too much code for simple action, so event notifications are also notify to callbacks. So you can write code like that:

   1  var fx = new FX.Element(element)
   2    .onBeforeStarted(function() {element.show();})
   3    .animate({height: '+=100px'})
   4    .play();

Instead of

   1  var fx = new FX.Element(element)
   2    .animate({height: '+=100px'})
   3    .play();
   4  
   5  
   6  document.observe('fx:beforeStarted', function(event) {
   7    event.element().show();
   8  }  
   9  
  10  // And do not forget to unregister the event!!
  11  

Element methods

I have also added some usefull element methods that I use a lot with scripty like Element#fade/appear, Element#blindUp/blindDown. I will add more if needed.

Based on Penner equations

Effect transitions are based on the famous Penner equations (like jQuery). It gives nice and fluid effects like bouncing effects.

Score

As I said, the queue system is called Score. but Score is an effect itself (subclass of Fx.Base) so you can also call play/stop/reverse/rewind on it!!

You can add effect at the beginning, at the end, after a specific effect. You can add delay between effects, even negative delay for effect overlap.

   1  var group = new FX.Score('group1');
   2  group.add(fx1)
   3       .add(fx2, {delay: -1000, position: 'last'})
   4       .add(fx3, {delay: -1000, position: 'first'})
   5       .add(fx4, {delay: 1000, after: 'fx2'});

Samples

Some samples are included with the distrib on github. Check out this fun example. Play with the play/stop and reverse checkbox. click on it when animation is running!!

Get it!

ProtoFX is under MIT Licence like Prototype. You can get it from github here: http://github.com/xilinus/protofx/tree/master

Documentation is generated with pdoc from Tobie Langel. Just run: rake doc to generate it locally.

Unit tests are coming soon :)

RailsParty 2008

December 3rd, 2008

Comme promis voici les slides des deux présentations de la RailsParty:

J’en profite pour remercier encore JF pour l’organisation de l’événement. Il faudrait juste qu’il améliore son DSL pour le planning des présentations ;)

I have added a new component in Prototype UI after having seeing this auto_complete from InteRiders

First of all, I want to thanks those guys and also Guillermo Rauch for the first version based on mootools.

For a customer, I needed an component based on prototype butn with content set by Ajax request and with some other features. I decided to port this component in prototype UI.

The main advantage of being part of Prototype UI is I can use some great functionnalities of this frame work without adding complicated code like:
  • Shadowing system for a better look and feel and better user experience. It does not look like a “flat” div under the input field
  • IFrameShim to avoid the bug of having select box over the completion
  • packr version

The component is fully unobtrusive, all HTML code needed for displaying completion is built by the script. As always, I try to make component skinnable. You can see below a “facebook” style as the original version and a more Apple like look and feel.

Facebook style

Apple style

It’s only available in trunk version right now but it will be included in the next release candidate planned for March.

If you really want to use it :), you can dowload a zip file with functionnal tests included.

I will add some features like serialization or a way to hand automatically hidden fields for an easier submit process. I have also to work on unit tests and documentation before the release.

If you want to try it, check those two functional tests: non ajax and ajax fill (be aware that it’s faking an ajax request, some browser do not like it :)).

PS: I will be away from my computer for a week, so I won’t reply to any comments before March.

I am very proud to announce First Release Candidate of Prototype UI.

This release only includes Window and Carousel. In trunk version you will find also Context Menu and an experimental Dock. Really soon, we will add Tooltips, Calendar (from Min), Accordion and more

So stay tuned :)

I am very happy and proud to announce prototype UI is officially open today.

At the beginning of the project, it was only a full rewrite of Prototype Window but it became quickly a UI library based on Prototype 1.6 and script.aculo.us 1.8 to include all my previous components like Prototype Carousel ....

This library is developed by Samuel Lebeau and myself. Sam worked hard on the core classes and the object design. It’s also done with help of Juriy Zaytsev and Vincent Le Moign for the design.

And I want to thank Emanuel ‘Mila76’ for his help on IE (BIG HELP) and for his div version of PWC (the new window system is based on it).

This version is only for developer and early adopters. You can only download it with subversion. The final release will be done when prototype 1.6 will be stable and of course when prototype UI too :).

You will be able to download a JS per component, a JS file with the full library and a build page will allow you to create your own JS file with UI components you need.

This goal is to build to best free UI library (under MIT licence) based on Prototype.

In the current version you have
  • window
    • skinnable
    • shadowing system independent from window and skinnable
    • div based
    • resizable from all borders and corners
    • custom buttons
    • Dialogs (like it’s done in PWC) are not yet implemented but will be done soon
  • carousel: only HTML content (no Ajax content)
  • dock (experimental)
  • shadow: a simple class to add shadow on any element with a absolute position.

Stay tuned ;) and long life to prototype UI.

Here is a sample test to see the new window system (from functional tests included in the distrib)

PS: Any feedback is really appreciated (bugs, documentation, patches, API …)

Aaron (Aaron @ ennerchi) ask me to develop a simple layout manager for a web application. First of all, I want to thanks him for accepting to release this layout manager in open source under MIT-license.

This class is inspired by RUZEE.LayoutManager but based on prototype 1.6. RUZEE version was to slow on complex layout.

It’s an unobtrusive script based on CSS classes. This picture shows what CSS class to use.


Inside a lm_container you can add:

  • lm_top / lm_bottom for top/bottom rows with fixed height and resizable width, you can add as many rows as you want,
  • lm_left / lm_right for left/right columns with fixed width and resizable height, you can add as many columns as you want,
  • lm_center, middle content with resizable width and height, you can have only one per container.
Here is a sample HTML code to show how it works:
   1  <div class="lm_container">    
   2    <div class="lm_top"></div>
   3  
   4    <div class="lm_left"></div>
   5  
   6    <div class="lm_center"></div>  
   7  
   8    <div class="lm_right"></div>  
   9  
  10    <div class="lm_bottom"> </div> 
  11  </div>
And just included layoutmanager.js in your head section
   1  <script type="text/javascript" src="prototype.js"></script>
   2  <script type="text/javascript" src="layout_manager.js"></script>

You can see it in this simple example

Of course layout can be nested like this:
   1  <div class="lm_container">    
   2    <div class="lm_top"></div>
   3  
   4    <div class="lm_left"></div>
   5  
   6    <div class="lm_center">
   7      <div class="lm_container">    
   8        <div class="lm_top"></div>
   9        <div class="lm_left"></div>
  10        <div class="lm_center"></div>  
  11        <div class="lm_right"></div>  
  12        <div class="lm_bottom"> </div> 
  13      </div>
  14    </div>  
  15  
  16    <div class="lm_right"></div>  
  17  
  18    <div class="lm_bottom"> </div> 
  19  </div>

You can see it in this embedded example

If you work with ajax request and want to add dynamically content, you just need to call

   1  layoutManager.add('your_element_id');

because you have a global variable: layoutManager. This zip file contains a sample with an Ajax Request.

So download it and focus on your web application :)

Prototype Portal Class #2

September 4th, 2007

I have added a new option to prototype portal window class to be able to have multiple portals on the same page. The new option is accept, based on accept option of Droppable. So you can do something like this;

   1  var  portal = new Xilinus.Portal("#page2 div", { accept:"portal1"});
   2  var  portal = new Xilinus.Portal("#page2 div", { accept:"portal2"});
for having to portal in the same window. With a new HTML file:
   1    <div id="page1">
   2        <div id="widget_col_0"></div>
   3        <div id="widget_col_1"></div>
   4        <div id="widget_col_2"></div>
   5   </div>       
   6    <div id="page2">
   7        <div id="widget_col_3"></div>
   8        <div id="widget_col_4"></div>
   9   </div>    
I have added a new sample file. you can give it a try. I have updated widget.js javascript file or check out code from svn: svn co http://svn.itseb.com/public/prototype-portal/trunk prototype-portal

Prototype Portal Class

August 26th, 2007

I have always wanted to create a Class to handle in a easy way portal page like netvibes. After having tried to used Sortable of script.aculo.us, I decided to write my own Class. I really like Sortable Class but it was too tricky to use it for a portal behavior. But I use Draggable and Droppable of course!

This article talks about the first version I made. It has been tested on Safari, Firefox, Opera and IE 6/7. The first version is based on Prototype 1.5.1.1 because I could not use 1.6. but the next version will be based on 1.6.

Here is how it works.

1) Create an HTML page with as many columns you need. Columns width can be fixed or variable, and with different size.

Here is a HTML sample with 3 columns
   1  <div id="page">
   2    <div id="widget_col_0"></div>
   3    <div id="widget_col_1"></div>
   4    <div id="widget_col_2"></div>
   5  </div>
And the CSS file
   1  #page {
   2    margin: 10px auto;
   3  }
   4  
   5  #widget_col_0 { 
   6    float:left;
   7    width: 30%;  
   8  }
   9  
  10  #widget_col_1 {
  11    width: 50%;
  12    float:left;
  13  }   
  14  
  15  #widget_col_2 { 
  16    float:left;
  17    width: 20%;  
  18  } 
Pretty easy!

2) You need to instanciate a Portal class with those columns:
   1  var  portal = new Xilinus.Portal("#page div")
3) Add widgets to this portal. There is a Widget class, fully CSS skinnable (there is a default theme), just create a new Widget instance and add it to the portal by specifying the column index. For example:
   1  portal.add(new Xilinus.Widget(), 0)
   2  
   3  // Or with title and content
   4  portal.add(new Xilinus.Widget().setTitle("Widget Title").setContent("bla bla bla"), 1);
And that’s it!! There are also some options when you create the portal:
  • url: Url called by Ajax.Request after a drop (default null, no requests)
  • onOverWidget: Called when the mouse goes over a widget (default null)
  • onOutWidget: Called when the mouse goes out of a widget (default null)
  • onChange: Called a widget has been move during drag and drop (default null)
  • onUpdate: Called a widget has been move after drag and drop (default null)
  • removeEffect: Remove effect (by default no effects), you can set it to Effect.SwitchOff for example
And main functions are:
  • add(widget, columnIndex): add a new widget .
  • remove(widget): remove a new widget.
  • serialize(): returns a parameters string for Ajax.Request

You could a see a live example here. I have used onOverWidget/onOutWidget to add edit/delete buttons on widget and I added a remove effect to show how to use it with advanced features.

You can download the widget.js javascript file or check out code from svn: svn co http://svn.itseb.com/public/prototype-portal/trunk prototype-portal

Next I will create a full website for this class with documentation and CSS details (it’s based on sliding doors technique), port it to prototype 1.6 with new Element class (I will remove builder.js) and the new class model. Prototype rocks!!

The 1.6 version will also include unit tests.

One more thing, it’s under MIT license, as Prototype and script.aculo.us, so feel free to use it.

PS: Thanks to Seb for testing and debugging!

After a while without any new versions (as PWC) becomes complete and pretty stable) here comes 1.3.

The main features are blur/focus events with possibility of having 2 themes to make the focused window looks different. And a new theme by Emanuel Mila

Also a new example/tutorial, PWC-OS, a lightweight Web OS using PWC. It uses the focus/blur feature, of course.

I have also added a PWC section in this blog to post every new ideas/features.