今天给sandbox的dom添加了一些常规方法,attr,css,style,empty,append,copy等等,行为大都依照jquery-dom的api来做,我删掉了那些性能上的hack,想重写性能的部分,不过这都不是难点,这些方法中,麻烦的是节点的拷贝,因为要考虑事件的拷贝,节点复制一个新的,新节点的事件不能丢。在ie中,原生的cloneNode就可以复制事件,但有点囧。jquery源码中是这样描述事件拷贝的
// IE copies events bound via attachEvent when
// using cloneNode. Calling detachEvent on the
// clone will also remove the events from the orignal
// In order to get around this, we use innerHTML.
// Unfortunately, this means some modifications to
// attributes in IE that are actually only stored
// as properties will not be copied (such as the
// the name attribute on an input).
解决方法似乎是找出所有的问题种类一个一个hack,之前给Node的事件已经封装好,在非ie中,只需要给新生成的节点挂载一个新的"事件中心",这个事件中心的事件依然指向旧有的节点,实际上两者公用一个回调,这个回调是存储在Sandbox._ENV.Event中的,并不会因为旧节点的删除而消失,因此,demo就是这样:
http://tbexample.googlecode.com/svn/tru ... -copy.html
dom中有太多细节需要考究,并发现jquery内部各模块之间的耦合简直像胶水粘上一样,在模块组织这方面,john真的要向zakas学学了。
下一步,继续杯具的Dom
to be continue...
[ view entry ] ( 3966 views ) | permalink |




( 3 / 171 )




