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
| <!doctype html>
<html lang="fr">
<head>
<meta charset="utf-8">
<meta name="Author" content="Daniel Hagnoul">
<title>Forum jQuery</title>
<style>
/* BASE */
body {
background-color:#dcdcdc;
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:serif;
}
div,p,h1,h2,h3,h4,h5,h6,ul,ol,dl,form,table,img {
margin:0px;
padding:0px;
}
p {
padding:6px;
}
ul,ol,dl {
list-style:none;
padding-left:6px;
padding-top:6px;
}
li {
padding-bottom:6px;
}
/* dvjh */
h1 {
text-align:center;
font-style:italic;
text-shadow: 4px 4px 4px #bbbbbb;
}
h2 {
text-align:center;
}
div#conteneur {
width:95%;
height:auto;
margin:12px auto;
padding:6px;
background-color:#FFFFFF;
color:#000000;
border:1px solid #666666;
}
div#affiche {
clear:both;
margin:12px;
padding:6px;
border:1px solid #999999;
background-color:#FFFFFF;
color:#000000;
}
/* TEST */
.building {
float:left;
top:12px;
left:12px;
width:100px;
height:100px;
margin:12px;
padding:6px;
border:1px solid gray;
}
</style>
<script charset="utf-8" src="../lib/jqueryui/js/jquery-1.4.2.min.js"></script>
<script>
(function($) {
$.fn.building = function(options){
var opts = $.extend({}, $.fn.building.defaults, options);
return this.each(function(i, item){
var obj = $(item);
opts.largeur += i * 50;
$.each(opts, function(key, value) {
obj.data(key, value);
});
/*
* Attention, après cette ligne :
* 1) on ne doit plus manipuler ou modifier opts.
* 2) obj.data(), get et set.
*
* Si l'on ne respecte pas cette règle, il y
* aura des confusions du genre : "j'ai modifié
* opts.largeur mais il n'en tient pas compte" !
*/
trace();
obj.bind("trace.building", function(){
trace();
});
obj.bind("zoom.building", function(event, factor){
obj.data("largeur", obj.data("largeur") * factor);
obj.data("hauteur", obj.data("hauteur") * factor);
trace();
});
function trace(){
obj.css({
width: obj.data("largeur") + "px",
height: obj.data("hauteur") + "px"
});
}
});
};
$.fn.building.defaults = {
"nom": "",
"longueur": 0,
"largeur": 0,
"hauteur": 0,
"direction": "landscape",
"draggable" : "false"
};
})(jQuery);
function dimensions(){
var tab = [];
tab.push("<p>Les nouvelles dimensions :</p>");
$("div.building").each(function(i, item){
tab.push("<p>div.building[" + i + "], largeur = " + $(item).data("largeur") + "</p>");
tab.push("<p>div.building[" + i + "], hauteur = " + $(item).data("hauteur") + "</p>");
});
tab.push("<p> ---------------- </p>");
$("#affiche").prepend(tab.join(""));
}
$(function(){
$("div.building").building({
"largeur": 100,
"hauteur": 100
}).css("color","grey");
$("#btnData").click(function(){
// on modifient toutes les hauteur
$("div.building").data("hauteur", 150);
// on modifie le deuxième élément de la sélection
$("div.building").eq(1).data("hauteur", 200);
// on trace
$("div.building").trigger("trace.building");
dimensions();
});
$("#btnZoom").click(function(){
// zoom d'un facteur 0.5
$("div.building").trigger("zoom.building", 0.5);
dimensions();
});
});
</script>
</head>
<body>
<h1>Forum jQuery</h1>
<div id="conteneur">
<div class="building">
<p>Un mot pour remplir</p>
</div>
<div class="building">
<p>Un mot pour remplir</p>
</div>
<div class="building">
<p>Un mot pour remplir</p>
</div>
<div id="affiche"></div>
<p style="text-align:center;"><button id="btnData">Data</button> <button id="btnZoom">Zoom</button></p>
</div>
</body>
</html> |