- LSformElement_date : Correction d'un bug énervant dans le JS
authorBenjamin Renard <brenard@easter-eggs.com>
Tue, 14 Apr 2009 15:21:17 +0000 (15:21 +0000)
committerBenjamin Renard <brenard@easter-eggs.com>
Tue, 14 Apr 2009 15:21:17 +0000 (15:21 +0000)
trunk/includes/js/LSformElement_date_field.js

index 00e2feb..5c1f1e6 100644 (file)
@@ -20,7 +20,8 @@ var LSformElement_date_field = new Class({
         this.params.firstDayOfWeek=0;
       }
       
-      this.input.addEvent('click',this.onCalendarBtnClick.bind(this));
+      this.firstInputClick = 1;
+      this.input.addEvent('click',this.onInputClick.bind(this));
       
       this.date = Date.parseDate(this.input.value,this.params.format);
       
@@ -42,16 +43,42 @@ var LSformElement_date_field = new Class({
       varLSdefault.addHelpInfo(this.nowBtn,'LSformElement_date','now');
     },
     
+    onInputClick: function() {
+      if(this.firstInputClick==1) {
+        this.toogle();
+        this.firstInputClick=0;
+      }
+    },
+    
     onCalendarBtnClick: function() {
+      this.toogle();
+    },
+    
+    open: function() {
+      this.opened = 1;
       this.calendar.showAtElement(this.calendarBtn);
     },
     
+    close: function() {
+      this.opened = 0;
+      this.calendar.hide();
+    },
+    
+    toogle: function() {
+      if (this.opened) {
+        this.close();
+      }
+      else {
+        this.open();
+      }
+    },
+    
     onChangeCalendar: function(calendar, date) {
       this.input.value = date;
     },
     
     onCloseCalendar: function() {
-      this.calendar.hide();
+      this.close();
     },
     
     onNowBtnClick: function() {