NyroBlog
Banniere NyroBlog
Image de deuJeff - ?
« juin 2008
lunmarmerjeuvensamdim
1
2345678
9101112131415
16171819202122
23242526272829
30

nyroModal, results after 2 months

2 months day for day after the first release of plugin nyroModal, it's time to make a first overview.

Let's start with some numbers:

  • Visits: 28 800
  • Unique Visitors: 23 660
  • Pages viewed: 26 039
  • 11 Releases (the 1.2.7 just came out)
  • 2 859 download (and more made directly in the jQuery plugin page where there is no stats available)

The problem with this kind of script, you never know where it's used. I can't make a long list here.

And maybe elsewhere that I didn't hear about... If you're using it (or saw it somewhere), don't hesitate to write a quick comment here.

This is the first open-source script I did. And the experience is great, regarding the numbers shown aboce, and the quotes below. More than 2000 visits the second day after the first release. I didn't thought it could be so much in this time. Then the numbers calmed down to around 300 daily visits (less during the weekend).

I had a proposal from the New-York Times to integrate my script in a future website. But I didn't get any news...

If you still hesitate between open-source or keep it for you, especially for a javascript code, don't hesitate! If this script is good, you'll have some return for sure. Event if it's not directly in money or contract, you'll gain recognition from others developers, but more important, Experience! You'll learn that you have to make many tests (and maybe more...) before every releases, and retest everything everytime in every browser.

What the people said:

jarro:

Nice job, trying it on a site and so far works great.

Leo:

I dig your scripts - I like this clean & correct code ;) Great work! Thanks for your nice work. Best wishes!

Clocal:

Oui félicitations ce plugin m'a l'air très bien, bonne doc, ça fait en plus plaisir de voir des français à l'oeuvre! Bonne continuation.

Jmc:

At this point i must congratulate and thank you for what i'd call the best modal plug-in for jquery EVER!!

C. Spenser Beggs (New-York Times):

I have been looking for an elegant modal box script and think that nyroModal is one of the best I have seen.

sunbeatn:

Thank you, and keep creating great scripts. Your contributions keep us newbies inspired.

A guy after reporting a bug:

Great! And thank you for a great plugin - it's been a real time saver! :)

Finally, the websites which linked:

And many others... The page was also bookmarked a lot, especially in delicious. The page went in the homepage for a few hours:
Delicious

Version française de ce billet

nyroModal, bilan après 2 mois

2 mois jour pour jour après la première sortie de mon plugin nyroModal, il est temps de faire un 1er bilan.

Pour commencer quelques chiffres :

  • Visites : 28 800
  • Visiteurs uniques : 23 660
  • Pages vues : 26 039
  • 11 Releases (la 1.2.7 vient de sortir)
  • 2 859 téléchargements (plus tous ceux effectués directement depuis jQuery Plugins où il n'y a pas de statistiques)

Le problème avec de tels scripts, c'est qu'on ne sait jamais où il est utilisé. Je ne peux donc pas dresser ici une longue liste.

Et sans doute d'autres dont je n'ai eu aucun écho... Si vous l'avez utilisez (ou l'avez vu quelque part), n'hésiter à mettre un petit commentaire ici.

C'est le premier script que je rends open source. Et je dois dire que l'expérience est plus que satisfaisante, au regard des chiffres annoncés au dessus, et des citations des gens plus bas. Près de 2000 visiteurs le 2ème jour après son lancement. Je ne pensais pas avoir autant en si peu de temps. Puis les compteurs sont très vite retombé à un peu plus de 300 visiteurs journaliers (moins le week-end).

J'ai eu une proposition du New-York Times pour intégrer ce script dans un de leur prochain site, mais je n'ai pas eu de nouvelles...

Si vous hésitez entre open-source ou bien garder pour vous, surtout dans le cadre d'un script javascript, néhsitez pas. Si votre script est bon, vous aurez forcément des retours. Même si cela ne se traduit pas en contrat ou rémunération directe, vous acquériez de la reconnaissance par vos pères (ça fait bien juteux quand même là) mais surtout de l'expérience. Vous apprendrez qu'avant de rendre publique une nouvelle version, vous devez par toute une batterie de test, et surtout à retester l'ensemble du script à chaque fois.

Ce que les gens ont dit :

jarro :

Nice job, trying it on a site and so far works great.

Leo :

I dig your scripts - I like this clean & correct code ;) Great work! Thanks for your nice work. Best wishes!

Clocal :

Oui félicitations ce plugin m'a l'air très bien, bonne doc, ça fait en plus plaisir de voir des français à l'oeuvre! Bonne continuation.

Jmc :

At this point i must congratulate and thank you for what i'd call the best modal plug-in for jquery EVER!!

C. Spenser Beggs (New-York Times) :

I have been looking for an elegant modal box script and think that nyroModal is one of the best I have seen.

sunbeatn :

Thank you, and keep creating great scripts. Your contributions keep us newbies inspired.

Une personne après avoir reporté un bug :

Great! And thank you for a great plugin - it's been a real time saver! :)

Enfin, les sites qui ont fait un lien :

Et d'autres encore... La page a été aussi beaucoup bookmarké, notamment dans delicious, au point de me faire monter en 1ère page pour quelques heures :
Delicious

English Version of this post

nyroModal 1.1 release

2 weeks since my last English post, 1 month before my real new post (the last was only translation of older posts). During this time I was busy to translate these posts, busy at work in Fluidesign, busy to live in LA.

During the last days, I developed my first own jQuery plugin: nyroModal.

nyroModal

Why a new plugin of this kind when there is already too many?

4 answers:

  • There is no too much using jQuery, most of them use Prototype/Scriptaculous
  • Most of them aren't too customizable as expected
  • When you find a bug, it's difficult to contact the developer -who often ask some Paypal donations- or understand the code to fix it
  • Because it's still pleasant for his ego to realize the things by himself

My plugin provides all the features I saw in the differents plugins I tried. In bulk:

  • Ajax Request
  • Display an hidden DOM element
  • Image
  • Gallery
  • Form
  • Iframe

But I also added some stuff I don't believe see elsewhere, or not enough:

  • You can target the content inside an Ajax request or a form
  • Forms works with a file upload
  • Background color is modifiable dynamically
  • Display an error message if needed
  • Ability to resize from an Ajax Request

Moreover I took care about the ability to customize the modal, to allow everybody to change the way the elements are animated. There is alos many possible callbacks to done every JavaScript action tou need. Thus every animation function could be fully rewritten and everything is documented: all available settings and the full modal process to allow each developer to understand how it works et to do what ever he want. I probably create more callback than necessary but better more than not enough!

And yes, it's already the 1.1 version because I showed it to my Fluidesign colleagues and all told me the transition -especially for the gallery- didn't look so good. So I created 2 new animations callback the same evening to get round of that.

If you have any suggestions, bug, improvement idea or if you use it, don't hesitate to let a comment. I'll be glad to answer it.

PS : I know, I didn't search too far for the name...

Version française de ce billet

sortie de nyroModal 1.1

Bientôt un mois que je n'ai pas publié de billet en français. Occupé à traduire des billets en anglais, occupé à développer chez Fluidesign, occupé à vivre à Los Angeles.

Et puis ces derniers temps, je me suis aussi attelé à développer mon premier plugin jQuery : nyroModal.

nyroModal

Alors pourquoi un nouveau plugin de ce genre alors qu'il en existe déjà tant ?

4 réponses :

  • Il n'en existe pas tant que ça sous jQuery, la plupart étant sur Prototype/Scriptaculous
  • La plupart ne sont pas autant personnalisable qu'il ne le laisse entendre
  • Lorsqu'on trouve un bug, il est difficile de contacter le développeur (qui demande souvent un peu de Paypal) ou d'appréhender le code d'un autre pour le corriger
  • Parce qu'il est toujours plaisant pour son égo de réaliser les choses soi-même.

Mon plugin reprend donc l'ensemble des fonctionnalités que j'ai pu voir dans les différents plugins que j'ai testés. En vrac :

  • Requête Ajax
  • Affichage d'un élément du DOM caché
  • Image
  • Galerie
  • Formulaire
  • Iframe

Mais j'ai aussi ajoutés des choses que je ne crois pas avoir vu ailleurs, ou pas assez souvent :

  • Il est possible de cibler l'élément affiché au sein d'une requête Ajax ou d'un formulaire
  • Les formulaires fonctionnent même avec un upload de fichiers
  • La couleur de fond est paramétrable dynamiquement
  • Affichage d'un message d'erreur si besoin
  • Possibilté de modifier la taille de la modale depuis une requête Ajax

De plus, j'ai beaucoup prêté attention à la personnalisation, pour permettre à chacun de modifier la façon dont sont animés les éléments. Il y a aussi de nombreux callback possible pour effectuer toutes les actions JavaScript dont vous avez besoin. Ainsi, toutes les fonctions d'animations sont entièrement redéfinissable et tout est documenté : l'ensemble des paramètres disponibles et le processus complet de la modale pour permettre à toute personne de comprendre comment il fonctionne et d'en faire ce qu'il en veut. J'ai sans doute créer plus de callback que nécessaire, mais de cette façon tout est possible.

Et oui, on en est déjà à la version 1.1 puisque je l'ai montré à mes collègues de bureau et tous m'ont dit que les transitions (pour la gallerie notamment) n'était vraiment pas bon. J'ai donc créer deux nouvelles fonctions d'animation le soir même pour pallier à cela.

Si vous avez une suggestion, un bug, une idée d'amélioration ou si l'utiliser sur votre site, n'hésitez pas à laisser un commentaire. J'y répondrai avec plaisir.

PS : hé oui, je ne suis pas allé chercher bien loin pour le nom...

English version of this post

Howto update a website to reload the page through Ajax

I deployed in a website an Ajax reload for every pages. This website use a small audio player and the sound was stopped each time a new page was requested. That wasn't so graceful. The result now is exactly the same website reloading the pages through Ajax, without changing accessibility: I didn't modify ehe HTML source.

I did it quickly bu using jQuery. As this method could be useful for others, I will describe step by step how I made it.
The website which I worked on was pretty small: Amandine Café. Nothing better to train himself in a small example and then apply it in big projects

Current Website Analysis

The first thing to do is to navigate in the whole website to deduct the fixed zone and dynamic zone to reload. You have to identify which links will reload which zones, and what will be happen regarding the reloaded page. For instance you have to worry about the possible javascript control which could be a problem. Write down them and we'll take care of that at the end.
This part was pretty fast for me as the website don't use sub navigation and contains only 5 pages. I found 2 zones delimited by 3 div identified with the id header, page, and footer. Only the div#page vary regarding the pages. That will be only this content that I will update with Ajax.

PHP Side Preparation

Before dealing with the javascript code, we'll update the PHP code of our pages. When an Ajax load is made, we won't reload the full page, but only the content to update. For more simplicity and flexibility, we'll use the same URL than the real links. That's mean we have to be able to provide only the requested content in PHP, without the head page, or the fixed div. If you don't want –can't– do that, take a look to the little bonus at the bottom of this post...
The easiest way to do that is to put the fix part in separate files, named randomly header.php and footer.php. These files will be include in every pages; that's may already the case, using the include function. The thing is now to don't show these parts when the request is an Ajax request. Pretty easy, we'll write a PHP function: isAjax. The file includes will occur only if isAjax is false. In others words:
if (!isAjax())
    inlcude('header.php');

The isAjax function is, as you can see, very very hard:
function isAjax() {
    return array_key_exists('HTTP_X_REQUESTED_WITH', $_SERVER);
}
Actually jQuery –also Prototype, I don't know about the others– add a HTTP_X_REQUESTED_WITH element in the request that you can retrieve in the $_SERVER global variable.
We're done with the PHP preparation pages, which are now able to provide light version of your pages especially for the Ajax request.

Javascript Integration

We're moving now on the real Ajax request programmation. To keep the website totally accessible, which will works exactly in the same way without Javascript, We won't modify any current HTML sources. We'll just include jQuery in all the pages and one other javascript file containing the upcoming code.
The script schema will be:
  1. On the page load, intercept all links pointed to .php pages
  2. Add an onclick function to make the Ajax request and stop the page change
  3. On the click, call the page through Ajax with the same URL and then integrate the result where we want.
  4. Stop the click propagation
With jQuery, we're writing that very simply:
$(function() {
    $('a[href*=.php]').click(function() {
       $('#page').load(this.href);
return false;
    });
});
Very short, isn't it?
Of course this code won't work perfectly in every case. In my example I have to update the body id according to the requested page; that's mean the navigation bar link will going brown as expected by the graphic designer. To do so we can use the third parameter of the load function which will be called once the Ajax load is done. Here is how looks like my function:
$(function() {
    $('a[href*=.php]').click(function() {
        $('#page').load(this.href, null, function() {
        $('body').attr('id', this.href.substring(this.href.indexOf('.')));
        });
return false;
    });
});
If you read the code in the live site, that's not at all like that because I occured other problems.

Little Bonus

If you can't–don't want– deploy the PHP cutting for the Ajax request, don't stop right now! Firstly it could be possible to reload the whole page. This solution will be very sad and you'll probably occurs many others problems.
jQuery will help. Indeed, in the URL provided to the load function, you can specifiy a HTML selector to filter the result and show only the part you want to.
In my example the call could become simply:
$('#page').load(this.href+' #page');

I dissuade to use this technique as that's mean you will reload the whole page. So we loose the Ajax utility to reduce data transfer between clients and server.

If it's not that simple?

Give proof of imagination!
As I already thought about this question, I'll give you some example soon. This post is yet consistent and you can start to enjoy. Finally I hope you won't wait me to do that... Or if you have a website where do you want deploy this kind of solution, let me know and I will use it as my example.

Express Yourself!

How did you find this post? Interesting, boring, totally useless, can do better?
Do you have some questions? Suggestions?
Did you read some English mistakes?
Use the comments!

Version française de ce billet

Backup and Restore MySQL Database through command line

When you want backup a MySQL database, you don't have many solutions.

You can use PhpMyAdmin to backup the database but you will figured out that the export doesn't work so good: there is some information lacks like the Foreign key or other things like that. You'll also occur timeout problem when trying to backup -and restore- huge database.

You can also read a fex pages in the MySQL doc and you'll find Bash command to do exactly what you want. In only 1 line you'll be able to backup you're whole database in one text file.

Here is the backup command:

mysqldump --user=USER --password=PASS --add-drop-table DATABASENAME

This command show you all the MySQL query to execute to retrieve your entire database: the CREATE instructions, adding the constraints if needed and of course, the INSERT lines. The option --add-drop-table add the instruction to delete the table just before their creation: very useful to don't worry about cleaning the database before the backup.

If you want save more than one database, you have to replace DATABASENAME by --databases DATABASENAME1 DATABASENAME2 DATABASENAME3.

And if you want save all the database in you server, you can use --all-databases instead. Be sure the user used in the command line have access to all the databases you want back up.

Right now the command show you the query. Even if you're Flash Gordon, you can't do anything with that. A simple pipe to a file will save everything for you:

mysqldump --user=USER --password=PASS --add-drop-table DATABASENAME > DUMP.sql


To restore the database -or create it in an other server-, you have simply to upload the file saved just before and run this command in the same place of this file:

mysql -u USER --password=PASS DATABASENAME < DUMP.sql

PHP/MySQL: Howto paged with a random order

The problem is simple: we have to list randomly data from a MySQL table, by creating a paging.

Let's start with the basis: A normal paging. To do so, you use the LIMIT parameter in the MySQL query:

SELECT * FROM user LIMIT 20,10

Where we show the second page for the users with 10 elements by page.

You will probably order the result to be easier to use. For example:

SELECT * FROM user LIMIT 20,10 ORDER BY name ASC

At this point, everything was pretty easy and you probably already knew that.

Now we want to randomly order the result. Intuitively, you will do something like:

SELECT * FROM user LIMIT 20,10 ORDER BY RAND()

Which is not totally wrong. The problem with this solution will occur when changing the page, the order will be different -for sure, it's random. By changing the page you will probably see some recurrent data, and the visitor will never see all the result by reading all the pages. That's not expected.

The solution consists to generate a random number in PHP, stores it in a session variable, and finally use it in the MySQL query inside the RAND parenthesis. And it's finish. Therefore the random number used is every time the same for the visitor session, and the global order will stay the same in the differents pages.

The PHP code to generate and stored the random number:

$rand = $_SESSION['rand'];
if (empty($rand)) {
srand((float)microtime()*1000000);
$rand = "0.".rand();
$_SESSION['rand'] = $rand;
}

Of course, you have to open the session with session_start() at the top of your PHP script before every out or header send -or you can use ob_start().

Finally the MySQL query becomes:

SELECT * FROM user LIMIT 20,10 ORDER BY RAND($rand)

Voilà, you can make pagination with random order.

Version française de ce billet

1 2 3 4 5 >