-
-
Save Nia-TN1012/f6a829c7ba9737d9ab689f2f660705fd to your computer and use it in GitHub Desktop.
CoffeeScriptでカレンダーを出力するソースコードです。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 名前 : Nia Tomonaka | |
# Twitter : https://twitter.com/nia_tn1012 | |
window.onload = () -> | |
# 現在日を取得し、当月1日の曜日と末日を求めます。 | |
now = new Date() | |
prePad = new Date( now.getFullYear(), now.getMonth(), 1 ).getDay() | |
lastDay = new Date( now.getFullYear(), now.getMonth() + 1, 0 ).getDate() | |
# カレンダーを出力します。 | |
el = document.getElementById( 'content' ) | |
for curDay in [( -prePad + 1 )..lastDay] | |
# 半角スペース1つ出力します。curDayが負の時はさらに2つ出力します。 | |
el.innerHTML += " " + if curDay < 1 then " " | |
# curDayが正の時です。1桁なら半角スペースを1つ出力します。そして日付を出力します。 | |
else ( if curDay < 10 then " " else "" ) + curDay.toString() + | |
# 土曜日を出力したら、改行タグを入れます。 | |
if ( prePad + curDay ) % 7 is 0 then "<br/>" else "" | |
# Calendar.coffee | |
# Copyright (c) 2014-2023 Nia T.N. Tech Lab. / Chronoir.net. | |
# This software is released under the MIT License. | |
# http://opensource.org/licenses/mit-license.php |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Visual StudioでそのCoffeeScriptファイルをビルドした時に生成されるJavaScriptコードです。 | |
(function() { | |
window.onload = function() { | |
var curDay, el, lastDay, now, prePad, _i, _ref, _results; | |
now = new Date(); | |
prePad = new Date(now.getFullYear(), now.getMonth(), 1).getDay(); | |
lastDay = new Date(now.getFullYear(), now.getMonth() + 1, 0).getDate(); | |
el = document.getElementById('content'); | |
_results = []; | |
for (curDay = _i = _ref = -prePad + 1; _ref <= lastDay ? _i <= lastDay : _i >= lastDay; curDay = _ref <= lastDay ? ++_i : --_i) { | |
_results.push(el.innerHTML += " " + (curDay < 1 ? " " : (curDay < 10 ? " " : "") + curDay.toString() + ((prePad + curDay) % 7 === 0 ? "<br/>" : ""))); | |
} | |
return _results; | |
}; | |
}).call(this); | |
//# sourceMappingURL=Calendar.js.map |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
GitHubのアカウント統合のため、Myoga1012→Nia-TN1012に移行しました。
旧URL: https://gist.github.com/Myoga1012/38cacec36f4233137738