Jump to content

Quick Question


jhecht
 Share

Recommended Posts

I'm good with javascript, yes. There's just one thing that never made much of any sense to me in Javascript(or any other language for that matter), and thats calendars. But a recent project I've started to work on(i had hoped it to be a Google Calendar AIR client, but apparently Google Calendar's API HATES AIR so im starting from scratch) requires me to make a calendar. Now this is all well and good, except for the fact that it completely escapes me as to how to do this. I can understand and use Javascript's date object. It's just a matter of presenting the data in a table that messes me up. So far I have this(keep in mind, I'm using MooTools)

var Calendar = new Class({	options:{		showFull:true,		lang:'en',		forceTranslation:false,		onClick:Class.empty(),		calendarId:Class.empty()	},	//Options to be set;	lang:{		en:{			month:{				abbr:['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'],				full:['January','Febuary','March','April','May','June','July','August','September','October','November','December']			},			day:{				abbr:['Su','M','T','W','Th','F','Sa'],				full:['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday']			}		},//End English Translations		es:{			month:{				abbr:['En','Feb','Mar','Abr','May','Jun','Jul','Aug','Oct','Nov','Dec'],				full:['Enero','Febrero','Marzo','Abril','Mayo','Junio','Julio','Augusto','Octubre','Noviembre','Deciembre']			},			day:{				abbr:['D','L','Ma','Mi','J','V','S'],				full:['Domingo','Lunes','Martes','Miercoles','Jueves','Viernes','Sabado']			}		}//End Spanish Translations	},		initialize:function(options){		var language = ($defined(options.forceTranslation) && $type(options.forceTranslation)=='string') ? options.forceTranslation : navigator.language;		//If forced translation is defined and a string, override the user's browser language; otherwise return the navigator language;				if($defined(this.lang[language])){			//If the language translation is present, set the language option to it			this.options.lang=language;		}else{			//Otherwise return error message;			alert("Your browser's language isn't supported");			return false;		}//End language set;				this.setOptions(options);		this.today = new Date();		//today's date object		this.div = ($defined(this.options.calendarId)) ? $(this.options.calendarId) : new Element('div',{'id':'calendar_'+this.today.getFullYear+this.today.getDate()});		//Voila! he is clean;						var table = new Element('table');		var row = new Element('tr');		var header = new Element('tr');		//Creates a new table and a new row Element;		var days = (this.options.showFull) ? this.lang[language].day.full : this.lang[language].day.abbr;		//Gets the dayset we're gonna use		var months =(this.options.showFull) ? this.lang[language].month.full : this.lang[language].month.abbr;		var thisMonth = months[this.today.getMonth()];		header.setHTML("<th colspan=\"7\">",thisMonth,"</th>");		header.injectInside(table);		days.each(function(day,i){			var Elm = new Element('td');			Elm.setHTML("<strong>",day,"</strong>");			Elm.injectInside(row);		});		//We have created a new table element;		var firstDay = new Date();		firstDay.setDate(1);		var dayOfWeek = firstDay.getDay();		var WeekString = ""		for(var x=0;x<dayOfWeek;x++){			WeekString+="<td> </td>\n";		}//Pads the Table to make sure that everything is allright;		row.injectInside(table);		table.injectInside($E('body'));					},			setOptions:function(ops){		for(x in ops){			//Loop through options						if($type(x)!='function'){				this.options[x] = ops[x];			}else{				if(x.match(/^on/)){					this.options[x] = ops[x];				}			}					}//End For Loop	}});

Any help or suggestions on where to go from there would be greatly helpful. And if you wanna help with the project, i wouldn't complain either :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...