• R/O
  • SSH
  • HTTPS

rbanner: Commit


Commit MetaInfo

Revision14 (tree)
Time2010-07-01 14:16:41
Authorpine613

Log Message

(empty log message)

Change Summary

Incremental Difference

--- trunk/src/rbanner.js (revision 13)
+++ trunk/src/rbanner.js (revision 14)
@@ -10,11 +10,13 @@
1010
1111 // 定数の宣言 --------------------------------------------------
1212
13+ // ライブラリのバージョン
1314 var const_version = "1.2 alpha";
1415
1516
1617 // ロード時の引数の処理 ----------------------------------------
1718
19+ // デフォルト設定
1820 var config = {
1921 className: "RBanner",
2022 sprintf: "sprintf",
@@ -23,6 +25,7 @@
2325 target: "_self"
2426 };
2527
28+ // ロード時引数で設定を上書き
2629 (function(){
2730 var elements = document.getElementsByTagName("script");
2831
@@ -55,11 +58,12 @@
5558
5659 eval("var _sprintf = " + config.sprintf);
5760
61+ // グローバルに値を定義する
5862 function define_global(name, value){
5963 global[name] = value;
6064 }
6165
62- function to_string(object){
66+ function to_obj_string(object){
6367 return Object.prototype.toString.call(object);
6468 }
6569
@@ -73,28 +77,57 @@
7377 return array;
7478 }
7579
80+ function to_date(object){
81+ if(is_date(object)){
82+ return object;
83+ }
84+
85+ if(is_string(object)){
86+ var date = new Date(object);
87+
88+ if(isNaN(date.getTime())){
89+ return null;
90+ }
91+
92+ return date;
93+ }
94+
95+ if(is_number(object)){
96+ if(isNaN(object)){
97+ return null;
98+ }
99+
100+ var date = new Date();
101+ date.setTime(object);
102+
103+ return date;
104+ }
105+
106+ return null;
107+ }
108+
76109 function is_array(object){
77- return to_string(object) == "[object Array]";
110+ return to_obj_string(object) == "[object Array]";
78111 }
79112
80113 function is_string(object){
81- return to_string(object) == "[object String]";
114+ return to_obj_string(object) == "[object String]";
82115 }
83116
84117 function is_function(object){
85- return to_string(object) == "[object Function]";
118+ return to_obj_string(object) == "[object Function]";
86119 }
87120
88121 function is_number(object){
89- return to_string(object) == "[object Number]";
122+ return to_obj_string(object) == "[object Number]";
90123 }
91124
92125 function is_boolean(object){
93- return to_string(object) == "[object Boolean]";
126+ return to_obj_string(object) == "[object Boolean]";
94127 }
95128
96129 function is_date(object){
97- return to_string(object) == "[object Date]";
130+ return to_obj_string(object) == "[object Date]";
98131 }
99132
100133 function get_rand(a, b){
@@ -382,14 +415,12 @@
382415 // 日付を指定して出力
383416 // rbs_date(date, comp, func)
384417 function rbs_date(date, comp, func){
385- if(!is_date(date) && !is_string(date)){
418+ date = to_date(date);
419+
420+ if(!date){
386421 return "";
387422 }
388423
389- if(is_string(date)){
390- date = new Date(date);
391- }
392-
393424 var now = new Date();
394425
395426 if(!comp(date, now)){
@@ -414,7 +445,11 @@
414445 // rbs_since(date, func);
415446 // rbs_since(date, <rbs args ...>); -> rbs_since(date, function(){ rbs(<rbs args>) });
416447 function rbs_since(date, func){
417- return rbs_date.apply(null, [date, function(a, b){ return a < b }].concat(to_array(arguments).slice(1)));
448+ var comp = function(date, now){
449+ return date < now;
450+ };
451+
452+ return rbs_date.apply(null, [date, comp].concat(to_array(arguments).slice(1)));
418453 }
419454
420455 // 指定した時より前なら出力
Show on old repository browser