<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>JQuery, PHP, html, design... // arnaud-k : un blog de geek &#187; JQueryUI</title>
	<atom:link href="http://blog.arnaud-k.fr/tag/jqueryui/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.arnaud-k.fr</link>
	<description>Le blog JQuery, Html, Web Design</description>
	<lastBuildDate>Thu, 21 Apr 2011 08:10:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Tutorial JQuery : trier une liste en drag&#8217;n&#039;drop avec JQueryUI Sortable</title>
		<link>http://blog.arnaud-k.fr/2010/09/29/tutorial-jquery-trier-une-liste-en-dragndrop-avec-jqueryui-sortable/</link>
		<comments>http://blog.arnaud-k.fr/2010/09/29/tutorial-jquery-trier-une-liste-en-dragndrop-avec-jqueryui-sortable/#comments</comments>
		<pubDate>Wed, 29 Sep 2010 07:14:59 +0000</pubDate>
		<dc:creator>arnaud</dc:creator>
				<category><![CDATA[JQuery]]></category>
		<category><![CDATA[drag'n'drop]]></category>
		<category><![CDATA[JQueryUI]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://blog.arnaud-k.fr/?p=1943</guid>
		<description><![CDATA[Il est toujours compliqué de proposer au internautes de trier des éléments et faire ça de manière simple et ergonomique. On peut, par exemple, proposer de saisir la position pour chaque élément. Mais ça reste contraignant. C&#8217;est dans cette optique&#160;[...]</p> <p class="read-more"><a class="gray normal" href="http://blog.arnaud-k.fr/2010/09/29/tutorial-jquery-trier-une-liste-en-dragndrop-avec-jqueryui-sortable/">Lire la suite&#160;&#62;&#62;</a></p>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.arnaud-k.fr%2F2010%2F09%2F29%2Ftutorial-jquery-trier-une-liste-en-dragndrop-avec-jqueryui-sortable%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.arnaud-k.fr%2F2010%2F09%2F29%2Ftutorial-jquery-trier-une-liste-en-dragndrop-avec-jqueryui-sortable%2F&amp;source=arnaudk&amp;style=compact&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p><img class="aligncenter size-full wp-image-1944" title="tuto-sortable" src="http://blog.arnaud-k.fr/wp-content/uploads/2010/09/tuto-sortable.jpg" alt="" width="600" height="200" />Il est <strong>toujours compliqué de proposer au internautes de trier des éléments</strong> et faire ça de manière simple et ergonomique. On peut, par exemple, proposer de saisir la position pour chaque élément. Mais ça reste contraignant.</p>
<p>C&#8217;est dans cette optique qu&#8217;<strong>apparaît l&#8217;option du drag&#8217;n'drop (glisser-déposer en français)</strong>. Je pense que c&#8217;est <strong>ce qu&#8217;il y a de plus simple et intuitif pour l&#8217;internaute</strong>. Il faut néanmoins le prévenir que l&#8217;on attend un glisser-déposer de sa part car ce n&#8217;est pas encore répandu absolument partout&nbsp;!</p>
<h3 class="aligncenter"><a class="demo" href="http://blog.arnaud-k.fr/demos/jquery-drag-n-drop/">Voir la démo du tutorial</a></h3>
<p><strong>Pour réaliser cela, <a href="http://www.jqueryui.com">JQueryUI</a> nous propose le widget nommé Sortable</strong>. Il permet de créer et de configurer le drag&#8217;n'drop pour une liste d&#8217;éléments. Pour commencer, <strong>il faut donc inclure : JQuery et JQueryUI (javascript et CSS).</strong></p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">link</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;stylesheet&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;jquery-ui-1.8.5.custom.css&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;jquery-ui-1.8.5.custom.min.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span></pre></div></div>

<p>Pour sauvegarder le tri fait par l&#8217;internaute, <strong>il faut enregistrer le tout dans la base de données</strong>. Je te fournis donc celle utilisée dans la démo. Où chauqe élément à un id unique, name contient le nom du fichier de la photo et position pour enregistrer l&#8217;ordre des photos.</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">-- </span>
<span style="color: #808080; font-style: italic;">-- Structure de la table `demo_photo`</span>
<span style="color: #808080; font-style: italic;">-- </span>
<span style="color: #990099; font-weight: bold;">CREATE</span> <span style="color: #990099; font-weight: bold;">TABLE</span> <span style="color: #008000;">`demo<span style="color: #008080; font-weight: bold;">_</span>photo`</span> <span style="color: #FF00FF;">&#40;</span>
  <span style="color: #008000;">`id`</span> <span style="color: #999900; font-weight: bold;">int</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">11</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span> <span style="color: #FF9900; font-weight: bold;">auto_increment</span><span style="color: #000033;">,</span>
  <span style="color: #008000;">`name`</span> <span style="color: #999900; font-weight: bold;">varchar</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">255</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099; font-weight: bold;">collate</span> latin1_german2_ci <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>
  <span style="color: #008000;">`position`</span> <span style="color: #999900; font-weight: bold;">int</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">11</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>
  <span style="color: #990099; font-weight: bold;">PRIMARY KEY</span>  <span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">`id`</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span>
  <span style="color: #990099; font-weight: bold;">KEY</span> <span style="color: #008000;">`order`</span> <span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">`position`</span><span style="color: #FF00FF;">&#41;</span>
<span style="color: #FF00FF;">&#41;</span> <span style="color: #FF9900; font-weight: bold;">AUTO_INCREMENT</span><span style="color: #CC0099;">=</span><span style="color: #008080;">6</span> <span style="color: #000033;">;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">-- </span>
<span style="color: #808080; font-style: italic;">-- Contenu de la table `demo_photo`</span>
<span style="color: #808080; font-style: italic;">-- </span>
<span style="color: #990099; font-weight: bold;">INSERT</span> <span style="color: #990099; font-weight: bold;">INTO</span> <span style="color: #008000;">`demo<span style="color: #008080; font-weight: bold;">_</span>photo`</span> <span style="color: #990099; font-weight: bold;">VALUES</span> <span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">1</span><span style="color: #000033;">,</span> <span style="color: #008000;">'1.jpg'</span><span style="color: #000033;">,</span> <span style="color: #008080;">2</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
<span style="color: #990099; font-weight: bold;">INSERT</span> <span style="color: #990099; font-weight: bold;">INTO</span> <span style="color: #008000;">`demo<span style="color: #008080; font-weight: bold;">_</span>photo`</span> <span style="color: #990099; font-weight: bold;">VALUES</span> <span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">2</span><span style="color: #000033;">,</span> <span style="color: #008000;">'2.jpg'</span><span style="color: #000033;">,</span> <span style="color: #008080;">3</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
<span style="color: #990099; font-weight: bold;">INSERT</span> <span style="color: #990099; font-weight: bold;">INTO</span> <span style="color: #008000;">`demo<span style="color: #008080; font-weight: bold;">_</span>photo`</span> <span style="color: #990099; font-weight: bold;">VALUES</span> <span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">3</span><span style="color: #000033;">,</span> <span style="color: #008000;">'3.jpg'</span><span style="color: #000033;">,</span> <span style="color: #008080;">4</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
<span style="color: #990099; font-weight: bold;">INSERT</span> <span style="color: #990099; font-weight: bold;">INTO</span> <span style="color: #008000;">`demo<span style="color: #008080; font-weight: bold;">_</span>photo`</span> <span style="color: #990099; font-weight: bold;">VALUES</span> <span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">4</span><span style="color: #000033;">,</span> <span style="color: #008000;">'4.jpg'</span><span style="color: #000033;">,</span> <span style="color: #008080;">1</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
<span style="color: #990099; font-weight: bold;">INSERT</span> <span style="color: #990099; font-weight: bold;">INTO</span> <span style="color: #008000;">`demo<span style="color: #008080; font-weight: bold;">_</span>photo`</span> <span style="color: #990099; font-weight: bold;">VALUES</span> <span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">5</span><span style="color: #000033;">,</span> <span style="color: #008000;">'5.jpg'</span><span style="color: #000033;">,</span> <span style="color: #008080;">0</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span></pre></div></div>

<p>Ensuite <strong>il faut préparer la liste d&#8217;éléments sur lequel se portera le tri</strong>. Les attributs &laquo;&nbsp;id&nbsp;&raquo; des éléments de la liste devront respecter une syntaxe particulière : &laquo;&nbsp;nomGenerique_id&nbsp;&raquo;. Ou nomGenerique est le même pour tout les éléments (par exemple &laquo;&nbsp;photo&nbsp;&raquo;) et id l&#8217;identifiant unique (dans la base de données) de l&#8217;élément à trier. </p>
<p>Pour afficher la liste, on récupère bien sûr les éléments dans la base de données, en respectant l&#8217;ordre enregistré :</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&lt;ul id=&quot;list-photos&quot;&gt;
	<span style="color: #000000; font-weight: bold;">&lt;?php</span>
	<span style="color: #666666; font-style: italic;">//connexion à la base de données </span>
        <span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'DB_NAME'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'nom_de_la_base'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'DB_USER'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'nom_utilisateur'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'DB_PASSWORD'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'mot_de_passe'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'DB_HOST'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'localhost'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$link</span>   <span style="color: #339933;">=</span>   <span style="color: #990000;">mysql_connect</span><span style="color: #009900;">&#40;</span> DB_HOST <span style="color: #339933;">,</span> DB_USER <span style="color: #339933;">,</span> DB_PASSWORD <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">mysql_select_db</span><span style="color: #009900;">&#40;</span> DB_NAME <span style="color: #339933;">,</span> <span style="color: #000088;">$link</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// récupération des photos dans le bon ordre</span>
	<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span>   <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'SELECT demo_photo.id, demo_photo.name FROM demo_photo ORDER BY demo_photo.position ASC'</span> <span style="color: #339933;">,</span> <span style="color: #000088;">$link</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$photo</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_assoc</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$result</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">?&gt;</span>
	&lt;li id=&quot;photo_<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$photo</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'id'</span><span style="color: #009900;">&#93;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;
		&lt;img src=&quot;photos_NY/<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$photo</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span> ?<span style="color: #339933;">/&gt;</span><span style="color: #0000ff;">&quot; alt=&quot;</span>Photos NY <span style="color: #339933;">-</span> Arnaud<span style="color: #339933;">-</span>k<span style="color: #0000ff;">&quot; /&gt;
		&lt;p&gt;par Arnaud-k&lt;/p&gt;
	&lt;/li&gt;
	&lt;?php
	}
	?&gt;</span>
&lt;/ul&gt;</pre></div></div>

<p>Il faut ensuite <strong>mettre en forme cette liste avec du CSS</strong>. Je ne pense pas qu&#8217;il faille beaucoup d&#8217;explications pour cette partie là.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/* style global de la liste non ordonné */</span>
ul<span style="color: #cc00cc;">#list-photos</span><span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">list-style</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">140px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #808080; font-style: italic;">/* style des éléments de la liste */</span>
ul<span style="color: #cc00cc;">#list-photos</span> li<span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#ddd</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">10px</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">cursor</span><span style="color: #00AA00;">:</span>move<span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">100px</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">75px</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">margin-right</span><span style="color: #00AA00;">:</span><span style="color: #933;">10px</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#fff</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#212326</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span><span style="color: #933;">12px</span><span style="color: #00AA00;">;</span>
  -moz-box-shadow<span style="color: #00AA00;">:</span><span style="color: #933;">2px</span> <span style="color: #933;">2px</span> <span style="color: #933;">5px</span> <span style="color: #cc00cc;">#ccc</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #808080; font-style: italic;">/* style de l'élément fantome, qui apparait losque que l'on bouge un élément */</span>
ul<span style="color: #cc00cc;">#list-photos</span> li.highlight<span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#f2f2f2</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">dashed</span> <span style="color: #cc00cc;">#212326</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Ensuite vient <strong>la partie qui nous intéresse vraiment, le code JQuery</strong>. On initialise Sortable avec l&#8217;id de la liste et on met en Callback l&#8217;appel Ajax au fichier PHP qui va procéder à l&#8217;enregistrement dans la base données :</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">// quand la page a fini de se charger</span>
  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#list-photos&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">sortable</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">// initialisation de Sortable sur #list-photos</span>
	placeholder<span style="color: #339933;">:</span> <span style="color: #3366CC;">'highlight'</span><span style="color: #339933;">,</span> <span style="color: #006600; font-style: italic;">// classe à ajouter à l'élément fantome</span>
	update<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>  <span style="color: #006600; font-style: italic;">// callback quand l'ordre de la liste est changé</span>
		<span style="color: #003366; font-weight: bold;">var</span> order <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#list-photos'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">sortable</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'serialize'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// récupération des données à envoyer</span>
		$.<span style="color: #660066;">post</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'ajax.php'</span><span style="color: #339933;">,</span>order<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// appel ajax au fichier ajax.php avec l'ordre des photos</span>
	<span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#list-photos&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">disableSelection</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// on désactive la possibilité au navigateur de faire des sélections</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Et voici enfin <strong>le contenu du fichier ajax.php</strong> qui enregistre les positions des éléments. On récupère un $_POST de la forme : photo[] = id_photo. Il suffit de boucler sur ce tableau ($_POST['photo']) et on récupère les id des photos dans l&#8217;ordre :</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">//connexion à la base de données </span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'DB_NAME'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'nom_de_la_base'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'DB_USER'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'nom_utilisateur'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'DB_PASSWORD'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'mot_de_passe'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'DB_HOST'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'localhost'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$link</span>   <span style="color: #339933;">=</span>   <span style="color: #990000;">mysql_connect</span><span style="color: #009900;">&#40;</span> DB_HOST <span style="color: #339933;">,</span> DB_USER <span style="color: #339933;">,</span> DB_PASSWORD <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">mysql_select_db</span><span style="color: #009900;">&#40;</span> DB_NAME <span style="color: #339933;">,</span> <span style="color: #000088;">$link</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// changement de l'ordre des photos dans la base de données, photo par photo</span>
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'photo'</span><span style="color: #009900;">&#93;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$order</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$id_photo</span> <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'UPDATE demo_photo SET position = \''</span> <span style="color: #339933;">.</span> safe<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$order</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'\' WHERE id = \''</span> <span style="color: #339933;">.</span> safe<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$id_photo</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'\''</span> <span style="color: #339933;">,</span> <span style="color: #000088;">$link</span> <span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span> <span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*****
fonctions
*****/</span>
<span style="color: #000000; font-weight: bold;">function</span> safe<span style="color: #009900;">&#40;</span><span style="color: #000088;">$var</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$var</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_real_escape_string</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$var</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$var</span> <span style="color: #339933;">=</span> <span style="color: #990000;">addcslashes</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$var</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'%_'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$var</span> <span style="color: #339933;">=</span> <span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$var</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$var</span> <span style="color: #339933;">=</span> <span style="color: #990000;">htmlspecialchars</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$var</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$var</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p><strong>J&#8217;espère que tutoriel est clair et compréhensible</strong>. Il faut, certes, un minimum de connaissances en html, javascript et php mais je pense que ça vaut quand même le coup !</p>


<p>Pas encore de billet sur le même sujet !</p>]]></content:encoded>
			<wfw:commentRss>http://blog.arnaud-k.fr/2010/09/29/tutorial-jquery-trier-une-liste-en-dragndrop-avec-jqueryui-sortable/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Des select améliorés avec le plugin JQuery UI Multiselect</title>
		<link>http://blog.arnaud-k.fr/2009/09/17/des-select-ameliores-avec-le-plugin-jquery-ui-multiselect/</link>
		<comments>http://blog.arnaud-k.fr/2009/09/17/des-select-ameliores-avec-le-plugin-jquery-ui-multiselect/#comments</comments>
		<pubDate>Thu, 17 Sep 2009 10:05:11 +0000</pubDate>
		<dc:creator>arnaud</dc:creator>
				<category><![CDATA[JQuery]]></category>
		<category><![CDATA[JQueryUI]]></category>
		<category><![CDATA[plguin jquery]]></category>
		<category><![CDATA[select]]></category>

		<guid isPermaLink="false">http://blog.arnaud-k.fr/?p=1392</guid>
		<description><![CDATA[Le plugin JQuery Multiselect, qui fonctionne uniquement avec JQuery et JQuery UI, permet de créer des listes &#60;select&#62; améliorées. Avec le plugin, il est possible chercher un mot, une expression dans la liste, de classer les divers éléments sélectionnés, d&#8217;utiliser&#160;[...]</p> <p class="read-more"><a class="gray normal" href="http://blog.arnaud-k.fr/2009/09/17/des-select-ameliores-avec-le-plugin-jquery-ui-multiselect/">Lire la suite&#160;&#62;&#62;</a></p>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.arnaud-k.fr%2F2009%2F09%2F17%2Fdes-select-ameliores-avec-le-plugin-jquery-ui-multiselect%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.arnaud-k.fr%2F2009%2F09%2F17%2Fdes-select-ameliores-avec-le-plugin-jquery-ui-multiselect%2F&amp;source=arnaudk&amp;style=compact&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p><img class="aligncenter size-full wp-image-1393" title="jqueryui-multiselect" src="http://blog.arnaud-k.fr/wp-content/uploads/2009/09/jqueryui-multiselect.png" alt="jqueryui-multiselect" width="600" height="200" /></p>
<p>Le plugin JQuery <a href="http://quasipartikel.at/2009/05/10/jqueryui-multiselect/">Multiselect</a>, qui fonctionne uniquement avec JQuery et JQuery UI,<strong> permet de créer des listes &lt;select&gt; améliorées</strong>. Avec le plugin, il est possible chercher un mot, une expression dans la liste, de classer les divers éléments sélectionnés, d&#8217;utiliser les boutons &#8216;ajouter tout&#8217; et &#8216;retirer tout&#8217;.</p>
<p><strong>L&#8217;affichage est également optimisé</strong>, il est basé sur <a href="http://jqueryui.com/themeroller/">les thèmes de JQuery UI</a>. Plusieurs designs sont donc disponibles par défaut mais rien n&#8217;empêche de créer le sien.</p>
<p>Le plugin est <strong>très fonctionnel et bien pensé ergonomiquement</strong>. Il est également très simple à mettre en place, il suffit de créer le &lt;select&gt; comme normalement et d&#8217;initialiser le plugin avec le bon sélecteur. La démo du plugin se trouve <a href="http://michael.github.com/multiselect/">par ici</a>.</p>


<p>Pas encore de billet sur le même sujet !</p>]]></content:encoded>
			<wfw:commentRss>http://blog.arnaud-k.fr/2009/09/17/des-select-ameliores-avec-le-plugin-jquery-ui-multiselect/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Inspiration : un site avec plein de JQuery</title>
		<link>http://blog.arnaud-k.fr/2009/07/10/inspiration-un-site-avec-plein-de-jquery/</link>
		<comments>http://blog.arnaud-k.fr/2009/07/10/inspiration-un-site-avec-plein-de-jquery/#comments</comments>
		<pubDate>Fri, 10 Jul 2009 14:10:18 +0000</pubDate>
		<dc:creator>arnaud</dc:creator>
				<category><![CDATA[JQuery]]></category>
		<category><![CDATA[inspiration]]></category>
		<category><![CDATA[JQueryUI]]></category>
		<category><![CDATA[plugin JQuery]]></category>

		<guid isPermaLink="false">http://blog.arnaud-k.fr/?p=825</guid>
		<description><![CDATA[Pour ce post de fin de semaine, un lien sympa vers un site qui fait une belle utilisation de JQuery. Sur la page d&#8217;accueil de slicemachine.com tout d&#8217;abord avec le menu principal avec un affichage des éléments en pseudo 3d&#160;[...]</p> <p class="read-more"><a class="gray normal" href="http://blog.arnaud-k.fr/2009/07/10/inspiration-un-site-avec-plein-de-jquery/">Lire la suite&#160;&#62;&#62;</a></p>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.arnaud-k.fr%2F2009%2F07%2F10%2Finspiration-un-site-avec-plein-de-jquery%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.arnaud-k.fr%2F2009%2F07%2F10%2Finspiration-un-site-avec-plein-de-jquery%2F&amp;source=arnaudk&amp;style=compact&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p><a href="http://www.slicemachine.com/"><img class="aligncenter size-full wp-image-826" title="slice-machine" src="http://blog.arnaud-k.fr/wp-content/uploads/2009/07/slice-machine.png" alt="slice-machine" /></a></p>
<p>Pour ce post de fin de semaine, un lien sympa vers un site qui fait <strong>une belle utilisation de JQuery</strong>.</p>
<p>Sur la page d&#8217;accueil de <a href="http://www.slicemachine.com/">slicemachine.com</a> tout d&#8217;abord avec le menu principal avec un affichage des éléments en pseudo 3d (mais qui ne bougent pas) et un effet de rollover que je trouve sympa. On retrouve également des menus accordéon (sur tout le contenu) sur les pages &laquo;&nbsp;<strong>our services</strong>&nbsp;&raquo; et &laquo;&nbsp;<strong>faq</strong>&laquo;&nbsp;. Enfin, il y a l&#8217;utilisation de JQueryUI sur la page &laquo;&nbsp;<strong>order now</strong>&nbsp;&raquo; avec les slider, les cases à cocher et les effets d&#8217;apparition. Par ailleurs, je trouve ce formulaire assez bien réalisé.</p>


<p>Pas encore de billet sur le même sujet !</p>]]></content:encoded>
			<wfw:commentRss>http://blog.arnaud-k.fr/2009/07/10/inspiration-un-site-avec-plein-de-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

