1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
| <!doctype html>
<html lang="fr">
<head>
<meta charset="utf-8">
<meta name="Author" content="Daniel Hagnoul">
<title>Forum jQuery</title>
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/humanity/jquery-ui.css">
<link rel="stylesheet" href="http://danielhagnoul.developpez.com/lib/jPicker/css/jPicker.dvjh-1.1.6.min.css" />
<style>
/* Base */
div,p,h1,h2,h3,h4,h5,h6,ul,ol,dl,form,table,img {margin:0; padding:0; }
body {background-color:rgba(210, 214, 98, 0.5); color:#000000; font-family:sans-serif; font-size:medium; font-style:normal; font-weight:normal; line-height:normal; letter-spacing:normal; }
h1,h2,h3,h4,h5 {font-family:'Redressed', cursive; padding:6px; }
p, div, td {word-wrap:break-word; }
pre, code {white-space:pre-wrap; word-wrap:break-word; }
a {-webkit-transition: all 0.3s ease-in; -moz-transition: all 0.3s ease-in; -o-transition: all 0.3s ease-in; transition: all 0.3s ease-in; }
img, input, textarea, select {max-width:100%; }
img {border:none; }
h1 {font-size:2em; text-shadow: 4px 4px 4px #bbbbbb; text-align:center; }
p {padding:6px; }
ul,ol,dl {list-style:none; padding-left:6px; padding-top:6px; }
li {padding-bottom:6px; }
.conteneur {width:95%; min-width:800px; min-height:300px; margin:12px auto; background-color:#ffffff; color:#000000; border:1px solid #666666; }
footer {margin-left:36px; }
/* article */
.conteneur {border-spacing:4px; }
.ligne {display:table-row; }
article {display:table-cell; text-align:left; vertical-align:top; border:1px dotted grey; }
/* article:nth-of-type(1) {width:400px; height:120px; } */
/* -- */
#products { font-size:0.8em; float:left; width: 300px; margin-right: 2em; }
#cart { font-size:0.8em; width: 200px; float: left; }
/* style the list to maximize the droppable hitarea */
#cart ol { margin: 0; padding: 1em 0 1em 3em; }
#btnPanier {margin:12px; }
#dvjhSelectAllIDTShirt, #dvjhSelectAllIDBags, #dvjhSelectAllIDGadgets {font-size:0.8em; color:blue; text-decoration:none; }
</style>
</head>
<body>
<h1>Forum jQuery</h1>
<section class="conteneur">
<section class="ligne">
<article>
<div id="products">
<h1 class="ui-widget-header">Products</h1>
<div id="catalog">
<h3><a href="#">T-Shirts</a></h3>
<div>
<ul>
<li><a href="#" id="dvjhSelectAllIDTShirt">Select All</a></li>
<li>Lolcat Shirt</li>
<li>Cheezeburger Shirt</li>
<li>Buckit Shirt</li>
</ul>
</div>
<h3><a href="#">Bags</a></h3>
<div>
<ul>
<li><a href="#" id="dvjhSelectAllIDBags">Select All</a></li>
<li>Zebra Striped</li>
<li>Black Leather</li>
<li>Alligator Leather</li>
</ul>
</div>
<h3><a href="#">Gadgets</a></h3>
<div>
<ul>
<li><a href="#" id="dvjhSelectAllIDGadgets">Select All</a></li>
<li>iPhone</li>
<li>iPod</li>
<li>iPad</li>
</ul>
</div>
</div>
</div>
</article>
<article>
<div id="cart">
<h1 class="ui-widget-header">Shopping Cart</h1>
<div class="ui-widget-content">
<ol id="dvjhPanierList">
<li class="placeholder">Add your items here</li>
</ol>
</div>
</div>
</article>
<article>
<p>
<button id="btnArticleUniquePanier">Pas d'article en double dans le Panier</button>
</p>
<p>
<button id="btnContenuPanier">Contenu du Panier</button>
</p>
<p>
<button id="btnVidePanier">Vide le Panier</button>
</p>
</article>
</section>
</section>
<footer itemscope itemtype="http://data-vocabulary.org/Person">
<time datetime="2011-09-08T01:05:00.000+02:00" pubdate>2011-09-07</time>
<span itemprop="name">Daniel Hagnoul</span>
<a href="http://www.developpez.net/forums/u285162/danielhagnoul/" itemprop="url">@danielhagnoul</a>
</footer>
<script charset="utf-8" src="http://code.jquery.com/jquery-1.6.3.min.js"></script>
<script charset="utf-8" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/i18n/jquery-ui-i18n.min.js"></script>
<script charset="utf-8" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js"></script>
<script charset="utf-8" src="http://danielhagnoul.developpez.com/lib/jPicker/jpicker-1.1.6.min.js"></script>
<script>
$(function(){
/* -- */
$( "#catalog" ).accordion();
$( "#catalog li" ).draggable({
appendTo: "body",
helper: "clone"
});
$( "#cart ol" ).droppable({
activeClass: "ui-state-default",
hoverClass: "ui-state-hover",
accept: ":not(.ui-sortable-helper)",
drop: function( event, ui ) {
var str = ui.draggable.text();
// traitement du cas "Select All"
if (str.localeCompare("Select All") != 0){
$( this ).find( ".placeholder" ).remove();
$( "<li></li>" ).text( str ).appendTo( this );
}
}
}).sortable({
items: "li:not(.placeholder)",
sort: function() {
// gets added unintentionally by droppable interacting with sortable
// using connectWithSortable fixes this, but doesn't allow you to customize active/hoverClass options
$( this ).removeClass( "ui-state-default" );
}
});
var objPanier = $("#dvjhPanierList");
// contenu du panier
$("#btnContenuPanier").click(function(){
// tab est un array
var tab = objPanier.children("li").map(function(i, item){
return $(item).text();
}).get();
console.log(tab.join(" | "));
});
// vide le panier
$("#btnVidePanier").click(function(){
objPanier.html('<li class="placeholder">Add your items here</li>');
});
// voir : http://www.developpez.net/forums/d1091953/webmasters-developpement-web/contribuez/suppression-multiples-tableau-array-alphanumerique/
function dvjhUnique(tab){
// SpaceFrog
function replaceSpec(Texte){
var TabSpec = {"à":"a","á":"a","â":"a","ã":"a","ä":"a","å":"a","ò":"o","ó":"o","ô":"o","õ":"o","ö":"o","ø":"o","è":"e","é":"e","ê":"e","ë":"e","ç":"c","ì":"i","í":"i","î":"i","ï":"i","ù":"u","ú":"u","û":"u","ü":"u","ÿ":"y","ñ":"n","-":" ","_":" "},
reg=/[àáâãäåòóôõöøèéêëçìíîïùúûüÿñ_-]/gi;
return Texte.replace(reg, function(){
return TabSpec[arguments[0].toLowerCase()];
}).toLowerCase();
}
// danielhagnoul
tab.sort(function(a, b){
var x = parseInt(a, 10),
y = parseInt(b, 10),
c1 = replaceSpec(String(a)),
c2 = replaceSpec(String(b));
if (isNaN(x) || isNaN(y)){
if (c1 > c2){
return 1;
} else if(c1 < c2){
return -1;
} else {
return 0;
}
} else {
return(x - y);
}
});
var i = tab.length;
while(i-- > 1){
if (tab[i] == tab[i - 1]){
tab.splice(i, 1);
}
};
}
// Article unique, élimine les doublons
$("#btnArticleUniquePanier").click(function(){
// tab est un array
var tab = objPanier.children("li").map(function(i, item){
return $(item).text();
}).get();
dvjhUnique(tab);
objPanier.empty();
for (var i in tab){
$( "<li></li>" ).text( tab[i] ).appendTo( objPanier );
}
});
// traitement des dvjhSelectAllID
$("[id^='dvjhSelectAllID']").click(function(){
objPanier.find( ".placeholder" ).remove();
$(this).parents("ul").children("li").map(function(i, item){
if (i > 0){
$( "<li></li>" ).text( $(item).text() ).appendTo( objPanier );
}
});
});
/* jPicker : http://www.digitalmagicpro.com/jPicker/, outil pour choisir rapidement une couleur */
$.fn.jPicker.defaults.images.clientPath="http://danielhagnoul.developpez.com/lib/jPicker/images/";
$(".conteneur").jPicker({window:{expandable:true,title:"jPicker : choissisez une couleur :",
alphaSupport:true,position:{x:'screenCenter',y:'top'}},color:{ active:new $.jPicker.Color({ r: 210, g: 214, b: 98, a: 128 })}},
function(color, context){var c = color.val("all");if (c){$("body").css("backgroundColor", "rgba(" +
c.r + "," + c.g + "," + c.b + "," + (c.a/255).toFixed(2) + ")");}});
});
</script>
</body>
</html> |
Partager