|
本館粉絲專頁 |
|
|
使用者:Digipunk/FC/func.js:修訂版本之間的差異
台灣棒球維基館
< 使用者:Digipunk | FC
(新頁面: window.addEventListener("load", function(event) { try { DGPKJS_FC(); } catch (e) { console.log(e); } }, false); //-------------------------------------------------- // F...) |
小 |
||
第25行: | 第25行: | ||
} | } | ||
} | } | ||
− | + | ||
+ | attr.id = (attr.id || 'DGPK-FC') + '-' + i; | ||
+ | |||
__dgpkjs_fc_init(attr); | __dgpkjs_fc_init(attr); | ||
__dgpkjs_fc_create(attr, FC[i]); | __dgpkjs_fc_create(attr, FC[i]); | ||
第180行: | 第182行: | ||
stl = (attr.st.div ? ' STYLE="' + attr.st.div + '"' : ''); | stl = (attr.st.div ? ' STYLE="' + attr.st.div + '"' : ''); | ||
html += '<DIV ID="' + (attr.id || '') + '" CLASS="DGPK-FC DGPK-FC' + attr.ymp + '"' + stl + '>'; | html += '<DIV ID="' + (attr.id || '') + '" CLASS="DGPK-FC DGPK-FC' + attr.ymp + '"' + stl + '>'; | ||
− | html += '<TABLE | + | html += '<TABLE ID="TBL-' + attr.id + '" BORDER="0" CELLSPACING="0" CELLPADDING="2" STYLE="width:100%;opacity:0.1;transition:opacity 1s">'; |
//------------------------ | //------------------------ | ||
第287行: | 第289行: | ||
setTimeout(function() { | setTimeout(function() { | ||
− | + | document.getElementById('TBL-' + attr.id).style.opacity = 1; | |
− | + | ||
− | + | ||
− | + | ||
}, 1); | }, 1); | ||
} | } |
2018年7月25日 (三) 19:20的修訂版本
window.addEventListener("load", function(event) { try { DGPKJS_FC(); } catch (e) { console.log(e); } }, false); //-------------------------------------------------- // FC (floating calendar) //-------------------------------------------------- function DGPKJS_FC() { var FC = document.getElementsByClassName('DGPK-FC-JS'); for (var i = 0, ii = FC.length; i < ii; i++) { try { var attr = JSON.parse(FC[i].innerText.replace(/[\r\n]/g, '')); for (var j in attr) { if (typeof attr[j] == 'object') { for (var k in attr[j]) { attr[j][k] = decodeURIComponent(attr[j][k]).trim(); } } else { attr[j] = decodeURIComponent(attr[j]).trim(); if (!isNaN(attr[j])) attr[j] = parseInt(attr[j]); } } attr.id = (attr.id || 'DGPK-FC') + '-' + i; __dgpkjs_fc_init(attr); __dgpkjs_fc_create(attr, FC[i]); } catch (e) { console.log(e); } } } function __dgpkjs_fc_init(attr) { var tmp, dd; dd = new Date(); attr.today = new Date(dd.getFullYear() + '/' + (dd.getMonth() + 1) + '/' + dd.getDate()); // to avoid the trouble of 'H:i:s ms' attr.yy = null; if (attr.ymp == 1 && !attr.arg1 && (tmp = attr.pagename.match(/^(\d+)年(\d+)/)) != null) { attr.yy = parseInt(tmp[1]); attr.mm = parseInt(tmp[2]); } if (attr.yy == null) { if (attr.arg1) { tmp = attr.arg1.split('/'); attr.yy = parseInt(tmp[0]); attr.mm = parseInt(tmp[1]); } else { attr.yy = attr.today.getFullYear(); attr.mm = attr.today.getMonth() + 1; } } // normalize from and to if (attr.from) { try { attr.from = new Date(attr.from); } catch (e) { attr.from = new Date('1970/1'); } } if (attr.to) { try { attr.to = new Date(attr.to); } catch (e) { attr.to = new Date('1970/1'); } } // current month tmp = (attr.mm < 10 ? '0' : '') + attr.mm; attr.ym = attr.yy + '/' + tmp; attr.ym2 = attr.yy + '' + tmp; // previous month if (attr.mm == 1) { attr['p-ym'] = (parseInt(attr.yy) - 1) + '/12'; attr['p-ym2'] = (parseInt(attr.yy) - 1) + '12'; } else { tmp = attr.mm - 1; tmp = (tmp < 10 ? '0' : '') + tmp; attr['p-ym'] = attr.yy + '/' + tmp; attr['p-ym2'] = attr.yy + '' + tmp; } // next month if (attr.mm == 12) { attr['n-ym'] = (parseInt(attr.yy) + 1) + '/01'; attr['n-ym2'] = (parseInt(attr.yy) + 1) + '01'; } else { tmp = attr.mm + 1; tmp = (tmp < 10 ? '0' : '') + tmp; attr['n-ym'] = attr.yy + '/' + tmp; attr['n-ym2'] = attr.yy + '' + tmp; } // misc attr['days-left'] = 0; if (attr.countdown && attr.from) { attr['days-left'] = Math.floor((attr.from - attr.today) / (86400 * 1000)); if (attr['days-left'] <= 0) attr['days-left'] = 0; } // calc the first and last days of the calendar var offset_first, offset_last; offset_first = 0; offset_last = 0; if (attr.ymp == 1) { attr['show-pn'] = 0; } else { attr['show-pn'] = 1; switch (attr.more) { case 'p': offset_first = -1; break; case 'pp': offset_first = -2; break; case 'n': offset_last = 1; break; case 'nn': offset_last = 2; break; case 'pn': case 'np': offset_first = -1; offset_last = 1; break; default: switch (attr.shift) { case 'p': offset_first = -1; offset_last = -1; break; case 'pp': offset_first = -2; offset_last = -2; break; case 'n': offset_first = 1; offset_last = 1; break; case 'nn': offset_first = 2; offset_last = 2; break; default: attr['show-pn'] = 0; break; } break; } } attr.first = new Date(attr.ym); attr.wday = (attr.first.getDay() + 7 - attr.human) % 7; attr.first.setDate(1 + offset_first * 7 - attr.wday); attr.last = new Date(attr['n-ym']); attr.last.setDate(0 + offset_last * 7); if (attr.ymp == 0 && attr['show-pn'] == 0 && attr.row6 == 1) { attr.rows = 6; attr['show-pn'] = 1; } else { attr.rows = Math.ceil(((attr.last - attr.first) / (86400 * 1000) + 1) / 7); } } function __dgpkjs_fc_create(attr, fc) { var stl, tmp, html = ''; // outer div stl = (attr.st.div ? ' STYLE="' + attr.st.div + '"' : ''); html += '<DIV ID="' + (attr.id || '') + '" CLASS="DGPK-FC DGPK-FC' + attr.ymp + '"' + stl + '>'; html += '<TABLE ID="TBL-' + attr.id + '" BORDER="0" CELLSPACING="0" CELLPADDING="2" STYLE="width:100%;opacity:0.1;transition:opacity 1s">'; //------------------------ // title //------------------------ stl = (attr.st.header ? ' STYLE="' + attr.st.header + '"' : ''); html += '<TR CLASS="header' + attr.ymp + '"' + stl + '>'; if (attr.ymp == 1) { // Y/M Page html += '<TD><A HREF="' + attr.localurl + encodeURI(attr['p-ym'].replace('/', '年') + '月') + '">←</A></TD>'; html += '<TD><A HREF="' + attr.localurl + encodeURI(attr['n-ym'].replace('/', '年') + '月') + '">→</A></TD>'; html += '<TD COLSPAN="3" STYLE="color:white"><tt>' + attr.ym + '</tt></TD>'; html += '<TD><A HREF="#' + encodeURI(attr.mm + '月28日') + '">▼</A></TD>'; html += '<TD><A HREF="#top">▲</A></TD>'; } else { html += '<TD COLSPAN="7"' + stl + '>' + (attr.title || '<tt>' + attr.ym + '</tt>'); if (attr['days-left'] > 0) { html += '<tt> <A HREF="' + attr.localurl + encodeURI(attr.pagename); html += (attr.localurl.indexOf('?') >= 0 ? '&' : '?') + 'action=purge#' + (attr.id || '') + '" STYLE="color:yellow;font-style:italic">('; html += attr['days-left'] + ' day' + (attr['days-left'] > 1 ? 's' : '') + ' left)</A></tt>'; } html += '</TD>'; } html += '</TR>'; //------------------------ // header //------------------------ var WDAYS = ['日', '一', '二', '三', '四', '五', '六', '日']; stl = (attr.st.wday ? ' STYLE="' + attr.st.wday + '"' : ''); html += '<TR CLASS="wday">'; if (!attr.human) { html += '<TH' + stl + '>日</TH>'; } for (var i = 1; i < 7; i++) { html += '<TH' + stl + '>' + WDAYS[i] + '</TH>'; } if (attr.human) { html += '<TH' + stl + '>日</TH>'; } html += '</TR>'; //------------------------ // day rows //------------------------ var dd = attr.first; var mm = parseInt(attr.mm); var mm2 = mm - 1; var today_cls, today_stl; for (var week = 0; week < attr.rows; week++) { html += '<TR CLASS="days' + attr.ymp + '">'; for (var wday = 0; wday < 7; wday ++) { if (dd.getTime() === attr.today.getTime()) { today_cls = ' today'; today_stl = attr.st.today || ''; } else { today_cls = ''; today_stl = ''; } var day = dd.getDate(); html += '<TD CLASS="day' + (dd.getMonth() != mm2 ? ' day-pn' : '') + '">'; if (attr.ymp) { if (dd.getMonth() == mm2) { html += '<A HREF="#' + encodeURI(attr.mm + '月' + day + '日') + '"><SPAN CLASS="link' + today_cls + '">' + day + '</SPAN></A>'; } else { html += ' '; } } else { if (dd.getMonth() == mm2 || attr['show-pn']) { var link = null, stl; if (dd.getMonth() == mm2 && attr.links[day]) { link = attr.links[day]; stl = attr.st.link || ''; } else if (dd.getMonth() < mm2 && attr['p-links'][day]) { link = attr['p-links'][day]; stl = attr.st['link-pn'] || ''; } else if (dd.getMonth() > mm2 && attr['n-links'][day]) { link = attr['n-links'][day]; stl = attr.st['link-pn'] || ''; } if (link != null) { if (link.substr(0, 1) != '#') link = '#' + link; html += '<A HREF="' + encodeURI(link) + '"><SPAN CLASS="num link' + today_cls + '" STYLE="' + (attr.st.num || '') + ';' + stl + ';' + today_stl + '">' + day + '</SPAN></A>'; } else { if (dd >= attr.from && dd <= attr.to) { html += '<SPAN CLASS="num mark' + today_cls + '" STYLE="' + (attr.st.num || '') + ';' + (attr.st.mark || '') + ';' + today_stl + '">' + day + '</SPAN>'; } else { html += '<SPAN CLASS="num' + today_cls + '" STYLE="' + (attr.st.num || '') + ';' + today_stl + '">' + day + '</SPAN>'; } } } else { html += ' '; } } html += '</TD>'; dd.setDate(day + 1); } html += '</TR>'; } // done html += '</TABLE>'; html += '</DIV>'; fc.insertAdjacentHTML("afterend", html); setTimeout(function() { document.getElementById('TBL-' + attr.id).style.opacity = 1; }, 1); }