atLoad method now called internally by each widget, no need to call externally. Tweak...
[infodrom/rico3] / minsrc / ricoCalendar.js
index 5d7e589..b801bca 100644 (file)
@@ -1,6 +1,6 @@
 /*
- *  (c) 2005-2009 Richard Cowin (http://openrico.org)
- *  (c) 2005-2009 Matt Brown (http://dowdybrown.com)
+ *  (c) 2005-2011 Richard Cowin (http://openrico.org)
+ *  (c) 2005-2011 Matt Brown (http://dowdybrown.com)
  *
  *  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
  *  file except in compliance with the License. You may obtain a copy of the License at
@@ -56,10 +56,11 @@ Rico.CalendarControl.prototype = {
      */
     this.close=this.closePopup;
     this.bPageLoaded=false;
-    this.img=[];
     this.Holidays={};
     this.re=/^\s*(\w+)(\W)(\w+)(\W)(\w+)/i;
     this.setDateFmt(this.options.dateFmt);
+    var self=this;
+    Rico.onLoad(function() { self.atLoad(); })
   },
 
 
@@ -104,7 +105,7 @@ Rico.CalendarControl.prototype = {
     Rico.addClass(this.content, Rico.theme.calendar || 'ricoCalContainer');
     this.direction=Rico.direction(this.container);
 
-    var r,c,i,j,img,dow,a,s,tab;
+    var r,c,i,j,dow,a,s,tab;
     this.colStart=this.options.showWeekNumber ? 1 : 0;
     var colcnt=7+this.colStart
     this.maintab=document.createElement("table");
@@ -113,12 +114,29 @@ Rico.CalendarControl.prototype = {
     this.maintab.border=0;
     this.maintab.style.borderCollapse='separate';
     this.maintab.className=Rico.theme.calendarTable || 'ricoCalTab';
-    this.tbody=Rico.getTBody(this.maintab);
-    this.tbody.className='ricoCalBody';
+
+    // thead (Navigation controls)
     this.thead=this.maintab.createTHead();
     r=this.thead.insertRow(-1);
     this.heading=r.insertCell(-1);
     this.heading.colSpan=colcnt;
+    //this.heading=this.content.appendChild(document.createElement("div"));
+    this.heading.className='RicoCalHeading';
+    if (Rico.theme.calendarHeading) Rico.addClass(this.heading,Rico.theme.calendarHeading)
+
+    // table footer (today)
+    if (this.options.showToday) {
+      this.tfoot=this.maintab.createTFoot();
+      this.tfoot.className='ricoCalFoot';
+      r=this.tfoot.insertRow(-1);
+      this.todayCell=r.insertCell(-1);
+      this.todayCell.colSpan=colcnt;
+      this.todayCell.className=Rico.theme.calendarFooter || 'ricoCalFoot';
+      Rico.eventBind(this.todayCell,"click", Rico.eventHandle(this,'selectNow'), false);
+    }
+
+    this.tbody=Rico.getTBody(this.maintab);
+    this.tbody.className='ricoCalBody';
 
     this.content.style.display='block';
     if (this.position == 'absolute') {
@@ -132,18 +150,6 @@ Rico.CalendarControl.prototype = {
       this.maintab.style.width='100%';
     }
 
-    // Navigation controls
-    //this.heading=this.content.appendChild(document.createElement("div"));
-    this.heading.className='RicoCalHeading';
-    if (Rico.theme.calendarHeading) Rico.addClass(this.heading,Rico.theme.calendarHeading)
-    this.navtab=this.heading.appendChild(document.createElement("table"));
-    this.navrow=this.navtab.insertRow(-1);
-    this._createTitleSection('Month');
-    this.navrow.insertCell(-1).innerHTML="  ";
-    this._createTitleSection('Year');
-    new Rico.HoverSet(this.heading.getElementsByTagName('a'));
-    if (this.position == 'absolute') this.heading.appendChild(Rico.closeButton(Rico.eventHandle(this,'close')));
-
     this.styles=[];
     for (i=0; i<7; i++) {
       r=this.tbody.insertRow(-1);
@@ -166,18 +172,16 @@ Rico.CalendarControl.prototype = {
       }
     }
     
-    // table footer (today)
-    if (this.options.showToday) {
-      this.tfoot=this.maintab.createTFoot();
-      this.tfoot.className='ricoCalFoot';
-      r=this.tfoot.insertRow(-1);
-      this.todayCell=r.insertCell(-1);
-      this.todayCell.colSpan=colcnt;
-      this.todayCell.className=Rico.theme.calendarFooter || 'ricoCalFoot';
-      Rico.eventBind(this.todayCell,"click", Rico.eventHandle(this,'selectNow'), false);
-    }
     this.content.appendChild(this.maintab);
     new Rico.HoverSet(this.tbody.getElementsByTagName('td'),{ hoverNodes: function(e) { return e.innerHTML.match(/^\d+$/) ? [e] : []; } });
+
+    this.navtab=this.heading.appendChild(document.createElement("table"));
+    this.navrow=this.navtab.insertRow(-1);
+    this._createTitleSection('Month');
+    this.navrow.insertCell(-1).innerHTML="&nbsp;&nbsp;";
+    this._createTitleSection('Year');
+    new Rico.HoverSet(this.heading.getElementsByTagName('a'));
+    if (this.position == 'absolute') this.heading.appendChild(Rico.closeButton(Rico.eventHandle(this,'close')));
     
     // month selector
     this.monthPopup=new Rico.Popup(document.createElement("div"),{shim:false,zIndex:10});
@@ -234,7 +238,7 @@ Rico.CalendarControl.prototype = {
     }
     
     Rico.eventBind(this.tbody,"click", Rico.eventHandle(this,'saveAndClose'));
-    this.close();
+    //this.close();
     this.bPageLoaded=true;
   },
 
@@ -244,7 +248,8 @@ Rico.CalendarControl.prototype = {
     var c=this.navrow.insertCell(-1);
     var a=c.appendChild(document.createElement("a"));
     a.className='Rico_'+arrows[0]+'Arrow';
-    a.appendChild(this.createNavArrow('dec'+section,arrows[0]));
+    a.appendChild(this._createNavArrow(arrows[0]));
+    Rico.eventBind(a,"click", Rico.eventHandle(this,'dec'+section), false);
 
     c=this.navrow.insertCell(-1);
     a=c.appendChild(document.createElement("a"));
@@ -254,9 +259,17 @@ Rico.CalendarControl.prototype = {
     c=this.navrow.insertCell(-1);
     a=c.appendChild(document.createElement("a"));
     a.className='Rico_'+arrows[1]+'Arrow';
-    a.appendChild(this.createNavArrow('inc'+section,arrows[1]));
+    a.appendChild(this._createNavArrow(arrows[1]));
+    Rico.eventBind(a,"click", Rico.eventHandle(this,'inc'+section), false);
   },
   
+  _createNavArrow: function(direction) {
+    var span=document.createElement("span");
+    span.className=Rico.theme[direction+'Arrow'] || 'rico-icon Rico_'+direction+'Arrow';
+    span.style.display="inline-block";
+    return span;
+  },
+
   selectNow : function() {
     var today = new Date();
     this.dateNow  = today.getDate();
@@ -267,15 +280,6 @@ Rico.CalendarControl.prototype = {
     this.constructCalendar();
   },
   
-/** @private */
-  createNavArrow: function(funcname,direction) {
-    var span=document.createElement("span");
-    span.className=Rico.theme[direction+'Arrow'] || 'rico-icon Rico_'+direction+'Arrow';
-    span.style.display="inline-block";
-    Rico.eventBind(span,"click", Rico.eventHandle(this,funcname), false);
-    return span;
-  },
-
 /**
  * @returns true if yr/mo is within minDate/MaxDate
  */