Bonjour à tous,
j'ai un calendrier qui fonctionne trés bien en javascript et css mais il lui manque juste une chose que j'aimerais améliorer, c'est de pourvoir avoir la date du jour en rouge au demarrage du calendrier mais je n'y arrive pas. Je suis pas assez pechu en javasript pour cà.
Pourriez-vous me donner un coup de main?
Voulez mes deux codes
calendrier css
et le calendrier.js
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 /* jours pour Netscape */ .NSday { font-family: Arial,Helvetica,sans-serif; font-weight: bold; font-size: 12px; color: #0000cc; text-decoration: none; } /* tableau des jours */ .Gtab { font-family: Arial,Helvetica,sans-serif; font-weight: normal; font-size: 12px; text-decoration: none; border: solid 1px #000000; background: #6699FF; width: 152px; } /* champs texte */ .Gname { font-family: Arial,Helvetica,sans-serif; font-weight: bold; font-size: 12px; color: #ffffff; text-decoration: none; } /* champs texte */ .Gtxt { font-family: Arial,Helvetica,sans-serif; font-weight: normal; font-size: 12px; color: #6c628a; text-decoration: none; margin-left: 0px; } /* en-tete semaine */ .Gh1, .Gh2, .Gh3, .Gh4, .Gh5 { width: 20px; height: 16px; font-size: 12px; background: #6699FF; border: solid 1px #6699FF; font-family: Arial,Helvetica,sans-serif; font-weight: bold; color: #ffffff; text-align: center; line-height: 16px; } .Gh0, .Gh6 { width: 20px; font-size: 12px; height: 16px; border: solid 1px #b9c0d9; background: #b9c0d9; font-family: Arial,Helvetica,sans-serif; font-weight: bold; color: #ffffff; text-align: center; line-height: 16px; } .Gfree { width: 20px; height: 16px; background: #6699FF; border: solid 1px #ffffff; font-family: Arial,Helvetica,sans-serif; font-weight: normal; padding: 0px; margin: 0px; color: #000000; text-align: center; cursor: pointer; line-height: 16px; } .Gfreeon { width: 20px; height: 16px; background: #b9c0d9; border: solid 1px #000000; font-family: Arial,Helvetica,sans-serif; font-weight: normal; padding: 0px; margin: 0px; color: #000000; text-align: center; cursor: pointer; line-height: 16px; } .Gc1, .Gc2, .Gc3, .Gc4, .Gc5 { width: 20px; height: 16px; background: #6699FF; border: solid 1px #6699FF; font-family: Arial,Helvetica,sans-serif; font-weight: normal; padding: 0px; margin: 0px; color: #000000; text-align: center; cursor: default; line-height: 16px; } .Gc1on, .Gc2on, .Gc3on, .Gc4on, .Gc5on { width: 20px; height: 16px; background: #6699FF; border: solid 1px #ffffff; font-family: Arial,Helvetica,sans-serif; font-weight: normal; padding: 0px; margin: 0px; color: #ffffff; text-align: center; cursor: pointer; line-height: 16px; } .Gc0, .Gc6 { width: 20px; height: 16px; border: solid 1px #b9c0d9; background: #b9c0d9; font-family: Arial, Helvetica, sans-serif; font-weight: normal; padding: 0px; margin: 0px; color: #000000; text-align: center; cursor: default; line-height: 16px; } .Gc0on, .Gc6on { width: 20px; height: 16px; border: solid 1px #ffffff; background: #b9c0d9; font-family: Arial, Helvetica, sans-serif; font-weight: normal; padding: 0px; margin: 0px; color: #ffffff; text-align: center; cursor: pointer; line-height: 16px; }
Merci d'avance et bon courage à tous
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
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537 function calendrier(n, min, max) { this.target= null; this.name = new String(n); this.tag = new String(); this.title = new String(""); this.date=new Date(); this.moving = new Boolean(false); this.vis = new Boolean(false); this.free = new Boolean(false); this.curYear = new Number(this.date.getFullYear()); this.maxYear = new Number(this.curYear+max); this.minYear = new Number(this.curYear-min); this.curMonth= new Number(this.date.getMonth()); /* * calendrier.setFree(Boolean vis) * affiche ou non des jours feries */ this.setFree=function(vis) { this.free=vis; if(this.vis==true) this.show(); return; } /* * calendrier.IsDragable(Boolean drag) * active/desactive l'option drag&drop */ this.isDragable=function(drag) { if(drag==true && !document.layers) { document.onmousemove=this.getMouse; document.getElementById(this.div).root=this; document.getElementById(this.div).onmousedown=this.startMove; document.getElementById(this.div).onmouseup=this.endMove; } return; } /* * calendrier.startMove() * initialise le drag & drop */ this.startMove=function(evt) { var event; var tmp; if(this.root.vis!=true) return; if(document.all) { event = window.event; tmp = event.srcElement; if(!tmp.form) { this.root.fixX = tmp.offsetLeft+event.offsetX; this.root.fixY = event.offsetY; while(tmp.parentElement!=document.getElementById(this.root.div) && tmp.parentElement!=null ) { this.root.fixX += tmp.parentElement.offsetLeft; this.root.fixY += tmp.parentElement.offsetTop; tmp = tmp.parentElement; } this.root.moving=true; self.movingCalendar = this.root; } } else { event = evt; tmp = event.target; if( !tmp.form && tmp.tagName!="SELECT" && tmp.tagName!="OPTION" && tmp.tagName!="scrollbar" ) { this.root.fixX = event.layerX; this.root.fixY = event.layerY; this.root.moving=true; self.movingCalendar = this.root; } } return evt; } /* * calendrier.endMove() * termine le drag & drop */ this.endMove=function() { if(self.movingCalendar!=null) { self.movingCalendar.moving=false; } return false; } /* * calendrier.getMouse(Event evt) * change la liste des jours feriés jours feries */ this.getMouse=function(evt) { var event; if(document.all) { event = window.event; var scrollObj = (document.documentElement) ? document.documentElement : document.body; this.posX = self.event.clientX+scrollObj.scrollLeft; this.posY = self.event.clientY+scrollObj.scrollTop; } else { event = evt; this.posX = evt.pageX ; this.posY = evt.pageY ; } if(self.movingCalendar!=null) { if(self.movingCalendar.moving==true && self.movingCalendar.vis==true ) self.movingCalendar.move(this.posY-self.movingCalendar.fixY, this.posX-self.movingCalendar.fixX); } return false; } /* * calendrier.move(Number x, Number y) * déplace le calendrier */ this.move=function(x, y) { if(!document.layers) { document.getElementById(this.div).style.top = x+"px"; document.getElementById(this.div).style.left = y+"px"; } return false; } /* * calendrier.setFreeDay(Array fd) * change la liste des jours feriés jours feries */ this.setFreeDay=function(fd) { this.freeday.length=0; for(var i=0; i<fd.length; i++) this.freeday[i] = new String(fd[i]); if(this.vis==true) this.show(); return; } /* * calendrier.isFreeDay(d,m) * true si jour ferié */ this.isFreeDay=function(d,m) { var tmp = this.checkDate(d)+"-"+this.checkDate(parseInt(m)+1); if(this.free==false) return false; for(var i=0; i<this.freeday.length; i++) if( tmp == this.freeday[i]) return true; return false; } /* * calendrier.setTitle(t) * change le titre du calendrier */ this.setTitle=function(t) { this.title = t; if(this.vis==true) this.show(); return; } /* * calendrier.mList() * retourne la liste des mois */ this.mList=function() { var tmp = "<table border='0' cellpadding='0' cellspacing='0' class='Gtab'>"; tmp += "<tr><td align='center' colspan='2' class='Gname'>"; if(document.layers) { tmp += "<table width='100%'>"; tmp += "<tr>"; tmp += "<td class='Gname' align='center'>"+this.title+"</td>"; tmp += "<td><a href='javascript://' onclick='"+this.name+".hide();' class='Gname'>X</a></td>"; tmp += "</tr>"; tmp += "</table>"; } else { tmp += "<span style='float:left; text-indent:20px;'>"+this.title+"</span>"; tmp += "<span style='float:right;'>"; tmp += "<a href='javascript://' onclick='"+this.name+".hide();' class='Gname'>X</a>"; tmp += "</span>"; } tmp += "</td></tr>"; tmp += "<tr>"; tmp += "<td class='Gtxt'><select name='"+this.name+"month' class='Gtxt' "; tmp += "onchange='"+this.name+".setMonth(this[this.selectedIndex].value)' >\n"; for(var i=0; i<this.month.length; i++) { tmp += "<option value='"+i+"'"; if(this.curMonth==i) tmp += " selected"; tmp += ">"+ this.month[i] +"</option>\n"; } tmp += "</select></td><td class='Gtxt'>\n"; tmp += this.yList(); tmp += "</td></tr></table>"; tmp += this.dList(); return tmp; } /* * calendrier.yList() * retourne la liste des années */ this.yList=function() { var tmp = "<select name='"+this.name+"year' class='Gtxt' "; tmp += "onchange='"+this.name+".setYear(this[this.selectedIndex].value);' >\n"; for(var i=this.minYear; i<=this.maxYear; i+=1) { tmp += "<option value='"+i+"'"; if(this.curYear==i) tmp += " selected"; tmp += ">"+ i +"</option>\n"; } tmp += "</select>\n"; return tmp; } this.dayCell=function(d,n) { var tmp = new String(""); if(this.isFreeDay(d,this.curMonth)) tmp += "<td class='Gfree'"; else tmp += "<td class='Gc"+n+"'"; if(!document.layers) { tmp += "title='"+this.checkDate(d)+" "+this.month[this.curMonth]+" "+this.curYear+"'"; tmp += " onmousedown='"+this.name+".getDate(\""; tmp += this.checkDate(d)+"-"; tmp += this.checkDate(1+parseInt(this.curMonth))+"-"; tmp += this.curYear+"\""; tmp += ");' "; tmp += " onmouseover='this.className=this.className+\"on\";' "; tmp += " onmouseout='this.className= this.className.substring(0,this.className.indexOf(\"on\"));'"; } else tmp += " width='22' height='16' "; tmp += ">"; return tmp; } /* * calendrier.dList() * retourne le tableau des jours */ this.dList=function() { var cur=new Number(1); var tmpDate = new Date(); var tmp = new String("<table border='0' cellpadding='0' cellspacing='0' class='Gtab'>"); tmpDate.setDate(cur); tmpDate.setMonth(this.curMonth); tmpDate.setFullYear(this.curYear); tmp += "<tr>\n"; for(var i=1; i<this.day.length; i++) tmp += "<td class='Gh"+i+"'>"+ this.day[i] +"</td>\n"; tmp += "<td class='Gh0'>"+ this.day[0] +"</td>\n"; tmp += "</tr>\n"; for(var j=0; j<6; j++) { tmp += "<tr>\n"; for(var i=1; i<this.day.length; i++) { tmpDate.setDate(cur); if( cur<=31 && i==tmpDate.getDay() && this.curMonth==tmpDate.getMonth()) { tmp += this.dayCell(cur,i); tmp += this.getLink(cur); cur+=1; } else { tmp += "<td class='Gc"+i+"'"; tmp += "> "; } tmp += "</td>\n"; tmpDate.setDate(cur); } if( cur==tmpDate.getDate() && this.curMonth==tmpDate.getMonth()) { tmp += this.dayCell(cur,0); tmp += this.getLink(cur); cur+=1; } else { tmp += "<td class='Gc0'"; tmp += "> "; } tmp += "</td>\n</tr>\n"; } tmp += "</table>\n"; return tmp; } /* * calendrier.getLink(c) * retourne la balise d'un lien */ this.getLink = function(c) { var tmp = new String(""); if(document.layers) { tmp = "<a href='javascript://' "; tmp += "onclick='"+this.name+".getDate(\""; tmp += this.checkDate(d)+"-"; tmp += this.checkDate(1+parseInt(this.curMonth))+"-"; tmp += this.curYear+"\""; tmp += ");' class='NSday'>"+(c)+"</a>"; } else { tmp = (c); } return tmp; } /* * calendrier.setMonth( Integer m ) * modifie le mois à afficher */ this.setMonth = function(m) { this.curMonth = m; this.show(); return; } /* * calendrier.getYear( Integer y ) * modifie l'année à afficher */ this.getYear = function (y) { if(document.layers) { for(var i=0; i<document.layers[this.div].document.forms[this.name+"_form"][this.name+"year"].length; i++) { if(document.layers[this.div].document.forms[this.name+"_form"][this.name+"year"][i].value==y) { document.layers[this.div].document.forms[this.name+"_form"][this.name+"year"].selectedIndex=i; this.setYear(y); return; } } } else { for(var i=0; i<document.forms[this.name+"_form"].elements[this.name+"year"].length; i++) { if(document.forms[this.name+"_form"].elements[this.name+"year"][i].value==y) { document.forms[this.name+"_form"].elements[this.name+"year"].selectedIndex=i; this.setYear(y); return; } } } return; } /* * calendrier.getMonth( Integer m ) * modifie le mois à afficher */ this.getMonth = function (d) { if(document.layers) { for(var i=0; i<document.layers[this.div].document.forms[this.name+"_form"][this.name+"month"].length; i++) { if(document.layers[this.div].document.forms[this.name+"_form"][this.name+"month"][i].value==d) { document.layers[this.div].document.forms[this.name+"_form"][this.name+"month"].selectedIndex=i; this.setMonth(d); return; } } } else { for(var i=0; i<document.forms[this.name+"_form"].elements[this.name+"month"].length; i++) { if(document.forms[this.name+"_form"].elements[this.name+"month"][i].value==d) { document.forms[this.name+"_form"].elements[this.name+"month"].selectedIndex=i; this.setMonth(d); return; } } } return; } /* * calendrier.setYear( Integer y ) * modifie l'année à afficher */ this.setYear = function (y) { this.curYear = y; this.show(); return; } /* * calendrier.setTarget( Object obj ) * change le champs cible d'affichage de la date * BUG OPERA! */ this.setTarget = function (obj) { this.target = obj; return; } /* * calendrier.hide() * masque le calendrier */ this.hide = function() { if(document.layers) document.layers[this.div].visibility='hide'; else { document.getElementById(this.div).style.visibility = 'hidden'; document.getElementById(this.div).style.display = 'none'; } this.vis = false; this.endMove(); return; } /* * calendrier.getDate() * retourne la date selectionnée dans le champs cible */ this.getDate = function(d) { if(this.target!=null) { this.target.value=d; this.hide(); } return; } /* * calendrier.show() * affiche le calendrier */ this.show = function() { this.vis = true; this.tag = "<form name='"+this.name+"_form' method='post'>\n"; this.tag += this.mList(); this.tag += "</form>\n"; if(document.layers) { with(document.layers[this.div]) { document.open("text/html"); document.write(this.tag); document.close(); visibility='show'; } } else { document.getElementById(this.div).innerHTML = ""+this.tag; document.getElementById(this.div).style.visibility = 'visible'; document.getElementById(this.div).style.display = 'block'; } return; } /* * calendrier.init( String d ) * initialise le Calendrier à la date actuelle * paramêtres : * d : nom du calque d'affichage * obj : objet dont la propriété value va recevoir le String de la date */ this.init = function(d, obj) { this.div=d; this.target = obj; this.date=new Date(); this.date.setDate(1); this.curMonth = this.date.getMonth(); this.curYear = this.date.getFullYear(); if(!self.movingCalendar) self.movingCalendar=null; return; } /* * calendrier.checkDate( Integer d ) * paramêtre : le jour d'une date */ this.checkDate = function(d) { if(parseInt(d)<=9) return "0"+parseInt(d); return parseInt(d); } return this; } /******************************/ calendrier.prototype.day = ["D", "L", "M", "M", "J", "V", "S" ]; calendrier.prototype.month = ["Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre"]; /* jours feriés français */ calendrier.prototype.freeday= ["01/01","01/05","08/05","14/07","15/08","01/11","11/11","25/12"]; /******************************/
Partager