要么孵化 要么臭掉
attribute.specified属性
Pivot 自带的 wysiwyg 编辑器功能比较少,扩展起来也不方便,虽然 1.3 版本引入了 TinyMCE ,但都不合自己的习惯。好在可供选择的 wysiwyg 在线编辑器多得数不过来, Genii Software 甚至专门对这些编辑器做了详细对比。最终 我选择了 "excellent and easy to use" 的 Xinha 。不过再好的东西也会有 bug (尽管有时候 javascript 的脚本所谓 bug 往往是拜浏览标准的混乱所赐)。
最近发现用 Xinha 切换到 HTML Source 模式添加了图片 Map 区域之后( <AREA title="点击查看大图" shape="RECT" target="_blank" coords="0,0,81,150" href="http://www.zeali.net/images/lina/lina1.jpg"> ),切换回 wysiwyg 模式再切回来,AREA Tag 的 shape 和 coords 属性就消失了。一路跟踪下来,发现 Xinha 在 Toggle HTML Source 的过程中,使用了 HTMLArea.getHTMLWrapper 方法对整个内容进行了格式化处理,这其中用到了 attribute.specified 属性进行判断:
if (!a.specified && !(root.tagName.toLowerCase().match(/input|option/) && a.nodeName == 'value')) {
continue;
}
而让人想不通的是,对于 shape 和 coords 这两个属性来说,无论是否在 HTML 里面进行了设置, specified 的值都是 false ,而不是像 msdn 文档里面所描述的那样 “An attribute is specified if it is set through HTML or script”,只有像 title , target, href 这种比较常规的属性才能通过 specified 的值来判断是否已经做了设置。也正因为如此, Xinha 在对 HTML 代码进行重新格式化的时候, shape 和 coords 这两个属性的相关内容就被直接 continue 给忽略掉了。
有意思的是从 Xinha 上面的那段代码来看,已经对 input 和 option 这两个 Tag 的 value 属性进行了排除,可见 value 属性遭受的“不公平”待遇类似于 shape 和 coords 。可惜 Xinha 好事没做到底,msdn 貌似也没有明确的指出哪些 Tag 的哪些属性无法通过 specified 的值来判断存在与否,所以也只能是发现一例例外就在原来的语句基础上增加一个过滤语句了:
... &&
!(root.tagName.toLowerCase() == 'area' && a.nodeName.toLowerCase().match(/shape|coords/))
搞定,收工。
2008年 04月
2008年 03月
2008年 02月
2008年 01月
2007年 12月
2007年 11月
2007年 10月
2007年 09月
2007年 08月
2007年 07月
2007年 06月
2007年 05月
2007年 04月
2007年 03月
2007年 02月
2007年 01月
2006年 12月
2006年 11月
2006年 10月
2006年 09月
2006年 08月
2006年 07月
2006年 06月
2006年 05月
2006年 04月
2006年 03月
2006年 02月
2006年 01月
2005年 12月
2005年 11月
2005年 10月
2005年 09月
2005年 08月
2005年 07月
2005年 06月
2005年 05月
2005年 04月
Pivot1.24.1 开发
