昨天下了MagicAjax0.2.2-release看了看Example觉得还算不错,打开MA跟随的Docs看了看,然后打开VS2005准备操刀一下。

因为使用MA的无刷新效果总是在浏览器的可见客户区的右上角出现一个Loading ...的提示条,但自己觉得颜色不是很好看,想改一下,发现MA是把scripts都搞到dll里去了,然后通过实现httpModules把scripts再Export出来,具体是在编译时生成一个WebResource.axd(在运行时才动态生成)。可是自己想改script,看看文档的Configuration一节

ScriptPath

Type: string
Default: null (omitted)
Description: MagicAjax's script files are embedded in the dll and are put on page using script tags like this: 

    
<script type="text/javascript" src="AjaxCallObject.js.aspx"></script>
If you set ScriptPath to a value, the src attribute of the script tag will contain the path of ScriptPath. That way you can use your own modified versions of MagicAjax's script files. Example: 
    
<magicAjax ScriptPath="~/script" />


在Core里找到script文件夹,添加到工程目录里,然后按照文档设置web.config文件,再把AjaxCallObject.js中的
function CreateWaitElement() {
    
var elem = document.getElementById('__AjaxCall_Wait');    
    
if (!elem) {        
        elem 
= document.createElement("div");
        elem.id 
= '__AjaxCall_Wait';        
        elem.style.position 
= 'absolute';        
        elem.style.height 
= 17;        
        elem.border 
= "1px";
        elem.style.paddingLeft 
= "3px";
        elem.style.paddingRight 
= "3px";
        elem.style.fontSize 
= "11px";
        elem.style.borderColor 
= "#ffffff";
        elem.style.borderSize 
= "1px";
        elem.style.backgroundColor 
= "DimGray";
        elem.style.color 
= "#ffffff";
        elem.innerHTML 
= 'Loading ';
        elem.style.visibility 
= 'hidden';        
        document.body.insertBefore(elem, document.body.firstChild);        
    }
    waitElement 
= elem;    
}

一段代码做一些修改,比如elem.style.color="#000000";这样再出现Loading ...时字体应该是黑的了吧?
嘿,这一运行,还真没成功!!!

肯定不是script的错!玩了N的js,再把这搞错也太说不过去了!

判断问题出现在config里。

<?xml version="1.0"?>
<configuration>
    
<configSections>
        
<section name="magicAjax" type="MagicAjax.Configuration.MagicAjaxSectionHandler, MagicAjax"/>
    
</configSections>
    
<magicAjax ScriptPath="~/script">
        
<pageStore/>
    
</magicAjax>
    
<system.web>
        
<authentication mode="Forms" />
..
        
<httpModules>
            
<add name="MagicAjaxModule" type="MagicAjax.MagicAjaxModule, MagicAjax"/>
        
</httpModules>
    
</system.web>
</configuration>

路径没问题,XML大小写敏感,拼写都是按文档写的,没问题,靠,Where?

最后,幸好MA开源的,找到MA的代码工程,打开一看:靠,靠,靠!
看到MagicAjaxConfiguration.cs
        public MagicAjaxConfiguration(XmlNode xml)
        {
            
// Default values
            _scriptPath = null// Null implicates that the embedded javascripts will be used (default)
            _compareMode = OutputCompareMode.HashCode;
            _tracing 
= false;
            PageStoreMode mode 
= PageStoreMode.NoStore;
            
bool unloadStoredPage = false;
            
int cacheTimeout = 5;
            
int maxPages = 5;
            
bool maxPagesLimitAlert = false;

            
if (xml != null)
            {
                XmlAttribute attrib 
= (XmlAttribute)xml.Attributes.GetNamedItem("scriptPath");

倒,是scriptPath呀!!!
又看看文档,它真的是写的<magicAjax ScriptPath="~/script" />不是我的错!!!


该死的文档,不如不写!!!

准备,好好研究下MA的代码,因为昨晚发现把Loading改称中文出来的是乱码,是编码格式的问题。
如果,在浏览时把编码改为“简体中文”这样Loading条就正常显示了,可是页面其他中文都乱码了,应该把MA的Encoding改了。太晚了……就睡了,今天下午看看有时间的话来搞它!

我以后要么不写文档,写就负责任的写!

posted on 2006-01-13 10:35  雪美·考拉  阅读(4118)  评论(13编辑  收藏  举报