Bonjour,
je souhaite créer un système d'onglets, et j'en suis au redimensionnement des onglets lorsqu'on redimensionne la fenêtre. J'avance bien mais j'ai un problème : lorsque je réduis de trop, j'ai mon code qui fait n'importe quoi, qui freeze etc.
J'ai semi-adapté le code en version html sans ajax sql pour que vous puissiez voir le problème (qui visiblement se trouve à la fonction increaseStringMoreAsPossible). N'hésitez pas à la copiez et le tester pour voir.
Merci d'avance
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402 <html> <head> <title>Dashboard</title> <meta charset="utf-8"> <link rel="stylesheet" href="http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css"> <script src="http://code.jquery.com/jquery-1.10.2.js"></script> <script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script> <style> #bodyOverlayed{ background-color: #a1a1a1; } .dashboard{ width: 92%; height: 100%; border : 1px solid black; } #dashboard_menu{ display: inline; } #info{ position: fixed; top: 0; left: 92%; } .widget{ position : absolute; padding: 3px; border: 1px solid black; transition : 500ms easeout; } .widget:hover{ border: 2px dotted #00F; } #widget1{ width: 500px; height: 200px; background-color: transparent; } .xpos{ display: inline; } .ypos{ display: inline; } #draggable { width: 150px; height: 150px; padding: 0.5em; } .ui-resizable-helper { border: 2px dotted #00F; } .widget_title{ font-size: 12px; font-weight : bold; } .removed{ display: none; } .menuB{ width: 65%; margin: 3px; } #info{ border : 1px solid brown; padding: 3px; margin: 3px; } #overlay { visibility: hidden; position: absolute; left: 0px; top: 0px; width:100%; height:100%; text-align:center; z-index: 1000; } .popupContent{ width:300px; margin: 100px auto; background-color: #fff; border:1px solid #000; padding:15px; text-align:center; } .onglet { display:inline-block; margin-left:3px; margin-right:3px; padding:3px; border:1px solid black; cursor:pointer; border-top-left-radius: 20px; border-top-right-radius: 20px; color: white; font-weight : bold; transition: 200ms; } .onglet_0 { background:#474747; border-bottom:1px solid black; z-index: 0; } .onglet_0:hover{ background:#737373; border: 1px solid yellow; } .onglet_0:active{ z-index: 50; } .onglet_1:focus{ z-index: 25; } .onglet_1 { background:#737373; border-bottom:0px solid black; padding-bottom:4px; z-index: 25; } .onglet_1:hover { border: 1px solid yellow; } .contenu_onglet { background-color:#dddddd; border:1px solid black; margin-top:-1px; padding:5px; display:none; margin-left: 10px; margin-right: 10px; } </style> </head> <body onload="initiate()"> <div id="overlay"> <div class="popupContent"> <a href="#" onclick="overlay()">X</a> <div id="addWidget"> </div> </div> </div> <div class="systeme_onglets"> <div class="onglets"> <span class="onglet_1 onglet" id="onglet_dashboard_1" onclick="change_onglet("dashboard_1");" data-name="Dashboard::de::Nagiosadmin">Dashboard de ...</span><span class="onglet_0 onglet" id="onglet_dashboard_35" onclick="change_onglet("dashboard_35");" data-name="Etat::d'ASQL">Etat d'ASQ...</span><span class="onglet_0 onglet" id="onglet_dashboard_36" onclick="change_onglet("dashboard_36");" data-name="ar">ar</span><span class="onglet_0 onglet" id="onglet_dashboard_37" onclick="change_onglet("dashboard_37");" data-name="arez">arez</span><span class="onglet_0 onglet" id="onglet_dashboard_38" onclick="change_onglet("dashboard_38");" data-name="arezze">arezze</span><span class="onglet_0 onglet" id="onglet_dashboard_39" onclick="change_onglet("dashboard_39");" data-name="arezzea">arezzea</span><span class="onglet_0 onglet" id="onglet_dashboard_40" onclick="change_onglet("dashboard_40");" data-name="hj">hj</span><span class="onglet_0 onglet" id="onglet_dashboard_41" onclick="change_onglet("dashboard_41");" data-name="hjsd5sd5s4ds5d4s5d4s5">hjsd5sd5s4d...</span><span class="onglet_0 onglet" id="onglet_dashboard_42" onclick="change_onglet("dashboard_42");" data-name="dsdsd">dsdsd</span><span class="onglet_0 onglet" id="onglet_dashboard_43" onclick="change_onglet("dashboard_43");" data-name="iik">iik</span><span class="onglet_0 onglet" id="onglet_dashboard_44" onclick="change_onglet("dashboard_44");" data-name="iikzdzd">iikzdzd</span><span class="onglet_0 onglet" id="onglet_dashboard_46" onclick="change_onglet("dashboard_46");" data-name="iikzdzdwxccsdss">iikzdzdwxcc...</span><span class="onglet_0 onglet" id="onglet_dashboard_47" onclick="change_onglet("dashboard_47");" data-name="zeeffddfdffffd">zeeffddfdff...</span><span class="onglet_0 onglet" id="onglet_dashboard_49" onclick="change_onglet("dashboard_49");" data-name="sdfsfdfefefefdcv">sdfsfdfefef...</span><span class="onglet_0 onglet" id="onglet_dashboard_50" onclick="change_onglet("dashboard_50");" data-name="zdzdzds">zdzdzds</span><span class="onglet_0 onglet" id="onglet_dashboard_51" onclick="change_onglet("dashboard_51");" data-name="fbfb">fbfb</span><span class="onglet_0 onglet" id="onglet_dashboard_add" onclick="overlayDashboard()" style="width: 30px; text-align : center">+</span> </div> <div class="contenu_onglets"> <div class="dashboard" id="contenu_onglet_dashboard_1" style="display: block;" data-toggle="context" data-target="#context-menu"> <input type="hidden" value="1" id="dashboardId"> <div class="widget" id="widget0" style="z-index: 0; top: 241px; left: 453px; width: 249px;"> <input type="hidden" value="9" id="widgetId"> <div id="jscriptInclude0"> <h1 class="widget_title">Host Performance for Nagios</h1> <a href="/pnp4nagios/graph?host=Nagios&srv=_HOST_"><img src="/pnp4nagios/image?host=Nagios&srv=_HOST_" title="View Detailed _HOST_ Performance Graph" width="100%"></a> </div> </div> <div class="widget" id="widget1" style="z-index: 1; top: 241px; left: 13px; width: 391px;"> <input type="hidden" value="52" id="widgetId"> <div id="jscriptInclude1"> <h1 class="widget_title">DNS secondary - Resolution Service Performance for 3dx-us.com</h1> <a href="/pnp4nagios/graph?host=3dx-us.com&srv=DNS secondary - Resolution"><img src="/pnp4nagios/image?host=3dx-us.com&srv=DNS secondary - Resolution" title="View Detailed DNS secondary - Resolution Performance Graph" width="100%"></a> </div> </div> <div class="widget" id="widget2" style="z-index: 2; top: 61px; left: 84px; width: 313px;"> <input type="hidden" value="67" id="widgetId"> <div id="jscriptInclude2"> <h1 class="widget_title">Time delay Service Performance for ADC</h1> <a href="/pnp4nagios/graph?host=ADC&srv=Time delay"><img src="/pnp4nagios/image?host=ADC&srv=Time delay" title="View Detailed Time delay Performance Graph" width="100%"></a> </div> </div> <div class="widget" id="widget3" style="z-index: 3; top: 48px; left: 422px; width: 341px;"> <input type="hidden" value="69" id="widgetId"> <div id="jscriptInclude3"> <h1 class="widget_title">Time delay Service Performance for AESX4</h1> <a href="/pnp4nagios/graph?host=AESX4&srv=Time delay"><img src="/pnp4nagios/image?host=AESX4&srv=Time delay" title="View Detailed Time delay Performance Graph" width="100%"></a> </div> </div> </div> <div class="dashboard" id="contenu_onglet_dashboard_35" style="display: none;" data-toggle="context" data-target="#context-menu"> <input type="hidden" value="35" id="dashboardId"> <div class="widget" id="widget0" style="z-index: 0; top: 29px; left: 7px; width: 427px;"> <input type="hidden" value="72" id="widgetId"> <div id="jscriptInclude0"> <h1 class="widget_title">Time delay Service Performance for ASQL</h1> <a href="/pnp4nagios/graph?host=ASQL&srv=Time delay"><img src="/pnp4nagios/image?host=ASQL&srv=Time delay" title="View Detailed Time delay Performance Graph" width="100%"></a> </div> </div> <div class="widget" id="widget1" style="z-index: 1; top: 221px; left: 6px; width: 420px;"> <input type="hidden" value="73" id="widgetId"> <div id="jscriptInclude1"> <h1 class="widget_title">CPU Usage Service Performance for ASQL</h1> <a href="/pnp4nagios/graph?host=ASQL&srv=CPU Usage"><img src="/pnp4nagios/image?host=ASQL&srv=CPU Usage" title="View Detailed CPU Usage Performance Graph" width="100%"></a> </div> </div> <div class="widget" id="widget2" style="z-index: 2; top: 31px; left: 451px; width: 366px;"> <input type="hidden" value="74" id="widgetId"> <div id="jscriptInclude2"> <h1 class="widget_title">Memory Usage Service Performance for ASQL</h1> <a href="/pnp4nagios/graph?host=ASQL&srv=Memory Usage"><img src="/pnp4nagios/image?host=ASQL&srv=Memory Usage" title="View Detailed Memory Usage Performance Graph" width="100%"></a> </div> </div> <div class="widget" id="widget3" style="z-index: 3; top: 440px; left: 7px; width: 368px;"> <input type="hidden" value="75" id="widgetId"> <div id="jscriptInclude3"> <h1 class="widget_title">Drive D: Disk Usage Service Performance for ASQL</h1> <a href="/pnp4nagios/graph?host=ASQL&srv=Drive D: Disk Usage"><img src="/pnp4nagios/image?host=ASQL&srv=Drive D: Disk Usage" title="View Detailed Drive D: Disk Usage Performance Graph" width="100%"></a> </div> </div> <div class="widget" id="widget4" style="z-index: 4; top: 439px; left: 378px; width: 357px;"> <input type="hidden" value="76" id="widgetId"> <div id="jscriptInclude4"> <h1 class="widget_title">Drive E: Disk Usage Service Performance for ASQL</h1> <a href="/pnp4nagios/graph?host=ASQL&srv=Drive E: Disk Usage"><img src="/pnp4nagios/image?host=ASQL&srv=Drive E: Disk Usage" title="View Detailed Drive E: Disk Usage Performance Graph" width="100%"></a> </div> </div> <div class="widget" id="widget5" style="z-index: 5; top: 35px; left: 863px; width: 348px;"> <input type="hidden" value="77" id="widgetId"> <div id="jscriptInclude5"> <h1 class="widget_title">Page reads/s Service Performance for ASQL</h1> <a href="/pnp4nagios/graph?host=ASQL&srv=Page reads/s"><img src="/pnp4nagios/image?host=ASQL&srv=Page reads/s" title="View Detailed Page reads/s Performance Graph" width="100%"></a> </div> </div> <div class="widget" id="widget6" style="z-index: 6; top: 233px; left: 455px; width: 406px;"> <input type="hidden" value="78" id="widgetId"> <div id="jscriptInclude6"> <h1 class="widget_title">Average Wait Time Service Performance for ASQL</h1> <a href="/pnp4nagios/graph?host=ASQL&srv=Average Wait Time"><img src="/pnp4nagios/image?host=ASQL&srv=Average Wait Time" title="View Detailed Average Wait Time Performance Graph" width="100%"></a> </div> </div> </div> <div class="dashboard" id="contenu_onglet_dashboard_36" style="display: none;" data-toggle="context" data-target="#context-menu"><input type="hidden" value="36" id="dashboardId"></div> <div class="dashboard" id="contenu_onglet_dashboard_37" style="display: none;" data-toggle="context" data-target="#context-menu"><input type="hidden" value="37" id="dashboardId"></div> <div class="dashboard" id="contenu_onglet_dashboard_38" style="display: none;" data-toggle="context" data-target="#context-menu"><input type="hidden" value="38" id="dashboardId"></div> <div class="dashboard" id="contenu_onglet_dashboard_39" style="display: none;" data-toggle="context" data-target="#context-menu"><input type="hidden" value="39" id="dashboardId"></div> <div class="dashboard" id="contenu_onglet_dashboard_40" style="display: none;" data-toggle="context" data-target="#context-menu"><input type="hidden" value="40" id="dashboardId"></div> <div class="dashboard" id="contenu_onglet_dashboard_41" style="display: none;" data-toggle="context" data-target="#context-menu"><input type="hidden" value="41" id="dashboardId"></div> <div class="dashboard" id="contenu_onglet_dashboard_42" style="display: none;" data-toggle="context" data-target="#context-menu"><input type="hidden" value="42" id="dashboardId"></div> <div class="dashboard" id="contenu_onglet_dashboard_43" style="display: none;" data-toggle="context" data-target="#context-menu"><input type="hidden" value="43" id="dashboardId"></div> <div class="dashboard" id="contenu_onglet_dashboard_44" style="display: none;" data-toggle="context" data-target="#context-menu"><input type="hidden" value="44" id="dashboardId"></div> <div class="dashboard" id="contenu_onglet_dashboard_46" style="display: none;" data-toggle="context" data-target="#context-menu"><input type="hidden" value="46" id="dashboardId"></div> <div class="dashboard" id="contenu_onglet_dashboard_47" style="display: none;" data-toggle="context" data-target="#context-menu"><input type="hidden" value="47" id="dashboardId"></div> <div class="dashboard" id="contenu_onglet_dashboard_49" style="display: none;" data-toggle="context" data-target="#context-menu"><input type="hidden" value="49" id="dashboardId"></div> <div class="dashboard" id="contenu_onglet_dashboard_50" style="display: none;" data-toggle="context" data-target="#context-menu"><input type="hidden" value="50" id="dashboardId"></div> <div class="dashboard" id="contenu_onglet_dashboard_51" style="display: none;" data-toggle="context" data-target="#context-menu"><input type="hidden" value="51" id="dashboardId"></div> </div> </div> <script type="text/javascript"> //<!-- var anc_onglet; function menu(id){ if(id == 1){ overlay(); }else if(id == 2){ setAllWidget() }else if(id == 3){ setAllWidgetForDelete(); } } function change_onglet(name) { if(typeof anc_onglet == "undefined"){ document.getElementById('onglet_'+name).className = 'onglet_1 onglet'; $('.dashboard').each.style.display = 'none'; document.getElementById('contenu_onglet_'+name).style.display = 'block'; anc_onglet = name; } else { document.getElementById('onglet_'+anc_onglet).className = 'onglet_0 onglet'; document.getElementById('onglet_'+name).className = 'onglet_1 onglet'; document.getElementById('contenu_onglet_'+anc_onglet).style.display = 'none'; document.getElementById('contenu_onglet_'+name).style.display = 'block'; anc_onglet = name; var id = name.split("_"); console.log("Opened tab : "+id[1]) updatePosition(id[1]); } } function reduceString(s){ var retour = ""; if(s.length > $(".contenu_onglets").data("string_size")){ for(var i = 0; i< $(".contenu_onglets").data("string_size"); i++){ retour = retour+s.charAt(i); } }else{return s} retour = retour+"..." console.log("[DECREASE MODE] Now, we have "+ retour); return retour; } function increaseString(obj){ // permet d'ajouter 1 caractère à l'element envoyé var retour = ""; var source = transformWithSpace($(".onglets .onglet:nth-child("+obj+")").data("name")); var s = $(".onglets .onglet:nth-child("+obj+")").html(); var taille = s.length console.log("[INCREASE MODE] Will add 1 char to "+ s ); for(var i = 0; i< taille-2; i++){ retour = retour+transformWithSpace(source).charAt(i); } if(virtualizeSpace(s) != source){ retour = retour+"..." } console.log("[INCREASE MODE] Now, we have "+ retour); return retour; } function increaseStringMoreAsPossible(){ var ancienneChaine; var updatedString var numberChild = $(".onglets").children().length; var currentChild = 1; var lastModifAt = 0; var modified = false; var flag = true; console.log($(".onglets .onglet:nth-child(1)").html()); while(flag){ if($(".onglets .onglet:nth-child("+currentChild+")").html() != $(".onglets .onglet:nth-child("+currentChild+")").data("name")){ //Si la chaine courante peut être incrémentée de 1 updatedString = increaseString(currentChild) $(".onglets .onglet:nth-child("+currentChild+")").html(updatedString) ; lastModifAt = currentChild; // On enregistre la position de modification modified = true } if(OngletPlusGrand && modified == false){ //Si les onglets dépassent, on annule et on sort updatedString = reduceString($(".onglets .onglet:nth-child("+currentChild+")").html()) $(".onglets .onglet:nth-child("+currentChild+")").html(updatedString); flag = false; } if(currentChild == numberChild && flag == true){ // on change d'element currentChild = 1; }else { currentChild++; } if(currentChild == lastModifAt && flag == true){ //Si on a effectué un tour sans modification, on doit sortir, car on ne peut plus modifier les chaines flag = false; } modified = false } } function reduceAllString(){ var chaine; $(".onglet").each(function(){ chaine = $(this).html() $(this).html(reduceString(chaine)); }) } function OngletPlusGrand(){ //indique si la taille de la barre d'onglets et superieur à la taille du dashboard var widthDiv = $(".dashboard:first").width(); var widthOnglet = 0; $(".onglet").each(function(){ widthOnglet = widthOnglet+$(this).outerWidth( true ); }) $(".contenu_onglets").data("widthOnglet", widthOnglet) $(".contenu_onglets").data("widthDiv", widthDiv) if(widthDiv >= widthOnglet){ console.log("ON PEUT AUGMENTER") return false } else{ console.log("ON DOIT REDUIRE") return true; } } function adaptOnglet(){ while(OngletPlusGrand()){ $(".contenu_onglets").data("string_size", $(".contenu_onglets").data("string_size") - 1) reduceAllString(); } increaseStringMoreAsPossible(); } function virtualizeSpace(s){ return s.replace(/ /g, "::"); } function transformWithSpace(s){ return s.replace(/::/g, " "); } $( window ).resize(function() { adaptOnglet(); }); </script> </body> </html>
Partager