jscalendar 1.0 显示中文, 在IE7中位置不对,mojoPortal中应用

jscalendar-1.0中文解决方法


(1)jscalendar-1.0不支持中文
是由于没有设置每周的开始日期
修改方法是在lang目录中的文件calendar-cn_utf8.js(或cn_utf8.jscalendar-zh.js)加上Calendar._FD = 0;
代码片段如下:
// short day names
Calendar._SDN = new Array
(
"\u5468\u65e5",
 
"\u5468\u4e00",
 
"\u5468\u4e8c",
 
"\u5468\u4e09",
 
"\u5468\u56db",
 
"\u5468\u4e94",
 
"\u5468\u516d",
 
"\u5468\u65e5");

Calendar._FD 
= 0;   // ADDED THIS LINE

// full month names
Calendar._MN = new Array
(
"\u4e00\u6708",
 
"\u4e8c\u6708",
 
"\u4e09\u6708",
 
"\u56db\u6708",
 
"\u4e94\u6708",
 
"\u516d\u6708",
 
"\u4e03\u6708",
 
"\u516b\u6708",
 
"\u4e5d\u6708",
 
"\u5341\u6708",
 
"\u5341\u4e00\u6708",
 
"\u5341\u4e8c\u6708");

同时在用到该控件的页面必须加上<link href="css文件" type="text/css" rel="stylesheet" />

假设web application的编码规则是utf-8,那么js文件中如果有中文就会出现乱码(有可能是其它的页面不正常的情况) ,解决这个问题请在引用javascript的地方加上charset="gb2312"或者charset="big5" 
例如:<script type="text/javascript" language="javascript" src="scripts/function.js" charset="gb2312"></script>


(2)Fixed a bug when displaying calendar on IE7
Added to line 90 of calendar.js
Calendar.is_ie7 = ( Calendar.is_ie && /msie 7\.0/i.test(navigator.userAgent) );

Added to line 1396 of calendar.js

if (Calendar.is_ie7) {
br.y += window.scrollY;
br.x += window.scrollX;
}
else if (Calendar.is_ie) {
br.y += document.body.scrollTop;
br.x += document.body.scrollLeft;
}
else {
br.y += window.scrollY;
br.x += window.scrollX;
}

LOOK LIKE THIS:
        var cp = document.createElement("div");
        
var s = cp.style;
        s.position 
= "absolute";
        s.right 
= s.bottom = s.width = s.height = "0px";
        document.body.appendChild(cp);
        
var br = Calendar.getAbsolutePos(cp);
        document.body.removeChild(cp);
        
if (Calendar.is_ie7) {  //Added begin
        br.y += window.scrollY;
        br.x 
+= window.scrollX;
        }

        
else if (Calendar.is_ie) {
        br.y 
+= document.body.scrollTop;
        br.x 
+= document.body.scrollLeft;
        }

        
else {
        br.y 
+= window.scrollY;
        br.x 
+= window.scrollX;
        }
                        //Added end
        //        if (Calendar.is_ie) {
        //            br.y += document.body.scrollTop;
        //            br.x += document.body.scrollLeft;
        //        } else {
        //            br.y += window.scrollY;
        //            br.x += window.scrollX;
        //        }
        var tmp = box.x + box.width - br.x;
        
if (tmp > 0) box.x -= tmp;
        tmp 
= box.y + box.height - br.y;
        
if (tmp > 0) box.y -= tmp;



(3) For mojoPortal DatePicker:
除了按上面的要求修改件calendar-cn_utf8.js(或cn_utf8.jscalendar-zh.js)加上Calendar._FD = 0;
修改calendar.js
还要做以下改动:
为 \mojoPortal.Web.Controls\jsCalendarDatePicker.cs 添加  charset=\"gb2312\"

    private void SetupScripts()
        {
            
this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "jscalendarmain","<script type=\"text/javascript\" src=\"" 
                + ResolveUrl(this.ScriptDirectory + "/calendar.js"+ "\"></script>");

            
this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "jscalendarculture""<script type=\"text/javascript\" src=\""
                + ResolveUrl(this.ScriptDirectory + "/" + this.LanguageFile) + "\" charset=\"gb2312\"></script>");  //Aimin

            
this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(),"jscalendarsetup","<script type=\"text/javascript\" src=\"" 
                + ResolveUrl(this.ScriptDirectory + "/calendar-setup.js"+ "\"></script>");




ref:
http://www.dynarch.com/forums/1993
http://hi.baidu.com/ksir/blog/item/632a2d8169efc5dbbd3e1e1b.html
http://www.cnblogs.com/haojinguo/archive/2007/12/30/696579.html
http://javajiao.javaeye.com/blog/184014
http://blog.donews.com/shanyou/archive/2005/02/10/272908.aspx
posted @ 2008-05-11 08:48 emanlee 阅读(...) 评论(...) 编辑 收藏