1. 日曆外觀顏色的 CSS 樣式定義
操作:打開模板,修改HTML,將以下的code貼入<head>之後。
/* Feed Calendar Styles */
#Calendar {
margin: 0px;
}
#Calendar .act {
color: #fff;
padding: 4px;
}
#CalendarTable table {
border-collapse: collapse;
padding: 0px;
border: 0px;
}
#CalendarTable table th {
padding: 1px;
color: #777;
margin: 0;
}
#CalendarTable table td {
height: 25px;
color: #999;
text-align: center;
padding: 1px;
margin: 0;
}
#CalendarTable table td a {
display: block;
}
#CalendarTable .Today {
color: #fff;
background: #777;
}
#CalendarTable .Today a {
color: #fff;
}
#CalendarTable .Weekend {
color: #997777;
}
2.放置抓 Feed、產生日曆的Javascript程式碼
操作:將下列的code,放置在 ]]></b:skin> 之後。
<script type='text/javascript'>
//<![CDATA[
<!-- Script functions for generating Feed Calendar: generateCalendar(), collectPost(), BrowsePrev(), BrowseNext(), BackToday() -->
var baseURL = '';
var currentDay = new Date();
var today = new Date();
var monthLabels = new Array('01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12');
var monthDays = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
var weekLabels = new Array('一','二','三','四','五','六','日');
function generateCalendar(){
var thisYear = currentDay.getFullYear();
var thisMonth = monthLabels[currentDay.getMonth()];
var thisDay = today.getDate();
var nDays = monthDays[currentDay.getMonth()];
if (currentDay.getMonth() == 1 &&(((thisYear % 4 == 0) && (thisYear % 100 != 0)) || (thisYear % 400 == 0)))
nDays = 29;
var IsitNow = currentDay;
IsitNow.setDate(1);
var startDay = IsitNow.getDay() - 1;
if (startDay < 0)
startDay = 6;
var sCalendarCode = '<table><tr>';
for (var index=0;index<7;index++)
sCalendarCode+='<th style="width:25px;">'+ weekLabels[index]+'</th>';
sCalendarCode+='</tr>';
var nTableCol=0;
for (index=0;index<startDay;index++) {
if (nTableCol == 0)
sCalendarCode += '<tr>';
sCalendarCode+='<td> </td>';
nTableCol++;
}
for (index=1;index<=nDays;index++) {
if (nTableCol==0)
sCalendarCode+='<tr>';
if (index==thisDay && today.getMonth()==currentDay.getMonth() && today.getFullYear()==currentDay.getFullYear())
sCalendarCode+='<td id="Day'+index+'" class="Today">';
else {
if (nTableCol < 5)
sCalendarCode+='<td id="Day'+index+'">';
else
sCalendarCode+='<td id="Day'+index+'" class="Weekend">';
}
sCalendarCode+=index;
sCalendarCode+='</td>';
if (nTableCol==6) {
sCalendarCode+='</tr>';
nTableCol=0;
}
else
nTableCol++;
}
if (nTableCol>0) {
for (index=0;index<(7-nTableCol);index++) {
sCalendarCode+='<td> </td>';
}
sCalendarCode+='</tr>';
}
sCalendarCode+='</table>';
document.getElementById('CalendarTable').innerHTML = sCalendarCode;
var sFeedURL = baseURL + '/feeds/posts/summary?orderby=published&published-min='+thisYear+'-'+thisMonth+'-01T00:00:00&published-max='+thisYear+'-'+thisMonth+'-31T23:59:59&max-results=50&alt=json-in-script&callback=collectPost';
var script = document.createElement('script');
document.getElementById('CalendarCaption').innerHTML = '<span class="loading">Loading <blink>...</blink></span>';
script.setAttribute('src', sFeedURL);
script.setAttribute('type', 'text/javascript');
document.documentElement.firstChild.appendChild(script);
}
function collectPost(json) {
document.getElementById('CalendarCaption').innerHTML = currentDay.getFullYear()+'-'+monthLabels[currentDay.getMonth()];
var entries = json.feed.entry;
var nDay = 0, nCount = 0, nActual = 0;
var posts = new Array();
for (var i = 0, post; post = entries[i]; i++) {
nDay = parseInt(post.published.$t.substr(8,2),10);
if (i>0&&nDay==parseInt(entries[i-1].published.$t.substr(8,2),10)) {
var actualDay = post.published.$t.substr(0,10);
var actualTimezone = post.published.$t.substr(23,6);;
posts[nActual-1][1] = posts[nActual-1][1]+', '+post.title.$t;
posts[nActual-1][2] = baseURL +'/search?updated-min='+actualDay+'T00%3A00%3A00'+encodeURIComponent(actualTimezone)+'&updated-max='+actualDay+'T23%3A59%3A59'+encodeURIComponent(actualTimezone);
} else {
posts[nActual] = new Array(3);
posts[nActual][0] = nDay;
posts[nActual][1] = post.title.$t;
posts[nActual][2] = post.link[0].href;
nActual++;
}
}
for (i=0;i<nActual;i++) {
posts[i][1] = posts[i][1].replace('\"', '"').replace('\'', ''');
document.getElementById('Day'+posts[i][0]).innerHTML = '<a title="'+posts[i][1]+'" href="'+posts[i][2]+'target="blank_">'+posts[i][0]+'</a>';
}
}
function BrowsePrev() {
var thisMonth = currentDay.getMonth()-1;
var thisYear = currentDay.getFullYear();
if (thisMonth<0) {
thisMonth = 11;
thisYear = thisYear-1;
}
thisMonth = monthLabels[thisMonth];
currentDay = new Date(thisYear+'/'+thisMonth+'/1 00:01');
generateCalendar();
}
function BrowseNext() {
var thisMonth = currentDay.getMonth()+1;
var thisYear = currentDay.getFullYear();
if (thisMonth>11) {
thisMonth = 0;
thisYear = thisYear+1;
}
thisMonth = monthLabels[thisMonth];
currentDay = new Date(thisYear+'/'+thisMonth+'/1 00:01');
generateCalendar();
}
function BackToday() {
currentDay = new Date();
generateCalendar();
}
//]]>
</script>
ps.若是希望點選月曆不直接開個新頁,以上code拿掉target="blank_",就可以了。
3.樣板設定結束,存檔,接著安排這個新日曆模組位置。
操作:換到「網頁元素」的設定,在你想塞入日曆的地方新增一個網頁元素,選擇 HTML/JavaScript 類型。給個標題,然後貼入以下的 HTML 程式:
<center>
<table border="0" id="Calendar" cellpadding="0" cellspacing="0">
<caption>
<a href="javascript:;" onclick="BrowsePrev();" title="Previous Month"><<</a>
<a href="javascript:;" onclick="BackToday();" title="Back to Today"> <span id="CalendarCaption"> </span></a>
<a href="javascript:;" onclick="BrowseNext();" title="Next Month">>></a>
</caption>
<tr>
<td id="CalendarTable" class="act"> </td>
</tr>
</table>
<script type="text/javascript">
generateCalendar();
</script>
</center>
儲存,完成設定!!
5 則留言:
你的"code"的圖呢?
嗯...這個罵...我用IE看,就可以看到圖哩,我也不知道為什麼?囧
真是神奇啦,Firefox竟然看不到code圖…
應該跟你的火狐 外嵌程式有關吧
我用opera可以看得到 code圖
恩,根據阿呆的blog設置方式,或許換個語法可以解決,不過詳細原因等有空再來看看了。XD 懶ㄚ~~~
張貼留言