1: <script> 1:
2: KWizCom.DVPWP.Instances['_WPQ_'].Load = function()
3: {
4: var numOfWeeksToShow = 10;
5: var monthNames = {
6: "01": "Jan",
7: "02": "Feb",
8: "03": "Mar",
9: "04": "Apr",
10: "05": "May",
11: "06": "Jun",
12: "07": "Jul",
13: "08": "Aug",
14: "09": "Sep",
15: "010": "Oct",
16: "011": "Nov",
17: "012": "Dec",
18: }
19: var groupNames = {
20: "today": "Today",
21: "tomorrow": "Tomorrow",
22: "thisweek": "This week",
23: "upcoming": "Upcoming"
24: }
25:
26: var make2DigitString = function (n) {
27: return n < 10 ? "0" + n : "" + n;
28: }
29:
30: var now = new Date();
31: var tomorrow = new Date(now.getTime() + 24 * 60 * 60 * 1000);
32: var nextWeek = new Date(now.getTime() + 7 * 24 * 60 * 60 * 1000);
33: var endDate = new Date(now.getTime() + numOfWeeksToShow * 7 * 24 * 60 * 60 * 1000);
34: var $list = $kw("#_WPQ_Birthdays");
35: var $placeholder = $kw("#_WPQ_BirthdaysPlaceHolder");
36: var currentYear = now.getFullYear();
37: var nextYear = currentYear + 1;
38: var currentMonth = now.getMonth() + 1;//it is zero based
39: var currentDay = now.getDate();
40: var tomorrowMonth = tomorrow.getMonth() + 1;
41: var tomorrowDay = tomorrow.getDate();
42: var tomorrowYear = tomorrow.getFullYear();
43: var nextWeekMonth = nextWeek.getMonth() + 1;
44: var nextWeekDay = nextWeek.getDate();
45: var nextWeekYear = nextWeek.getFullYear();
46: var endMonth = endDate.getMonth() + 1;
47: var endDay = endDate.getDate();
48: var endYear = endDate.getFullYear();
49:
50: var todayString = currentYear + "-" + make2DigitString(currentMonth) + "-" + make2DigitString(currentDay);
51: var tomorrowString = tomorrowYear + "-" + make2DigitString(tomorrowMonth) + "-" + make2DigitString(tomorrowDay);
52: var nextWeekString = nextWeekYear + "-" + make2DigitString(nextWeekMonth) + "-" + make2DigitString(nextWeekDay);
53: var endDateString = endYear + "-" + make2DigitString(endMonth) + "-" + make2DigitString(endDay);
54: var birthdaysList = new Array();
55:
56: $list.find("li").each(function () {
57: try{
58: var title = $kw(this).attr("data-title");
59: var month = parseInt($kw(this).attr("data-month"),10);
60: var day = parseInt($kw(this).attr("data-day"),10);
61: var sortableString = currentYear + "-" + make2DigitString(month) + "-" + make2DigitString(day);
62: if (sortableString < todayString)//this one passed. move it to next year
63: sortableString = nextYear + "-" + make2DigitString(month) + "-" + make2DigitString(day);
64: if( sortableString <= endDateString )
65: birthdaysList[birthdaysList.length] = sortableString + ":" + title;
66: } catch (e) {
67: }
68: });
69:
70: birthdaysList.sort();//now we got sorted birthdays
71: var titleMode = null;
72: var html = "";
73: for (var i = 0; i < birthdaysList.length; i++) {
74: var datePart = birthdaysList[i].split(":")[0];
75: var titlePart = birthdaysList[i].split(":")[1];
76: var dateArr = datePart.split("-");
77: var dateString = monthNames[dateArr[1]] + " " + dateArr[2];
78:
79: var newGroup = false;
80: if (todayString == datePart) {
81: if (titleMode != "today")//add title
82: {
83: newGroup = true;
84: titleMode = "today";
85: }
86: }
87: else if (tomorrowString == datePart) {
88: if (titleMode != "tomorrow")//add title
89: {
90: newGroup = true;
91: titleMode = "tomorrow";
92: }
93: }
94: else if (nextWeekString >= datePart) {
95: if (titleMode != "thisweek")//add title
96: {
97: newGroup = true;
98: titleMode = "thisweek";
99: }
100: }
101: else {
102: if (titleMode != "upcoming")//add title
103: {
104: newGroup = true;
105: titleMode = "upcoming";
106: }
107: }
108:
109: if (newGroup)
110: {
111: if (html != "") html += "</div>";
112: html += "<h3>"+groupNames[titleMode]+"</h3><div>";
113: }
114:
115: html += "<p>" + titlePart + "<span style='float:right'>" + dateString + "</span></p>";
116: }
117: if (html != "") {
118: html += "</div>";
119: $placeholder.append(html);
120: //$placeholder.accordion({
121: // heightStyle: "content"
122: //});
123: }
124: else {
125: $kw("#_WPQ_NoBirthdaysPlaceHolder").show();
126: }
127: }
128: </script>