diff --git a/config/alfresco/messages/webclient.properties b/config/alfresco/messages/webclient.properties index c046396117..6c61f77820 100644 --- a/config/alfresco/messages/webclient.properties +++ b/config/alfresco/messages/webclient.properties @@ -1716,9 +1716,9 @@ error_search=Search failed due to system error: {0} error_search_query=Search failed as the system was unable to process your query, please try a different search. error_not_found={0} not found in {1}. error_exists=A Space or File with that name already exists: {0} -error_delete_space=Unable to delete Space due to system error: -error_delete_file=Unable to delete File due to system error: -error_delete_sandbox=Unable to delete Sandbox due to system error: +error_delete_space=Unable to delete Space due to system error: {0} +error_delete_file=Unable to delete File due to system error: {0} +error_delete_sandbox=Unable to delete Sandbox due to system error: {0} error_checkout=Unable to check out Content Node due to system error: error_update=Unable to update Content Node due to system error: error_cancel_checkout=Unable to cancel check out of Content Node due to system error: diff --git a/config/alfresco/web-client-config.xml b/config/alfresco/web-client-config.xml index a9a0dfdaab..0b8a1c12c0 100644 --- a/config/alfresco/web-client-config.xml +++ b/config/alfresco/web-client-config.xml @@ -438,5 +438,31 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/source/web/css/calendar/calendarMain.css b/source/web/css/calendar/calendarMain.css new file mode 100644 index 0000000000..cc98834f3b --- /dev/null +++ b/source/web/css/calendar/calendarMain.css @@ -0,0 +1,100 @@ +div.calendar_entry { + height: 30px; + width: 70px; + float: left; + background: white; + border-right: 1px solid black; + margin: 0 3px 0 3px; + padding-top: 1px; +} + +div.calendar_spacer { + height: 30px; + width: 77px; + float: left; + margin: 0 3px 0 3px; + padding-top: 1px; +} + +.buttonStyle +{ + font-size: smaller; + cursor: pointer; + color: white; + background-color: cornflowerblue; +} + +.inputBox +{ + border-right: 0px solid; + border-top: 0px solid; + border-left: 0px solid; + border-bottom: 0px solid; + background-color: lightyellow; +} + +.alternateRow +{ + background-color:#D3E6FE; +} + +.eventViewTable +{ + border:solid 1px #99CCFF; + border-collapse:collapse; +} + +.eventViewTable td +{ + border-right: 1px solid #99CCFF; + border-top: 1px solid #FFFFFF; + border-bottom: 1px solid #99CCFF; + border-left: 1px solid #99CCFF; +} + +.eventCaption +{ + cursor:pointer; + padding-left:1px; + margin-bottom:2px; +} + +.eventCaptionAllDay +{ + cursor:pointer; + vertical-align:top; + padding-left:1px; + margin-bottom:2px; +} + +.eventCaptionNonEditable +{ + padding-left:1px; + margin-bottom:2px; +} + +.eventCaptionAllDayNonEditable +{ + vertical-align:top; + padding-left:1px; + margin-bottom:2px; +} + +.divDates +{ + background-color: #e9f0f4; + color: blue; + text-align: center; + font-size:x-small; + text-align:center; +} + +.weekDay +{ + vertical-align:top; +} + +.weekEnd +{ + vertical-align:top; +} diff --git a/source/web/css/calendar/js_color_picker_v2.css b/source/web/css/calendar/js_color_picker_v2.css new file mode 100644 index 0000000000..07782cf907 --- /dev/null +++ b/source/web/css/calendar/js_color_picker_v2.css @@ -0,0 +1,191 @@ + #dhtmlgoodies_colorPicker{ + position:absolute; + width:250px; + padding-bottom:1px; + background-color:#FFF; + border:1px solid #317082; + + width: 252px; /* IE 5.x */ + width/* */:/**/250px; /* Other browsers */ + width: /**/250px; + + } + + #dhtmlgoodies_colorPicker .colorPicker_topRow{ + padding-bottom:1px; + border-bottom:3px double #317082; + background-color:#E2EBED; + padding-left:2px; + + width: 250px; /* IE 5.x */ + width/* */:/**/248px; /* Other browsers */ + width: /**/248px; + + height: 20px; /* IE 5.x */ + height/* */:/**/16px; /* Other browsers */ + height: /**/16px; + + } + + #dhtmlgoodies_colorPicker .colorPicker_statusBar{ + height:13px; + padding-bottom:2px; + width:248px; + border-top:3px double #317082; + background-color:#E2EBED; + padding-left:2px; + clear:both; + + width: 250px; /* IE 5.x */ + width/* */:/**/248px; /* Other browsers */ + width: /**/248px; + + height: 18px; /* IE 5.x */ + height/* */:/**/13px; /* Other browsers */ + height: /**/13px; + + } + + #dhtmlgoodies_colorPicker .colorSquare{ + margin-left:1px; + margin-bottom:1px; + float:left; + border:1px solid #000; + cursor:pointer; + + width: 12px; /* IE 5.x */ + width/* */:/**/10px; /* Other browsers */ + width: /**/10px; + + height: 12px; /* IE 5.x */ + height/* */:/**/10px; /* Other browsers */ + height: /**/10px; + + } + + .colorPickerTab_inactive,.colorPickerTab_active{ + + height:17px; + padding-left:4px; + cursor:pointer; + + + } + .colorPickerTab_inactive span{ + background-image:url('images/tab_left_inactive.gif'); + } + + .colorPickerTab_active span{ + background-image:url('images/tab_left_active.gif'); + + } + .colorPickerTab_inactive span, .colorPickerTab_active span{ + line-height:16px; + font-weight:bold; + font-family:arial; + font-size:11px; + padding-top:1px; + vertical-align:middle; + background-position:top left; + background-repeat: no-repeat; + float:left; + padding-left:6px; + -moz-user-select:no; + } + .colorPickerTab_inactive img,.colorPickerTab_active img{ + float:left; + } + .colorPickerCloseButton{ + width:11px; + height:11px; + text-align:center; + line-height:10px; + border:1px solid #317082; + position:absolute; + right:1px; + font-size:12px; + font-weight:bold; + top:1px; + padding:1px; + cursor:pointer; + + width: 15px; /* IE 5.x */ + width/* */:/**/11px; /* Other browsers */ + width: /**/11px; + + height: 15px; /* IE 5.x */ + height/* */:/**/11px; /* Other browsers */ + height: /**/11px; + + + } + #colorPicker_statusBarTxt{ + font-size:11px; + font-family:arial; + vertical-align:top; + line-height:13px; + + } + form{ + padding-left:5px; + } + + .form_widget_amount_slider{ + border-top:1px solid #9d9c99; + border-left:1px solid #9d9c99; + border-bottom:1px solid #eee; + border-right:1px solid #eee; + background-color:#f0ede0; + position:absolute; + bottom:0px; + + width: 5px; /* IE 5.x */ + width/* */:/**/3px; /* Other browsers */ + width: /**/3px; + + height: 5px; /* IE 5.x */ + height/* */:/**/3px; /* Other browsers */ + height: /**/3px; + + } + .colorSliderLabel{ + width:15px; + height:20px; + float:left; + font-size:11px; + font-weight:bold; + } + .colorSlider{ + width:175px; + height:20px; + float:left; + } + .colorInput{ + width:45px; + height:20px; + float:left; + } + .colorPreviewDiv{ + width:186px; + margin-right:2px; + margin-top:1px; + border:1px solid #CCC; + height:20px; + float:left; + cursor:pointer; + + width: 188px; /* IE 5.x */ + width/* */:/**/186px; /* Other browsers */ + width: /**/186px; + + height: 22px; /* IE 5.x */ + height/* */:/**/20px; /* Other browsers */ + height: /**/20px; + + + } + .colorCodeDiv{ + width:50px; + height:20px; + float:left; + } \ No newline at end of file diff --git a/source/web/images/calendar/color_picker.htm b/source/web/images/calendar/color_picker.htm new file mode 100644 index 0000000000..beb2ed6755 --- /dev/null +++ b/source/web/images/calendar/color_picker.htm @@ -0,0 +1,11 @@ + + + + + + +
+ +
+ + diff --git a/source/web/images/calendar/hline.png b/source/web/images/calendar/hline.png new file mode 100644 index 0000000000..e9b1649c81 Binary files /dev/null and b/source/web/images/calendar/hline.png differ diff --git a/source/web/images/calendar/pickerbg.png b/source/web/images/calendar/pickerbg.png new file mode 100644 index 0000000000..505af9d9ca Binary files /dev/null and b/source/web/images/calendar/pickerbg.png differ diff --git a/source/web/images/calendar/select.gif b/source/web/images/calendar/select.gif new file mode 100644 index 0000000000..599f7f13a6 Binary files /dev/null and b/source/web/images/calendar/select.gif differ diff --git a/source/web/images/calendar/select_arrow.gif b/source/web/images/calendar/select_arrow.gif new file mode 100644 index 0000000000..781c8bc433 Binary files /dev/null and b/source/web/images/calendar/select_arrow.gif differ diff --git a/source/web/images/calendar/select_arrow_down.gif b/source/web/images/calendar/select_arrow_down.gif new file mode 100644 index 0000000000..0be8124c20 Binary files /dev/null and b/source/web/images/calendar/select_arrow_down.gif differ diff --git a/source/web/images/calendar/select_arrow_over.gif b/source/web/images/calendar/select_arrow_over.gif new file mode 100644 index 0000000000..0620571c81 Binary files /dev/null and b/source/web/images/calendar/select_arrow_over.gif differ diff --git a/source/web/images/calendar/slider_handle.gif b/source/web/images/calendar/slider_handle.gif new file mode 100644 index 0000000000..28de71905b Binary files /dev/null and b/source/web/images/calendar/slider_handle.gif differ diff --git a/source/web/images/calendar/spacer.gif b/source/web/images/calendar/spacer.gif new file mode 100644 index 0000000000..388486517f Binary files /dev/null and b/source/web/images/calendar/spacer.gif differ diff --git a/source/web/images/calendar/tab_center_active.gif b/source/web/images/calendar/tab_center_active.gif new file mode 100644 index 0000000000..e09f86d952 Binary files /dev/null and b/source/web/images/calendar/tab_center_active.gif differ diff --git a/source/web/images/calendar/tab_left_active.gif b/source/web/images/calendar/tab_left_active.gif new file mode 100644 index 0000000000..888f608fc9 Binary files /dev/null and b/source/web/images/calendar/tab_left_active.gif differ diff --git a/source/web/images/calendar/tab_left_inactive.gif b/source/web/images/calendar/tab_left_inactive.gif new file mode 100644 index 0000000000..c037965607 Binary files /dev/null and b/source/web/images/calendar/tab_left_inactive.gif differ diff --git a/source/web/images/calendar/tab_right_active.gif b/source/web/images/calendar/tab_right_active.gif new file mode 100644 index 0000000000..7dedbc891a Binary files /dev/null and b/source/web/images/calendar/tab_right_active.gif differ diff --git a/source/web/images/calendar/tab_right_inactive.gif b/source/web/images/calendar/tab_right_inactive.gif new file mode 100644 index 0000000000..a64c7e4a97 Binary files /dev/null and b/source/web/images/calendar/tab_right_inactive.gif differ diff --git a/source/web/images/icons/calendar-16.gif b/source/web/images/icons/calendar-16.gif new file mode 100644 index 0000000000..d85740b41a Binary files /dev/null and b/source/web/images/icons/calendar-16.gif differ diff --git a/source/web/images/icons/calendar.gif b/source/web/images/icons/calendar.gif new file mode 100644 index 0000000000..9dfaf9a46c Binary files /dev/null and b/source/web/images/icons/calendar.gif differ diff --git a/source/web/scripts/calendar/ColorPicker2.js b/source/web/scripts/calendar/ColorPicker2.js new file mode 100644 index 0000000000..f1ae64dbff --- /dev/null +++ b/source/web/scripts/calendar/ColorPicker2.js @@ -0,0 +1,75 @@ +// =================================================================== +// Author: Matt Kruse +// WWW: http://www.mattkruse.com/ +// +// NOTICE: You may use this code for any purpose, commercial or +// private, without any further permission from the author. You may +// remove this notice from your final code if you wish, however it is +// appreciated by the author if at least my web site address is kept. +// +// You may *NOT* re-distribute this code in any way except through its +// use. That means, you can include it in your product, or your web +// site, or any other form where the code is actually being used. You +// may not put the plain javascript up on your site for download or +// include it in your javascript libraries for download. +// If you wish to share this code with others, please just point them +// to the URL instead. +// Please DO NOT link directly to my .js files from your site. Copy +// the files to your server and use them there. Thank you. +// =================================================================== + +/* SOURCE FILE: AnchorPosition.js */ +function getAnchorPosition(anchorname){var useWindow=false;var coordinates=new Object();var x=0,y=0;var use_gebi=false, use_css=false, use_layers=false;if(document.getElementById){use_gebi=true;}else if(document.all){use_css=true;}else if(document.layers){use_layers=true;}if(use_gebi && document.all){x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);}else if(use_gebi){var o=document.getElementById(anchorname);x=AnchorPosition_getPageOffsetLeft(o);y=AnchorPosition_getPageOffsetTop(o);}else if(use_css){x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);}else if(use_layers){var found=0;for(var i=0;i screen.availHeight){this.y = screen.availHeight - this.height;}}if(screen && screen.availWidth){if((this.x + this.width) > screen.availWidth){this.x = screen.availWidth - this.width;}}var avoidAboutBlank = window.opera ||( document.layers && !navigator.mimeTypes['*']) || navigator.vendor == 'KDE' ||( document.childNodes && !document.all && !navigator.taintEnabled);this.popupWindow = window.open(avoidAboutBlank?"":"about:blank","window_"+anchorname,this.windowProperties+",width="+this.width+",height="+this.height+",screenX="+this.x+",left="+this.x+",screenY="+this.y+",top="+this.y+"");}this.refresh();}} +function PopupWindow_hidePopup(){if(this.divName != null){if(this.use_gebi){document.getElementById(this.divName).style.display = "none";}else if(this.use_css){document.all[this.divName].style.display = "none";}else if(this.use_layers){document.layers[this.divName].visibility = "none";}}else{if(this.popupWindow && !this.popupWindow.closed){this.popupWindow.close();this.popupWindow = null;}}} +function PopupWindow_isClicked(e){if(this.divName != null){if(this.use_layers){var clickX = e.pageX;var clickY = e.pageY;var t = document.layers[this.divName];if((clickX > t.left) &&(clickX < t.left+t.clip.width) &&(clickY > t.top) &&(clickY < t.top+t.clip.height)){return true;}else{return false;}}else if(document.all){var t = window.event.srcElement;while(t.parentElement != null){if(t.id==this.divName){return true;}t = t.parentElement;}return false;}else if(this.use_gebi && e){var t = e.originalTarget;while(t.parentNode != null){if(t.id==this.divName){return true;}t = t.parentNode;}return false;}return false;}return false;} +function PopupWindow_hideIfNotClicked(e){if(this.autoHideEnabled && !this.isClicked(e)){this.hidePopup();}} +function PopupWindow_autoHide(){this.autoHideEnabled = true;} +function PopupWindow_hidePopupWindows(e){for(var i=0;i0){this.type="DIV";this.divName = arguments[0];}else{this.type="WINDOW";}this.use_gebi = false;this.use_css = false;this.use_layers = false;if(document.getElementById){this.use_gebi = true;}else if(document.all){this.use_css = true;}else if(document.layers){this.use_layers = true;}else{this.type = "WINDOW";}this.offsetX = 0;this.offsetY = 0;this.getXYPosition = PopupWindow_getXYPosition;this.populate = PopupWindow_populate;this.setUrl = PopupWindow_setUrl;this.setWindowProperties = PopupWindow_setWindowProperties;this.refresh = PopupWindow_refresh;this.showPopup = PopupWindow_showPopup;this.hidePopup = PopupWindow_hidePopup;this.setSize = PopupWindow_setSize;this.isClicked = PopupWindow_isClicked;this.autoHide = PopupWindow_autoHide;this.hideIfNotClicked = PopupWindow_hideIfNotClicked;} + + +/* SOURCE FILE: ColorPicker2.js */ + +ColorPicker_targetInput = null; +function ColorPicker_writeDiv(){document.writeln("
");} +function ColorPicker_show(anchorname){this.showPopup(anchorname);} +function ColorPicker_pickColor(color,obj){obj.hidePopup();pickColor(color);} +function pickColor(color){if(ColorPicker_targetInput==null){alert("Target Input is null, which means you either didn't use the 'select' function or you have no defined your own 'pickColor' function to handle the picked color!");return;}ColorPicker_targetInput.value = color;} +function ColorPicker_select(inputobj,linkname){if(inputobj.type!="text" && inputobj.type!="hidden" && inputobj.type!="textarea"){alert("colorpicker.select: Input object passed is not a valid form input object");window.ColorPicker_targetInput=null;return;}window.ColorPicker_targetInput = inputobj;this.show(linkname);} +function ColorPicker_highlightColor(c){var thedoc =(arguments.length>1)?arguments[1]:window.document;var d = thedoc.getElementById("colorPickerSelectedColor");d.style.backgroundColor = c;d = thedoc.getElementById("colorPickerSelectedColorValue");d.innerHTML = c;} +function ColorPicker(){var windowMode = false;if(arguments.length==0){var divname = "colorPickerDiv";}else if(arguments[0] == "window"){var divname = '';windowMode = true;}else{var divname = arguments[0];}if(divname != ""){var cp = new PopupWindow(divname);}else{var cp = new PopupWindow();cp.setSize(225,250);}cp.currentValue = "#FFFFFF";cp.writeDiv = ColorPicker_writeDiv;cp.highlightColor = ColorPicker_highlightColor;cp.show = ColorPicker_show;cp.select = ColorPicker_select;var colors = new Array("#000000","#000033","#000066","#000099","#0000CC","#0000FF","#330000","#330033","#330066","#330099","#3300CC", +"#3300FF","#660000","#660033","#660066","#660099","#6600CC","#6600FF","#990000","#990033","#990066","#990099", +"#9900CC","#9900FF","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#FF0000","#FF0033","#FF0066", +"#FF0099","#FF00CC","#FF00FF","#003300","#003333","#003366","#003399","#0033CC","#0033FF","#333300","#333333", +"#333366","#333399","#3333CC","#3333FF","#663300","#663333","#663366","#663399","#6633CC","#6633FF","#993300", +"#993333","#993366","#993399","#9933CC","#9933FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF", +"#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#006600","#006633","#006666","#006699","#0066CC", +"#0066FF","#336600","#336633","#336666","#336699","#3366CC","#3366FF","#666600","#666633","#666666","#666699", +"#6666CC","#6666FF","#996600","#996633","#996666","#996699","#9966CC","#9966FF","#CC6600","#CC6633","#CC6666", +"#CC6699","#CC66CC","#CC66FF","#FF6600","#FF6633","#FF6666","#FF6699","#FF66CC","#FF66FF","#009900","#009933", +"#009966","#009999","#0099CC","#0099FF","#339900","#339933","#339966","#339999","#3399CC","#3399FF","#669900", +"#669933","#669966","#669999","#6699CC","#6699FF","#999900","#999933","#999966","#999999","#9999CC","#9999FF", +"#CC9900","#CC9933","#CC9966","#CC9999","#CC99CC","#CC99FF","#FF9900","#FF9933","#FF9966","#FF9999","#FF99CC", +"#FF99FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#33CC00","#33CC33","#33CC66","#33CC99", +"#33CCCC","#33CCFF","#66CC00","#66CC33","#66CC66","#66CC99","#66CCCC","#66CCFF","#99CC00","#99CC33","#99CC66", +"#99CC99","#99CCCC","#99CCFF","#CCCC00","#CCCC33","#CCCC66","#CCCC99","#CCCCCC","#CCCCFF","#FFCC00","#FFCC33", +"#FFCC66","#FFCC99","#FFCCCC","#FFCCFF","#00FF00","#00FF33","#00FF66","#00FF99","#00FFCC","#00FFFF","#33FF00", +"#33FF33","#33FF66","#33FF99","#33FFCC","#33FFFF","#66FF00","#66FF33","#66FF66","#66FF99","#66FFCC","#66FFFF", +"#99FF00","#99FF33","#99FF66","#99FF99","#99FFCC","#99FFFF","#CCFF00","#CCFF33","#CCFF66","#CCFF99","#CCFFCC", +"#CCFFFF","#FFFF00","#FFFF33","#FFFF66","#FFFF99","#FFFFCC","#FFFFFF");var total = colors.length;var width = 18;var cp_contents = "";var windowRef =(windowMode)?"window.opener.":"";if(windowMode){cp_contents += "Select Color";cp_contents += "
";}cp_contents += "";var use_highlight =(document.getElementById || document.all)?true:false;for(var i=0;i   ';if( ((i+1)>=total) ||(((i+1) % width) == 0)){cp_contents += "";}}if(document.getElementById){var width1 = Math.floor(width/2);var width2 = width = width1;cp_contents += "";}cp_contents += "
 #FFFFFF
";if(windowMode){cp_contents += "
";}cp.populate(cp_contents+"\n");cp.offsetY = 25;cp.autoHide();return cp;} + diff --git a/source/web/scripts/calendar/calendarScripts.js b/source/web/scripts/calendar/calendarScripts.js new file mode 100644 index 0000000000..7ed95e5b44 --- /dev/null +++ b/source/web/scripts/calendar/calendarScripts.js @@ -0,0 +1,79 @@ + +var DaysArray = function() +{ + var _arr = new Array(); + _arr[0] = "Sunday"; + _arr[1] = "Monday"; + _arr[2] = "Tuesday"; + _arr[3] = "Wednesday"; + _arr[4] = "Thursday"; + _arr[5] = "Friday"; + _arr[6] = "Saturday"; + + return _arr; +} + +var HoursArray = function() +{ + var _arr = new Array(); + _arr[0] = "00:00"; + _arr[1] = "00:30"; + for (i=1; i<24; i++) { + _arr[i*2] = i + ":00"; + _arr[i*2+1] = i + ":30"; + } + return _arr; +} + +var MonthsArray = function() +{ + var _arr = new Array(); + _arr[0] = "January"; + _arr[1] = "February"; + _arr[2] = "March"; + _arr[3] = "April"; + _arr[4] = "May"; + _arr[5] = "June"; + _arr[6] = "July"; + _arr[7] = "August"; + _arr[8] = "September"; + _arr[9] = "October"; + _arr[10] = "November"; + _arr[11] = "December"; + + return _arr; +} + +function refreshAllViews() +{ + callEventRetrieverWeekView(); + callEventRetrieverDayView(); + callEventRetrieverMonthView(); +} + +// Removes leading whitespaces +function lTrim( value ) +{ + var re = /\s*((\S+\s*)*)/; + return value.replace(re, "$1"); +} + +// Removes ending whitespaces +function rTrim( value ) +{ + var re = /((\s*\S+)*)\s*/; + return value.replace(re, "$1"); +} + +// Removes leading and ending whitespaces +function trim( value ) +{ + return lTrim(rTrim(value)); +} + +String.prototype.pad = function(l, s, t) +{ + return s || (s = " "), (l -= this.length) > 0 ? (s = new Array(Math.ceil(l / s.length) + + 1).join(s)).substr(0, t = !t ? l : t == 1 ? 0 : Math.ceil(l / 2)) + + this + s.substr(0, l - t) : this; +}; diff --git a/source/web/scripts/calendar/calendarSearch.js b/source/web/scripts/calendar/calendarSearch.js new file mode 100644 index 0000000000..08819a4ce7 --- /dev/null +++ b/source/web/scripts/calendar/calendarSearch.js @@ -0,0 +1,114 @@ +// +// TODO: package up in an calendar object +// instead of having functions floating +// around in the global namespace. +// +// Author: simon@webteq.eu +// +function applyFilter(query) { + if (query == "") { + query = "\S"; // match everything + } + var re = new RegExp(query,"i"); + var select = document.getElementById("availcals"); + for (i=0; i -1) { + addCalendarSubscription(selectList.options[idx].value); + } +} + +function addCalendarSubscription(calendarRef) { + var url = getContextPath() + "/wcservice/calendar/calendarSubscriptions"; + var params = new Array(); + params[0] = "ref=" + spaceRef; + params[1] = "calendar=" + calendarRef; + var request = YAHOO.util.Connect.asyncRequest("POST", url + "?" + params.join("&"), addCallback, null); +} + +// +// Functions for removing subscriptions +// + +var removeFailureHandler = function(o) { + alert(o.responseText); +}; + +var removeCallback = { + success:addSuccessHandler, + failure:removeFailureHandler, + argument: { foo:"foo", bar:"bar" } +}; + +function removeCalendarSubscription() { + // Determine which option is selected + var selectList = document.getElementById("subscriptions"); + var idx = selectList.options.selectedIndex; + if (idx > -1) { + var url = getContextPath() + "/wcservice/calendar/calendarRemove"; + var params = new Array(); + params[0] = "ref=" + spaceRef; + params[1] = "calendar=" + selectList.options[idx].value; + var request = YAHOO.util.Connect.asyncRequest("POST", url + "?" + params.join("&"), removeCallback, null); + } +} + +function colorHandler(o) { + // Success +}; + +function colorFailureHandler(o) { + alert("Failed to set color"); +}; + +// Color picker functions +function pickColor(color) { + document.getElementById("color2").style.background = color; + // Update the calendar color property + var params = new Array(); + params[0] = "ref=" + spaceRef; + params[1] = "color=" + color; + var url = getContextPath() + "/wcservice/calendar/setColor"; + var colorCallback = { + success:colorHandler, + failure:colorFailureHandler, + argument: { ref:spaceRef, color:color } + }; + var request = YAHOO.util.Connect.asyncRequest("POST", url, colorCallback, null); +}; + + +//YAHOO.util.Event.addListener("window", "load", retrieveAvailableCalendars); + diff --git a/source/web/scripts/calendar/calendarUtil.js b/source/web/scripts/calendar/calendarUtil.js new file mode 100644 index 0000000000..962315c07e --- /dev/null +++ b/source/web/scripts/calendar/calendarUtil.js @@ -0,0 +1,11 @@ +var CalendarUtil = { + DAYTAB: 2, + setDayView: function(day, tabs) { + var thedate = new Date(_currentDateForMonthView); + thedate.setDate(day); + + _currentDateForDayView = thedate; // global refers to the current day + callEventRetrieverDayView(); // load the events for the given date + tabs.set('activeIndex', CalendarUtil.DAYTAB); + } +}; diff --git a/source/web/scripts/calendar/captureDayViewEvents.js b/source/web/scripts/calendar/captureDayViewEvents.js new file mode 100644 index 0000000000..469b57486c --- /dev/null +++ b/source/web/scripts/calendar/captureDayViewEvents.js @@ -0,0 +1,134 @@ + +function createDayTextBoxNode(e) +{ + var obj; + if (window.event) + obj = window.event.srcElement; + else + obj = e.target; + if (obj.tagName != 'TD') return false; + var newBox = document.createElement('input'); + newBox.className = "inputBox"; + newBox.value = defaultCaption; + newBox.size = 80; + newBox.onblur = function(e) { initiateSaveDayEvent(e); } + //newBox.onblur = function(e) { removeTextBoxNode(e); } + newBox.onkeypress = function(e) { checkDayKeyPressed(e); } + obj.appendChild(newBox); + newBox.focus(); +} + +function initiateSaveDayEvent(e) +{ + saveDayEvent(e); + removeTextBoxNode(e); +} + +function saveDayEvent(e) +{ + var newBox; + if (window.event) + newBox = window.event.srcElement; + else + newBox = e.target; + + var ownerTR = newBox.parentNode.parentNode; + var timeTD = ownerTR.firstChild; + var whatEvent = trim(newBox.value); + if (whatEvent.length <= 0) + { + return false; + } + if (!ValidateString(whatEvent)) + { + return false; + } + + showSavingIndicator('d'); + + var fromDate = _currentDateForDayView; + var toDate = _currentDateForDayView; + + var fromTime; + if (window.event) + fromTime = timeTD.innerText; + else + fromTime = timeTD.textContent; + + var x = fromTime.split(":"); + var y = ":00"; + var toTime = x[0]; + if (x[1] == "00") + y = ":30"; + else + toTime = parseInt(x[0]) + 1; + toTime += y; + + var whereEvent = defaultPlace; + var descriptionEvent = ""; + var fromMonth = fromDate.getMonth() + 1; + var toMonth = toDate.getMonth() + 1; + var colorEvent = defaultColor; + + var data = ""; + data += "s=" + spaceRef; + data += "&"; + data += "what=" + whatEvent; + data += "&"; + data += "fd=" + fromDate.getFullYear() + "/" + fromMonth + "/" + fromDate.getDate(); + data += "&"; + data += "ft=" + fromTime; + data += "&"; + data += "td=" + toDate.getFullYear() + "/" + toMonth + "/" + toDate.getDate(); + data += "&"; + data += "tt=" + toTime; + data += "&"; + data += "where=" + whereEvent; + data += "&"; + data += "desc=" + descriptionEvent; + data += "&"; + data += "color=" + colorEvent; + + var sUrl = getContextPath() + '/wcservice/calendar/SaveCalendarEvent?'; + sUrl += data; + var request = YAHOO.util.Connect.asyncRequest('GET', sUrl, callbackDayViewSaveEvent, null); +} + + +function checkDayKeyPressed(e) +{ + var key; + if (window.event) + key = window.event.keyCode; + else + key = e.which; + if (key == 13) + { + //saveDayEvent(e); + window.focus(); + return false; + } + else + return true; +} + + + +var handleSuccessDayViewSaveEvent = function(o) +{ + hideSavingIndicator('d'); + refreshAllViews(); +} + +var handleFailureDayViewSaveEvent = function(o) +{ + hideSavingIndicator('d'); + alert("Unable to Save, " + o.statusText); +} + +var callbackDayViewSaveEvent = +{ + success:handleSuccessDayViewSaveEvent, + failure:handleFailureDayViewSaveEvent, + argument: { foo:"foo", bar:"bar" } +}; diff --git a/source/web/scripts/calendar/captureWeekViewEvents.js b/source/web/scripts/calendar/captureWeekViewEvents.js new file mode 100644 index 0000000000..8a01d573d0 --- /dev/null +++ b/source/web/scripts/calendar/captureWeekViewEvents.js @@ -0,0 +1,140 @@ +var _currentSelectedDate = new Date(); + +function createWeekTextBoxNode(e, currYear, currMonth, currDate) +{ + _currentSelectedDate.setDate(currDate); + _currentSelectedDate.setMonth(currMonth); + _currentSelectedDate.setFullYear(currYear); + + var obj; + if (window.event) + obj = window.event.srcElement; + else + obj = e.target; + + if (obj.tagName != 'TD') return false; + var newBox = document.createElement('input'); + newBox.className = "inputBox"; + newBox.value = defaultCaption; + newBox.size = 10; + newBox.onblur = function(e) { initiateSaveWeekEvent(e); } + //newBox.onblur = function(e) { removeTextBoxNode(e); } + newBox.onkeypress = function(e) { checkWeekKeyPressed(e); } + obj.appendChild(newBox); + newBox.focus(); +} + +function initiateSaveWeekEvent(e) +{ + saveWeekEvent(e); + removeTextBoxNode(e); +} + +function saveWeekEvent(e) +{ + var newBox; + if (window.event) + newBox = window.event.srcElement; + else + newBox = e.target; + + var ownerTR = newBox.parentNode.parentNode; + var timeTD = ownerTR.firstChild; + var whatEvent = trim(newBox.value); + if (whatEvent.length <= 0) + { + return false; + } + if (!ValidateString(whatEvent)) + { + return false; + } + + showSavingIndicator('w'); + + var fromDate = _currentSelectedDate; + var toDate = _currentSelectedDate; + + var fromTime; + if (window.event) + fromTime = timeTD.innerText; + else + fromTime = timeTD.textContent; + + var x = fromTime.split(":"); + var y = ":00"; + var toTime = x[0]; + if (x[1] == "00") + y = ":30"; + else + toTime = parseInt(x[0]) + 1; + toTime += y; + + var whereEvent = defaultPlace; + var descriptionEvent = ""; + var fromMonth = fromDate.getMonth() + 1; + var toMonth = toDate.getMonth() + 1; + var colorEvent = defaultColor; + + var data = ""; + data += "s=" + spaceRef; + data += "&"; + data += "what=" + whatEvent; + data += "&"; + data += "fd=" + fromDate.getFullYear() + "/" + fromMonth + "/" + fromDate.getDate(); + data += "&"; + data += "ft=" + fromTime; + data += "&"; + data += "td=" + toDate.getFullYear() + "/" + toMonth + "/" + toDate.getDate(); + data += "&"; + data += "tt=" + toTime; + data += "&"; + data += "where=" + whereEvent; + data += "&"; + data += "desc=" + descriptionEvent; + data += "&"; + data += "color=" + colorEvent; + + var sUrl = getContextPath() + '/wcservice/calendar/SaveCalendarEvent?'; + sUrl += data; + var request = YAHOO.util.Connect.asyncRequest('GET', sUrl, callbackWeekViewSaveEvent, null); +} + + +function checkWeekKeyPressed(e) +{ + var key; + if (window.event) + key = window.event.keyCode; + else + key = e.which; + if (key == 13) + { + //saveWeekEvent(e); + window.focus(); + return false; + } + else + return true; +} + + + +var handleSuccessWeekViewSaveEvent = function(o) +{ + hideSavingIndicator('w'); + refreshAllViews(); +} + +var handleFailureWeekViewSaveEvent = function(o) +{ + hideSavingIndicator('w'); + alert("Unable to Save, " + o.statusText); +} + +var callbackWeekViewSaveEvent = +{ + success:handleSuccessWeekViewSaveEvent, + failure:handleFailureWeekViewSaveEvent, + argument: { foo:"foo", bar:"bar" } +}; diff --git a/source/web/scripts/calendar/color.js b/source/web/scripts/calendar/color.js new file mode 100644 index 0000000000..46826a7c08 --- /dev/null +++ b/source/web/scripts/calendar/color.js @@ -0,0 +1,97 @@ +/* Copyright (c) 2006 Yahoo! Inc. All rights reserved. */ + +YAHOO.util.Color = function() { + + var hexchars = "0123456789ABCDEF"; + + var real2int = function(n) { + return Math.min(255, Math.round(n*256)); + }; + + return { + + /** + * HSV to RGB. h[0,360], s[0,1], v[0,1] + */ + hsv2rgb: function(h,s,v) { + var r,g,b,i,f,p,q,t; + i = Math.floor((h/60)%6); + f = (h/60)-i; + p = v*(1-s); + q = v*(1-f*s); + t = v*(1-(1-f)*s); + switch(i) { + case 0: r=v; g=t; b=p; break; + case 1: r=q; g=v; b=p; break; + case 2: r=p; g=v; b=t; break; + case 3: r=p; g=q; b=v; break; + case 4: r=t; g=p; b=v; break; + case 5: r=v; g=p; b=q; break; + } + //alert([h,s,v] + "-" + [r,g,b]); + + return [real2int(r), real2int(g), real2int(b)]; + }, + + rgb2hsv: function(r,g,b) { + var min,max,delta,h,s,v; + min = Math.min(Math.min(r,g),b); + max = Math.max(Math.max(r,g),b); + delta = max-min; + + switch (max) { + case min: h=0; break; + case r: h=(g-b)/delta; + if (g 255) return false; + if ((!a[1] && a[1] !=0) || isNaN(a[1]) || a[1] < 0 || a[1] > 255) return false; + if ((!a[2] && a[2] !=0) || isNaN(a[2]) || a[2] < 0 || a[2] > 255) return false; + + return true; + } + } +}(); + diff --git a/source/web/scripts/calendar/color_functions.js b/source/web/scripts/calendar/color_functions.js new file mode 100644 index 0000000000..2e66767484 --- /dev/null +++ b/source/web/scripts/calendar/color_functions.js @@ -0,0 +1,167 @@ +function baseConverter (number,ob,nb) { + number = number + ""; + number = number.toUpperCase(); + var list = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + var dec = 0; + for (var i = 0; i <= number.length; i++) { + dec += (list.indexOf(number.charAt(i))) * (Math.pow(ob , (number.length - i - 1))); + } + number = ""; + var magnitude = Math.floor((Math.log(dec))/(Math.log(nb))); + for (var i = magnitude; i >= 0; i--) { + var amount = Math.floor(dec/Math.pow(nb,i)); + number = number + list.charAt(amount); + dec -= amount*(Math.pow(nb,i)); + } + if(number.length==0)number=0; + return number; +} + +// Converts a RGB color to HSV +function toHSV(rgbColor){ + rgbColor = rgbColor.replace('#',''); + + red = baseConverter(rgbColor.substr(0,2),16,10); + green = baseConverter(rgbColor.substr(2,2),16,10); + blue = baseConverter(rgbColor.substr(4,2),16,10); + if(red.length==0)red=0; + if(green.length==0)green=0; + if(blue.length==0)blue=0; + red = red/255; + green = green/255; + blue = blue/255; + + maxValue = Math.max(red,green,blue); + minValue = Math.min(red,green,blue); + + var hue = 0; + + if(maxValue==minValue){ + hue = 0; + saturation=0; + }else{ + if(red == maxValue){ + hue = (green - blue) / (maxValue-minValue)/1; + }else if(green == maxValue){ + hue = 2 + (blue - red)/1 / (maxValue-minValue)/1; + }else if(blue == maxValue){ + hue = 4 + (red - green) / (maxValue-minValue)/1; + } + saturation = (maxValue-minValue) / maxValue; + } + hue = hue * 60; + valueBrightness = maxValue; + + if(valueBrightness/1<0.5){ + //saturation = (maxValue - minValue) / (maxValue + minValue); + } + if(valueBrightness/1>= 0.5){ + //saturation = (maxValue - minValue) / (2 - maxValue - minValue); + } + + + returnArray = [hue,saturation,valueBrightness]; + return returnArray; +} + +function toRgb(hue,saturation,valueBrightness){ + Hi = Math.floor(hue / 60); + if(hue==360)Hi=0; + f = hue/60 - Hi; + p = (valueBrightness * (1- saturation)).toPrecision(2); + q = (valueBrightness * (1 - (f * saturation))).toPrecision(2); + t = (valueBrightness * (1 - ((1-f)*saturation))).toPrecision(2); + + switch(Hi){ + case 0: + red = valueBrightness; + green = t; + blue = p; + break; + case 1: + red = q; + green = valueBrightness; + blue = p; + break; + case 2: + red = q; + green = valueBrightness; + blue = t; + break; + case 3: + red = p; + green = q;; + blue = valueBrightness; + break; + case 4: + red = t; + green = p; + blue = valueBrightness; + break; + case 5: + red = valueBrightness; + green = p; + blue = q; + break; + } + + if(saturation==0){ + red = valueBrightness; + green = valueBrightness; + blue = valueBrightness; + } + + red*=255; + green*=255; + blue*=255; + + red = Math.round(red); + green = Math.round(green); + blue = Math.round(blue); + + red = baseConverter(red,10,16); + green = baseConverter(green,10,16); + blue = baseConverter(blue,10,16); + + red = red + ""; + green = green + ""; + blue = blue + ""; + + while(red.length<2){ + red = "0" + red; + } + while(green.length<2){ + green = "0" + green; + } + while(blue.length<2){ + blue = "0" + "" + blue; + } + rgbColor = "#" + red + "" + green + "" + blue; + return rgbColor.toUpperCase(); +} + +function findColorByDegrees(rgbColor,degrees){ + rgbColor = rgbColor.replace('#',''); + myArray = toHSV(rgbColor); + myArray[0]+=degrees; + if(myArray[0]>=360)myArray[0]-=360; + if(myArray[0]<0)myArray[0]+=360; + return toRgb(myArray[0],myArray[1],myArray[2]); +} + +function findColorByBrightness(rgbColor,brightness){ + + rgbColor = rgbColor.replace('#',''); + myArray = toHSV(rgbColor); + + myArray[2]+=brightness/100; + if(myArray[2]>1)myArray[2]=1; + if(myArray[2]<0)myArray[2]=0; + + myArray[1]+=brightness/100; + if(myArray[1]>1)myArray[1]=1; + if(myArray[1]<0)myArray[1]=0; + + return toRgb(myArray[0],myArray[1],myArray[2]); + +} diff --git a/source/web/scripts/calendar/color_picker.js b/source/web/scripts/calendar/color_picker.js new file mode 100644 index 0000000000..22743f03e3 --- /dev/null +++ b/source/web/scripts/calendar/color_picker.js @@ -0,0 +1,109 @@ + +function selectColor() { + var color = document.getElementById("selectedColorBox").value; + if (window.opener != null) + { + var mainWinTxtColor = window.opener.document.getElementById(window.colorControl); + if (mainWinTxtColor != null) + { + mainWinTxtColor.value = color; + mainWinTxtColor.style.backgroundColor = color; + } + } + window.close(); +} + +function showColor(color) { + document.getElementById("selectedColor").style.backgroundColor = color; + document.getElementById("selectedColorBox").value = color; +} + +var colors = new Array( + "#000000","#000033","#000066","#000099","#0000cc","#0000ff","#330000","#330033", + "#330066","#330099","#3300cc","#3300ff","#660000","#660033","#660066","#660099", + "#6600cc","#6600ff","#990000","#990033","#990066","#990099","#9900cc","#9900ff", + "#cc0000","#cc0033","#cc0066","#cc0099","#cc00cc","#cc00ff","#ff0000","#ff0033", + "#ff0066","#ff0099","#ff00cc","#ff00ff","#003300","#003333","#003366","#003399", + "#0033cc","#0033ff","#333300","#333333","#333366","#333399","#3333cc","#3333ff", + "#663300","#663333","#663366","#663399","#6633cc","#6633ff","#993300","#993333", + "#993366","#993399","#9933cc","#9933ff","#cc3300","#cc3333","#cc3366","#cc3399", + "#cc33cc","#cc33ff","#ff3300","#ff3333","#ff3366","#ff3399","#ff33cc","#ff33ff", + "#006600","#006633","#006666","#006699","#0066cc","#0066ff","#336600","#336633", + "#336666","#336699","#3366cc","#3366ff","#666600","#666633","#666666","#666699", + "#6666cc","#6666ff","#996600","#996633","#996666","#996699","#9966cc","#9966ff", + "#cc6600","#cc6633","#cc6666","#cc6699","#cc66cc","#cc66ff","#ff6600","#ff6633", + "#ff6666","#ff6699","#ff66cc","#ff66ff","#009900","#009933","#009966","#009999", + "#0099cc","#0099ff","#339900","#339933","#339966","#339999","#3399cc","#3399ff", + "#669900","#669933","#669966","#669999","#6699cc","#6699ff","#999900","#999933", + "#999966","#999999","#9999cc","#9999ff","#cc9900","#cc9933","#cc9966","#cc9999", + "#cc99cc","#cc99ff","#ff9900","#ff9933","#ff9966","#ff9999","#ff99cc","#ff99ff", + "#00cc00","#00cc33","#00cc66","#00cc99","#00cccc","#00ccff","#33cc00","#33cc33", + "#33cc66","#33cc99","#33cccc","#33ccff","#66cc00","#66cc33","#66cc66","#66cc99", + "#66cccc","#66ccff","#99cc00","#99cc33","#99cc66","#99cc99","#99cccc","#99ccff", + "#cccc00","#cccc33","#cccc66","#cccc99","#cccccc","#ccccff","#ffcc00","#ffcc33", + "#ffcc66","#ffcc99","#ffcccc","#ffccff","#00ff00","#00ff33","#00ff66","#00ff99", + "#00ffcc","#00ffff","#33ff00","#33ff33","#33ff66","#33ff99","#33ffcc","#33ffff", + "#66ff00","#66ff33","#66ff66","#66ff99","#66ffcc","#66ffff","#99ff00","#99ff33", + "#99ff66","#99ff99","#99ffcc","#99ffff","#ccff00","#ccff33","#ccff66","#ccff99", + "#ccffcc","#ccffff","#ffff00","#ffff33","#ffff66","#ffff99","#ffffcc","#ffffff" +); + +function convertRGBToHex(col) { + var re = new RegExp("rgb\\s*\\(\\s*([0-9]+).*,\\s*([0-9]+).*,\\s*([0-9]+).*\\)", "gi"); + + var rgb = col.replace(re, "$1,$2,$3").split(','); + if (rgb.length == 3) { + r = parseInt(rgb[0]).toString(16); + g = parseInt(rgb[1]).toString(16); + b = parseInt(rgb[2]).toString(16); + + r = r.length == 1 ? '0' + r : r; + g = g.length == 1 ? '0' + g : g; + b = b.length == 1 ? '0' + b : b; + + return "#" + r + g + b; + } + + return col; +} + +function convertHexToRGB(col) { + if (col.indexOf('#') != -1) { + col = col.replace(new RegExp('[^0-9A-F]', 'gi'), ''); + + r = parseInt(col.substring(0, 2), 16); + g = parseInt(col.substring(2, 4), 16); + b = parseInt(col.substring(4, 6), 16); + + return "rgb(" + r + "," + g + "," + b + ")"; + } + + return col; +} + +function renderColorMap() { + var html = ""; + var inputColor = convertRGBToHex('ff88ff'); + + html += '' + + ''; + for (var i=0; i' + + '' + + '' + colors[i] +  ''; + if ((i+1) % 18 == 0) + html += ''; + } + html += '' + + '
' + + '' + + '' + + '
' + + '' + + '' + + '' + + '
' + + '
'; + + document.write(html); +} \ No newline at end of file diff --git a/source/web/scripts/calendar/colorpicker.js b/source/web/scripts/calendar/colorpicker.js new file mode 100644 index 0000000000..969f5d0870 --- /dev/null +++ b/source/web/scripts/calendar/colorpicker.js @@ -0,0 +1,81 @@ +YAHOO.example.ColorPicker = function() { + + var Slider=YAHOO.widget.Slider; + var Color=YAHOO.util.Color; + var Dom=YAHOO.util.Dom; + + var pickerSize=180; + + var hue,picker,panel; + + // hue, int[0,359] + var getH = function() { + var h = (pickerSize - hue.getValue()) / pickerSize; + h = Math.round(h*360); + return (h == 360) ? 0 : h; + } + + // saturation, int[0,1], left to right + var getS = function() { + return picker.getXValue() / pickerSize; + } + + // value, int[0,1], top to bottom + var getV = function() { + return (pickerSize - picker.getYValue()) / pickerSize; + } + + var swatchUpdate = function() { + var h=getH(), s=getS(), v=getV(); + + Dom.get("hval").value = h; + Dom.get("sval").value = Math.round(s*100); + Dom.get("vval").value = Math.round(v*100); + + var rgb = Color.hsv2rgb(h, s, v); + + var styleDef = "rgb(" + rgb.join(",") + ")"; + Dom.setStyle("swatch", "background-color", styleDef); + + Dom.get("rval").value = rgb[0]; + Dom.get("gval").value = rgb[1]; + Dom.get("bval").value = rgb[2]; + + Dom.get("hexval").value = Color.rgb2hex(rgb[0], rgb[1], rgb[2]); + }; + + var hueUpdate = function(newOffset) { + YAHOO.log("hue update: " + newOffset , "warn"); + var rgb = Color.hsv2rgb(getH(), 1, 1); + var styleDef = "rgb(" + rgb.join(",") + ")"; + Dom.setStyle("pickerDiv", "background-color", styleDef); + + swatchUpdate(); + }; + + pickerUpdate = function(newOffset) { + YAHOO.log("picker update [" + newOffset.x + ", " + newOffset.y + "]" , "warn"); + swatchUpdate(); + }; + + return { + + init: function () { + + hue = Slider.getVertSlider("hueBg", "hueThumb", 0, pickerSize); + hue.subscribe("change", hueUpdate); + + picker = Slider.getSliderRegion("pickerDiv", "selector", + 0, pickerSize, 0, pickerSize); + picker.subscribe("change", pickerUpdate); + + hueUpdate(0); + + panel = new YAHOO.util.DD("ddPicker"); + panel.setHandleElId("pickerHandle"); + + } + } +}(); + +//YAHOO.util.Event.on(window, "load", YAHOO.example.ColorPicker.init); diff --git a/source/web/scripts/calendar/editEventHandlers.js b/source/web/scripts/calendar/editEventHandlers.js new file mode 100644 index 0000000000..1f8bca5624 --- /dev/null +++ b/source/web/scripts/calendar/editEventHandlers.js @@ -0,0 +1,64 @@ +var _currentActiveEditingEvent = null; + +function editEvent(eventId) +{ + _currentActiveEditingEvent = eventId; + if (_currentActiveEditingEvent == null) return false; + retrieveCalendarEvent(); +} + +function populateEventDetailsForEdit(response) +{ + var _details = response.split("^"); + if (_details.length <=0) + { + alert("Unable to Retrieve details of Event"); + return false; + } + + var _fromDate = new Date(_details[1]); + var _toDate = new Date(_details[3]); + + document.getElementById("txtWhatEvent").value = _details[0]; + document.getElementById("hidFromDate").value = _details[1]; + document.getElementById("txtFromDate").value = _fromDate.toDateString(); + document.getElementById("lstFromTime").value = _details[2]; + document.getElementById("hidToDate").value = _details[3]; + document.getElementById("txtToDate").value = _toDate.toDateString(); + document.getElementById("lstToTime").value = _details[4]; + document.getElementById("txtWhereEvent").value = _details[5]; + document.getElementById("txtDescriptionEvent").value = _details[6]; + document.getElementById("txtColor").value = _details[7]; + + tabView.set('activeIndex', 3); //tabView: the main YUI TabView Control - defined in FTL. + document.getElementById("txtWhatEvent").focus(); +} + + + +var handleSuccessRetrieveEvent = function(o) +{ + populateEventDetailsForEdit(o.responseText); +} + +var handleFailureRetrieveEvent = function(o) +{ + alert("Unable to Retrieve Event Details, " + o.statusText); +} + +var callbackRetrieveEvent = +{ + success:handleSuccessRetrieveEvent, + failure:handleFailureRetrieveEvent, + argument: { foo:"foo", bar:"bar" } +}; + +function retrieveCalendarEvent() +{ + var sUrl = getContextPath() + '/wcservice/calendar/RetrieveEventDetails?'; + var postData = "e=" + _currentActiveEditingEvent; + sUrl += postData; + var request = YAHOO.util.Connect.asyncRequest('GET', sUrl, callbackRetrieveEvent, null); +} + + diff --git a/source/web/scripts/calendar/eventCaptureHandlers.js b/source/web/scripts/calendar/eventCaptureHandlers.js new file mode 100644 index 0000000000..1b4428a8ec --- /dev/null +++ b/source/web/scripts/calendar/eventCaptureHandlers.js @@ -0,0 +1,70 @@ + +function showSavingIndicator(mode) +{ + var obj = null; + switch(mode) + { + case 'd': + { + obj = document.getElementById("spnCurrentDisplayDay"); + break; + } + case 'w': + { + obj = document.getElementById("spnCurrentDisplayWeek"); + break; + } + case 'c': + { + obj = document.getElementById("spnEventCapture"); + break; + } + } + if (obj == null) return false; + + var newImg = document.createElement('img'); + newImg.src = "/alfresco/yui/img/indicator.gif"; + var txt = document.createTextNode(' Saving...'); + obj.appendChild(newImg); + obj.appendChild(txt); +} + +function hideSavingIndicator(mode) +{ + var obj = null; + switch(mode) + { + case 'd': + { + obj = document.getElementById("spnCurrentDisplayDay"); + break; + } + case 'w': + { + obj = document.getElementById("spnCurrentDisplayWeek"); + break; + } + case 'c': + { + obj = document.getElementById("spnEventCapture"); + break; + } + } + if (obj == null) return false; + + while (obj.hasChildNodes()) + obj.removeChild(obj.firstChild); +} + + +function removeTextBoxNode(e) +{ + var txtNode; + if (window.event) + txtNode = window.event.srcElement; + else + txtNode = e.target; + + var owner = txtNode.parentNode; + owner.removeChild(txtNode); +} diff --git a/source/web/scripts/calendar/eventRetrieversDayView.js b/source/web/scripts/calendar/eventRetrieversDayView.js new file mode 100644 index 0000000000..6110a404bf --- /dev/null +++ b/source/web/scripts/calendar/eventRetrieversDayView.js @@ -0,0 +1,44 @@ +var _currentDateForDayView = new Date(); + +var handleSuccessDayView = function(o) +{ + var response = o.responseText; + var _divDayView = document.getElementById("divDayView"); + if (_divDayView != null) { + _divDayView.innerHTML = response; + document.getElementById("spnCurrentDisplayDayDayView").innerHTML = _currentDateForDayView.toDateString(); + } +} + +var handleFailureDayView = function(o) +{ + alert("Unable to retrieve, " + o.statusText); +} + +var callbackDayView = +{ + success:handleSuccessDayView, + failure:handleFailureDayView, + argument: { foo:"foo", bar:"bar" } +}; + +function callEventRetrieverDayView() +{ + var sUrl = getContextPath() + '/wcservice/calendar/RetrieveDayEvents?'; + var month = _currentDateForDayView.getMonth() + 1; + var postData = "s=" + spaceRef + "&d=" + _currentDateForDayView.getFullYear() + "/" + month + "/" + _currentDateForDayView.getDate(); + sUrl += postData; + var request = YAHOO.util.Connect.asyncRequest('GET', sUrl, callbackDayView, null); +} + + +function callLoadersDayView(change) +{ + if (isNaN(change)) change = 0; + if (change == 0) _currentDateForDayView = new Date(); + _currentDateForDayView.setDate(_currentDateForDayView.getDate() + change); + //document.getElementById("spnCurrentDisplayDayDayView").innerHTML = _currentDateForDayView.toDateString(); + callEventRetrieverDayView(); +} + +YAHOO.util.Event.addListener(window, "load", callLoadersDayView); diff --git a/source/web/scripts/calendar/eventRetrieversMonthView.js b/source/web/scripts/calendar/eventRetrieversMonthView.js new file mode 100644 index 0000000000..5285028a21 --- /dev/null +++ b/source/web/scripts/calendar/eventRetrieversMonthView.js @@ -0,0 +1,54 @@ +var _currentDateForMonthView = new Date(); + +function setCurrentMonthView() +{ + _currentDateForMonthView = new Date(); + callEventRetrieverMonthView(); +} + +function addMonthsMonthView(n) +{ + _currentDateForMonthView.setMonth(_currentDateForMonthView.getMonth() + n); + callEventRetrieverMonthView(); +} + +function addYearsMonthView(n) +{ + _currentDateForMonthView.setFullYear(_currentDateForMonthView.getFullYear() + n); + callEventRetrieverMonthView(); +} + +var handleSuccessMonthView = function(o) +{ + var response = o.responseText; + var _divMonthView = document.getElementById("divMonthView"); + if (_divMonthView != null) + _divMonthView.innerHTML = response; +} + +var handleFailureMonthView = function(o) +{ + alert("Unable to retrieve, " + o.statusText); +} + +var callbackMonthView = +{ + success:handleSuccessMonthView, + failure:handleFailureMonthView, + argument: { foo:"foo", bar:"bar" } +}; + +function callEventRetrieverMonthView() +{ + var _arrMonths = MonthsArray(); + var month = _currentDateForMonthView.getMonth() + 1; + document.getElementById("spnCurrentDisplayMonthMonthView").innerHTML = _arrMonths[month-1] + ", " + _currentDateForMonthView.getFullYear(); + + var sUrl = getContextPath() + '/wcservice/calendar/RetrieveMonthEvents?'; + var postData = "s=" + spaceRef + "&d=" + _currentDateForMonthView.getFullYear() + "/" + month + "/" + _currentDateForMonthView.getDate(); + sUrl += postData; + var request = YAHOO.util.Connect.asyncRequest('GET', sUrl, callbackMonthView, null); +} + + +YAHOO.util.Event.addListener(window, "load", callEventRetrieverMonthView); diff --git a/source/web/scripts/calendar/eventRetrieversWeekView.js b/source/web/scripts/calendar/eventRetrieversWeekView.js new file mode 100644 index 0000000000..552ac5eb12 --- /dev/null +++ b/source/web/scripts/calendar/eventRetrieversWeekView.js @@ -0,0 +1,49 @@ +var _currentDateForWeekView = new Date(); + +function setCurrentDateForWeekView(change) +{ + if (isNaN(change)) change = 0; + if (change == 0) _currentDateForWeekView = new Date(); + _currentDateForWeekView.setDate(_currentDateForWeekView.getDate() + change); +} + +var handleSuccessWeekView = function(o) +{ + var response = o.responseText; + var _divWeekView = document.getElementById("divWeekView"); + if (_divWeekView != null) + _divWeekView.innerHTML = response; + //document.getElementById("spnCurrentDisplayWeekWeekView").innerHTML = response[1]; +} + +var handleFailureWeekView = function(o) +{ + alert("Unable to retrieve, " + o.statusText); +} + +var callbackWeekView = +{ + success:handleSuccessWeekView, + failure:handleFailureWeekView, + argument: { foo:"foo", bar:"bar" } +}; + +function callEventRetrieverWeekView() +{ + var month = _currentDateForWeekView.getMonth() + 1; + + var sUrl = getContextPath() + '/wcservice/calendar/RetrieveWeekEvents?'; + var postData = "s=" + spaceRef + "&d=" + _currentDateForWeekView .getFullYear() + "/" + month + "/" + _currentDateForWeekView .getDate(); + sUrl += postData; + var request = YAHOO.util.Connect.asyncRequest('GET', sUrl, callbackWeekView, null); +} + + +function callLoadersWeekView(change) +{ + if (isNaN(change)) change = 0; + setCurrentDateForWeekView(change); + callEventRetrieverWeekView(); +} + +YAHOO.util.Event.addListener(window, "load", callLoadersWeekView); diff --git a/source/web/scripts/calendar/initializeEventDetails.js b/source/web/scripts/calendar/initializeEventDetails.js new file mode 100644 index 0000000000..ec953a5dda --- /dev/null +++ b/source/web/scripts/calendar/initializeEventDetails.js @@ -0,0 +1,200 @@ + +var currentBox = null; +var currentVisibleBox = null; + +// Variables to hold Event Default values. +var defaultCaption = ""; +var defaultPlace = ""; +var defaultFromDate = new Date(); +var defaultFromDateString = ""; +var defaultFromTime = ""; +var defaultToDate = new Date(); +var defaultToDateString = ""; +var defaultToTime = ""; +var defaultColor = ""; + + +YAHOO.namespace("example.calendar"); + +function handleSelect(type, args, obj) +{ + var dates = args[0]; + var date = dates[0]; + var year = date[0], month = date[1], day = date[2]; + var dateValue = month + "/" + day + "/" + year; + var dateData = new Date(); + dateData.setFullYear(year, month-1, day); + + if (currentBox != null) + { + currentBox.value = dateValue; + } + if (currentVisibleBox != null) + { + currentVisibleBox.value = dateData.toDateString(); + } + + ToggleCalendar(0, null); +} + + +function init() +{ + YAHOO.example.calendar.cal1 = new YAHOO.widget.Calendar("cal1","cal1Container", { mindate:"1/1/2006", maxdate:"12/31/2008" }); + YAHOO.example.calendar.cal1.selectEvent.subscribe(handleSelect, YAHOO.example.calendar.cal1, true); + YAHOO.example.calendar.cal1.render(); + + tabView = new YAHOO.widget.TabView('divCalendarMainContainer'); + + document.onclick = function(e) { HideCalendar(e); } + + PopulateTimes(); + retrieveEventDefaults(); + initCalendarProperties(); +} + + +function ToggleCalendar(mode, txtBox) +{ + if (isNaN(mode)) mode = 0; + var calendar = document.getElementById("cal1Container"); + if (calendar == null) return; + calendar.style.display = mode == 1 ? "inline" : "none"; + + if (txtBox == null) return; + + if (mode == 1) + { + calendar.style.left = txtBox.offsetParent.offsetLeft + txtBox.offsetLeft; + calendar.style.top = txtBox.offsetParent.offsetTop + txtBox.offsetHeight; + } + + currentVisibleBox = txtBox; + if (txtBox.id == "txtFromDate") + currentBox = document.getElementById("hidFromDate"); + else if (txtBox.id == "txtToDate") + currentBox = document.getElementById("hidToDate"); +} + +function HideCalendar(e) +{ + var obj = null; + if (window.event) + obj = window.event.srcElement; + else + obj = e.target; + + if (obj.id != "txtFromDate" && obj.id != "txtToDate") + ToggleCalendar(0); +} + +function PopulateTimes() +{ + var _arr = HoursArray(); + for (i=0; i<_arr.length; i++) + { + var _option1 = document.createElement("OPTION"); + _option1.text = _arr[i]; + _option1.value = _arr[i]; + document.getElementById("lstFromTime").options.add(_option1); + + var _option2 = document.createElement("OPTION"); + _option2.text = _arr[i]; + _option2.value = _arr[i]; + document.getElementById("lstToTime").options.add(_option2); + } +} + +///////////// + +function initSuccessHandler(o) { + var result = o.responseText; + var _div = document.getElementById("calendarSubscribe"); + if (_div != null) { + _div.innerHTML = result; + } +} + +function initFailureHandler(o) { + alert("Failed to initialise calendar properties"); +} + +function initCalendarProperties() { + var url = getContextPath() + "/wcservice/calendar/calendarInit"; + var initCallback = { + success:initSuccessHandler, + failure:initFailureHandler + }; + var request = YAHOO.util.Connect.asyncRequest("GET", url + "?ref=" + spaceRef, initCallback, null); +} + +///////////// + +YAHOO.util.Event.addListener(window, "load", init); + + + + +var handleSuccessInitEvent = function(o) +{ + populateEventDefaults(o.responseText); +} + +var handleFailureInitEvent = function(o) +{ + alert("Unable to Retrieve Default values for Events, " + o.statusText); +} + +var callbackInitEvent = +{ + success:handleSuccessInitEvent, + failure:handleFailureInitEvent, + argument: { foo:"foo", bar:"bar" } +}; + +function retrieveEventDefaults() +{ + var sUrl = getContextPath() + '/wcservice/calendar/RetrieveEventDefaults?'; + var postData = "s=" + spaceRef; + sUrl += postData; + var request = YAHOO.util.Connect.asyncRequest('GET', sUrl, callbackInitEvent, null); +} + +function populateEventDefaults(response) +{ + var _details = response.split("^"); + if (_details.length <=0) + { + alert("Unable to Retrieve Event Defaults"); + return false; + } + + + defaultCaption = _details[0]; + + var _fromDate = new Date(_details[1]); + defaultFromDate = new Date(_fromDate); + var x = _fromDate.getMonth() + 1; + defaultFromDateString = x + "/" + _fromDate.getDate() + "/" + _fromDate.getFullYear(); + defaultFromTime = _fromDate.getHours() + ":" + _fromDate.getMinutes().toString().pad(2, "0", 1); + + var _toDate = new Date(_details[2]); + defaultToDate = new Date(_toDate); + var y = _toDate.getMonth() + 1; + defaultToDateString = y + "/" + _toDate.getDate() + "/" + _toDate.getFullYear(); + defaultToTime = _toDate.getHours() + ":" + _toDate.getMinutes().toString().pad(2, "0", 1); + + defaultPlace = _details[3]; + defaultColor = _details[4]; + + + document.getElementById("txtWhatEvent").value = defaultCaption; + document.getElementById("hidFromDate").value = defaultFromDateString; + document.getElementById("txtFromDate").value = _fromDate.toDateString(); + document.getElementById("lstFromTime").value = defaultFromTime; + document.getElementById("hidToDate").value = defaultToDateString; + document.getElementById("txtToDate").value = _toDate.toDateString(); + document.getElementById("lstToTime").value = defaultToTime; + document.getElementById("txtWhereEvent").value = defaultPlace; + document.getElementById("txtColor").value = defaultColor; +} diff --git a/source/web/scripts/calendar/js_color_picker_v2.js b/source/web/scripts/calendar/js_color_picker_v2.js new file mode 100644 index 0000000000..1ab5c9623e --- /dev/null +++ b/source/web/scripts/calendar/js_color_picker_v2.js @@ -0,0 +1,585 @@ + /************************************************************************************************************ + (C) www.dhtmlgoodies.com, October 2005 + + This is a script from www.dhtmlgoodies.com. You will find this and a lot of other scripts at our website. + + Terms of use: + You are free to use this script as long as the copyright message is kept intact. However, you may not + redistribute, sell or repost it without our permission. + + Thank you! + + www.dhtmlgoodies.com + Alf Magne Kalleland + + ************************************************************************************************************/ + + var MSIE = navigator.userAgent.indexOf('MSIE')>=0?true:false; + var navigatorVersion = navigator.appVersion.replace(/.*?MSIE (\d\.\d).*/g,'$1')/1; + + var form_widget_amount_slider_handle = '/alfresco/images/calendar/slider_handle.gif'; + var slider_handle_image_obj = false; + var sliderObjectArray = new Array(); + var slider_counter = 0; + var slideInProgress = false; + var handle_start_x; + var event_start_x; + var currentSliderIndex; + + function form_widget_cancel_event() + { + return false; + } + + function getImageSliderHeight(){ + if(!slider_handle_image_obj){ + slider_handle_image_obj = new Image(); + slider_handle_image_obj.src = form_widget_amount_slider_handle; + } + if(slider_handle_image_obj.width>0){ + return; + }else{ + setTimeout('getImageSliderHeight()',50); + } + } + + function positionSliderImage(e,theIndex,inputObj) + { + if(this)inputObj = this; + if(!theIndex)theIndex = inputObj.getAttribute('sliderIndex'); + var handleImg = document.getElementById('slider_handle' + theIndex); + var ratio = sliderObjectArray[theIndex]['width'] / (sliderObjectArray[theIndex]['max']-sliderObjectArray[theIndex]['min']); + var currentValue = sliderObjectArray[theIndex]['formTarget'].value-sliderObjectArray[theIndex]['min']; + handleImg.style.left = currentValue * ratio + 'px'; + setColorByRGB(); + } + + function adjustFormValue(theIndex) + { + var handleImg = document.getElementById('slider_handle' + theIndex); + var ratio = sliderObjectArray[theIndex]['width'] / (sliderObjectArray[theIndex]['max']-sliderObjectArray[theIndex]['min']); + var currentPos = handleImg.style.left.replace('px',''); + sliderObjectArray[theIndex]['formTarget'].value = Math.round(currentPos / ratio) + sliderObjectArray[theIndex]['min']; + + } + + function initMoveSlider(e) + { + + if(document.all)e = event; + slideInProgress = true; + event_start_x = e.clientX; + handle_start_x = this.style.left.replace('px',''); + currentSliderIndex = this.id.replace(/[^\d]/g,''); + return false; + } + + function startMoveSlider(e) + { + if(document.all)e = event; + if(!slideInProgress)return; + var leftPos = handle_start_x/1 + e.clientX/1 - event_start_x; + if(leftPos<0)leftPos = 0; + if(leftPos/1>sliderObjectArray[currentSliderIndex]['width'])leftPos = sliderObjectArray[currentSliderIndex]['width']; + document.getElementById('slider_handle' + currentSliderIndex).style.left = leftPos + 'px'; + adjustFormValue(currentSliderIndex); + if(sliderObjectArray[currentSliderIndex]['onchangeAction']){ + eval(sliderObjectArray[currentSliderIndex]['onchangeAction']); + } + } + + function stopMoveSlider() + { + slideInProgress = false; + } + + + function form_widget_amount_slider(targetElId,formTarget,width,min,max,onchangeAction) + { + if(!slider_handle_image_obj){ + getImageSliderHeight(); + } + + slider_counter = slider_counter +1; + sliderObjectArray[slider_counter] = new Array(); + sliderObjectArray[slider_counter] = {"width":width - 9,"min":min,"max":max,"formTarget":formTarget,"onchangeAction":onchangeAction}; + + formTarget.setAttribute('sliderIndex',slider_counter); + formTarget.onchange = positionSliderImage; + var parentObj = document.createElement('DIV'); + parentObj.style.width = width + 'px'; + parentObj.style.height = '12px'; // The height of the image + parentObj.style.position = 'relative'; + parentObj.id = 'slider_container' + slider_counter; + document.getElementById(targetElId).appendChild(parentObj); + + var obj = document.createElement('DIV'); + obj.className = 'form_widget_amount_slider'; + obj.innerHTML = ''; + obj.style.width = width + 'px'; + obj.id = 'slider_slider' + slider_counter; + obj.style.position = 'absolute'; + obj.style.bottom = '0px'; + parentObj.appendChild(obj); + + var handleImg = document.createElement('IMG'); + handleImg.style.position = 'absolute'; + handleImg.style.left = '0px'; + handleImg.style.zIndex = 5; + handleImg.src = slider_handle_image_obj.src; + handleImg.id = 'slider_handle' + slider_counter; + handleImg.onmousedown = initMoveSlider; + if(document.body.onmouseup){ + if(document.body.onmouseup.toString().indexOf('stopMoveSlider')==-1){ + alert('You allready have an onmouseup event assigned to the body tag'); + } + }else{ + document.body.onmouseup = stopMoveSlider; + document.body.onmousemove = startMoveSlider; + } + handleImg.ondragstart = form_widget_cancel_event; + parentObj.appendChild(handleImg); + positionSliderImage(false,slider_counter); + } + + + + var namedColors = new Array('AliceBlue','AntiqueWhite','Aqua','Aquamarine','Azure','Beige','Bisque','Black','BlanchedAlmond','Blue','BlueViolet','Brown', + 'BurlyWood','CadetBlue','Chartreuse','Chocolate','Coral','CornflowerBlue','Cornsilk','Crimson','Cyan','DarkBlue','DarkCyan','DarkGoldenRod','DarkGray', + 'DarkGreen','DarkKhaki','DarkMagenta','DarkOliveGreen','Darkorange','DarkOrchid','DarkRed','DarkSalmon','DarkSeaGreen','DarkSlateBlue','DarkSlateGray', + 'DarkTurquoise','DarkViolet','DeepPink','DeepSkyBlue','DimGray','DodgerBlue','Feldspar','FireBrick','FloralWhite','ForestGreen','Fuchsia','Gainsboro', + 'GhostWhite','Gold','GoldenRod','Gray','Green','GreenYellow','HoneyDew','HotPink','IndianRed','Indigo','Ivory','Khaki','Lavender','LavenderBlush', + 'LawnGreen','LemonChiffon','LightBlue','LightCoral','LightCyan','LightGoldenRodYellow','LightGrey','LightGreen','LightPink','LightSalmon','LightSeaGreen', + 'LightSkyBlue','LightSlateBlue','LightSlateGray','LightSteelBlue','LightYellow','Lime','LimeGreen','Linen','Magenta','Maroon','MediumAquaMarine', + 'MediumBlue','MediumOrchid','MediumPurple','MediumSeaGreen','MediumSlateBlue','MediumSpringGreen','MediumTurquoise','MediumVioletRed','MidnightBlue', + 'MintCream','MistyRose','Moccasin','NavajoWhite','Navy','OldLace','Olive','OliveDrab','Orange','OrangeRed','Orchid','PaleGoldenRod','PaleGreen', + 'PaleTurquoise','PaleVioletRed','PapayaWhip','PeachPuff','Peru','Pink','Plum','PowderBlue','Purple','Red','RosyBrown','RoyalBlue','SaddleBrown', + 'Salmon','SandyBrown','SeaGreen','SeaShell','Sienna','Silver','SkyBlue','SlateBlue','SlateGray','Snow','SpringGreen','SteelBlue','Tan','Teal','Thistle', + 'Tomato','Turquoise','Violet','VioletRed','Wheat','White','WhiteSmoke','Yellow','YellowGreen'); + + var namedColorRGB = new Array('#F0F8FF','#FAEBD7','#00FFFF','#7FFFD4','#F0FFFF','#F5F5DC','#FFE4C4','#000000','#FFEBCD','#0000FF','#8A2BE2','#A52A2A','#DEB887', + '#5F9EA0','#7FFF00','#D2691E','#FF7F50','#6495ED','#FFF8DC','#DC143C','#00FFFF','#00008B','#008B8B','#B8860B','#A9A9A9','#006400','#BDB76B','#8B008B', + '#556B2F','#FF8C00','#9932CC','#8B0000','#E9967A','#8FBC8F','#483D8B','#2F4F4F','#00CED1','#9400D3','#FF1493','#00BFFF','#696969','#1E90FF','#D19275', + '#B22222','#FFFAF0','#228B22','#FF00FF','#DCDCDC','#F8F8FF','#FFD700','#DAA520','#808080','#008000','#ADFF2F','#F0FFF0','#FF69B4','#CD5C5C','#4B0082', + '#FFFFF0','#F0E68C','#E6E6FA','#FFF0F5','#7CFC00','#FFFACD','#ADD8E6','#F08080','#E0FFFF','#FAFAD2','#D3D3D3','#90EE90','#FFB6C1','#FFA07A','#20B2AA', + '#87CEFA','#8470FF','#778899','#B0C4DE','#FFFFE0','#00FF00','#32CD32','#FAF0E6','#FF00FF','#800000','#66CDAA','#0000CD','#BA55D3','#9370D8','#3CB371', + '#7B68EE','#00FA9A','#48D1CC','#C71585','#191970','#F5FFFA','#FFE4E1','#FFE4B5','#FFDEAD','#000080','#FDF5E6','#808000','#6B8E23','#FFA500','#FF4500', + '#DA70D6','#EEE8AA','#98FB98','#AFEEEE','#D87093','#FFEFD5','#FFDAB9','#CD853F','#FFC0CB','#DDA0DD','#B0E0E6','#800080','#FF0000','#BC8F8F','#4169E1', + '#8B4513','#FA8072','#F4A460','#2E8B57','#FFF5EE','#A0522D','#C0C0C0','#87CEEB','#6A5ACD','#708090','#FFFAFA','#00FF7F','#4682B4','#D2B48C','#008080', + '#D8BFD8','#FF6347','#40E0D0','#EE82EE','#D02090','#F5DEB3','#FFFFFF','#F5F5F5','#FFFF00','#9ACD32'); + + + var color_picker_div = false; + var color_picker_active_tab = false; + var color_picker_form_field = false; + var color_picker_active_input = false; + function baseConverter (number,ob,nb) { + number = number + ""; + number = number.toUpperCase(); + var list = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + var dec = 0; + for (var i = 0; i <= number.length; i++) { + dec += (list.indexOf(number.charAt(i))) * (Math.pow(ob , (number.length - i - 1))); + } + number = ""; + var magnitude = Math.floor((Math.log(dec))/(Math.log(nb))); + for (var i = magnitude; i >= 0; i--) { + var amount = Math.floor(dec/Math.pow(nb,i)); + number = number + list.charAt(amount); + dec -= amount*(Math.pow(nb,i)); + } + if(number.length==0)number=0; + return number; + } + + function colorPickerGetTopPos(inputObj) + { + + var returnValue = inputObj.offsetTop; + while((inputObj = inputObj.offsetParent) != null){ + returnValue += inputObj.offsetTop; + } + return returnValue; + } + + function colorPickerGetLeftPos(inputObj) + { + var returnValue = inputObj.offsetLeft; + while((inputObj = inputObj.offsetParent) != null)returnValue += inputObj.offsetLeft; + return returnValue; + } + + function cancelColorPickerEvent(){ + return false; + } + + function showHideColorOptions(e,inputObj) + { + + + var thisObj = this; + if(inputObj){ + var parentNode = inputObj.parentNode; + thisObj = inputObj; + }else var parentNode = this.parentNode; + var activeColorDiv = false; + var subDiv = parentNode.getElementsByTagName('DIV')[0]; + counter=0; + var initZIndex = 10; + var contentDiv = document.getElementById('color_picker_content').getElementsByTagName('DIV')[0]; + do{ + if(subDiv.tagName=='DIV' && subDiv.className!='colorPickerCloseButton'){ + if(subDiv==thisObj){ + thisObj.className='colorPickerTab_active'; + thisObj.style.zIndex = 50; + var img = thisObj.getElementsByTagName('IMG')[0]; + img.src = "/alfresco/images/calendar/tab_right_active.gif" + img.src = img.src.replace(/inactive/,'active'); + contentDiv.style.display='block'; + activeColorDiv = contentDiv; + }else{ + subDiv.className = 'colorPickerTab_inactive'; + var img = subDiv.getElementsByTagName('IMG')[0]; + img.src = "/alfresco/images/calendar/tab_right_inactive.gif"; + if(activeColorDiv) + subDiv.style.zIndex = initZIndex - counter; + else + subDiv.style.zIndex = counter; + contentDiv.style.display='none'; + } + counter++; + } + subDiv = subDiv.nextSibling; + if(contentDiv.nextSibling)contentDiv = contentDiv.nextSibling; + }while(subDiv); + + + document.getElementById('colorPicker_statusBarTxt').innerHTML = ' '; + + + } + + function createColorPickerTopRow(inputObj){ + var tabs = ['RGB','Named colors','Color slider']; + var tabWidths = [37,90,70]; + var div = document.createElement('DIV'); + div.className='colorPicker_topRow'; + + inputObj.appendChild(div); + var currentWidth = 0; + for(var no=0;no=0;r-=3){ + for(var g=0;g<=15;g+=3){ + for(var b=0;b<=15;b+=3){ + var red = baseConverter(r,10,16) + ''; + var green = baseConverter(g,10,16) + ''; + var blue = baseConverter(b,10,16) + ''; + + var color = '#' + red + red + green + green + blue + blue; + var div = document.createElement('DIV'); + div.style.backgroundColor=color; + div.innerHTML = ''; + div.className='colorSquare'; + div.title = color; + div.onclick = chooseColor; + div.setAttribute('rgbColor',color); + div.onmouseover = colorPickerShowStatusBarText; + div.onmouseout = colorPickerHideStatusBarText; + webColorDiv.appendChild(div); + } + } + } + } + + function createNamedColors(inputObj){ + var namedColorDiv = document.createElement('DIV'); + namedColorDiv.style.paddingTop = '1px'; + namedColorDiv.style.display='none'; + inputObj.appendChild(namedColorDiv); + for(var no=0;no255)r=255; + if(g/1>255)g=255; + if(b/1>255)b=255; + r = baseConverter(r,10,16) + ''; + g = baseConverter(g,10,16) + ''; + b = baseConverter(b,10,16) + ''; + if(r.length==1)r = '0' + r; + if(g.length==1)g = '0' + g; + if(b.length==1)b = '0' + b; + + document.getElementById('colorPreview').style.backgroundColor = '#' + r + g + b; + document.getElementById('js_color_picker_color_code').value = '#' + r + g + b; + } \ No newline at end of file diff --git a/source/web/scripts/calendar/saveEventDetails.js b/source/web/scripts/calendar/saveEventDetails.js new file mode 100644 index 0000000000..4ed059bdfc --- /dev/null +++ b/source/web/scripts/calendar/saveEventDetails.js @@ -0,0 +1,187 @@ + +var handleSuccessSaveEvent = function(o) +{ + hideSavingIndicator('c'); + alert("Calendar updated!"); + resetEventDetails(); + refreshAllViews(); +} + +var handleFailureSaveEvent = function(o) +{ + hideSavingIndicator('c'); + alert("Unable to Save, " + o.statusText); +} + +var callbackSaveEvent = +{ + success:handleSuccessSaveEvent, + failure:handleFailureSaveEvent, + argument: { foo:"foo", bar:"bar" } +}; + +function saveCalendarEvent(toDelete) +{ + if (!validateEventDetails(toDelete)) return; + showSavingIndicator('c'); + + var sUrl = getContextPath() + '/wcservice/calendar/SaveCalendarEvent?'; + var postData = constructCalendarData(toDelete); + sUrl += postData; + var request = YAHOO.util.Connect.asyncRequest('GET', sUrl, callbackSaveEvent, null); +} + +function constructCalendarData(toDelete) +{ + var data = ""; + data += "s=" + spaceRef; + data += "&"; + data += "what=" + document.getElementById("txtWhatEvent").value; + data += "&"; + data += "fd=" + document.getElementById("hidFromDate").value; + data += "&"; + data += "ft=" + document.getElementById("lstFromTime").value; + data += "&"; + data += "td=" + document.getElementById("hidToDate").value; + data += "&"; + data += "tt=" + document.getElementById("lstToTime").value; + data += "&"; + data += "where=" + document.getElementById("txtWhereEvent").value; + data += "&"; + data += "desc=" + document.getElementById("txtDescriptionEvent").value; + data += "&"; + data += "color=" + document.getElementById("txtColor").value; + data += "&"; + if (toDelete) + { + data += "d=true"; + } + else + { + data += "d=false"; + } + if (_currentActiveEditingEvent != null) + { + data += "&"; + data += "e=" + _currentActiveEditingEvent; + } + + return data; +} + +function resetEventDetails() +{ + document.getElementById("txtWhatEvent").value = defaultCaption; + document.getElementById("hidFromDate").value = defaultFromDateString; + document.getElementById("txtFromDate").value = defaultFromDate.toDateString(); + document.getElementById("lstFromTime").value = defaultFromTime; + document.getElementById("hidToDate").value = defaultToDateString; + document.getElementById("txtToDate").value = defaultToDate.toDateString(); + document.getElementById("lstToTime").value = defaultToTime; + document.getElementById("txtWhereEvent").value = defaultPlace; + document.getElementById("txtColor").value = defaultColor; + + /*document.getElementById("txtWhatEvent").value = ""; + document.getElementById("hidFromDate").value = ""; + document.getElementById("txtFromDate").value = ""; + document.getElementById("lstFromTime").selectedIndex = 0; + document.getElementById("hidToDate").value = ""; + document.getElementById("txtToDate").value = ""; + document.getElementById("lstToTime").selectedIndex = 0; + document.getElementById("txtWhereEvent").value = ""; + document.getElementById("txtDescriptionEvent").value = ""; + document.getElementById("txtColor").value = "";*/ + + document.getElementById("txtWhatEvent").focus(); + + _currentActiveEditingEvent = null; +} + +function validateEventDetails(toDelete) +{ + if (toDelete) + if (_currentActiveEditingEvent == null) + { + alert("No Event Currently selected.\rPlease select an Event first from Month/Week/Day view to delete."); + return false; + } + + if (trim(document.getElementById("txtWhatEvent").value) == "") + { + alert("Please enter Event Information!"); + document.getElementById("txtWhatEvent").focus(); + return false; + } + if (!ValidateString(trim(document.getElementById("txtWhatEvent").value))) + { + document.getElementById("txtWhatEvent").focus(); + return false; + } + if (trim(document.getElementById("txtFromDate").value) == "") + { + alert("Please select a valid Starting Date!"); + document.getElementById("txtFromDate").focus(); + return false; + } + if (trim(document.getElementById("txtToDate").value) == "") + { + alert("Please select a valid Ending Date!"); + document.getElementById("txtToDate").focus(); + return false; + } + if (!ValidateDateSet()) + { + alert("Ending Date must be greater than Starting Date!"); + document.getElementById("txtToDate").focus(); + return false; + } + return true; +} + +function ValidateString(dataValue) +{ + for(var j=0; j 0-9 + 64-91 -> A-Z + 96-123 -> a-z + 32 -> space bar + 44 -> , + 59 -> ; + 40 -> ( + 41 -> ) + 63 -> ? + 33 -> ! + 45 -> - + 95 -> _ + */ + if((hh>=48 && hh<=57) || (hh>64 && hh<91) || (hh>96 && hh<123) || (hh==32) || (hh==44) || (hh==59) || (hh==40) || (hh==41) || (hh==63) || (hh==33) || (hh==45) || (hh==95)) + { + } + else + { + alert("Event Information has some invalid characters.\rAllowed Characters are 0-9 a-z A-Z , ; ( ) ? ! - _"); + return false; + } + } + return true; +} + +function ValidateDateSet() +{ + var fromDate = new Date(document.getElementById("hidFromDate").value); + var fromTime = document.getElementById("lstFromTime").value.split(":"); + fromDate.setHours(fromTime[0]); + fromDate.setMinutes(fromTime[1]); + + var toDate = new Date(document.getElementById("hidToDate").value); + var toTime = document.getElementById("lstToTime").value.split(":"); + toDate.setHours(toTime[0]); + toDate.setMinutes(toTime[1]); + + return !(toDate <= fromDate); +} diff --git a/source/web/yui/Custom.css b/source/web/yui/Custom.css new file mode 100644 index 0000000000..88f9cf2eca --- /dev/null +++ b/source/web/yui/Custom.css @@ -0,0 +1,5 @@ +.eventCapture, showDayEvents, showWeekEvents, showMonthEvents +{ + background-color:#EFF7FF; +} + diff --git a/source/web/yui/assets/border_tabs.css b/source/web/yui/assets/border_tabs.css new file mode 100644 index 0000000000..436c6b757a --- /dev/null +++ b/source/web/yui/assets/border_tabs.css @@ -0,0 +1,54 @@ +/* +Copyright (c) 2007, Yahoo! Inc. All rights reserved. +Code licensed under the BSD License: +http://developer.yahoo.net/yui/license.txt +version: 2.2.0 +*/ +.yui-navset .yui-nav li a, .yui-navset .yui-content { + border:1px solid #000; /* label and content borders */ +} + +.yui-navset .yui-nav .selected a, .yui-navset .yui-nav a:hover, .yui-navset .yui-content { + background-color:#f6f7ee; /* active tab, tab hover, and content bgcolor */ +} + +.yui-navset .yui-nav li em { padding:.5em; } /* tab padding */ + +/* defaults to orientation "top" */ +.yui-navset .yui-nav .selected a { + border-bottom-width:0; /* no bottom border for active tab */ + padding-bottom:1px; /* to match height of other tabs */ +} + +.yui-navset .yui-content { + margin-top:-1px; /* for active tab overlap */ +} + +/* overrides for other orientations */ + +.yui-navset-bottom .yui-nav .selected a { + border-width:0 1px 1px; /* no top border for active tab */ + padding:1px 0 0; /* to match height of other tabs */ +} + +.yui-navset-bottom .yui-content { + margin:0 0 -1px; /* for active tab overlap */ +} + +.yui-navset-left .yui-nav li.selected a { + border-width:1px 0 1px 1px; /* no right border for active tab */ + padding:0 1px 0 0; /* to match width of other tabs */ +} + +.yui-navset-left .yui-content { + margin:0 0 0 -1px; /* for active tab overlap */ +} + +.yui-navset-right .yui-nav li.selected a { + border-width:1px 1px 1px 0; /* no left border for active tab */ + padding:0 0 0 1px; /* to match width of other tabs */ +} + +.yui-navset-right .yui-content { + margin:0 -1px 0 0; /* for active tab overlap */ +} \ No newline at end of file diff --git a/source/web/yui/assets/calendar.css b/source/web/yui/assets/calendar.css new file mode 100644 index 0000000000..c9d43ebcdd --- /dev/null +++ b/source/web/yui/assets/calendar.css @@ -0,0 +1,197 @@ +/* +Copyright (c) 2007, Yahoo! Inc. All rights reserved. +Code licensed under the BSD License: +http://developer.yahoo.net/yui/license.txt +version: 2.2.0 +*/ +.yui-calcontainer { + position:relative; + padding:5px; + background-color:#F7F9FB; + border:1px solid #7B9EBD; + float:left; + overflow:hidden; +} + +.yui-calcontainer iframe { + position:absolute; + border:none; + margin:0;padding:0; + left:-1px; + top:-1px; + z-index:0; + width:50em; + height:50em; +} + +.yui-calcontainer.multi { + padding:0; +} + +.yui-calcontainer.multi .groupcal { + padding:5px; + background-color:transparent; + z-index:1; + float:left; + position:relative; + border:none; +} + +.yui-calcontainer .title { + font:100% sans-serif; + color:#000; + font-weight:bold; + margin-bottom:5px; + height:25px; + position:absolute; + top:3px;left:5px; + z-index:1; +} + +.yui-calcontainer .close-icon { + position:absolute; + right:3px; + top:3px; + border:none; + z-index:1; +} + +.yui-calcontainer .calclose { + background: url("calx.gif") no-repeat; + width:17px; + height:13px; + cursor:pointer; +} + +/* Calendar element styles */ + +.yui-calendar { + font:100% sans-serif; + text-align:center; + border-spacing:0; + border-collapse:separate; + position:relative; +} + +.yui-calcontainer.withtitle { + padding-top:1.5em; +} + +.yui-calendar .calnavleft { + position:absolute; + cursor:pointer; + top:2px; + bottom:0; + width:9px; + height:12px; + left:2px; + z-index:1; + background: url("callt.gif") no-repeat; +} + +.yui-calendar .calnavright { + position:absolute; + cursor:pointer; + top:2px; + bottom:0; + width:9px; + height:12px; + right:2px; + z-index:1; + background: url("calrt.gif") no-repeat; +} + +.yui-calendar td.calcell { + padding:.1em .2em; + border:1px solid #E0E0E0; + text-align:center; +} + +.yui-calendar td.calcell a { + color:#003DB8; + text-decoration:none; +} + +.yui-calendar td.calcell.today { + border:1px solid #000; +} + +.yui-calendar td.calcell.oom { + cursor:default; + color:#999; + background-color:#EEE; + border:1px solid #E0E0E0; +} + +.yui-calendar td.calcell.selected { + color:#003DB8; + background-color:#FFF19F; + border:1px solid #FF9900; +} + +.yui-calendar td.calcell.calcellhover { + cursor:pointer; + color:#FFF; + background-color:#FF9900; + border:1px solid #FF9900; +} + +.yui-calendar td.calcell.calcellhover a { + color:#FFF; +} + +.yui-calendar td.calcell.restricted { + text-decoration:line-through; +} + +.yui-calendar td.calcell.previous { + color:#CCC; +} + +.yui-calendar td.calcell.highlight1 { background-color:#CCFF99; } +.yui-calendar td.calcell.highlight2 { background-color:#99CCFF; } +.yui-calendar td.calcell.highlight3 { background-color:#FFCCCC; } +.yui-calendar td.calcell.highlight4 { background-color:#CCFF99; } + +.yui-calendar .calhead { + border:1px solid #E0E0E0; + vertical-align:middle; + background-color:#FFF; +} + +.yui-calendar .calheader { + position:relative; + width:100%; + text-align:center; +} + +.yui-calendar .calheader img { + border:none; +} + +.yui-calendar .calweekdaycell { + color:#666; + font-weight:normal; + text-align:center; + width:1.5em; +} + +.yui-calendar .calfoot { + background-color:#EEE; +} + +.yui-calendar .calrowhead, .yui-calendar .calrowfoot { + color:#666; + font-size:9px; + font-style:italic; + font-weight:normal; + width:15px; +} + +.yui-calendar .calrowhead { + border-right-width:2px; +} + +/* Specific changes for calendar running under fonts/reset */ +.yui-calendar .calbody a:hover {background:inherit;} +p#clear {clear:left; padding-top:10px;} diff --git a/source/web/yui/assets/callt.gif b/source/web/yui/assets/callt.gif new file mode 100644 index 0000000000..a6cc8da5b2 Binary files /dev/null and b/source/web/yui/assets/callt.gif differ diff --git a/source/web/yui/assets/calrt.gif b/source/web/yui/assets/calrt.gif new file mode 100644 index 0000000000..ee137b2ff7 Binary files /dev/null and b/source/web/yui/assets/calrt.gif differ diff --git a/source/web/yui/assets/calx.gif b/source/web/yui/assets/calx.gif new file mode 100644 index 0000000000..27e7bc36e4 Binary files /dev/null and b/source/web/yui/assets/calx.gif differ diff --git a/source/web/yui/assets/round_tabs.css b/source/web/yui/assets/round_tabs.css new file mode 100644 index 0000000000..47e8b2bf22 --- /dev/null +++ b/source/web/yui/assets/round_tabs.css @@ -0,0 +1,76 @@ +.yui-navset .yui-content { + border:1px solid #99CCFF; +} +.yui-navset .yui-nav .selected a, .yui-navset .yui-nav a:hover { + background-color:#EFF7FF; +} + +.yui-navset .yui-nav li a { + background:#EFF7FF url(../img/round_4px_trans_gray.gif) no-repeat; +} +.yui-navset .yui-nav li a em { + background:transparent url(../img/round_4px_trans_gray.gif) no-repeat top right; + padding:0.5em; +} + +/* top oriented */ + +.yui-navset-top .yui-nav { margin-bottom:-1px; } /* for overlap, based on content border-width */ +.yui-navset-top .yui-nav li a { + border-bottom:1px solid #ccc; +} + +.yui-navset-top .yui-nav .selected a { border-bottom:0; } +.yui-navset-top .yui-nav .selected a em { padding-bottom:0.6em; } /* adjust height */ + +/* top & bottom oriented */ +.yui-navset-top .yui-nav li a em, .yui-navset-bottom .yui-nav li a em { + margin-left:4px; /* based on border-radius */ + padding-right:8px; /* based on border-radius (2x left to balance margin) */ + padding-left:4px; +} + +/* bottom oriented */ + +.yui-navset-bottom .yui-nav { margin-top:-1px; } /* for overlap, based on content border-width */ +.yui-navset-bottom .yui-nav li a { border-top:1px solid #ccc; } + +.yui-navset-bottom .yui-nav .selected a { border-top:0; } +.yui-navset-bottom .yui-nav .selected a em { padding-top:0.6em; } /* adjust height */ + +.yui-navset-bottom .yui-nav li a { background-position:bottom left; } +.yui-navset-bottom .yui-nav li a em { background-position:bottom right; } + +/* left oriented */ + +.yui-navset-left .yui-content { margin-left:-1px; } /* for overlap, based on content border-width */ + +.yui-navset-left .yui-nav li a { + border-right:1px solid #ccc; + padding-bottom:4px; +} + +.yui-navset-left .yui-nav li a em, .yui-navset-right .yui-nav li a em { + padding-top:8px; /* based on border-radius (2x left to balance margin) */ +} + +.yui-navset-left .yui-nav .selected a { border-right:0; } +.yui-navset-left .yui-nav .selected a em { padding-left:0.6em; } /* adjust width */ + +.yui-navset-left .yui-nav li a { background-position:bottom left; } +.yui-navset-left .yui-nav li a em { background-position:top left; } + +/* right oriented */ + +.yui-navset-right .yui-content { margin-right:-1px; } /* for overlap, based on content border-width */ + +.yui-navset-right .yui-nav li a { + border-left:1px solid #ccc; + padding-bottom:4px; +} + +.yui-navset-right .yui-nav .selected a { border-left:0; } +.yui-navset-right .yui-nav .selected a em { padding-left:0.6em; } /* adjust width */ + +.yui-navset-right .yui-nav li a { background-position:bottom right; } +.yui-navset-right .yui-nav li a em { background-position:top right; } \ No newline at end of file diff --git a/source/web/yui/assets/tabview.css b/source/web/yui/assets/tabview.css new file mode 100644 index 0000000000..d14ecd3dc7 --- /dev/null +++ b/source/web/yui/assets/tabview.css @@ -0,0 +1,75 @@ +/* +Copyright (c) 2007, Yahoo! Inc. All rights reserved. +Code licensed under the BSD License: +http://developer.yahoo.net/yui/license.txt +version: 2.2.0 +*/ +/* default space between tabs */ +.yui-navset .yui-nav li { + margin-right:0.5em; /* horizontal tabs */ +} +.yui-navset-left .yui-nav li, .yui-navset-right .yui-nav li { + margin:0 0 0.5em; /* vertical tabs */ +} + +/* default width for side tabs */ +.yui-navset-left .yui-nav, .yui-navset-right .yui-nav { width:6em; } +.yui-navset-left { padding-left:6em; } /* map to nav width */ +.yui-navset-right { padding-right:6em; } /* ditto */ + +/* core */ + +.yui-nav, .yui-nav li { + margin:0; + padding:0; + list-style:none; +} +.yui-navset li em { font-style:normal; } + +.yui-navset { + position:relative; /* contain absolute positioned tabs (left/right) */ + zoom:1; +} + +.yui-navset .yui-content { zoom:1; } + +.yui-navset .yui-nav li { + display:inline-block; + display:-moz-inline-stack; + *display:inline; /* IE */ + vertical-align:bottom; /* safari: for overlap */ + cursor:pointer; /* gecko: due to -moz-inline-stack on anchor */ + zoom:1; /* IE: kill space between horizontal tabs */ +} + +.yui-navset-left .yui-nav li, .yui-navset-right .yui-nav li { + display:block; +} + +.yui-navset .yui-nav a { + outline:0; /* gecko: keep from shifting */ +} + +.yui-navset .yui-nav a { position:relative; } /* IE: to allow overlap */ + +.yui-navset .yui-nav li a { + display:block; + display:inline-block; + vertical-align:bottom; /* safari: for overlap */ + zoom:1; +} + +.yui-navset-left .yui-nav li a, .yui-navset-right .yui-nav li a { + display:block; +} + +.yui-navset-bottom .yui-nav li a { + vertical-align:text-top; /* for inline overlap (reverse for Op border bug) */ +} + +.yui-navset .yui-nav li a em { display:block; } + +/* position left and right oriented tabs */ +.yui-navset-left .yui-nav, .yui-navset-right .yui-nav { position:absolute; z-index:1; } +.yui-navset-left .yui-nav { left:0; } +.yui-navset-right .yui-nav { right:0; } diff --git a/source/web/yui/calendar.js b/source/web/yui/calendar.js new file mode 100644 index 0000000000..a75c9f3304 --- /dev/null +++ b/source/web/yui/calendar.js @@ -0,0 +1,4309 @@ +/* +Copyright (c) 2007, Yahoo! Inc. All rights reserved. +Code licensed under the BSD License: +http://developer.yahoo.net/yui/license.txt +version: 2.2.0 +*/ +/** +* Config is a utility used within an Object to allow the implementer to maintain a list of local configuration properties and listen for changes to those properties dynamically using CustomEvent. The initial values are also maintained so that the configuration can be reset at any given point to its initial state. +* @namespace YAHOO.util +* @class Config +* @constructor +* @param {Object} owner The owner Object to which this Config Object belongs +*/ +YAHOO.util.Config = function(owner) { + if (owner) { + this.init(owner); + } +}; + +YAHOO.util.Config.prototype = { + + /** + * Object reference to the owner of this Config Object + * @property owner + * @type Object + */ + owner : null, + + /** + * Boolean flag that specifies whether a queue is currently being executed + * @property queueInProgress + * @type Boolean + */ + queueInProgress : false, + + + /** + * Validates that the value passed in is a Boolean. + * @method checkBoolean + * @param {Object} val The value to validate + * @return {Boolean} true, if the value is valid + */ + checkBoolean: function(val) { + if (typeof val == 'boolean') { + return true; + } else { + return false; + } + }, + + /** + * Validates that the value passed in is a number. + * @method checkNumber + * @param {Object} val The value to validate + * @return {Boolean} true, if the value is valid + */ + checkNumber: function(val) { + if (isNaN(val)) { + return false; + } else { + return true; + } + } +}; + + +/** +* Initializes the configuration Object and all of its local members. +* @method init +* @param {Object} owner The owner Object to which this Config Object belongs +*/ +YAHOO.util.Config.prototype.init = function(owner) { + + this.owner = owner; + + /** + * Object reference to the owner of this Config Object + * @event configChangedEvent + */ + this.configChangedEvent = new YAHOO.util.CustomEvent("configChanged"); + this.queueInProgress = false; + + /* Private Members */ + + /** + * Maintains the local collection of configuration property objects and their specified values + * @property config + * @private + * @type Object + */ + var config = {}; + + /** + * Maintains the local collection of configuration property objects as they were initially applied. + * This object is used when resetting a property. + * @property initialConfig + * @private + * @type Object + */ + var initialConfig = {}; + + /** + * Maintains the local, normalized CustomEvent queue + * @property eventQueue + * @private + * @type Object + */ + var eventQueue = []; + + /** + * Fires a configuration property event using the specified value. + * @method fireEvent + * @private + * @param {String} key The configuration property's name + * @param {value} Object The value of the correct type for the property + */ + var fireEvent = function( key, value ) { + key = key.toLowerCase(); + + var property = config[key]; + + if (typeof property != 'undefined' && property.event) { + property.event.fire(value); + } + }; + /* End Private Members */ + + /** + * Adds a property to the Config Object's private config hash. + * @method addProperty + * @param {String} key The configuration property's name + * @param {Object} propertyObject The Object containing all of this property's arguments + */ + this.addProperty = function( key, propertyObject ) { + key = key.toLowerCase(); + + config[key] = propertyObject; + + propertyObject.event = new YAHOO.util.CustomEvent(key); + propertyObject.key = key; + + if (propertyObject.handler) { + propertyObject.event.subscribe(propertyObject.handler, this.owner, true); + } + + this.setProperty(key, propertyObject.value, true); + + if (! propertyObject.suppressEvent) { + this.queueProperty(key, propertyObject.value); + } + }; + + /** + * Returns a key-value configuration map of the values currently set in the Config Object. + * @method getConfig + * @return {Object} The current config, represented in a key-value map + */ + this.getConfig = function() { + var cfg = {}; + + for (var prop in config) { + var property = config[prop]; + if (typeof property != 'undefined' && property.event) { + cfg[prop] = property.value; + } + } + + return cfg; + }; + + /** + * Returns the value of specified property. + * @method getProperty + * @param {String} key The name of the property + * @return {Object} The value of the specified property + */ + this.getProperty = function(key) { + key = key.toLowerCase(); + + var property = config[key]; + if (typeof property != 'undefined' && property.event) { + return property.value; + } else { + return undefined; + } + }; + + /** + * Resets the specified property's value to its initial value. + * @method resetProperty + * @param {String} key The name of the property + * @return {Boolean} True is the property was reset, false if not + */ + this.resetProperty = function(key) { + key = key.toLowerCase(); + + var property = config[key]; + if (typeof property != 'undefined' && property.event) { + if (initialConfig[key] && initialConfig[key] != 'undefined') { + this.setProperty(key, initialConfig[key]); + } + return true; + } else { + return false; + } + }; + + /** + * Sets the value of a property. If the silent property is passed as true, the property's event will not be fired. + * @method setProperty + * @param {String} key The name of the property + * @param {String} value The value to set the property to + * @param {Boolean} silent Whether the value should be set silently, without firing the property event. + * @return {Boolean} True, if the set was successful, false if it failed. + */ + this.setProperty = function(key, value, silent) { + key = key.toLowerCase(); + + if (this.queueInProgress && ! silent) { + this.queueProperty(key,value); // Currently running through a queue... + return true; + } else { + var property = config[key]; + if (typeof property != 'undefined' && property.event) { + if (property.validator && ! property.validator(value)) { // validator + return false; + } else { + property.value = value; + if (! silent) { + fireEvent(key, value); + this.configChangedEvent.fire([key, value]); + } + return true; + } + } else { + return false; + } + } + }; + + /** + * Sets the value of a property and queues its event to execute. If the event is already scheduled to execute, it is + * moved from its current position to the end of the queue. + * @method queueProperty + * @param {String} key The name of the property + * @param {String} value The value to set the property to + * @return {Boolean} true, if the set was successful, false if it failed. + */ + this.queueProperty = function(key, value) { + key = key.toLowerCase(); + + var property = config[key]; + + if (typeof property != 'undefined' && property.event) { + if (typeof value != 'undefined' && property.validator && ! property.validator(value)) { // validator + return false; + } else { + + if (typeof value != 'undefined') { + property.value = value; + } else { + value = property.value; + } + + var foundDuplicate = false; + + for (var i=0;i 11) { + while (newMonth > 11) { + newMonth -= 12; + years += 1; + } + } + + d.setMonth(newMonth); + d.setFullYear(date.getFullYear() + years); + break; + case this.DAY: + d.setDate(date.getDate() + amount); + break; + case this.YEAR: + d.setFullYear(date.getFullYear() + amount); + break; + case this.WEEK: + d.setDate(date.getDate() + (amount * 7)); + break; + } + return d; + }, + + /** + * Subtracts the specified amount of time from the this instance. + * @method subtract + * @param {Date} date The JavaScript Date object to perform subtraction on + * @param {Number} field The this field constant to be used for performing subtraction. + * @param {Number} amount The number of units (measured in the field constant) to subtract from the date. + * @return {Date} The resulting Date object + */ + subtract : function(date, field, amount) { + return this.add(date, field, (amount*-1)); + }, + + /** + * Determines whether a given date is before another date on the calendar. + * @method before + * @param {Date} date The Date object to compare with the compare argument + * @param {Date} compareTo The Date object to use for the comparison + * @return {Boolean} true if the date occurs before the compared date; false if not. + */ + before : function(date, compareTo) { + var ms = compareTo.getTime(); + if (date.getTime() < ms) { + return true; + } else { + return false; + } + }, + + /** + * Determines whether a given date is after another date on the calendar. + * @method after + * @param {Date} date The Date object to compare with the compare argument + * @param {Date} compareTo The Date object to use for the comparison + * @return {Boolean} true if the date occurs after the compared date; false if not. + */ + after : function(date, compareTo) { + var ms = compareTo.getTime(); + if (date.getTime() > ms) { + return true; + } else { + return false; + } + }, + + /** + * Determines whether a given date is between two other dates on the calendar. + * @method between + * @param {Date} date The date to check for + * @param {Date} dateBegin The start of the range + * @param {Date} dateEnd The end of the range + * @return {Boolean} true if the date occurs between the compared dates; false if not. + */ + between : function(date, dateBegin, dateEnd) { + if (this.after(date, dateBegin) && this.before(date, dateEnd)) { + return true; + } else { + return false; + } + }, + + /** + * Retrieves a JavaScript Date object representing January 1 of any given year. + * @method getJan1 + * @param {Number} calendarYear The calendar year for which to retrieve January 1 + * @return {Date} January 1 of the calendar year specified. + */ + getJan1 : function(calendarYear) { + return new Date(calendarYear,0,1); + }, + + /** + * Calculates the number of days the specified date is from January 1 of the specified calendar year. + * Passing January 1 to this function would return an offset value of zero. + * @method getDayOffset + * @param {Date} date The JavaScript date for which to find the offset + * @param {Number} calendarYear The calendar year to use for determining the offset + * @return {Number} The number of days since January 1 of the given year + */ + getDayOffset : function(date, calendarYear) { + var beginYear = this.getJan1(calendarYear); // Find the start of the year. This will be in week 1. + + // Find the number of days the passed in date is away from the calendar year start + var dayOffset = Math.ceil((date.getTime()-beginYear.getTime()) / this.ONE_DAY_MS); + return dayOffset; + }, + + /** + * Calculates the week number for the given date. This function assumes that week 1 is the + * week in which January 1 appears, regardless of whether the week consists of a full 7 days. + * The calendar year can be specified to help find what a the week number would be for a given + * date if the date overlaps years. For instance, a week may be considered week 1 of 2005, or + * week 53 of 2004. Specifying the optional calendarYear allows one to make this distinction + * easily. + * @method getWeekNumber + * @param {Date} date The JavaScript date for which to find the week number + * @param {Number} calendarYear OPTIONAL - The calendar year to use for determining the week number. Default is + * the calendar year of parameter "date". + * @param {Number} weekStartsOn OPTIONAL - The integer (0-6) representing which day a week begins on. Default is 0 (for Sunday). + * @return {Number} The week number of the given date. + */ + getWeekNumber : function(date, calendarYear) { + date = this.clearTime(date); + var nearestThurs = new Date(date.getTime() + (4 * this.ONE_DAY_MS) - ((date.getDay()) * this.ONE_DAY_MS)); + + var jan1 = new Date(nearestThurs.getFullYear(),0,1); + var dayOfYear = ((nearestThurs.getTime() - jan1.getTime()) / this.ONE_DAY_MS) - 1; + + var weekNum = Math.ceil((dayOfYear)/ 7); + return weekNum; + }, + + /** + * Determines if a given week overlaps two different years. + * @method isYearOverlapWeek + * @param {Date} weekBeginDate The JavaScript Date representing the first day of the week. + * @return {Boolean} true if the date overlaps two different years. + */ + isYearOverlapWeek : function(weekBeginDate) { + var overlaps = false; + var nextWeek = this.add(weekBeginDate, this.DAY, 6); + if (nextWeek.getFullYear() != weekBeginDate.getFullYear()) { + overlaps = true; + } + return overlaps; + }, + + /** + * Determines if a given week overlaps two different months. + * @method isMonthOverlapWeek + * @param {Date} weekBeginDate The JavaScript Date representing the first day of the week. + * @return {Boolean} true if the date overlaps two different months. + */ + isMonthOverlapWeek : function(weekBeginDate) { + var overlaps = false; + var nextWeek = this.add(weekBeginDate, this.DAY, 6); + if (nextWeek.getMonth() != weekBeginDate.getMonth()) { + overlaps = true; + } + return overlaps; + }, + + /** + * Gets the first day of a month containing a given date. + * @method findMonthStart + * @param {Date} date The JavaScript Date used to calculate the month start + * @return {Date} The JavaScript Date representing the first day of the month + */ + findMonthStart : function(date) { + var start = new Date(date.getFullYear(), date.getMonth(), 1); + return start; + }, + + /** + * Gets the last day of a month containing a given date. + * @method findMonthEnd + * @param {Date} date The JavaScript Date used to calculate the month end + * @return {Date} The JavaScript Date representing the last day of the month + */ + findMonthEnd : function(date) { + var start = this.findMonthStart(date); + var nextMonth = this.add(start, this.MONTH, 1); + var end = this.subtract(nextMonth, this.DAY, 1); + return end; + }, + + /** + * Clears the time fields from a given date, effectively setting the time to 12 noon. + * @method clearTime + * @param {Date} date The JavaScript Date for which the time fields will be cleared + * @return {Date} The JavaScript Date cleared of all time fields + */ + clearTime : function(date) { + date.setHours(12,0,0,0); + return date; + } +}; + +/** +* The Calendar component is a UI control that enables users to choose one or more dates from a graphical calendar presented in a one-month ("one-up") or two-month ("two-up") interface. Calendars are generated entirely via script and can be navigated without any page refreshes. +* @module calendar +* @title Calendar +* @namespace YAHOO.widget +* @requires yahoo,dom,event +*/ + +/** +* Calendar is the base class for the Calendar widget. In its most basic +* implementation, it has the ability to render a calendar widget on the page +* that can be manipulated to select a single date, move back and forth between +* months and years. +*

To construct the placeholder for the calendar widget, the code is as +* follows: +*

+* <div id="cal1Container"></div> +* +* Note that the table can be replaced with any kind of element. +*

+* @namespace YAHOO.widget +* @class Calendar +* @constructor +* @param {String} id The id of the table element that will represent the calendar widget +* @param {String} containerId The id of the container div element that will wrap the calendar table +* @param {Object} config The configuration object containing the Calendar's arguments +*/ +YAHOO.widget.Calendar = function(id, containerId, config) { + this.init(id, containerId, config); +}; + +/** +* The path to be used for images loaded for the Calendar +* @property YAHOO.widget.Calendar.IMG_ROOT +* @static +* @deprecated You can now customize images by overriding the calclose, calnavleft and calnavright default CSS classes for the close icon, left arrow and right arrow respectively +* @type String +*/ +YAHOO.widget.Calendar.IMG_ROOT = null; + +/** +* Type constant used for renderers to represent an individual date (M/D/Y) +* @property YAHOO.widget.Calendar.DATE +* @static +* @final +* @type String +*/ +YAHOO.widget.Calendar.DATE = "D"; + +/** +* Type constant used for renderers to represent an individual date across any year (M/D) +* @property YAHOO.widget.Calendar.MONTH_DAY +* @static +* @final +* @type String +*/ +YAHOO.widget.Calendar.MONTH_DAY = "MD"; + +/** +* Type constant used for renderers to represent a weekday +* @property YAHOO.widget.Calendar.WEEKDAY +* @static +* @final +* @type String +*/ +YAHOO.widget.Calendar.WEEKDAY = "WD"; + +/** +* Type constant used for renderers to represent a range of individual dates (M/D/Y-M/D/Y) +* @property YAHOO.widget.Calendar.RANGE +* @static +* @final +* @type String +*/ +YAHOO.widget.Calendar.RANGE = "R"; + +/** +* Type constant used for renderers to represent a month across any year +* @property YAHOO.widget.Calendar.MONTH +* @static +* @final +* @type String +*/ +YAHOO.widget.Calendar.MONTH = "M"; + +/** +* Constant that represents the total number of date cells that are displayed in a given month +* @property YAHOO.widget.Calendar.DISPLAY_DAYS +* @static +* @final +* @type Number +*/ +YAHOO.widget.Calendar.DISPLAY_DAYS = 42; + +/** +* Constant used for halting the execution of the remainder of the render stack +* @property YAHOO.widget.Calendar.STOP_RENDER +* @static +* @final +* @type String +*/ +YAHOO.widget.Calendar.STOP_RENDER = "S"; + +YAHOO.widget.Calendar.prototype = { + + /** + * The configuration object used to set up the calendars various locale and style options. + * @property Config + * @private + * @deprecated Configuration properties should be set by calling Calendar.cfg.setProperty. + * @type Object + */ + Config : null, + + /** + * The parent CalendarGroup, only to be set explicitly by the parent group + * @property parent + * @type CalendarGroup + */ + parent : null, + + /** + * The index of this item in the parent group + * @property index + * @type Number + */ + index : -1, + + /** + * The collection of calendar table cells + * @property cells + * @type HTMLTableCellElement[] + */ + cells : null, + + /** + * The collection of calendar cell dates that is parallel to the cells collection. The array contains dates field arrays in the format of [YYYY, M, D]. + * @property cellDates + * @type Array[](Number[]) + */ + cellDates : null, + + /** + * The id that uniquely identifies this calendar. This id should match the id of the placeholder element on the page. + * @property id + * @type String + */ + id : null, + + /** + * The DOM element reference that points to this calendar's container element. The calendar will be inserted into this element when the shell is rendered. + * @property oDomContainer + * @type HTMLElement + */ + oDomContainer : null, + + /** + * A Date object representing today's date. + * @property today + * @type Date + */ + today : null, + + /** + * The list of render functions, along with required parameters, used to render cells. + * @property renderStack + * @type Array[] + */ + renderStack : null, + + /** + * A copy of the initial render functions created before rendering. + * @property _renderStack + * @private + * @type Array + */ + _renderStack : null, + + /** + * The private list of initially selected dates. + * @property _selectedDates + * @private + * @type Array + */ + _selectedDates : null, + + /** + * A map of DOM event handlers to attach to cells associated with specific CSS class names + * @property domEventMap + * @type Object + */ + domEventMap : null +}; + + + +/** +* Initializes the Calendar widget. +* @method init +* @param {String} id The id of the table element that will represent the calendar widget +* @param {String} containerId The id of the container div element that will wrap the calendar table +* @param {Object} config The configuration object containing the Calendar's arguments +*/ +YAHOO.widget.Calendar.prototype.init = function(id, containerId, config) { + this.initEvents(); + this.today = new Date(); + YAHOO.widget.DateMath.clearTime(this.today); + + this.id = id; + this.oDomContainer = document.getElementById(containerId); + + /** + * The Config object used to hold the configuration variables for the Calendar + * @property cfg + * @type YAHOO.util.Config + */ + this.cfg = new YAHOO.util.Config(this); + + /** + * The local object which contains the Calendar's options + * @property Options + * @type Object + */ + this.Options = {}; + + /** + * The local object which contains the Calendar's locale settings + * @property Locale + * @type Object + */ + this.Locale = {}; + + this.initStyles(); + + YAHOO.util.Dom.addClass(this.oDomContainer, this.Style.CSS_CONTAINER); + YAHOO.util.Dom.addClass(this.oDomContainer, this.Style.CSS_SINGLE); + + this.cellDates = []; + this.cells = []; + this.renderStack = []; + this._renderStack = []; + + this.setupConfig(); + + if (config) { + this.cfg.applyConfig(config, true); + } + + this.cfg.fireQueue(); +}; + +/** +* Renders the built-in IFRAME shim for the IE6 and below +* @method configIframe +*/ +YAHOO.widget.Calendar.prototype.configIframe = function(type, args, obj) { + var useIframe = args[0]; + + if (YAHOO.util.Dom.inDocument(this.oDomContainer)) { + if (useIframe) { + var pos = YAHOO.util.Dom.getStyle(this.oDomContainer, "position"); + + if (this.browser == "ie" && (pos == "absolute" || pos == "relative")) { + if (! YAHOO.util.Dom.inDocument(this.iframe)) { + this.iframe = document.createElement("iframe"); + this.iframe.src = "javascript:false;"; + YAHOO.util.Dom.setStyle(this.iframe, "opacity", "0"); + this.oDomContainer.insertBefore(this.iframe, this.oDomContainer.firstChild); + } + } + } else { + if (this.iframe) { + if (this.iframe.parentNode) { + this.iframe.parentNode.removeChild(this.iframe); + } + this.iframe = null; + } + } + } +}; + +/** +* Default handler for the "title" property +* @method configTitle +*/ +YAHOO.widget.Calendar.prototype.configTitle = function(type, args, obj) { + var title = args[0]; + var close = this.cfg.getProperty("close"); + + var titleDiv; + + if (title && title !== "") { + titleDiv = YAHOO.util.Dom.getElementsByClassName(YAHOO.widget.CalendarGroup.CSS_2UPTITLE, "div", this.oDomContainer)[0] || document.createElement("div"); + titleDiv.className = YAHOO.widget.CalendarGroup.CSS_2UPTITLE; + titleDiv.innerHTML = title; + this.oDomContainer.insertBefore(titleDiv, this.oDomContainer.firstChild); + YAHOO.util.Dom.addClass(this.oDomContainer, "withtitle"); + } else { + titleDiv = YAHOO.util.Dom.getElementsByClassName(YAHOO.widget.CalendarGroup.CSS_2UPTITLE, "div", this.oDomContainer)[0] || null; + + if (titleDiv) { + YAHOO.util.Event.purgeElement(titleDiv); + this.oDomContainer.removeChild(titleDiv); + } + if (! close) { + YAHOO.util.Dom.removeClass(this.oDomContainer, "withtitle"); + } + } +}; + +/** +* Default handler for the "close" property +* @method configClose +*/ +YAHOO.widget.Calendar.prototype.configClose = function(type, args, obj) { + var close = args[0]; + var title = this.cfg.getProperty("title"); + + var DEPR_CLOSE_PATH = "us/my/bn/x_d.gif"; + + var linkClose; + + if (close === true) { + linkClose = YAHOO.util.Dom.getElementsByClassName("link-close", "a", this.oDomContainer)[0] || document.createElement("a"); + linkClose.href = "javascript:void(null);"; + linkClose.className = "link-close"; + YAHOO.util.Event.addListener(linkClose, "click", this.hide, this, true); + + if (YAHOO.widget.Calendar.IMG_ROOT !== null) { + var imgClose = document.createElement("img"); + imgClose.src = YAHOO.widget.Calendar.IMG_ROOT + DEPR_CLOSE_PATH; + imgClose.className = YAHOO.widget.CalendarGroup.CSS_2UPCLOSE; + linkClose.appendChild(imgClose); + } else { + linkClose.innerHTML = ''; + } + + this.oDomContainer.appendChild(linkClose); + YAHOO.util.Dom.addClass(this.oDomContainer, "withtitle"); + } else { + linkClose = YAHOO.util.Dom.getElementsByClassName("link-close", "a", this.oDomContainer)[0] || null; + if (linkClose) { + YAHOO.util.Event.purgeElement(linkClose); + this.oDomContainer.removeChild(linkClose); + } + if (! title || title === "") { + YAHOO.util.Dom.removeClass(this.oDomContainer, "withtitle"); + } + } +}; + +/** +* Initializes Calendar's built-in CustomEvents +* @method initEvents +*/ +YAHOO.widget.Calendar.prototype.initEvents = function() { + + /** + * Fired before a selection is made + * @event beforeSelectEvent + */ + this.beforeSelectEvent = new YAHOO.util.CustomEvent("beforeSelect"); + + /** + * Fired when a selection is made + * @event selectEvent + * @param {Array} Array of Date field arrays in the format [YYYY, MM, DD]. + */ + this.selectEvent = new YAHOO.util.CustomEvent("select"); + + /** + * Fired before a selection is made + * @event beforeDeselectEvent + */ + this.beforeDeselectEvent = new YAHOO.util.CustomEvent("beforeDeselect"); + + /** + * Fired when a selection is made + * @event deselectEvent + * @param {Array} Array of Date field arrays in the format [YYYY, MM, DD]. + */ + this.deselectEvent = new YAHOO.util.CustomEvent("deselect"); + + /** + * Fired when the Calendar page is changed + * @event changePageEvent + */ + this.changePageEvent = new YAHOO.util.CustomEvent("changePage"); + + /** + * Fired before the Calendar is rendered + * @event beforeRenderEvent + */ + this.beforeRenderEvent = new YAHOO.util.CustomEvent("beforeRender"); + + /** + * Fired when the Calendar is rendered + * @event renderEvent + */ + this.renderEvent = new YAHOO.util.CustomEvent("render"); + + /** + * Fired when the Calendar is reset + * @event resetEvent + */ + this.resetEvent = new YAHOO.util.CustomEvent("reset"); + + /** + * Fired when the Calendar is cleared + * @event clearEvent + */ + this.clearEvent = new YAHOO.util.CustomEvent("clear"); + + this.beforeSelectEvent.subscribe(this.onBeforeSelect, this, true); + this.selectEvent.subscribe(this.onSelect, this, true); + this.beforeDeselectEvent.subscribe(this.onBeforeDeselect, this, true); + this.deselectEvent.subscribe(this.onDeselect, this, true); + this.changePageEvent.subscribe(this.onChangePage, this, true); + this.renderEvent.subscribe(this.onRender, this, true); + this.resetEvent.subscribe(this.onReset, this, true); + this.clearEvent.subscribe(this.onClear, this, true); +}; + + +/** +* The default event function that is attached to a date link within a calendar cell +* when the calendar is rendered. +* @method doSelectCell +* @param {DOMEvent} e The event +* @param {Calendar} cal A reference to the calendar passed by the Event utility +*/ +YAHOO.widget.Calendar.prototype.doSelectCell = function(e, cal) { + var target = YAHOO.util.Event.getTarget(e); + + var cell,index,d,date; + + while (target.tagName.toLowerCase() != "td" && ! YAHOO.util.Dom.hasClass(target, cal.Style.CSS_CELL_SELECTABLE)) { + target = target.parentNode; + if (target.tagName.toLowerCase() == "html") { + return; + } + } + + cell = target; + + if (YAHOO.util.Dom.hasClass(cell, cal.Style.CSS_CELL_SELECTABLE)) { + index = cell.id.split("cell")[1]; + d = cal.cellDates[index]; + date = new Date(d[0],d[1]-1,d[2]); + + var link; + + if (cal.Options.MULTI_SELECT) { + link = cell.getElementsByTagName("a")[0]; + if (link) { + link.blur(); + } + + var cellDate = cal.cellDates[index]; + var cellDateIndex = cal._indexOfSelectedFieldArray(cellDate); + + if (cellDateIndex > -1) { + cal.deselectCell(index); + } else { + cal.selectCell(index); + } + + } else { + link = cell.getElementsByTagName("a")[0]; + if (link) { + link.blur(); + } + cal.selectCell(index); + } + } +}; + +/** +* The event that is executed when the user hovers over a cell +* @method doCellMouseOver +* @param {DOMEvent} e The event +* @param {Calendar} cal A reference to the calendar passed by the Event utility +*/ +YAHOO.widget.Calendar.prototype.doCellMouseOver = function(e, cal) { + var target; + if (e) { + target = YAHOO.util.Event.getTarget(e); + } else { + target = this; + } + + while (target.tagName.toLowerCase() != "td") { + target = target.parentNode; + if (target.tagName.toLowerCase() == "html") { + return; + } + } + + if (YAHOO.util.Dom.hasClass(target, cal.Style.CSS_CELL_SELECTABLE)) { + YAHOO.util.Dom.addClass(target, cal.Style.CSS_CELL_HOVER); + } +}; + +/** +* The event that is executed when the user moves the mouse out of a cell +* @method doCellMouseOut +* @param {DOMEvent} e The event +* @param {Calendar} cal A reference to the calendar passed by the Event utility +*/ +YAHOO.widget.Calendar.prototype.doCellMouseOut = function(e, cal) { + var target; + if (e) { + target = YAHOO.util.Event.getTarget(e); + } else { + target = this; + } + + while (target.tagName.toLowerCase() != "td") { + target = target.parentNode; + if (target.tagName.toLowerCase() == "html") { + return; + } + } + + if (YAHOO.util.Dom.hasClass(target, cal.Style.CSS_CELL_SELECTABLE)) { + YAHOO.util.Dom.removeClass(target, cal.Style.CSS_CELL_HOVER); + } +}; + +YAHOO.widget.Calendar.prototype.setupConfig = function() { + + /** + * The month/year representing the current visible Calendar date (mm/yyyy) + * @config pagedate + * @type String + * @default today's date + */ + this.cfg.addProperty("pagedate", { value:new Date(), handler:this.configPageDate } ); + + /** + * The date or range of dates representing the current Calendar selection + * @config selected + * @type String + * @default [] + */ + this.cfg.addProperty("selected", { value:[], handler:this.configSelected } ); + + /** + * The title to display above the Calendar's month header + * @config title + * @type String + * @default "" + */ + this.cfg.addProperty("title", { value:"", handler:this.configTitle } ); + + /** + * Whether or not a close button should be displayed for this Calendar + * @config close + * @type Boolean + * @default false + */ + this.cfg.addProperty("close", { value:false, handler:this.configClose } ); + + /** + * Whether or not an iframe shim should be placed under the Calendar to prevent select boxes from bleeding through in Internet Explorer 6 and below. + * @config iframe + * @type Boolean + * @default true + */ + this.cfg.addProperty("iframe", { value:true, handler:this.configIframe, validator:this.cfg.checkBoolean } ); + + /** + * The minimum selectable date in the current Calendar (mm/dd/yyyy) + * @config mindate + * @type String + * @default null + */ + this.cfg.addProperty("mindate", { value:null, handler:this.configMinDate } ); + + /** + * The maximum selectable date in the current Calendar (mm/dd/yyyy) + * @config maxdate + * @type String + * @default null + */ + this.cfg.addProperty("maxdate", { value:null, handler:this.configMaxDate } ); + + + // Options properties + + /** + * True if the Calendar should allow multiple selections. False by default. + * @config MULTI_SELECT + * @type Boolean + * @default false + */ + this.cfg.addProperty("MULTI_SELECT", { value:false, handler:this.configOptions, validator:this.cfg.checkBoolean } ); + + /** + * The weekday the week begins on. Default is 0 (Sunday). + * @config START_WEEKDAY + * @type number + * @default 0 + */ + this.cfg.addProperty("START_WEEKDAY", { value:0, handler:this.configOptions, validator:this.cfg.checkNumber } ); + + /** + * True if the Calendar should show weekday labels. True by default. + * @config SHOW_WEEKDAYS + * @type Boolean + * @default true + */ + this.cfg.addProperty("SHOW_WEEKDAYS", { value:true, handler:this.configOptions, validator:this.cfg.checkBoolean } ); + + /** + * True if the Calendar should show week row headers. False by default. + * @config SHOW_WEEK_HEADER + * @type Boolean + * @default false + */ + this.cfg.addProperty("SHOW_WEEK_HEADER",{ value:false, handler:this.configOptions, validator:this.cfg.checkBoolean } ); + + /** + * True if the Calendar should show week row footers. False by default. + * @config SHOW_WEEK_FOOTER + * @type Boolean + * @default false + */ + this.cfg.addProperty("SHOW_WEEK_FOOTER",{ value:false, handler:this.configOptions, validator:this.cfg.checkBoolean } ); + + /** + * True if the Calendar should suppress weeks that are not a part of the current month. False by default. + * @config HIDE_BLANK_WEEKS + * @type Boolean + * @default false + */ + this.cfg.addProperty("HIDE_BLANK_WEEKS",{ value:false, handler:this.configOptions, validator:this.cfg.checkBoolean } ); + + /** + * The image that should be used for the left navigation arrow. + * @config NAV_ARROW_LEFT + * @type String + * @deprecated You can customize the image by overriding the default CSS class for the left arrow - "calnavleft" + * @default null + */ + this.cfg.addProperty("NAV_ARROW_LEFT", { value:null, handler:this.configOptions } ); + + /** + * The image that should be used for the right navigation arrow. + * @config NAV_ARROW_RIGHT + * @type String + * @deprecated You can customize the image by overriding the default CSS class for the right arrow - "calnavright" + * @default null + */ + this.cfg.addProperty("NAV_ARROW_RIGHT", { value:null, handler:this.configOptions } ); + + // Locale properties + + /** + * The short month labels for the current locale. + * @config MONTHS_SHORT + * @type String[] + * @default ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"] + */ + this.cfg.addProperty("MONTHS_SHORT", { value:["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"], handler:this.configLocale } ); + + /** + * The long month labels for the current locale. + * @config MONTHS_LONG + * @type String[] + * @default ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" + */ + this.cfg.addProperty("MONTHS_LONG", { value:["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"], handler:this.configLocale } ); + + /** + * The 1-character weekday labels for the current locale. + * @config WEEKDAYS_1CHAR + * @type String[] + * @default ["S", "M", "T", "W", "T", "F", "S"] + */ + this.cfg.addProperty("WEEKDAYS_1CHAR", { value:["S", "M", "T", "W", "T", "F", "S"], handler:this.configLocale } ); + + /** + * The short weekday labels for the current locale. + * @config WEEKDAYS_SHORT + * @type String[] + * @default ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"] + */ + this.cfg.addProperty("WEEKDAYS_SHORT", { value:["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"], handler:this.configLocale } ); + + /** + * The medium weekday labels for the current locale. + * @config WEEKDAYS_MEDIUM + * @type String[] + * @default ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"] + */ + this.cfg.addProperty("WEEKDAYS_MEDIUM", { value:["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"], handler:this.configLocale } ); + + /** + * The long weekday labels for the current locale. + * @config WEEKDAYS_LONG + * @type String[] + * @default ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"] + */ + this.cfg.addProperty("WEEKDAYS_LONG", { value:["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"], handler:this.configLocale } ); + + /** + * Refreshes the locale values used to build the Calendar. + * @method refreshLocale + * @private + */ + var refreshLocale = function() { + this.cfg.refireEvent("LOCALE_MONTHS"); + this.cfg.refireEvent("LOCALE_WEEKDAYS"); + }; + + this.cfg.subscribeToConfigEvent("START_WEEKDAY", refreshLocale, this, true); + this.cfg.subscribeToConfigEvent("MONTHS_SHORT", refreshLocale, this, true); + this.cfg.subscribeToConfigEvent("MONTHS_LONG", refreshLocale, this, true); + this.cfg.subscribeToConfigEvent("WEEKDAYS_1CHAR", refreshLocale, this, true); + this.cfg.subscribeToConfigEvent("WEEKDAYS_SHORT", refreshLocale, this, true); + this.cfg.subscribeToConfigEvent("WEEKDAYS_MEDIUM", refreshLocale, this, true); + this.cfg.subscribeToConfigEvent("WEEKDAYS_LONG", refreshLocale, this, true); + + /** + * The setting that determines which length of month labels should be used. Possible values are "short" and "long". + * @config LOCALE_MONTHS + * @type String + * @default "long" + */ + this.cfg.addProperty("LOCALE_MONTHS", { value:"long", handler:this.configLocaleValues } ); + + /** + * The setting that determines which length of weekday labels should be used. Possible values are "1char", "short", "medium", and "long". + * @config LOCALE_WEEKDAYS + * @type String + * @default "short" + */ + this.cfg.addProperty("LOCALE_WEEKDAYS", { value:"short", handler:this.configLocaleValues } ); + + /** + * The value used to delimit individual dates in a date string passed to various Calendar functions. + * @config DATE_DELIMITER + * @type String + * @default "," + */ + this.cfg.addProperty("DATE_DELIMITER", { value:",", handler:this.configLocale } ); + + /** + * The value used to delimit date fields in a date string passed to various Calendar functions. + * @config DATE_FIELD_DELIMITER + * @type String + * @default "/" + */ + this.cfg.addProperty("DATE_FIELD_DELIMITER",{ value:"/", handler:this.configLocale } ); + + /** + * The value used to delimit date ranges in a date string passed to various Calendar functions. + * @config DATE_RANGE_DELIMITER + * @type String + * @default "-" + */ + this.cfg.addProperty("DATE_RANGE_DELIMITER",{ value:"-", handler:this.configLocale } ); + + /** + * The position of the month in a month/year date string + * @config MY_MONTH_POSITION + * @type Number + * @default 1 + */ + this.cfg.addProperty("MY_MONTH_POSITION", { value:1, handler:this.configLocale, validator:this.cfg.checkNumber } ); + + /** + * The position of the year in a month/year date string + * @config MY_YEAR_POSITION + * @type Number + * @default 2 + */ + this.cfg.addProperty("MY_YEAR_POSITION", { value:2, handler:this.configLocale, validator:this.cfg.checkNumber } ); + + /** + * The position of the month in a month/day date string + * @config MD_MONTH_POSITION + * @type Number + * @default 1 + */ + this.cfg.addProperty("MD_MONTH_POSITION", { value:1, handler:this.configLocale, validator:this.cfg.checkNumber } ); + + /** + * The position of the day in a month/year date string + * @config MD_DAY_POSITION + * @type Number + * @default 2 + */ + this.cfg.addProperty("MD_DAY_POSITION", { value:2, handler:this.configLocale, validator:this.cfg.checkNumber } ); + + /** + * The position of the month in a month/day/year date string + * @config MDY_MONTH_POSITION + * @type Number + * @default 1 + */ + this.cfg.addProperty("MDY_MONTH_POSITION", { value:1, handler:this.configLocale, validator:this.cfg.checkNumber } ); + + /** + * The position of the day in a month/day/year date string + * @config MDY_DAY_POSITION + * @type Number + * @default 2 + */ + this.cfg.addProperty("MDY_DAY_POSITION", { value:2, handler:this.configLocale, validator:this.cfg.checkNumber } ); + + /** + * The position of the year in a month/day/year date string + * @config MDY_YEAR_POSITION + * @type Number + * @default 3 + */ + this.cfg.addProperty("MDY_YEAR_POSITION", { value:3, handler:this.configLocale, validator:this.cfg.checkNumber } ); +}; + +/** +* The default handler for the "pagedate" property +* @method configPageDate +*/ +YAHOO.widget.Calendar.prototype.configPageDate = function(type, args, obj) { + this.cfg.setProperty("pagedate", this._parsePageDate(args[0]), true); +}; + +/** +* The default handler for the "mindate" property +* @method configMinDate +*/ +YAHOO.widget.Calendar.prototype.configMinDate = function(type, args, obj) { + var val = args[0]; + if (typeof val == 'string') { + val = this._parseDate(val); + this.cfg.setProperty("mindate", new Date(val[0],(val[1]-1),val[2])); + } +}; + +/** +* The default handler for the "maxdate" property +* @method configMaxDate +*/ +YAHOO.widget.Calendar.prototype.configMaxDate = function(type, args, obj) { + var val = args[0]; + if (typeof val == 'string') { + val = this._parseDate(val); + this.cfg.setProperty("maxdate", new Date(val[0],(val[1]-1),val[2])); + } +}; + +/** +* The default handler for the "selected" property +* @method configSelected +*/ +YAHOO.widget.Calendar.prototype.configSelected = function(type, args, obj) { + var selected = args[0]; + + if (selected) { + if (typeof selected == 'string') { + this.cfg.setProperty("selected", this._parseDates(selected), true); + } + } + if (! this._selectedDates) { + this._selectedDates = this.cfg.getProperty("selected"); + } +}; + +/** +* The default handler for all configuration options properties +* @method configOptions +*/ +YAHOO.widget.Calendar.prototype.configOptions = function(type, args, obj) { + type = type.toUpperCase(); + var val = args[0]; + this.Options[type] = val; +}; + +/** +* The default handler for all configuration locale properties +* @method configLocale +*/ +YAHOO.widget.Calendar.prototype.configLocale = function(type, args, obj) { + type = type.toUpperCase(); + var val = args[0]; + this.Locale[type] = val; + + this.cfg.refireEvent("LOCALE_MONTHS"); + this.cfg.refireEvent("LOCALE_WEEKDAYS"); + +}; + +/** +* The default handler for all configuration locale field length properties +* @method configLocaleValues +*/ +YAHOO.widget.Calendar.prototype.configLocaleValues = function(type, args, obj) { + type = type.toUpperCase(); + var val = args[0]; + + switch (type) { + case "LOCALE_MONTHS": + switch (val) { + case "short": + this.Locale.LOCALE_MONTHS = this.cfg.getProperty("MONTHS_SHORT").concat(); + break; + case "long": + this.Locale.LOCALE_MONTHS = this.cfg.getProperty("MONTHS_LONG").concat(); + break; + } + break; + case "LOCALE_WEEKDAYS": + switch (val) { + case "1char": + this.Locale.LOCALE_WEEKDAYS = this.cfg.getProperty("WEEKDAYS_1CHAR").concat(); + break; + case "short": + this.Locale.LOCALE_WEEKDAYS = this.cfg.getProperty("WEEKDAYS_SHORT").concat(); + break; + case "medium": + this.Locale.LOCALE_WEEKDAYS = this.cfg.getProperty("WEEKDAYS_MEDIUM").concat(); + break; + case "long": + this.Locale.LOCALE_WEEKDAYS = this.cfg.getProperty("WEEKDAYS_LONG").concat(); + break; + } + + var START_WEEKDAY = this.cfg.getProperty("START_WEEKDAY"); + + if (START_WEEKDAY > 0) { + for (var w=0;w'; + html[html.length] = '
'; + + var renderLeft, renderRight = false; + + if (this.parent) { + if (this.index === 0) { + renderLeft = true; + } + if (this.index == (this.parent.cfg.getProperty("pages") -1)) { + renderRight = true; + } + } else { + renderLeft = true; + renderRight = true; + } + + var cal = this.parent || this; + + if (renderLeft) { + var leftArrow = this.cfg.getProperty("NAV_ARROW_LEFT"); + // Check for deprecated customization - If someone set IMG_ROOT, but didn't set NAV_ARROW_LEFT, then set NAV_ARROW_LEFT to the old deprecated value + if (leftArrow === null && YAHOO.widget.Calendar.IMG_ROOT !== null) { + leftArrow = YAHOO.widget.Calendar.IMG_ROOT + DEPR_NAV_LEFT; + } + var leftStyle = (leftArrow === null) ? "" : ' style="background-image:url(' + leftArrow + ')"'; + html[html.length] = ' '; + } + + html[html.length] = this.buildMonthLabel(); + + if (renderRight) { + var rightArrow = this.cfg.getProperty("NAV_ARROW_RIGHT"); + if (rightArrow === null && YAHOO.widget.Calendar.IMG_ROOT !== null) { + rightArrow = YAHOO.widget.Calendar.IMG_ROOT + DEPR_NAV_RIGHT; + } + var rightStyle = (rightArrow === null) ? "" : ' style="background-image:url(' + rightArrow + ')"'; + html[html.length] = ' '; + } + + html[html.length] = '
'; + html[html.length] = ''; + html[html.length] = ''; + + if (this.cfg.getProperty("SHOW_WEEKDAYS")) { + html = this.buildWeekdays(html); + } + + html[html.length] = ''; + + return html; +}; + +/** +* Renders the Calendar's weekday headers. +* @method buildWeekdays +* @param {Array} html The current working HTML array +* @return {Array} The current working HTML array +*/ +YAHOO.widget.Calendar.prototype.buildWeekdays = function(html) { + + html[html.length] = ''; + + if (this.cfg.getProperty("SHOW_WEEK_HEADER")) { + html[html.length] = ' '; + } + + for(var i=0;i'; + } + + if (this.cfg.getProperty("SHOW_WEEK_FOOTER")) { + html[html.length] = ' '; + } + + html[html.length] = ''; + + return html; +}; + +/** +* Renders the calendar body. +* @method renderBody +* @param {Date} workingDate The current working Date being used for the render process +* @param {Array} html The current working HTML array +* @return {Array} The current working HTML array +*/ +YAHOO.widget.Calendar.prototype.renderBody = function(workingDate, html) { + + var startDay = this.cfg.getProperty("START_WEEKDAY"); + + this.preMonthDays = workingDate.getDay(); + if (startDay > 0) { + this.preMonthDays -= startDay; + } + if (this.preMonthDays < 0) { + this.preMonthDays += 7; + } + + this.monthDays = YAHOO.widget.DateMath.findMonthEnd(workingDate).getDate(); + this.postMonthDays = YAHOO.widget.Calendar.DISPLAY_DAYS-this.preMonthDays-this.monthDays; + + workingDate = YAHOO.widget.DateMath.subtract(workingDate, YAHOO.widget.DateMath.DAY, this.preMonthDays); + + var useDate,weekNum,weekClass; + useDate = this.cfg.getProperty("pagedate"); + + html[html.length] = ''; + + var i = 0; + + var tempDiv = document.createElement("div"); + var cell = document.createElement("td"); + tempDiv.appendChild(cell); + + var jan1 = new Date(useDate.getFullYear(),0,1); + + var cal = this.parent || this; + + for (var r=0;r<6;r++) { + + weekNum = YAHOO.widget.DateMath.getWeekNumber(workingDate, useDate.getFullYear(), startDay); + + weekClass = "w" + weekNum; + + if (r !== 0 && this.isDateOOM(workingDate) && this.cfg.getProperty("HIDE_BLANK_WEEKS") === true) { + break; + } else { + + html[html.length] = ''; + + if (this.cfg.getProperty("SHOW_WEEK_HEADER")) { html = this.renderRowHeader(weekNum, html); } + + for (var d=0;d<7;d++){ // Render actual days + + var cellRenderers = []; + + this.clearElement(cell); + + YAHOO.util.Dom.addClass(cell, "calcell"); + + cell.id = this.id + "_cell" + i; + + cell.innerHTML = i; + + var renderer = null; + + if (workingDate.getFullYear() == this.today.getFullYear() && + workingDate.getMonth() == this.today.getMonth() && + workingDate.getDate() == this.today.getDate()) { + cellRenderers[cellRenderers.length]=cal.renderCellStyleToday; + } + + this.cellDates[this.cellDates.length]=[workingDate.getFullYear(),workingDate.getMonth()+1,workingDate.getDate()]; // Add this date to cellDates + + if (this.isDateOOM(workingDate)) { + cellRenderers[cellRenderers.length]=cal.renderCellNotThisMonth; + } else { + + YAHOO.util.Dom.addClass(cell, "wd" + workingDate.getDay()); + YAHOO.util.Dom.addClass(cell, "d" + workingDate.getDate()); + + for (var s=0;s= d1.getTime() && workingDate.getTime() <= d2.getTime()) { + renderer = rArray[2]; + + if (workingDate.getTime()==d2.getTime()) { + this.renderStack.splice(s,1); + } + } + break; + case YAHOO.widget.Calendar.WEEKDAY: + + var weekday = rArray[1][0]; + if (workingDate.getDay()+1 == weekday) { + renderer = rArray[2]; + } + break; + case YAHOO.widget.Calendar.MONTH: + + month = rArray[1][0]; + if (workingDate.getMonth()+1 == month) { + renderer = rArray[2]; + } + break; + } + + if (renderer) { + cellRenderers[cellRenderers.length]=renderer; + } + } + + } + + if (this._indexOfSelectedFieldArray([workingDate.getFullYear(),workingDate.getMonth()+1,workingDate.getDate()]) > -1) { + cellRenderers[cellRenderers.length]=cal.renderCellStyleSelected; + } + + var mindate = this.cfg.getProperty("mindate"); + var maxdate = this.cfg.getProperty("maxdate"); + + if (mindate) { + mindate = YAHOO.widget.DateMath.clearTime(mindate); + } + if (maxdate) { + maxdate = YAHOO.widget.DateMath.clearTime(maxdate); + } + + if ( + (mindate && (workingDate.getTime() < mindate.getTime())) || + (maxdate && (workingDate.getTime() > maxdate.getTime())) + ) { + cellRenderers[cellRenderers.length]=cal.renderOutOfBoundsDate; + } else { + cellRenderers[cellRenderers.length]=cal.styleCellDefault; + cellRenderers[cellRenderers.length]=cal.renderCellDefault; + } + + + + for (var x=0;x= 0 && i <= 6) { + YAHOO.util.Dom.addClass(cell, this.Style.CSS_CELL_TOP); + } + if ((i % 7) === 0) { + YAHOO.util.Dom.addClass(cell, this.Style.CSS_CELL_LEFT); + } + if (((i+1) % 7) === 0) { + YAHOO.util.Dom.addClass(cell, this.Style.CSS_CELL_RIGHT); + } + + var postDays = this.postMonthDays; + if (postDays >= 7 && this.cfg.getProperty("HIDE_BLANK_WEEKS")) { + var blankWeeks = Math.floor(postDays/7); + for (var p=0;p= ((this.preMonthDays+postDays+this.monthDays)-7)) { + YAHOO.util.Dom.addClass(cell, this.Style.CSS_CELL_BOTTOM); + } + + html[html.length] = tempDiv.innerHTML; + + i++; + } + + if (this.cfg.getProperty("SHOW_WEEK_FOOTER")) { html = this.renderRowFooter(weekNum, html); } + + html[html.length] = ''; + } + } + + html[html.length] = ''; + + return html; +}; + +/** +* Renders the calendar footer. In the default implementation, there is +* no footer. +* @method renderFooter +* @param {Array} html The current working HTML array +* @return {Array} The current working HTML array +*/ +YAHOO.widget.Calendar.prototype.renderFooter = function(html) { return html; }; + +/** +* Renders the calendar after it has been configured. The render() method has a specific call chain that will execute +* when the method is called: renderHeader, renderBody, renderFooter. +* Refer to the documentation for those methods for information on +* individual render tasks. +* @method render +*/ +YAHOO.widget.Calendar.prototype.render = function() { + this.beforeRenderEvent.fire(); + + // Find starting day of the current month + var workingDate = YAHOO.widget.DateMath.findMonthStart(this.cfg.getProperty("pagedate")); + + this.resetRenderers(); + this.cellDates.length = 0; + + YAHOO.util.Event.purgeElement(this.oDomContainer, true); + + var html = []; + + html[html.length] = ''; + html = this.renderHeader(html); + html = this.renderBody(workingDate, html); + html = this.renderFooter(html); + html[html.length] = '
'; + + this.oDomContainer.innerHTML = html.join("\n"); + + this.applyListeners(); + this.cells = this.oDomContainer.getElementsByTagName("td"); + + this.cfg.refireEvent("title"); + this.cfg.refireEvent("close"); + this.cfg.refireEvent("iframe"); + + this.renderEvent.fire(); +}; + +/** +* Applies the Calendar's DOM listeners to applicable elements. +* @method applyListeners +*/ +YAHOO.widget.Calendar.prototype.applyListeners = function() { + + var root = this.oDomContainer; + var cal = this.parent || this; + + var linkLeft, linkRight; + + linkLeft = YAHOO.util.Dom.getElementsByClassName(this.Style.CSS_NAV_LEFT, "a", root); + linkRight = YAHOO.util.Dom.getElementsByClassName(this.Style.CSS_NAV_RIGHT, "a", root); + + if (linkLeft) { + this.linkLeft = linkLeft[0]; + YAHOO.util.Event.addListener(this.linkLeft, "mousedown", cal.previousMonth, cal, true); + } + + if (linkRight) { + this.linkRight = linkRight[0]; + YAHOO.util.Event.addListener(this.linkRight, "mousedown", cal.nextMonth, cal, true); + } + + if (this.domEventMap) { + var el,elements; + for (var cls in this.domEventMap) { + if (YAHOO.lang.hasOwnProperty(this.domEventMap, cls)) { + var items = this.domEventMap[cls]; + + if (! (items instanceof Array)) { + items = [items]; + } + + for (var i=0;i'; + return html; +}; + +/** +* Renders the row footer for a week. +* @method renderRowFooter +* @param {Number} weekNum The week number of the current row +* @param {Array} cell The current working HTML array +*/ +YAHOO.widget.Calendar.prototype.renderRowFooter = function(weekNum, html) { + html[html.length] = '' + weekNum + ''; + return html; +}; + +/** +* Renders a single standard calendar cell in the calendar widget table. +* All logic for determining how a standard default cell will be rendered is +* encapsulated in this method, and must be accounted for when extending the +* widget class. +* @method renderCellDefault +* @param {Date} workingDate The current working Date object being used to generate the calendar +* @param {HTMLTableCellElement} cell The current working cell in the calendar +*/ +YAHOO.widget.Calendar.prototype.renderCellDefault = function(workingDate, cell) { + cell.innerHTML = '' + this.buildDayLabel(workingDate) + ""; +}; + +/** +* Styles a selectable cell. +* @method styleCellDefault +* @param {Date} workingDate The current working Date object being used to generate the calendar +* @param {HTMLTableCellElement} cell The current working cell in the calendar +*/ +YAHOO.widget.Calendar.prototype.styleCellDefault = function(workingDate, cell) { + YAHOO.util.Dom.addClass(cell, this.Style.CSS_CELL_SELECTABLE); +}; + + +/** +* Renders a single standard calendar cell using the CSS hightlight1 style +* @method renderCellStyleHighlight1 +* @param {Date} workingDate The current working Date object being used to generate the calendar +* @param {HTMLTableCellElement} cell The current working cell in the calendar +*/ +YAHOO.widget.Calendar.prototype.renderCellStyleHighlight1 = function(workingDate, cell) { + YAHOO.util.Dom.addClass(cell, this.Style.CSS_CELL_HIGHLIGHT1); +}; + +/** +* Renders a single standard calendar cell using the CSS hightlight2 style +* @method renderCellStyleHighlight2 +* @param {Date} workingDate The current working Date object being used to generate the calendar +* @param {HTMLTableCellElement} cell The current working cell in the calendar +*/ +YAHOO.widget.Calendar.prototype.renderCellStyleHighlight2 = function(workingDate, cell) { + YAHOO.util.Dom.addClass(cell, this.Style.CSS_CELL_HIGHLIGHT2); +}; + +/** +* Renders a single standard calendar cell using the CSS hightlight3 style +* @method renderCellStyleHighlight3 +* @param {Date} workingDate The current working Date object being used to generate the calendar +* @param {HTMLTableCellElement} cell The current working cell in the calendar +*/ +YAHOO.widget.Calendar.prototype.renderCellStyleHighlight3 = function(workingDate, cell) { + YAHOO.util.Dom.addClass(cell, this.Style.CSS_CELL_HIGHLIGHT3); +}; + +/** +* Renders a single standard calendar cell using the CSS hightlight4 style +* @method renderCellStyleHighlight4 +* @param {Date} workingDate The current working Date object being used to generate the calendar +* @param {HTMLTableCellElement} cell The current working cell in the calendar +*/ +YAHOO.widget.Calendar.prototype.renderCellStyleHighlight4 = function(workingDate, cell) { + YAHOO.util.Dom.addClass(cell, this.Style.CSS_CELL_HIGHLIGHT4); +}; + +/** +* Applies the default style used for rendering today's date to the current calendar cell +* @method renderCellStyleToday +* @param {Date} workingDate The current working Date object being used to generate the calendar +* @param {HTMLTableCellElement} cell The current working cell in the calendar +*/ +YAHOO.widget.Calendar.prototype.renderCellStyleToday = function(workingDate, cell) { + YAHOO.util.Dom.addClass(cell, this.Style.CSS_CELL_TODAY); +}; + +/** +* Applies the default style used for rendering selected dates to the current calendar cell +* @method renderCellStyleSelected +* @param {Date} workingDate The current working Date object being used to generate the calendar +* @param {HTMLTableCellElement} cell The current working cell in the calendar +* @return {String} YAHOO.widget.Calendar.STOP_RENDER if rendering should stop with this style, null or nothing if rendering +* should not be terminated +*/ +YAHOO.widget.Calendar.prototype.renderCellStyleSelected = function(workingDate, cell) { + YAHOO.util.Dom.addClass(cell, this.Style.CSS_CELL_SELECTED); +}; + +/** +* Applies the default style used for rendering dates that are not a part of the current +* month (preceding or trailing the cells for the current month) +* @method renderCellNotThisMonth +* @param {Date} workingDate The current working Date object being used to generate the calendar +* @param {HTMLTableCellElement} cell The current working cell in the calendar +* @return {String} YAHOO.widget.Calendar.STOP_RENDER if rendering should stop with this style, null or nothing if rendering +* should not be terminated +*/ +YAHOO.widget.Calendar.prototype.renderCellNotThisMonth = function(workingDate, cell) { + YAHOO.util.Dom.addClass(cell, this.Style.CSS_CELL_OOM); + cell.innerHTML=workingDate.getDate(); + return YAHOO.widget.Calendar.STOP_RENDER; +}; + +/** +* Renders the current calendar cell as a non-selectable "black-out" date using the default +* restricted style. +* @method renderBodyCellRestricted +* @param {Date} workingDate The current working Date object being used to generate the calendar +* @param {HTMLTableCellElement} cell The current working cell in the calendar +* @return {String} YAHOO.widget.Calendar.STOP_RENDER if rendering should stop with this style, null or nothing if rendering +* should not be terminated +*/ +YAHOO.widget.Calendar.prototype.renderBodyCellRestricted = function(workingDate, cell) { + YAHOO.util.Dom.addClass(cell, this.Style.CSS_CELL); + YAHOO.util.Dom.addClass(cell, this.Style.CSS_CELL_RESTRICTED); + cell.innerHTML=workingDate.getDate(); + return YAHOO.widget.Calendar.STOP_RENDER; +}; + +// END BUILT-IN TABLE CELL RENDERERS + +// BEGIN MONTH NAVIGATION METHODS + +/** +* Adds the designated number of months to the current calendar month, and sets the current +* calendar page date to the new month. +* @method addMonths +* @param {Number} count The number of months to add to the current calendar +*/ +YAHOO.widget.Calendar.prototype.addMonths = function(count) { + this.cfg.setProperty("pagedate", YAHOO.widget.DateMath.add(this.cfg.getProperty("pagedate"), YAHOO.widget.DateMath.MONTH, count)); + this.resetRenderers(); + this.changePageEvent.fire(); +}; + +/** +* Subtracts the designated number of months from the current calendar month, and sets the current +* calendar page date to the new month. +* @method subtractMonths +* @param {Number} count The number of months to subtract from the current calendar +*/ +YAHOO.widget.Calendar.prototype.subtractMonths = function(count) { + this.cfg.setProperty("pagedate", YAHOO.widget.DateMath.subtract(this.cfg.getProperty("pagedate"), YAHOO.widget.DateMath.MONTH, count)); + this.resetRenderers(); + this.changePageEvent.fire(); +}; + +/** +* Adds the designated number of years to the current calendar, and sets the current +* calendar page date to the new month. +* @method addYears +* @param {Number} count The number of years to add to the current calendar +*/ +YAHOO.widget.Calendar.prototype.addYears = function(count) { + this.cfg.setProperty("pagedate", YAHOO.widget.DateMath.add(this.cfg.getProperty("pagedate"), YAHOO.widget.DateMath.YEAR, count)); + this.resetRenderers(); + this.changePageEvent.fire(); +}; + +/** +* Subtcats the designated number of years from the current calendar, and sets the current +* calendar page date to the new month. +* @method subtractYears +* @param {Number} count The number of years to subtract from the current calendar +*/ +YAHOO.widget.Calendar.prototype.subtractYears = function(count) { + this.cfg.setProperty("pagedate", YAHOO.widget.DateMath.subtract(this.cfg.getProperty("pagedate"), YAHOO.widget.DateMath.YEAR, count)); + this.resetRenderers(); + this.changePageEvent.fire(); +}; + +/** +* Navigates to the next month page in the calendar widget. +* @method nextMonth +*/ +YAHOO.widget.Calendar.prototype.nextMonth = function() { + this.addMonths(1); +}; + +/** +* Navigates to the previous month page in the calendar widget. +* @method previousMonth +*/ +YAHOO.widget.Calendar.prototype.previousMonth = function() { + this.subtractMonths(1); +}; + +/** +* Navigates to the next year in the currently selected month in the calendar widget. +* @method nextYear +*/ +YAHOO.widget.Calendar.prototype.nextYear = function() { + this.addYears(1); +}; + +/** +* Navigates to the previous year in the currently selected month in the calendar widget. +* @method previousYear +*/ +YAHOO.widget.Calendar.prototype.previousYear = function() { + this.subtractYears(1); +}; + +// END MONTH NAVIGATION METHODS + +// BEGIN SELECTION METHODS + +/** +* Resets the calendar widget to the originally selected month and year, and +* sets the calendar to the initial selection(s). +* @method reset +*/ +YAHOO.widget.Calendar.prototype.reset = function() { + this.cfg.resetProperty("selected"); + this.cfg.resetProperty("pagedate"); + this.resetEvent.fire(); +}; + +/** +* Clears the selected dates in the current calendar widget and sets the calendar +* to the current month and year. +* @method clear +*/ +YAHOO.widget.Calendar.prototype.clear = function() { + this.cfg.setProperty("selected", []); + this.cfg.setProperty("pagedate", new Date(this.today.getTime())); + this.clearEvent.fire(); +}; + +/** +* Selects a date or a collection of dates on the current calendar. This method, by default, +* does not call the render method explicitly. Once selection has completed, render must be +* called for the changes to be reflected visually. +* @method select +* @param {String/Date/Date[]} date The date string of dates to select in the current calendar. Valid formats are +* individual date(s) (12/24/2005,12/26/2005) or date range(s) (12/24/2005-1/1/2006). +* Multiple comma-delimited dates can also be passed to this method (12/24/2005,12/11/2005-12/13/2005). +* This method can also take a JavaScript Date object or an array of Date objects. +* @return {Date[]} Array of JavaScript Date objects representing all individual dates that are currently selected. +*/ +YAHOO.widget.Calendar.prototype.select = function(date) { + this.beforeSelectEvent.fire(); + + var selected = this.cfg.getProperty("selected"); + var aToBeSelected = this._toFieldArray(date); + + for (var a=0;a -1) { + if (this.cfg.getProperty("pagedate").getMonth() == dCellDate.getMonth() && + this.cfg.getProperty("pagedate").getFullYear() == dCellDate.getFullYear()) { + YAHOO.util.Dom.removeClass(cell, this.Style.CSS_CELL_SELECTED); + } + + selected.splice(cellDateIndex, 1); + } + + + if (this.parent) { + this.parent.cfg.setProperty("selected", selected); + } else { + this.cfg.setProperty("selected", selected); + } + + this.deselectEvent.fire(selectDate); + return this.getSelectedDates(); +}; + +/** +* Deselects all dates on the current calendar. +* @method deselectAll +* @return {Date[]} Array of JavaScript Date objects representing all individual dates that are currently selected. +* Assuming that this function executes properly, the return value should be an empty array. +* However, the empty array is returned for the sake of being able to check the selection status +* of the calendar. +*/ +YAHOO.widget.Calendar.prototype.deselectAll = function() { + this.beforeDeselectEvent.fire(); + + var selected = this.cfg.getProperty("selected"); + var count = selected.length; + var sel = selected.concat(); + + if (this.parent) { + this.parent.cfg.setProperty("selected", []); + } else { + this.cfg.setProperty("selected", []); + } + + if (count > 0) { + this.deselectEvent.fire(sel); + } + + return this.getSelectedDates(); +}; + +// END SELECTION METHODS + +// BEGIN TYPE CONVERSION METHODS + +/** +* Converts a date (either a JavaScript Date object, or a date string) to the internal data structure +* used to represent dates: [[yyyy,mm,dd],[yyyy,mm,dd]]. +* @method _toFieldArray +* @private +* @param {String/Date/Date[]} date The date string of dates to deselect in the current calendar. Valid formats are +* individual date(s) (12/24/2005,12/26/2005) or date range(s) (12/24/2005-1/1/2006). +* Multiple comma-delimited dates can also be passed to this method (12/24/2005,12/11/2005-12/13/2005). +* This method can also take a JavaScript Date object or an array of Date objects. +* @return {Array[](Number[])} Array of date field arrays +*/ +YAHOO.widget.Calendar.prototype._toFieldArray = function(date) { + var returnDate = []; + + if (date instanceof Date) { + returnDate = [[date.getFullYear(), date.getMonth()+1, date.getDate()]]; + } else if (typeof date == 'string') { + returnDate = this._parseDates(date); + } else if (date instanceof Array) { + for (var i=0;i +*
+*
+* +* The tables for the calendars ("cal1_0" and "cal1_1") will be inserted into those containers. +* @namespace YAHOO.widget +* @class CalendarGroup +* @constructor +* @param {String} id The id of the table element that will represent the calendar widget +* @param {String} containerId The id of the container div element that will wrap the calendar table +* @param {Object} config The configuration object containing the Calendar's arguments +*/ +YAHOO.widget.CalendarGroup = function(id, containerId, config) { + if (arguments.length > 0) { + this.init(id, containerId, config); + } +}; + +/** +* Initializes the calendar group. All subclasses must call this method in order for the +* group to be initialized properly. +* @method init +* @param {String} id The id of the table element that will represent the calendar widget +* @param {String} containerId The id of the container div element that will wrap the calendar table +* @param {Object} config The configuration object containing the Calendar's arguments +*/ +YAHOO.widget.CalendarGroup.prototype.init = function(id, containerId, config) { + this.initEvents(); + this.initStyles(); + + /** + * The collection of Calendar pages contained within the CalendarGroup + * @property pages + * @type YAHOO.widget.Calendar[] + */ + this.pages = []; + + /** + * The unique id associated with the CalendarGroup + * @property id + * @type String + */ + this.id = id; + + /** + * The unique id associated with the CalendarGroup container + * @property containerId + * @type String + */ + this.containerId = containerId; + + /** + * The outer containing element for the CalendarGroup + * @property oDomContainer + * @type HTMLElement + */ + this.oDomContainer = document.getElementById(containerId); + + YAHOO.util.Dom.addClass(this.oDomContainer, YAHOO.widget.CalendarGroup.CSS_CONTAINER); + YAHOO.util.Dom.addClass(this.oDomContainer, YAHOO.widget.CalendarGroup.CSS_MULTI_UP); + + /** + * The Config object used to hold the configuration variables for the CalendarGroup + * @property cfg + * @type YAHOO.util.Config + */ + this.cfg = new YAHOO.util.Config(this); + + /** + * The local object which contains the CalendarGroup's options + * @property Options + * @type Object + */ + this.Options = {}; + + /** + * The local object which contains the CalendarGroup's locale settings + * @property Locale + * @type Object + */ + this.Locale = {}; + + this.setupConfig(); + + if (config) { + this.cfg.applyConfig(config, true); + } + + this.cfg.fireQueue(); + + // OPERA HACK FOR MISWRAPPED FLOATS + if (this.browser == "opera"){ + var fixWidth = function() { + var startW = this.oDomContainer.offsetWidth; + var w = 0; + for (var p=0;p 0) { + this.oDomContainer.style.width = w + "px"; + } + }; + this.renderEvent.subscribe(fixWidth,this,true); + } +}; + + +YAHOO.widget.CalendarGroup.prototype.setupConfig = function() { + /** + * The number of pages to include in the CalendarGroup. This value can only be set once, in the CalendarGroup's constructor arguments. + * @config pages + * @type Number + * @default 2 + */ + this.cfg.addProperty("pages", { value:2, validator:this.cfg.checkNumber, handler:this.configPages } ); + + /** + * The month/year representing the current visible Calendar date (mm/yyyy) + * @config pagedate + * @type String + * @default today's date + */ + this.cfg.addProperty("pagedate", { value:new Date(), handler:this.configPageDate } ); + + /** + * The date or range of dates representing the current Calendar selection + * @config selected + * @type String + * @default [] + */ + this.cfg.addProperty("selected", { value:[], handler:this.delegateConfig } ); + + /** + * The title to display above the CalendarGroup's month header + * @config title + * @type String + * @default "" + */ + this.cfg.addProperty("title", { value:"", handler:this.configTitle } ); + + /** + * Whether or not a close button should be displayed for this CalendarGroup + * @config close + * @type Boolean + * @default false + */ + this.cfg.addProperty("close", { value:false, handler:this.configClose } ); + + /** + * Whether or not an iframe shim should be placed under the Calendar to prevent select boxes from bleeding through in Internet Explorer 6 and below. + * @config iframe + * @type Boolean + * @default true + */ + this.cfg.addProperty("iframe", { value:true, handler:this.delegateConfig, validator:this.cfg.checkBoolean } ); + + /** + * The minimum selectable date in the current Calendar (mm/dd/yyyy) + * @config mindate + * @type String + * @default null + */ + this.cfg.addProperty("mindate", { value:null, handler:this.delegateConfig } ); + + /** + * The maximum selectable date in the current Calendar (mm/dd/yyyy) + * @config maxdate + * @type String + * @default null + */ + this.cfg.addProperty("maxdate", { value:null, handler:this.delegateConfig } ); + + // Options properties + + /** + * True if the Calendar should allow multiple selections. False by default. + * @config MULTI_SELECT + * @type Boolean + * @default false + */ + this.cfg.addProperty("MULTI_SELECT", { value:false, handler:this.delegateConfig, validator:this.cfg.checkBoolean } ); + + /** + * The weekday the week begins on. Default is 0 (Sunday). + * @config START_WEEKDAY + * @type number + * @default 0 + */ + this.cfg.addProperty("START_WEEKDAY", { value:0, handler:this.delegateConfig, validator:this.cfg.checkNumber } ); + + /** + * True if the Calendar should show weekday labels. True by default. + * @config SHOW_WEEKDAYS + * @type Boolean + * @default true + */ + this.cfg.addProperty("SHOW_WEEKDAYS", { value:true, handler:this.delegateConfig, validator:this.cfg.checkBoolean } ); + + /** + * True if the Calendar should show week row headers. False by default. + * @config SHOW_WEEK_HEADER + * @type Boolean + * @default false + */ + this.cfg.addProperty("SHOW_WEEK_HEADER",{ value:false, handler:this.delegateConfig, validator:this.cfg.checkBoolean } ); + + /** + * True if the Calendar should show week row footers. False by default. + * @config SHOW_WEEK_FOOTER + * @type Boolean + * @default false + */ + this.cfg.addProperty("SHOW_WEEK_FOOTER",{ value:false, handler:this.delegateConfig, validator:this.cfg.checkBoolean } ); + + /** + * True if the Calendar should suppress weeks that are not a part of the current month. False by default. + * @config HIDE_BLANK_WEEKS + * @type Boolean + * @default false + */ + this.cfg.addProperty("HIDE_BLANK_WEEKS",{ value:false, handler:this.delegateConfig, validator:this.cfg.checkBoolean } ); + + /** + * The image that should be used for the left navigation arrow. + * @config NAV_ARROW_LEFT + * @type String + * @deprecated You can customize the image by overriding the default CSS class for the left arrow - "calnavleft" + * @default null + */ + this.cfg.addProperty("NAV_ARROW_LEFT", { value:null, handler:this.delegateConfig } ); + + /** + * The image that should be used for the right navigation arrow. + * @config NAV_ARROW_RIGHT + * @type String + * @deprecated You can customize the image by overriding the default CSS class for the right arrow - "calnavright" + * @default null + */ + this.cfg.addProperty("NAV_ARROW_RIGHT", { value:null, handler:this.delegateConfig } ); + + // Locale properties + + /** + * The short month labels for the current locale. + * @config MONTHS_SHORT + * @type String[] + * @default ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"] + */ + this.cfg.addProperty("MONTHS_SHORT", { value:["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"], handler:this.delegateConfig } ); + + /** + * The long month labels for the current locale. + * @config MONTHS_LONG + * @type String[] + * @default ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" + */ + this.cfg.addProperty("MONTHS_LONG", { value:["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"], handler:this.delegateConfig } ); + + /** + * The 1-character weekday labels for the current locale. + * @config WEEKDAYS_1CHAR + * @type String[] + * @default ["S", "M", "T", "W", "T", "F", "S"] + */ + this.cfg.addProperty("WEEKDAYS_1CHAR", { value:["S", "M", "T", "W", "T", "F", "S"], handler:this.delegateConfig } ); + + /** + * The short weekday labels for the current locale. + * @config WEEKDAYS_SHORT + * @type String[] + * @default ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"] + */ + this.cfg.addProperty("WEEKDAYS_SHORT", { value:["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"], handler:this.delegateConfig } ); + + /** + * The medium weekday labels for the current locale. + * @config WEEKDAYS_MEDIUM + * @type String[] + * @default ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"] + */ + this.cfg.addProperty("WEEKDAYS_MEDIUM", { value:["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"], handler:this.delegateConfig } ); + + /** + * The long weekday labels for the current locale. + * @config WEEKDAYS_LONG + * @type String[] + * @default ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"] + */ + this.cfg.addProperty("WEEKDAYS_LONG", { value:["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"], handler:this.delegateConfig } ); + + /** + * The setting that determines which length of month labels should be used. Possible values are "short" and "long". + * @config LOCALE_MONTHS + * @type String + * @default "long" + */ + this.cfg.addProperty("LOCALE_MONTHS", { value:"long", handler:this.delegateConfig } ); + + /** + * The setting that determines which length of weekday labels should be used. Possible values are "1char", "short", "medium", and "long". + * @config LOCALE_WEEKDAYS + * @type String + * @default "short" + */ + this.cfg.addProperty("LOCALE_WEEKDAYS", { value:"short", handler:this.delegateConfig } ); + + /** + * The value used to delimit individual dates in a date string passed to various Calendar functions. + * @config DATE_DELIMITER + * @type String + * @default "," + */ + this.cfg.addProperty("DATE_DELIMITER", { value:",", handler:this.delegateConfig } ); + + /** + * The value used to delimit date fields in a date string passed to various Calendar functions. + * @config DATE_FIELD_DELIMITER + * @type String + * @default "/" + */ + this.cfg.addProperty("DATE_FIELD_DELIMITER",{ value:"/", handler:this.delegateConfig } ); + + /** + * The value used to delimit date ranges in a date string passed to various Calendar functions. + * @config DATE_RANGE_DELIMITER + * @type String + * @default "-" + */ + this.cfg.addProperty("DATE_RANGE_DELIMITER",{ value:"-", handler:this.delegateConfig } ); + + /** + * The position of the month in a month/year date string + * @config MY_MONTH_POSITION + * @type Number + * @default 1 + */ + this.cfg.addProperty("MY_MONTH_POSITION", { value:1, handler:this.delegateConfig, validator:this.cfg.checkNumber } ); + + /** + * The position of the year in a month/year date string + * @config MY_YEAR_POSITION + * @type Number + * @default 2 + */ + this.cfg.addProperty("MY_YEAR_POSITION", { value:2, handler:this.delegateConfig, validator:this.cfg.checkNumber } ); + + /** + * The position of the month in a month/day date string + * @config MD_MONTH_POSITION + * @type Number + * @default 1 + */ + this.cfg.addProperty("MD_MONTH_POSITION", { value:1, handler:this.delegateConfig, validator:this.cfg.checkNumber } ); + + /** + * The position of the day in a month/year date string + * @config MD_DAY_POSITION + * @type Number + * @default 2 + */ + this.cfg.addProperty("MD_DAY_POSITION", { value:2, handler:this.delegateConfig, validator:this.cfg.checkNumber } ); + + /** + * The position of the month in a month/day/year date string + * @config MDY_MONTH_POSITION + * @type Number + * @default 1 + */ + this.cfg.addProperty("MDY_MONTH_POSITION", { value:1, handler:this.delegateConfig, validator:this.cfg.checkNumber } ); + + /** + * The position of the day in a month/day/year date string + * @config MDY_DAY_POSITION + * @type Number + * @default 2 + */ + this.cfg.addProperty("MDY_DAY_POSITION", { value:2, handler:this.delegateConfig, validator:this.cfg.checkNumber } ); + + /** + * The position of the year in a month/day/year date string + * @config MDY_YEAR_POSITION + * @type Number + * @default 3 + */ + this.cfg.addProperty("MDY_YEAR_POSITION", { value:3, handler:this.delegateConfig, validator:this.cfg.checkNumber } ); + +}; + +/** +* Initializes CalendarGroup's built-in CustomEvents +* @method initEvents +*/ +YAHOO.widget.CalendarGroup.prototype.initEvents = function() { + var me = this; + + /** + * Proxy subscriber to subscribe to the CalendarGroup's child Calendars' CustomEvents + * @method sub + * @private + * @param {Function} fn The function to subscribe to this CustomEvent + * @param {Object} obj The CustomEvent's scope object + * @param {Boolean} bOverride Whether or not to apply scope correction + */ + var sub = function(fn, obj, bOverride) { + for (var p=0;p0) { + year+=1; + } + cal.setYear(year); + } +}; +/** +* Calls the render function of all child calendars within the group. +* @method render +*/ +YAHOO.widget.CalendarGroup.prototype.render = function() { + this.renderHeader(); + for (var p=0;p=0;--p) { + var cal = this.pages[p]; + cal.previousMonth(); + } +}; + +/** +* Navigates to the next year in the currently selected month in the calendar widget. +* @method nextYear +*/ +YAHOO.widget.CalendarGroup.prototype.nextYear = function() { + for (var p=0;p 11)) { + var DM = YAHOO.widget.DateMath; + var newDate = DM.add(date, DM.MONTH, iMonth-date.getMonth()); + date.setTime(newDate.getTime()); + } else { + date.setMonth(iMonth); + } +}; + + +/** +* CSS class representing the container for the calendar +* @property YAHOO.widget.CalendarGroup.CSS_CONTAINER +* @static +* @final +* @type String +*/ +YAHOO.widget.CalendarGroup.CSS_CONTAINER = "yui-calcontainer"; + +/** +* CSS class representing the container for the calendar +* @property YAHOO.widget.CalendarGroup.CSS_MULTI_UP +* @static +* @final +* @type String +*/ +YAHOO.widget.CalendarGroup.CSS_MULTI_UP = "multi"; + +/** +* CSS class representing the title for the 2-up calendar +* @property YAHOO.widget.CalendarGroup.CSS_2UPTITLE +* @static +* @final +* @type String +*/ +YAHOO.widget.CalendarGroup.CSS_2UPTITLE = "title"; + +/** +* CSS class representing the close icon for the 2-up calendar +* @property YAHOO.widget.CalendarGroup.CSS_2UPCLOSE +* @static +* @final +* @deprecated Along with Calendar.IMG_ROOT and NAV_ARROW_LEFT, NAV_ARROW_RIGHT configuration properties. +* Calendar's Style.CSS_CLOSE property now represents the CSS class used to render the close icon +* @type String +*/ +YAHOO.widget.CalendarGroup.CSS_2UPCLOSE = "close-icon"; + +YAHOO.augment(YAHOO.widget.CalendarGroup, YAHOO.widget.Calendar, "buildDayLabel", + "buildMonthLabel", + "renderOutOfBoundsDate", + "renderRowHeader", + "renderRowFooter", + "renderCellDefault", + "styleCellDefault", + "renderCellStyleHighlight1", + "renderCellStyleHighlight2", + "renderCellStyleHighlight3", + "renderCellStyleHighlight4", + "renderCellStyleToday", + "renderCellStyleSelected", + "renderCellNotThisMonth", + "renderBodyCellRestricted", + "initStyles", + "configTitle", + "configClose", + "hide", + "show", + "browser"); + +/** +* Returns a string representation of the object. +* @method toString +* @return {String} A string representation of the CalendarGroup object. +*/ +YAHOO.widget.CalendarGroup.prototype.toString = function() { + return "CalendarGroup " + this.id; +}; + +YAHOO.widget.CalGrp = YAHOO.widget.CalendarGroup; + +/** +* @class YAHOO.widget.Calendar2up +* @extends YAHOO.widget.CalendarGroup +* @deprecated The old Calendar2up class is no longer necessary, since CalendarGroup renders in a 2up view by default. +*/ +YAHOO.widget.Calendar2up = function(id, containerId, config) { + this.init(id, containerId, config); +}; + +YAHOO.extend(YAHOO.widget.Calendar2up, YAHOO.widget.CalendarGroup); + +/** +* @deprecated The old Calendar2up class is no longer necessary, since CalendarGroup renders in a 2up view by default. +*/ +YAHOO.widget.Cal2up = YAHOO.widget.Calendar2up; + +YAHOO.register("calendar", YAHOO.widget.Calendar, {version: "2.2.0", build: "127"}); diff --git a/source/web/yui/connection-min.js b/source/web/yui/connection-min.js new file mode 100644 index 0000000000..3f29aa5812 --- /dev/null +++ b/source/web/yui/connection-min.js @@ -0,0 +1,104 @@ +/* +Copyright (c) 2007, Yahoo! Inc. All rights reserved. +Code licensed under the BSD License: +http://developer.yahoo.net/yui/license.txt +version: 2.2.0 +*/ +YAHOO.util.Connect={_msxml_progid:['MSXML2.XMLHTTP.3.0','MSXML2.XMLHTTP','Microsoft.XMLHTTP'],_http_headers:{},_has_http_headers:false,_use_default_post_header:true,_default_post_header:'application/x-www-form-urlencoded',_use_default_xhr_header:true,_default_xhr_header:'XMLHttpRequest',_has_default_headers:true,_default_headers:{},_isFormSubmit:false,_isFileUpload:false,_formNode:null,_sFormData:null,_poll:{},_timeOut:{},_polling_interval:50,_transaction_id:0,setProgId:function(id) +{this._msxml_progid.unshift(id);},setDefaultPostHeader:function(b) +{this._use_default_post_header=b;},setDefaultXhrHeader:function(b) +{this._use_default_xhr_header=b;},setPollingInterval:function(i) +{if(typeof i=='number'&&isFinite(i)){this._polling_interval=i;}},createXhrObject:function(transactionId) +{var obj,http;try +{http=new XMLHttpRequest();obj={conn:http,tId:transactionId};} +catch(e) +{for(var i=0;i=200&&httpStatus<300){responseObject=this.createResponseObject(o,callback.argument);if(callback.success){if(!callback.scope){callback.success(responseObject);} +else{callback.success.apply(callback.scope,[responseObject]);}}} +else{switch(httpStatus){case 12002:case 12029:case 12030:case 12031:case 12152:case 13030:responseObject=this.createExceptionObject(o.tId,callback.argument,(isAbort?isAbort:false));if(callback.failure){if(!callback.scope){callback.failure(responseObject);} +else{callback.failure.apply(callback.scope,[responseObject]);}} +break;default:responseObject=this.createResponseObject(o,callback.argument);if(callback.failure){if(!callback.scope){callback.failure(responseObject);} +else{callback.failure.apply(callback.scope,[responseObject]);}}}} +this.releaseObject(o);responseObject=null;},createResponseObject:function(o,callbackArg) +{var obj={};var headerObj={};try +{var headerStr=o.conn.getAllResponseHeaders();var header=headerStr.split('\n');for(var i=0;i');if(typeof secureUri=='boolean'){io.src='javascript:false';} +else if(typeof secureURI=='string'){io.src=secureUri;}} +else{var io=document.createElement('iframe');io.id=frameId;io.name=frameId;} +io.style.position='absolute';io.style.top='-1000px';io.style.left='-1000px';document.body.appendChild(io);},appendPostData:function(postData) +{var formElements=[];var postMessage=postData.split('&');for(var i=0;i0){for(var i=0;i= 200 && httpStatus < 300){ + responseObject = this.createResponseObject(o, callback.argument); + if(callback.success){ + if(!callback.scope){ + callback.success(responseObject); + } + else{ + // If a scope property is defined, the callback will be fired from + // the context of the object. + callback.success.apply(callback.scope, [responseObject]); + } + } + } + else{ + switch(httpStatus){ + // The following cases are wininet.dll error codes that may be encountered. + case 12002: // Server timeout + case 12029: // 12029 to 12031 correspond to dropped connections. + case 12030: + case 12031: + case 12152: // Connection closed by server. + case 13030: // See above comments for variable status. + responseObject = this.createExceptionObject(o.tId, callback.argument, (isAbort?isAbort:false)); + if(callback.failure){ + if(!callback.scope){ + callback.failure(responseObject); + } + else{ + callback.failure.apply(callback.scope, [responseObject]); + } + } + break; + default: + responseObject = this.createResponseObject(o, callback.argument); + if(callback.failure){ + if(!callback.scope){ + callback.failure(responseObject); + } + else{ + callback.failure.apply(callback.scope, [responseObject]); + } + } + } + } + + this.releaseObject(o); + responseObject = null; + }, + + /** + * @description This method evaluates the server response, creates and returns the results via + * its properties. Success and failure cases will differ in the response + * object's property values. + * @method createResponseObject + * @private + * @static + * @param {object} o The connection object + * @param {callbackArg} callbackArg The user-defined argument or arguments to be passed to the callback + * @return {object} + */ + createResponseObject:function(o, callbackArg) + { + var obj = {}; + var headerObj = {}; + + try + { + var headerStr = o.conn.getAllResponseHeaders(); + var header = headerStr.split('\n'); + for(var i=0; i'); + + // IE will throw a security exception in an SSL environment if the + // iframe source is undefined. + if(typeof secureUri == 'boolean'){ + io.src = 'javascript:false'; + } + else if(typeof secureURI == 'string'){ + // Deprecated + io.src = secureUri; + } + } + else{ + var io = document.createElement('iframe'); + io.id = frameId; + io.name = frameId; + } + + io.style.position = 'absolute'; + io.style.top = '-1000px'; + io.style.left = '-1000px'; + + document.body.appendChild(io); + }, + + /** + * @description Parses the POST data and creates hidden form elements + * for each key-value, and appends them to the HTML form object. + * @method appendPostData + * @private + * @static + * @param {string} postData The HTTP POST data + * @return {array} formElements Collection of hidden fields. + */ + appendPostData:function(postData) + { + var formElements = []; + var postMessage = postData.split('&'); + for(var i=0; i < postMessage.length; i++){ + var delimitPos = postMessage[i].indexOf('='); + if(delimitPos != -1){ + formElements[i] = document.createElement('input'); + formElements[i].type = 'hidden'; + formElements[i].name = postMessage[i].substring(0,delimitPos); + formElements[i].value = postMessage[i].substring(delimitPos+1); + this._formNode.appendChild(formElements[i]); + } + } + + return formElements; + }, + + /** + * @description Uploads HTML form, including files/attachments, to the + * iframe created in createFrame. + * @method uploadFile + * @private + * @static + * @param {int} id The transaction id. + * @param {object} callback - User-defined callback object. + * @param {string} uri Fully qualified path of resource. + * @return {void} + */ + uploadFile:function(id, callback, uri, postData){ + + // Each iframe has an id prefix of "yuiIO" followed + // by the unique transaction id. + var frameId = 'yuiIO' + id; + var uploadEncoding = 'multipart/form-data'; + var io = document.getElementById(frameId); + + // Initialize the HTML form properties in case they are + // not defined in the HTML form. + this._formNode.action = uri; + this._formNode.method = 'POST'; + this._formNode.target = frameId; + + if(this._formNode.encoding){ + // IE does not respect property enctype for HTML forms. + // Instead it uses the property - "encoding". + this._formNode.encoding = uploadEncoding; + } + else{ + this._formNode.enctype = uploadEncoding; + } + + + if(postData){ + var oElements = this.appendPostData(postData); + } + + this._formNode.submit(); + + if(oElements && oElements.length > 0){ + for(var i=0; i < oElements.length; i++){ + this._formNode.removeChild(oElements[i]); + } + } + + // Reset HTML form status properties. + this.resetFormState(); + + // Create the upload callback handler that fires when the iframe + // receives the load event. Subsequently, the event handler is detached + // and the iframe removed from the document. + + var uploadCallback = function() + { + var obj = {}; + obj.tId = id; + obj.argument = callback.argument; + + try + { + obj.responseText = io.contentWindow.document.body?io.contentWindow.document.body.innerHTML:null; + obj.responseXML = io.contentWindow.document.XMLDocument?io.contentWindow.document.XMLDocument:io.contentWindow.document; + } + catch(e){} + + if(callback && callback.upload){ + if(!callback.scope){ + callback.upload(obj); + } + else{ + callback.upload.apply(callback.scope, [obj]); + } + } + + if(YAHOO.util.Event){ + YAHOO.util.Event.removeListener(io, "load", uploadCallback); + } + else if(window.detachEvent){ + io.detachEvent('onload', uploadCallback); + } + else{ + io.removeEventListener('load', uploadCallback, false); + } + setTimeout( + function(){ + document.body.removeChild(io); + }, 100); + }; + + + // Bind the onload handler to the iframe to detect the file upload response. + if(YAHOO.util.Event){ + YAHOO.util.Event.addListener(io, "load", uploadCallback); + } + else if(window.attachEvent){ + io.attachEvent('onload', uploadCallback); + } + else{ + io.addEventListener('load', uploadCallback, false); + } + }, + + /** + * @description Method to terminate a transaction, if it has not reached readyState 4. + * @method abort + * @public + * @static + * @param {object} o The connection object returned by asyncRequest. + * @param {object} callback User-defined callback object. + * @param {string} isTimeout boolean to indicate if abort was a timeout. + * @return {boolean} + */ + abort:function(o, callback, isTimeout) + { + if(this.isCallInProgress(o)){ + o.conn.abort(); + window.clearInterval(this._poll[o.tId]); + delete this._poll[o.tId]; + if(isTimeout){ + delete this._timeOut[o.tId]; + } + + this.handleTransactionResponse(o, callback, true); + + return true; + } + else{ + return false; + } + }, + + /** + * Public method to check if the transaction is still being processed. + * + * @method isCallInProgress + * @public + * @static + * @param {object} o The connection object returned by asyncRequest + * @return {boolean} + */ + isCallInProgress:function(o) + { + // if the XHR object assigned to the transaction has not been dereferenced, + // then check its readyState status. Otherwise, return false. + if(o.conn){ + return o.conn.readyState != 4 && o.conn.readyState != 0; + } + else{ + //The XHR object has been destroyed. + return false; + } + }, + + /** + * @description Dereference the XHR instance and the connection object after the transaction is completed. + * @method releaseObject + * @private + * @static + * @param {object} o The connection object + * @return {void} + */ + releaseObject:function(o) + { + //dereference the XHR instance. + o.conn = null; + //dereference the connection object. + o = null; + } +}; +YAHOO.register("connection", YAHOO.widget.Module, {version: "2.2.0", build: "127"}); \ No newline at end of file diff --git a/source/web/yui/dom.js b/source/web/yui/dom.js new file mode 100644 index 0000000000..93febc4484 --- /dev/null +++ b/source/web/yui/dom.js @@ -0,0 +1,901 @@ +/* +Copyright (c) 2007, Yahoo! Inc. All rights reserved. +Code licensed under the BSD License: +http://developer.yahoo.net/yui/license.txt +version: 2.2.0 +*/ +/* +Copyright (c) 2006, Yahoo! Inc. All rights reserved. +Code licensed under the BSD License: +http://developer.yahoo.net/yui/license.txt +*/ + +/** + * The dom module provides helper methods for manipulating Dom elements. + * @module dom + * + */ + +(function() { + var Y = YAHOO.util, // internal shorthand + getStyle, // for load time browser branching + setStyle, // ditto + id_counter = 0, // for use with generateId + propertyCache = {}; // for faster hyphen converts + + // brower detection + var ua = navigator.userAgent.toLowerCase(), + isOpera = (ua.indexOf('opera') > -1), + isSafari = (ua.indexOf('safari') > -1), + isGecko = (!isOpera && !isSafari && ua.indexOf('gecko') > -1), + isIE = (!isOpera && ua.indexOf('msie') > -1); + + // regex cache + var patterns = { + HYPHEN: /(-[a-z])/i + }; + + + var toCamel = function(property) { + if ( !patterns.HYPHEN.test(property) ) { + return property; // no hyphens + } + + if (propertyCache[property]) { // already converted + return propertyCache[property]; + } + + while( patterns.HYPHEN.exec(property) ) { + property = property.replace(RegExp.$1, + RegExp.$1.substr(1).toUpperCase()); + } + + propertyCache[property] = property; + return property; + //return property.replace(/-([a-z])/gi, function(m0, m1) {return m1.toUpperCase()}) // cant use function as 2nd arg yet due to safari bug + }; + + // branching at load instead of runtime + if (document.defaultView && document.defaultView.getComputedStyle) { // W3C DOM method + getStyle = function(el, property) { + var value = null; + + var computed = document.defaultView.getComputedStyle(el, ''); + if (computed) { // test computed before touching for safari + value = computed[toCamel(property)]; + } + + return el.style[property] || value; + }; + } else if (document.documentElement.currentStyle && isIE) { // IE method + getStyle = function(el, property) { + switch( toCamel(property) ) { + case 'opacity' :// IE opacity uses filter + var val = 100; + try { // will error if no DXImageTransform + val = el.filters['DXImageTransform.Microsoft.Alpha'].opacity; + + } catch(e) { + try { // make sure its in the document + val = el.filters('alpha').opacity; + } catch(e) { + } + } + return val / 100; + break; + default: + // test currentStyle before touching + var value = el.currentStyle ? el.currentStyle[property] : null; + return ( el.style[property] || value ); + } + }; + } else { // default to inline only + getStyle = function(el, property) { return el.style[property]; }; + } + + if (isIE) { + setStyle = function(el, property, val) { + switch (property) { + case 'opacity': + if ( typeof el.style.filter == 'string' ) { // in case not appended + el.style.filter = 'alpha(opacity=' + val * 100 + ')'; + + if (!el.currentStyle || !el.currentStyle.hasLayout) { + el.style.zoom = 1; // when no layout or cant tell + } + } + break; + default: + el.style[property] = val; + } + }; + } else { + setStyle = function(el, property, val) { + el.style[property] = val; + }; + } + + /** + * Provides helper methods for DOM elements. + * @namespace YAHOO.util + * @class Dom + */ + YAHOO.util.Dom = { + /** + * Returns an HTMLElement reference. + * @method get + * @param {String | HTMLElement |Array} el Accepts a string to use as an ID for getting a DOM reference, an actual DOM reference, or an Array of IDs and/or HTMLElements. + * @return {HTMLElement | Array} A DOM reference to an HTML element or an array of HTMLElements. + */ + get: function(el) { + if (!el) { return null; } // nothing to work with + + if (typeof el != 'string' && !(el instanceof Array) ) { // assuming HTMLElement or HTMLCollection, so pass back as is + return el; + } + + if (typeof el == 'string') { // ID + return document.getElementById(el); + } + else { // array of ID's and/or elements + var collection = []; + for (var i = 0, len = el.length; i < len; ++i) { + collection[collection.length] = Y.Dom.get(el[i]); + } + + return collection; + } + + return null; // safety, should never happen + }, + + /** + * Normalizes currentStyle and ComputedStyle. + * @method getStyle + * @param {String | HTMLElement |Array} el Accepts a string to use as an ID, an actual DOM reference, or an Array of IDs and/or HTMLElements. + * @param {String} property The style property whose value is returned. + * @return {String | Array} The current value of the style property for the element(s). + */ + getStyle: function(el, property) { + property = toCamel(property); + + var f = function(element) { + return getStyle(element, property); + }; + + return Y.Dom.batch(el, f, Y.Dom, true); + }, + + /** + * Wrapper for setting style properties of HTMLElements. Normalizes "opacity" across modern browsers. + * @method setStyle + * @param {String | HTMLElement | Array} el Accepts a string to use as an ID, an actual DOM reference, or an Array of IDs and/or HTMLElements. + * @param {String} property The style property to be set. + * @param {String} val The value to apply to the given property. + */ + setStyle: function(el, property, val) { + property = toCamel(property); + + var f = function(element) { + setStyle(element, property, val); + + }; + + Y.Dom.batch(el, f, Y.Dom, true); + }, + + /** + * Gets the current position of an element based on page coordinates. Element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false). + * @method getXY + * @param {String | HTMLElement | Array} el Accepts a string to use as an ID, an actual DOM reference, or an Array of IDs and/or HTMLElements + * @return {Array} The XY position of the element(s) + */ + getXY: function(el) { + var f = function(el) { + + // has to be part of document to have pageXY + if (el.parentNode === null || el.offsetParent === null || + this.getStyle(el, 'display') == 'none') { + return false; + } + + var parentNode = null; + var pos = []; + var box; + + if (el.getBoundingClientRect) { // IE + box = el.getBoundingClientRect(); + var doc = document; + if ( !this.inDocument(el) && parent.document != document) {// might be in a frame, need to get its scroll + doc = parent.document; + + if ( !this.isAncestor(doc.documentElement, el) ) { + return false; + } + + } + + var scrollTop = Math.max(doc.documentElement.scrollTop, doc.body.scrollTop); + var scrollLeft = Math.max(doc.documentElement.scrollLeft, doc.body.scrollLeft); + + return [box.left + scrollLeft, box.top + scrollTop]; + } + else { // safari, opera, & gecko + pos = [el.offsetLeft, el.offsetTop]; + parentNode = el.offsetParent; + if (parentNode != el) { + while (parentNode) { + pos[0] += parentNode.offsetLeft; + pos[1] += parentNode.offsetTop; + parentNode = parentNode.offsetParent; + } + } + if (isSafari && this.getStyle(el, 'position') == 'absolute' ) { // safari doubles in some cases + pos[0] -= document.body.offsetLeft; + pos[1] -= document.body.offsetTop; + } + } + + if (el.parentNode) { parentNode = el.parentNode; } + else { parentNode = null; } + + while (parentNode && parentNode.tagName.toUpperCase() != 'BODY' && parentNode.tagName.toUpperCase() != 'HTML') + { // account for any scrolled ancestors + if (Y.Dom.getStyle(parentNode, 'display') != 'inline') { // work around opera inline scrollLeft/Top bug + pos[0] -= parentNode.scrollLeft; + pos[1] -= parentNode.scrollTop; + } + + if (parentNode.parentNode) { + parentNode = parentNode.parentNode; + } else { parentNode = null; } + } + + + return pos; + }; + + return Y.Dom.batch(el, f, Y.Dom, true); + }, + + /** + * Gets the current X position of an element based on page coordinates. The element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false). + * @method getX + * @param {String | HTMLElement | Array} el Accepts a string to use as an ID, an actual DOM reference, or an Array of IDs and/or HTMLElements + * @return {String | Array} The X position of the element(s) + */ + getX: function(el) { + var f = function(el) { + return Y.Dom.getXY(el)[0]; + }; + + return Y.Dom.batch(el, f, Y.Dom, true); + }, + + /** + * Gets the current Y position of an element based on page coordinates. Element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false). + * @method getY + * @param {String | HTMLElement | Array} el Accepts a string to use as an ID, an actual DOM reference, or an Array of IDs and/or HTMLElements + * @return {String | Array} The Y position of the element(s) + */ + getY: function(el) { + var f = function(el) { + return Y.Dom.getXY(el)[1]; + }; + + return Y.Dom.batch(el, f, Y.Dom, true); + }, + + /** + * Set the position of an html element in page coordinates, regardless of how the element is positioned. + * The element(s) must be part of the DOM tree to have page coordinates (display:none or elements not appended return false). + * @method setXY + * @param {String | HTMLElement | Array} el Accepts a string to use as an ID, an actual DOM reference, or an Array of IDs and/or HTMLElements + * @param {Array} pos Contains X & Y values for new position (coordinates are page-based) + * @param {Boolean} noRetry By default we try and set the position a second time if the first fails + */ + setXY: function(el, pos, noRetry) { + var f = function(el) { + var style_pos = this.getStyle(el, 'position'); + if (style_pos == 'static') { // default to relative + this.setStyle(el, 'position', 'relative'); + style_pos = 'relative'; + } + + var pageXY = this.getXY(el); + if (pageXY === false) { // has to be part of doc to have pageXY + return false; + } + + var delta = [ // assuming pixels; if not we will have to retry + parseInt( this.getStyle(el, 'left'), 10 ), + parseInt( this.getStyle(el, 'top'), 10 ) + ]; + + if ( isNaN(delta[0]) ) {// in case of 'auto' + delta[0] = (style_pos == 'relative') ? 0 : el.offsetLeft; + } + if ( isNaN(delta[1]) ) { // in case of 'auto' + delta[1] = (style_pos == 'relative') ? 0 : el.offsetTop; + } + + if (pos[0] !== null) { el.style.left = pos[0] - pageXY[0] + delta[0] + 'px'; } + if (pos[1] !== null) { el.style.top = pos[1] - pageXY[1] + delta[1] + 'px'; } + + if (!noRetry) { + var newXY = this.getXY(el); + + // if retry is true, try one more time if we miss + if ( (pos[0] !== null && newXY[0] != pos[0]) || + (pos[1] !== null && newXY[1] != pos[1]) ) { + this.setXY(el, pos, true); + } + } + + }; + + Y.Dom.batch(el, f, Y.Dom, true); + }, + + /** + * Set the X position of an html element in page coordinates, regardless of how the element is positioned. + * The element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false). + * @method setX + * @param {String | HTMLElement | Array} el Accepts a string to use as an ID, an actual DOM reference, or an Array of IDs and/or HTMLElements. + * @param {Int} x The value to use as the X coordinate for the element(s). + */ + setX: function(el, x) { + Y.Dom.setXY(el, [x, null]); + }, + + /** + * Set the Y position of an html element in page coordinates, regardless of how the element is positioned. + * The element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false). + * @method setY + * @param {String | HTMLElement | Array} el Accepts a string to use as an ID, an actual DOM reference, or an Array of IDs and/or HTMLElements. + * @param {Int} x To use as the Y coordinate for the element(s). + */ + setY: function(el, y) { + Y.Dom.setXY(el, [null, y]); + }, + + /** + * Returns the region position of the given element. + * The element must be part of the DOM tree to have a region (display:none or elements not appended return false). + * @method getRegion + * @param {String | HTMLElement | Array} el Accepts a string to use as an ID, an actual DOM reference, or an Array of IDs and/or HTMLElements. + * @return {Region | Array} A Region or array of Region instances containing "top, left, bottom, right" member data. + */ + getRegion: function(el) { + var f = function(el) { + var region = new Y.Region.getRegion(el); + return region; + }; + + return Y.Dom.batch(el, f, Y.Dom, true); + }, + + /** + * Returns the width of the client (viewport). + * @method getClientWidth + * @deprecated Now using getViewportWidth. This interface left intact for back compat. + * @return {Int} The width of the viewable area of the page. + */ + getClientWidth: function() { + return Y.Dom.getViewportWidth(); + }, + + /** + * Returns the height of the client (viewport). + * @method getClientHeight + * @deprecated Now using getViewportHeight. This interface left intact for back compat. + * @return {Int} The height of the viewable area of the page. + */ + getClientHeight: function() { + return Y.Dom.getViewportHeight(); + }, + + /** + * Returns a array of HTMLElements with the given class. + * For optimized performance, include a tag and/or root node when possible. + * @method getElementsByClassName + * @param {String} className The class name to match against + * @param {String} tag (optional) The tag name of the elements being collected + * @param {String | HTMLElement} root (optional) The HTMLElement or an ID to use as the starting point + * @return {Array} An array of elements that have the given class name + */ + getElementsByClassName: function(className, tag, root) { + var method = function(el) { return Y.Dom.hasClass(el, className); }; + return Y.Dom.getElementsBy(method, tag, root); + }, + + /** + * Determines whether an HTMLElement has the given className. + * @method hasClass + * @param {String | HTMLElement | Array} el The element or collection to test + * @param {String} className the class name to search for + * @return {Boolean | Array} A boolean value or array of boolean values + */ + hasClass: function(el, className) { + var re = new RegExp('(?:^|\\s+)' + className + '(?:\\s+|$)'); + + var f = function(el) { + return re.test(el['className']); + }; + + return Y.Dom.batch(el, f, Y.Dom, true); + }, + + /** + * Adds a class name to a given element or collection of elements. + * @method addClass + * @param {String | HTMLElement | Array} el The element or collection to add the class to + * @param {String} className the class name to add to the class attribute + */ + addClass: function(el, className) { + var f = function(el) { + if (this.hasClass(el, className)) { return; } // already present + + + el['className'] = [el['className'], className].join(' '); + }; + + Y.Dom.batch(el, f, Y.Dom, true); + }, + + /** + * Removes a class name from a given element or collection of elements. + * @method removeClass + * @param {String | HTMLElement | Array} el The element or collection to remove the class from + * @param {String} className the class name to remove from the class attribute + */ + removeClass: function(el, className) { + var re = new RegExp('(?:^|\\s+)' + className + '(?:\\s+|$)', 'g'); + + var f = function(el) { + if (!this.hasClass(el, className)) { return; } // not present + + + var c = el['className']; + el['className'] = c.replace(re, ' '); + if ( this.hasClass(el, className) ) { // in case of multiple adjacent + this.removeClass(el, className); + } + + }; + + Y.Dom.batch(el, f, Y.Dom, true); + }, + + /** + * Replace a class with another class for a given element or collection of elements. + * If no oldClassName is present, the newClassName is simply added. + * @method replaceClass + * @param {String | HTMLElement | Array} el The element or collection to remove the class from + * @param {String} oldClassName the class name to be replaced + * @param {String} newClassName the class name that will be replacing the old class name + */ + replaceClass: function(el, oldClassName, newClassName) { + if (oldClassName === newClassName) { // avoid infinite loop + return false; + } + + var re = new RegExp('(?:^|\\s+)' + oldClassName + '(?:\\s+|$)', 'g'); + + var f = function(el) { + + if ( !this.hasClass(el, oldClassName) ) { + this.addClass(el, newClassName); // just add it if nothing to replace + return; // note return + } + + el['className'] = el['className'].replace(re, ' ' + newClassName + ' '); + + if ( this.hasClass(el, oldClassName) ) { // in case of multiple adjacent + this.replaceClass(el, oldClassName, newClassName); + } + }; + + Y.Dom.batch(el, f, Y.Dom, true); + }, + + /** + * Generates a unique ID + * @method generateId + * @param {String | HTMLElement | Array} el (optional) An optional element array of elements to add an ID to (no ID is added if one is already present). + * @param {String} prefix (optional) an optional prefix to use (defaults to "yui-gen"). + * @return {String | Array} The generated ID, or array of generated IDs (or original ID if already present on an element) + */ + generateId: function(el, prefix) { + prefix = prefix || 'yui-gen'; + el = el || {}; + + var f = function(el) { + if (el) { + el = Y.Dom.get(el); + } else { + el = {}; // just generating ID in this case + } + + if (!el.id) { + el.id = prefix + id_counter++; + } // dont override existing + + + return el.id; + }; + + return Y.Dom.batch(el, f, Y.Dom, true); + }, + + /** + * Determines whether an HTMLElement is an ancestor of another HTML element in the DOM hierarchy. + * @method isAncestor + * @param {String | HTMLElement} haystack The possible ancestor + * @param {String | HTMLElement} needle The possible descendent + * @return {Boolean} Whether or not the haystack is an ancestor of needle + */ + isAncestor: function(haystack, needle) { + haystack = Y.Dom.get(haystack); + if (!haystack || !needle) { return false; } + + var f = function(needle) { + if (haystack.contains && !isSafari) { // safari "contains" is broken + return haystack.contains(needle); + } + else if ( haystack.compareDocumentPosition ) { + return !!(haystack.compareDocumentPosition(needle) & 16); + } + else { // loop up and test each parent + var parent = needle.parentNode; + + while (parent) { + if (parent == haystack) { + return true; + } + else if (!parent.tagName || parent.tagName.toUpperCase() == 'HTML') { + return false; + } + + parent = parent.parentNode; + } + return false; + } + }; + + return Y.Dom.batch(needle, f, Y.Dom, true); + }, + + /** + * Determines whether an HTMLElement is present in the current document. + * @method inDocument + * @param {String | HTMLElement} el The element to search for + * @return {Boolean} Whether or not the element is present in the current document + */ + inDocument: function(el) { + var f = function(el) { + return this.isAncestor(document.documentElement, el); + }; + + return Y.Dom.batch(el, f, Y.Dom, true); + }, + + /** + * Returns a array of HTMLElements that pass the test applied by supplied boolean method. + * For optimized performance, include a tag and/or root node when possible. + * @method getElementsBy + * @param {Function} method - A boolean method for testing elements which receives the element as its only argument. + + * @param {String} tag (optional) The tag name of the elements being collected + * @param {String | HTMLElement} root (optional) The HTMLElement or an ID to use as the starting point + * @return {Array} Array of HTMLElements + */ + getElementsBy: function(method, tag, root) { + tag = tag || '*'; + + var nodes = []; + + if (root) { + root = Y.Dom.get(root); + if (!root) { // if no root node, then no children + return nodes; + } + } else { + root = document; + } + + var elements = root.getElementsByTagName(tag); + + if ( !elements.length && (tag == '*' && root.all) ) { + elements = root.all; // IE < 6 + } + + for (var i = 0, len = elements.length; i < len; ++i) { + if ( method(elements[i]) ) { nodes[nodes.length] = elements[i]; } + } + + + return nodes; + }, + + /** + * Returns an array of elements that have had the supplied method applied. + * The method is called with the element(s) as the first arg, and the optional param as the second ( method(el, o) ). + * @method batch + * @param {String | HTMLElement | Array} el (optional) An element or array of elements to apply the method to + * @param {Function} method The method to apply to the element(s) + * @param {Any} o (optional) An optional arg that is passed to the supplied method + * @param {Boolean} override (optional) Whether or not to override the scope of "method" with "o" + * @return {HTMLElement | Array} The element(s) with the method applied + */ + batch: function(el, method, o, override) { + var id = el; + el = Y.Dom.get(el); + + var scope = (override) ? o : window; + + if (!el || el.tagName || !el.length) { // is null or not a collection (tagName for SELECT and others that can be both an element and a collection) + if (!el) { + return false; + } + return method.call(scope, el, o); + } + + var collection = []; + + for (var i = 0, len = el.length; i < len; ++i) { + if (!el[i]) { + id = el[i]; + } + collection[collection.length] = method.call(scope, el[i], o); + } + + return collection; + }, + + /** + * Returns the height of the document. + * @method getDocumentHeight + * @return {Int} The height of the actual document (which includes the body and its margin). + */ + getDocumentHeight: function() { + var scrollHeight = (document.compatMode != 'CSS1Compat') ? document.body.scrollHeight : document.documentElement.scrollHeight; + + var h = Math.max(scrollHeight, Y.Dom.getViewportHeight()); + return h; + }, + + /** + * Returns the width of the document. + * @method getDocumentWidth + * @return {Int} The width of the actual document (which includes the body and its margin). + */ + getDocumentWidth: function() { + var scrollWidth = (document.compatMode != 'CSS1Compat') ? document.body.scrollWidth : document.documentElement.scrollWidth; + var w = Math.max(scrollWidth, Y.Dom.getViewportWidth()); + return w; + }, + + /** + * Returns the current height of the viewport. + * @method getViewportHeight + * @return {Int} The height of the viewable area of the page (excludes scrollbars). + */ + getViewportHeight: function() { + var height = self.innerHeight; // Safari, Opera + var mode = document.compatMode; + + if ( (mode || isIE) && !isOpera ) { // IE, Gecko + height = (mode == 'CSS1Compat') ? + document.documentElement.clientHeight : // Standards + document.body.clientHeight; // Quirks + } + + return height; + }, + + /** + * Returns the current width of the viewport. + * @method getViewportWidth + * @return {Int} The width of the viewable area of the page (excludes scrollbars). + */ + + getViewportWidth: function() { + var width = self.innerWidth; // Safari + var mode = document.compatMode; + + if (mode || isIE) { // IE, Gecko, Opera + width = (mode == 'CSS1Compat') ? + document.documentElement.clientWidth : // Standards + document.body.clientWidth; // Quirks + } + return width; + } + }; +})(); +/** + * A region is a representation of an object on a grid. It is defined + * by the top, right, bottom, left extents, so is rectangular by default. If + * other shapes are required, this class could be extended to support it. + * @namespace YAHOO.util + * @class Region + * @param {Int} t the top extent + * @param {Int} r the right extent + * @param {Int} b the bottom extent + * @param {Int} l the left extent + * @constructor + */ +YAHOO.util.Region = function(t, r, b, l) { + + /** + * The region's top extent + * @property top + * @type Int + */ + this.top = t; + + /** + * The region's top extent as index, for symmetry with set/getXY + * @property 1 + * @type Int + */ + this[1] = t; + + /** + * The region's right extent + * @property right + * @type int + */ + this.right = r; + + /** + * The region's bottom extent + * @property bottom + * @type Int + */ + this.bottom = b; + + /** + * The region's left extent + * @property left + * @type Int + */ + this.left = l; + + /** + * The region's left extent as index, for symmetry with set/getXY + * @property 0 + * @type Int + */ + this[0] = l; +}; + +/** + * Returns true if this region contains the region passed in + * @method contains + * @param {Region} region The region to evaluate + * @return {Boolean} True if the region is contained with this region, + * else false + */ +YAHOO.util.Region.prototype.contains = function(region) { + return ( region.left >= this.left && + region.right <= this.right && + region.top >= this.top && + region.bottom <= this.bottom ); + +}; + +/** + * Returns the area of the region + * @method getArea + * @return {Int} the region's area + */ +YAHOO.util.Region.prototype.getArea = function() { + return ( (this.bottom - this.top) * (this.right - this.left) ); +}; + +/** + * Returns the region where the passed in region overlaps with this one + * @method intersect + * @param {Region} region The region that intersects + * @return {Region} The overlap region, or null if there is no overlap + */ +YAHOO.util.Region.prototype.intersect = function(region) { + var t = Math.max( this.top, region.top ); + var r = Math.min( this.right, region.right ); + var b = Math.min( this.bottom, region.bottom ); + var l = Math.max( this.left, region.left ); + + if (b >= t && r >= l) { + return new YAHOO.util.Region(t, r, b, l); + } else { + return null; + } +}; + +/** + * Returns the region representing the smallest region that can contain both + * the passed in region and this region. + * @method union + * @param {Region} region The region that to create the union with + * @return {Region} The union region + */ +YAHOO.util.Region.prototype.union = function(region) { + var t = Math.min( this.top, region.top ); + var r = Math.max( this.right, region.right ); + var b = Math.max( this.bottom, region.bottom ); + var l = Math.min( this.left, region.left ); + + return new YAHOO.util.Region(t, r, b, l); +}; + +/** + * toString + * @method toString + * @return string the region properties + */ +YAHOO.util.Region.prototype.toString = function() { + return ( "Region {" + + "top: " + this.top + + ", right: " + this.right + + ", bottom: " + this.bottom + + ", left: " + this.left + + "}" ); +}; + +/** + * Returns a region that is occupied by the DOM element + * @method getRegion + * @param {HTMLElement} el The element + * @return {Region} The region that the element occupies + * @static + */ +YAHOO.util.Region.getRegion = function(el) { + var p = YAHOO.util.Dom.getXY(el); + + var t = p[1]; + var r = p[0] + el.offsetWidth; + var b = p[1] + el.offsetHeight; + var l = p[0]; + + return new YAHOO.util.Region(t, r, b, l); +}; + +///////////////////////////////////////////////////////////////////////////// + + +/** + * A point is a region that is special in that it represents a single point on + * the grid. + * @namespace YAHOO.util + * @class Point + * @param {Int} x The X position of the point + * @param {Int} y The Y position of the point + * @constructor + * @extends YAHOO.util.Region + */ +YAHOO.util.Point = function(x, y) { + if (x instanceof Array) { // accept output from Dom.getXY + y = x[1]; + x = x[0]; + } + + /** + * The X position of the point, which is also the right, left and index zero (for Dom.getXY symmetry) + * @property x + * @type Int + */ + + this.x = this.right = this.left = this[0] = x; + + /** + * The Y position of the point, which is also the top, bottom and index one (for Dom.getXY symmetry) + * @property y + * @type Int + */ + this.y = this.top = this.bottom = this[1] = y; +}; + +YAHOO.util.Point.prototype = new YAHOO.util.Region(); + +YAHOO.register("dom", YAHOO.util.Dom, {version: "2.2.0", build: "127"}); diff --git a/source/web/yui/element-beta.js b/source/web/yui/element-beta.js new file mode 100644 index 0000000000..bf4d408095 --- /dev/null +++ b/source/web/yui/element-beta.js @@ -0,0 +1,896 @@ +/* +Copyright (c) 2007, Yahoo! Inc. All rights reserved. +Code licensed under the BSD License: +http://developer.yahoo.net/yui/license.txt +version: 2.2.0 +*/ +/** + * Provides Attribute configurations. + * @namespace YAHOO.util + * @class Attribute + * @constructor + * @param hash {Object} The intial Attribute. + * @param {YAHOO.util.AttributeProvider} The owner of the Attribute instance. + */ + +YAHOO.util.Attribute = function(hash, owner) { + if (owner) { + this.owner = owner; + this.configure(hash, true); + } +}; + +YAHOO.util.Attribute.prototype = { + /** + * The name of the attribute. + * @property name + * @type String + */ + name: undefined, + + /** + * The value of the attribute. + * @property value + * @type String + */ + value: null, + + /** + * The owner of the attribute. + * @property owner + * @type YAHOO.util.AttributeProvider + */ + owner: null, + + /** + * Whether or not the attribute is read only. + * @property readOnly + * @type Boolean + */ + readOnly: false, + + /** + * Whether or not the attribute can only be written once. + * @property writeOnce + * @type Boolean + */ + writeOnce: false, + + /** + * The attribute's initial configuration. + * @private + * @property _initialConfig + * @type Object + */ + _initialConfig: null, + + /** + * Whether or not the attribute's value has been set. + * @private + * @property _written + * @type Boolean + */ + _written: false, + + /** + * The method to use when setting the attribute's value. + * The method recieves the new value as the only argument. + * @property method + * @type Function + */ + method: null, + + /** + * The validator to use when setting the attribute's value. + * @property validator + * @type Function + * @return Boolean + */ + validator: null, + + /** + * Retrieves the current value of the attribute. + * @method getValue + * @return {any} The current value of the attribute. + */ + getValue: function() { + return this.value; + }, + + /** + * Sets the value of the attribute and fires beforeChange and change events. + * @method setValue + * @param {Any} value The value to apply to the attribute. + * @param {Boolean} silent If true the change events will not be fired. + * @return {Boolean} Whether or not the value was set. + */ + setValue: function(value, silent) { + var beforeRetVal; + var owner = this.owner; + var name = this.name; + + var event = { + type: name, + prevValue: this.getValue(), + newValue: value + }; + + if (this.readOnly || ( this.writeOnce && this._written) ) { + return false; // write not allowed + } + + if (this.validator && !this.validator.call(owner, value) ) { + return false; // invalid value + } + + if (!silent) { + beforeRetVal = owner.fireBeforeChangeEvent(event); + if (beforeRetVal === false) { + return false; + } + } + + if (this.method) { + this.method.call(owner, value); + } + + this.value = value; + this._written = true; + + event.type = name; + + if (!silent) { + this.owner.fireChangeEvent(event); + } + + return true; + }, + + /** + * Allows for configuring the Attribute's properties. + * @method configure + * @param {Object} map A key-value map of Attribute properties. + * @param {Boolean} init Whether or not this should become the initial config. + */ + configure: function(map, init) { + map = map || {}; + this._written = false; // reset writeOnce + this._initialConfig = this._initialConfig || {}; + + for (var key in map) { + if ( key && YAHOO.lang.hasOwnProperty(map, key) ) { + this[key] = map[key]; + if (init) { + this._initialConfig[key] = map[key]; + } + } + } + }, + + /** + * Resets the value to the initial config value. + * @method resetValue + * @return {Boolean} Whether or not the value was set. + */ + resetValue: function() { + return this.setValue(this._initialConfig.value); + }, + + /** + * Resets the attribute config to the initial config state. + * @method resetConfig + */ + resetConfig: function() { + this.configure(this._initialConfig); + }, + + /** + * Resets the value to the current value. + * Useful when values may have gotten out of sync with actual properties. + * @method refresh + * @return {Boolean} Whether or not the value was set. + */ + refresh: function(silent) { + this.setValue(this.value, silent); + } +}; + +(function() { + var Lang = YAHOO.util.Lang; + + /* + Copyright (c) 2006, Yahoo! Inc. All rights reserved. + Code licensed under the BSD License: + http://developer.yahoo.net/yui/license.txt + */ + + /** + * Provides and manages YAHOO.util.Attribute instances + * @namespace YAHOO.util + * @class AttributeProvider + * @uses YAHOO.util.EventProvider + */ + YAHOO.util.AttributeProvider = function() {}; + + YAHOO.util.AttributeProvider.prototype = { + + /** + * A key-value map of Attribute configurations + * @property _configs + * @protected (may be used by subclasses and augmentors) + * @private + * @type {Object} + */ + _configs: null, + /** + * Returns the current value of the attribute. + * @method get + * @param {String} key The attribute whose value will be returned. + */ + get: function(key){ + var configs = this._configs || {}; + var config = configs[key]; + + if (!config) { + return undefined; + } + + return config.value; + }, + + /** + * Sets the value of a config. + * @method set + * @param {String} key The name of the attribute + * @param {Any} value The value to apply to the attribute + * @param {Boolean} silent Whether or not to suppress change events + * @return {Boolean} Whether or not the value was set. + */ + set: function(key, value, silent){ + var configs = this._configs || {}; + var config = configs[key]; + + if (!config) { + return false; + } + + return config.setValue(value, silent); + }, + + /** + * Returns an array of attribute names. + * @method getAttributeKeys + * @return {Array} An array of attribute names. + */ + getAttributeKeys: function(){ + var configs = this._configs; + var keys = []; + var config; + for (var key in configs) { + config = configs[key]; + if ( Lang.hasOwnProperty(configs, key) && + !Lang.isUndefined(config) ) { + keys[keys.length] = key; + } + } + + return keys; + }, + + /** + * Sets multiple attribute values. + * @method setAttributes + * @param {Object} map A key-value map of attributes + * @param {Boolean} silent Whether or not to suppress change events + */ + setAttributes: function(map, silent){ + for (var key in map) { + if ( Lang.hasOwnProperty(map, key) ) { + this.set(key, map[key], silent); + } + } + }, + + /** + * Resets the specified attribute's value to its initial value. + * @method resetValue + * @param {String} key The name of the attribute + * @param {Boolean} silent Whether or not to suppress change events + * @return {Boolean} Whether or not the value was set + */ + resetValue: function(key, silent){ + var configs = this._configs || {}; + if (configs[key]) { + this.set(key, configs[key]._initialConfig.value, silent); + return true; + } + return false; + }, + + /** + * Sets the attribute's value to its current value. + * @method refresh + * @param {String | Array} key The attribute(s) to refresh + * @param {Boolean} silent Whether or not to suppress change events + */ + refresh: function(key, silent){ + var configs = this._configs; + + key = ( ( Lang.isString(key) ) ? [key] : key ) || + this.getAttributeKeys(); + + for (var i = 0, len = key.length; i < len; ++i) { + if ( // only set if there is a value and not null + configs[key[i]] && + ! Lang.isUndefined(configs[key[i]].value) && + ! Lang.isNull(configs[key[i]].value) ) { + configs[key[i]].refresh(silent); + } + } + }, + + /** + * Adds an Attribute to the AttributeProvider instance. + * @method register + * @param {String} key The attribute's name + * @param {Object} map A key-value map containing the + * attribute's properties. + * @deprecated Use setAttributeConfig + */ + register: function(key, map) { + this.setAttributeConfig(key, map); + }, + + + /** + * Returns the attribute's properties. + * @method getAttributeConfig + * @param {String} key The attribute's name + * @private + * @return {object} A key-value map containing all of the + * attribute's properties. + */ + getAttributeConfig: function(key) { + var configs = this._configs || {}; + var config = configs[key] || {}; + var map = {}; // returning a copy to prevent overrides + + for (key in config) { + if ( Lang.hasOwnProperty(config, key) ) { + map[key] = config[key]; + } + } + + return map; + }, + + /** + * Sets or updates an Attribute instance's properties. + * @method setAttributeConfig + * @param {String} key The attribute's name. + * @param {Object} map A key-value map of attribute properties + * @param {Boolean} init Whether or not this should become the intial config. + */ + setAttributeConfig: function(key, map, init) { + var configs = this._configs || {}; + map = map || {}; + if (!configs[key]) { + map.name = key; + configs[key] = new YAHOO.util.Attribute(map, this); + } else { + configs[key].configure(map, init); + } + }, + + /** + * Sets or updates an Attribute instance's properties. + * @method configureAttribute + * @param {String} key The attribute's name. + * @param {Object} map A key-value map of attribute properties + * @param {Boolean} init Whether or not this should become the intial config. + */ + configureAttribute: function(key, map, init) { + this.setAttributeConfig(key, map, init); + }, + + /** + * Resets an attribute to its intial configuration. + * @method resetAttributeConfig + * @param {String} key The attribute's name. + * @private + */ + resetAttributeConfig: function(key){ + var configs = this._configs || {}; + configs[key].resetConfig(); + }, + + /** + * Fires the attribute's beforeChange event. + * @method fireBeforeChangeEvent + * @param {String} key The attribute's name. + * @param {Obj} e The event object to pass to handlers. + */ + fireBeforeChangeEvent: function(e) { + var type = 'before'; + type += e.type.charAt(0).toUpperCase() + e.type.substr(1) + 'Change'; + e.type = type; + return this.fireEvent(e.type, e); + }, + + /** + * Fires the attribute's change event. + * @method fireChangeEvent + * @param {String} key The attribute's name. + * @param {Obj} e The event object to pass to the handlers. + */ + fireChangeEvent: function(e) { + e.type += 'Change'; + return this.fireEvent(e.type, e); + } + }; + + YAHOO.augment(YAHOO.util.AttributeProvider, YAHOO.util.EventProvider); +})(); + +(function() { +// internal shorthand +var Dom = YAHOO.util.Dom, + EventPublisher = YAHOO.util.EventPublisher, + AttributeProvider = YAHOO.util.AttributeProvider; + +/** + * Element provides an wrapper object to simplify adding + * event listeners, using dom methods, and managing attributes. + * @module element + * @namespace YAHOO.util + * @requires yahoo, dom, event + * @beta + */ + +/** + * Element provides an wrapper object to simplify adding + * event listeners, using dom methods, and managing attributes. + * @class Element + * @uses YAHOO.util.AttributeProvider + * @constructor + * @param el {HTMLElement | String} The html element that + * represents the Element. + * @param {Object} map A key-value map of initial config names and values + */ +YAHOO.util.Element = function(el, map) { + if (arguments.length) { + this.init(el, map); + } +}; + +YAHOO.util.Element.prototype = { + /** + * Dom events supported by the Element instance. + * @property DOM_EVENTS + * @type Object + */ + DOM_EVENTS: null, + + /** + * Wrapper for HTMLElement method. + * @method appendChild + * @param {Boolean} deep Whether or not to do a deep clone + */ + appendChild: function(child) { + child = child.get ? child.get('element') : child; + this.get('element').appendChild(child); + }, + + /** + * Wrapper for HTMLElement method. + * @method getElementsByTagName + * @param {String} tag The tagName to collect + */ + getElementsByTagName: function(tag) { + return this.get('element').getElementsByTagName(tag); + }, + + /** + * Wrapper for HTMLElement method. + * @method hasChildNodes + * @return {Boolean} Whether or not the element has childNodes + */ + hasChildNodes: function() { + return this.get('element').hasChildNodes(); + }, + + /** + * Wrapper for HTMLElement method. + * @method insertBefore + * @param {HTMLElement} element The HTMLElement to insert + * @param {HTMLElement} before The HTMLElement to insert + * the element before. + */ + insertBefore: function(element, before) { + element = element.get ? element.get('element') : element; + before = (before && before.get) ? before.get('element') : before; + + this.get('element').insertBefore(element, before); + }, + + /** + * Wrapper for HTMLElement method. + * @method removeChild + * @param {HTMLElement} child The HTMLElement to remove + */ + removeChild: function(child) { + child = child.get ? child.get('element') : child; + this.get('element').removeChild(child); + return true; + }, + + /** + * Wrapper for HTMLElement method. + * @method replaceChild + * @param {HTMLElement} newNode The HTMLElement to insert + * @param {HTMLElement} oldNode The HTMLElement to replace + */ + replaceChild: function(newNode, oldNode) { + newNode = newNode.get ? newNode.get('element') : newNode; + oldNode = oldNode.get ? oldNode.get('element') : oldNode; + return this.get('element').replaceChild(newNode, oldNode); + }, + + + /** + * Registers Element specific attributes. + * @method initAttributes + * @param {Object} map A key-value map of initial attribute configs + */ + initAttributes: function(map) { + map = map || {}; + var element = Dom.get(map.element) || null; + + /** + * The HTMLElement the Element instance refers to. + * @config element + * @type HTMLElement + */ + this.setAttributeConfig('element', { + value: element, + readOnly: true + }); + }, + + /** + * Adds a listener for the given event. These may be DOM or + * customEvent listeners. Any event that is fired via fireEvent + * can be listened for. All handlers receive an event object. + * @method addListener + * @param {String} type The name of the event to listen for + * @param {Function} fn The handler to call when the event fires + * @param {Any} obj A variable to pass to the handler + * @param {Object} scope The object to use for the scope of the handler + */ + addListener: function(type, fn, obj, scope) { + var el = this.get('element'); + var scope = scope || this; + + el = this.get('id') || el; + + if (!this._events[type]) { // create on the fly + if ( this.DOM_EVENTS[type] ) { + YAHOO.util.Event.addListener(el, type, function(e) { + if (e.srcElement && !e.target) { // supplement IE with target + e.target = e.srcElement; + } + this.fireEvent(type, e); + }, obj, scope); + } + + this.createEvent(type, this); + this._events[type] = true; + } + + this.subscribe.apply(this, arguments); // notify via customEvent + }, + + + /** + * Alias for addListener + * @method on + * @param {String} type The name of the event to listen for + * @param {Function} fn The function call when the event fires + * @param {Any} obj A variable to pass to the handler + * @param {Object} scope The object to use for the scope of the handler + */ + on: function() { this.addListener.apply(this, arguments); }, + + + /** + * Remove an event listener + * @method removeListener + * @param {String} type The name of the event to listen for + * @param {Function} fn The function call when the event fires + */ + removeListener: function(type, fn) { + this.unsubscribe.apply(this, arguments); + }, + + /** + * Wrapper for Dom method. + * @method addClass + * @param {String} className The className to add + */ + addClass: function(className) { + Dom.addClass(this.get('element'), className); + }, + + /** + * Wrapper for Dom method. + * @method getElementsByClassName + * @param {String} className The className to collect + * @param {String} tag (optional) The tag to use in + * conjunction with class name + * @return {Array} Array of HTMLElements + */ + getElementsByClassName: function(className, tag) { + return Dom.getElementsByClassName(className, tag, + this.get('element') ); + }, + + /** + * Wrapper for Dom method. + * @method hasClass + * @param {String} className The className to add + * @return {Boolean} Whether or not the element has the class name + */ + hasClass: function(className) { + return Dom.hasClass(this.get('element'), className); + }, + + /** + * Wrapper for Dom method. + * @method removeClass + * @param {String} className The className to remove + */ + removeClass: function(className) { + return Dom.removeClass(this.get('element'), className); + }, + + /** + * Wrapper for Dom method. + * @method replaceClass + * @param {String} oldClassName The className to replace + * @param {String} newClassName The className to add + */ + replaceClass: function(oldClassName, newClassName) { + return Dom.replaceClass(this.get('element'), + oldClassName, newClassName); + }, + + /** + * Wrapper for Dom method. + * @method setStyle + * @param {String} property The style property to set + * @param {String} value The value to apply to the style property + */ + setStyle: function(property, value) { + var el = this.get('element'); + if (!el) { + this._queue[this._queue.length] = ['setStyle', arguments]; + return false; + } + return Dom.setStyle(this.get('element'), property, value); + }, + + /** + * Wrapper for Dom method. + * @method getStyle + * @param {String} property The style property to retrieve + * @return {String} The current value of the property + */ + getStyle: function(property) { + return Dom.getStyle(this.get('element'), property); + }, + + /** + * Apply any queued set calls. + * @method fireQueue + */ + fireQueue: function() { + var queue = this._queue; + for (var i = 0, len = queue.length; i < len; ++i) { + this[queue[i][0]].apply(this, queue[i][1]); + } + }, + + /** + * Appends the HTMLElement into either the supplied parentNode. + * @method appendTo + * @param {HTMLElement | Element} parentNode The node to append to + * @param {HTMLElement | Element} before An optional node to insert before + */ + appendTo: function(parent, before) { + parent = (parent.get) ? parent.get('element') : Dom.get(parent); + + this.fireEvent('beforeAppendTo', { + type: 'beforeAppendTo', + target: parent + }); + + + before = (before && before.get) ? + before.get('element') : Dom.get(before); + var element = this.get('element'); + + if (!element) { + return false; + } + + if (!parent) { + return false; + } + + if (element.parent != parent) { + if (before) { + parent.insertBefore(element, before); + } else { + parent.appendChild(element); + } + } + + + this.fireEvent('appendTo', { + type: 'appendTo', + target: parent + }); + }, + + get: function(key) { + var configs = this._configs || {}; + var el = configs.element; // avoid loop due to 'element' + if (el && !configs[key] && !YAHOO.lang.isUndefined(el.value[key]) ) { + return el.value[key]; + } + + return AttributeProvider.prototype.get.call(this, key); + }, + + set: function(key, value, silent) { + var el = this.get('element'); + if (!el) { + this._queue[this._queue.length] = ['set', arguments]; + if (this._configs[key]) { + this._configs[key].value = value; // so "get" works while queueing + + } + return; + } + + // set it on the element if not configured and is an HTML attribute + if ( !this._configs[key] && !YAHOO.lang.isUndefined(el[key]) ) { + _registerHTMLAttr.call(this, key); + } + + return AttributeProvider.prototype.set.apply(this, arguments); + }, + + setAttributeConfig: function(key, map, init) { + var el = this.get('element'); + + if (el && !this._configs[key] && !YAHOO.lang.isUndefined(el[key]) ) { + _registerHTMLAttr.call(this, key, map); + } else { + AttributeProvider.prototype.setAttributeConfig.apply(this, arguments); + } + }, + + getAttributeKeys: function() { + var el = this.get('element'); + var keys = AttributeProvider.prototype.getAttributeKeys.call(this); + + //add any unconfigured element keys + for (var key in el) { + if (!this._configs[key]) { + keys[key] = keys[key] || el[key]; + } + } + + return keys; + }, + + init: function(el, attr) { + this._queue = this._queue || []; + this._events = this._events || {}; + this._configs = this._configs || {}; + attr = attr || {}; + attr.element = attr.element || el || null; + + this.DOM_EVENTS = { + 'click': true, + 'keydown': true, + 'keypress': true, + 'keyup': true, + 'mousedown': true, + 'mousemove': true, + 'mouseout': true, + 'mouseover': true, + 'mouseup': true + }; + + var readyHandler = function() { + this.initAttributes(attr); + this.setAttributes(attr, true); + this.fireQueue(); + this.fireEvent('contentReady', { + type: 'contentReady', + target: attr.element + }); + }; + + if ( YAHOO.lang.isString(el) ) { + _registerHTMLAttr.call(this, 'id', { value: el }); + YAHOO.util.Event.onAvailable(el, function() { + attr.element = Dom.get(el); + this.fireEvent('available', { + type: 'available', + target: attr.element + }); + }, this, true); + + YAHOO.util.Event.onContentReady(el, function() { + readyHandler.call(this); + }, this, true); + } else { + readyHandler.call(this); + } + } +}; + +/** + * Sets the value of the property and fires beforeChange and change events. + * @private + * @method _registerHTMLAttr + * @param {YAHOO.util.Element} element The Element instance to + * register the config to. + * @param {String} key The name of the config to register + * @param {Object} map A key-value map of the config's params + */ +var _registerHTMLAttr = function(key, map) { + var el = this.get('element'); + map = map || {}; + map.name = key; + map.method = map.method || function(value) { + el[key] = value; + }; + map.value = map.value || el[key]; + this._configs[key] = new YAHOO.util.Attribute(map, this); +}; + +/** + * Fires when the Element's HTMLElement can be retrieved by Id. + *

See: Element.addListener

+ *

Event fields:
+ * <String> type available
+ * <HTMLElement> + * target the HTMLElement bound to this Element instance
+ *

Usage:
+ * var handler = function(e) {var target = e.target};
+ * myTabs.addListener('available', handler);

+ * @event available + */ + +/** + * Fires when the Element's HTMLElement subtree is rendered. + *

See: Element.addListener

+ *

Event fields:
+ * <String> type contentReady
+ * <HTMLElement> + * target the HTMLElement bound to this Element instance
+ *

Usage:
+ * var handler = function(e) {var target = e.target};
+ * myTabs.addListener('contentReady', handler);

+ * @event contentReady + */ + + +YAHOO.augment(YAHOO.util.Element, AttributeProvider); +})(); + +YAHOO.register("element", YAHOO.util.Element, {version: "2.2.0", build: "127"}); diff --git a/source/web/yui/event-min.js b/source/web/yui/event-min.js new file mode 100644 index 0000000000..575a08e154 --- /dev/null +++ b/source/web/yui/event-min.js @@ -0,0 +1,84 @@ +/* +Copyright (c) 2007, Yahoo! Inc. All rights reserved. +Code licensed under the BSD License: +http://developer.yahoo.net/yui/license.txt +version: 2.2.0 +*/ + +if(!YAHOO.util.Event){YAHOO.util.Event=function(){var loadComplete=false;var listeners=[];var unloadListeners=[];var legacyEvents=[];var legacyHandlers=[];var retryCount=0;var onAvailStack=[];var legacyMap=[];var counter=0;var lastError=null;return{POLL_RETRYS:200,POLL_INTERVAL:20,EL:0,TYPE:1,FN:2,WFN:3,OBJ:3,ADJ_SCOPE:4,isSafari:(/KHTML/gi).test(navigator.userAgent),webkit:function(){var v=navigator.userAgent.match(/AppleWebKit\/([^ ]*)/);if(v&&v[1]){return v[1];} +return null;}(),isIE:(!this.webkit&&!navigator.userAgent.match(/opera/gi)&&navigator.userAgent.match(/msie/gi)),_interval:null,startInterval:function(){if(!this._interval){var self=this;var callback=function(){self._tryPreloadAttach();};this._interval=setInterval(callback,this.POLL_INTERVAL);}},onAvailable:function(p_id,p_fn,p_obj,p_override){onAvailStack.push({id:p_id,fn:p_fn,obj:p_obj,override:p_override,checkReady:false});retryCount=this.POLL_RETRYS;this.startInterval();},onContentReady:function(p_id,p_fn,p_obj,p_override){onAvailStack.push({id:p_id,fn:p_fn,obj:p_obj,override:p_override,checkReady:true});retryCount=this.POLL_RETRYS;this.startInterval();},addListener:function(el,sType,fn,obj,override){if(!fn||!fn.call){return false;} +if(this._isValidCollection(el)){var ok=true;for(var i=0,len=el.length;i=0){cacheItem=listeners[index];} +if(!el||!cacheItem){return false;} +if(this.useLegacyEvent(el,sType)){var legacyIndex=this.getLegacyIndex(el,sType);var llist=legacyHandlers[legacyIndex];if(llist){for(i=0,len=llist.length;i0);} +var notAvail=[];for(var i=0,len=onAvailStack.length;i0){for(var i=0,len=searchList.length;i0){j=listeners.length;while(j){index=j-1;l=listeners[index];if(l){EU.removeListener(l[EU.EL],l[EU.TYPE],l[EU.FN],index);} +j=j-1;} +l=null;EU.clearCache();} +for(i=0,len=legacyEvents.length;i0){param=args[0];} +ret=s.fn.call(scope,param,s.obj);}else{ret=s.fn.call(scope,this.type,args,s.obj);} +if(false===ret){if(!this.silent){} +return false;}}} +return true;},unsubscribeAll:function(){for(var i=0,len=this.subscribers.length;i