jquery源码——buildFragment
来源:互联网 发布:java获取svn文件列表 编辑:程序博客网 时间:2024/06/05 20:53
buildFragment是在context上,根据args创建一个div区域。核心部分是调用了clean部分。但是buildFragment添加了cache的部分。如果能cache的话,则直接返回创建好的。
具体情况加下:
jQuery.buildFragment = function( args, context, scripts ) { //传入的html代码段(好几段),上下文,是否有scriptvar fragment, cacheable, cachehit,first = args[ 0 ];// Set context from what may come in as undefined or a jQuery collection or a nodecontext = context || document; //处理undefined的情况context = (context[0] || context).ownerDocument || context[0] || context; //处理jquery set 或者node的情况// Ensure that an attr object doesn't incorrectly stand in as a document object// Chrome and Firefox seem to allow this to occur and will throw exception// Fixes #8950if ( typeof context.createDocumentFragment === "undefined" ) { //createDocumentFragment常见用法是创建一个空的dom fragment,然后把elem append到fragment上,最后再把fragment append到doc 的DOM tree上context = document;}// Only cache "small" (1/2 KB) HTML strings that are associated with the main document// Cloning options loses the selected state, so don't cache them// IE 6 doesn't like it when you put <object> or <embed> elements in a fragment// Also, WebKit does not clone 'checked' attributes on cloneNode, so don't cache// Lastly, IE6,7,8 will not correctly reuse cached fragments that were created from unknown elems #10501if ( args.length === 1 && typeof first === "string" && first.length < 512 && context === document && //保证是小的代码段, 并且associated with main documentfirst.charAt(0) === "<" && !rnocache.test( first ) && //不是embed等情况(jQuery.support.checkClone || !rchecked.test( first )) && //允许clone并且没有checked属性(jQuery.support.html5Clone || !rnoshimcache.test( first )) ) { //允许h5特性,并且不是h5的那些新特性// Mark cacheable and look for a hitcacheable = true;fragment = jQuery.fragments[ first ]; //看看是不是有缓存的结果cachehit = fragment !== undefined;}if ( !fragment ) { //如果jQuery.fragments[]跪了,那么就创建一个空的 dom fragment,然后调用cleanfragment = context.createDocumentFragment();jQuery.clean( args, context, fragment, scripts );// Update the cache, but only store false// unless this is a second parsing of the same contentif ( cacheable ) {jQuery.fragments[ first ] = cachehit && fragment; //cache元素,cachehit的存在保证了只cache哪些能cache的元素}}return { fragment: fragment, cacheable: cacheable };};
0 0
- jquery源码——buildFragment
- 字符串缓存jQuery.buildFragment源码分析
- jQuery源码研究分析学习笔记-jQuery.buildFragment()(六)
- jQuery源码分析之buildFragment方法和clone方法
- jQuery源码阅读(七)--init()遗留部分buildFragment()函数
- jQuery源码分析-12 DOM操作-Manipulation-核心函数jQuery.buildFragment()
- JQuery源码学习——(一)JQuery起步
- jQuery源码分析——jQuery对象怎么来的
- jquery源码——jquery.fn.access()函数
- jquery源码分析——元素大小
- jQuery源码——find函数
- jQuery源码——extend()函数
- JQuery源码学习——匿名函数
- jQuery源码解析—— Animation动画
- JQuery源码之——变量,正则
- jquery源码分析—data缓存
- JQuery源码之——— 方法和属性
- jquery1.11源码学习——揭秘jquery内幕
- 第2.1.4章 WEB系统最佳实践Spring文件配置之spring-hessian-server.xml
- C++Virus手打系列,仅供研究
- 图像处理(二)opencv处理图像二值化,灰度化等
- 第二次作业——Service、Listview与ACtivity参数传递
- spring声明式事务管理
- jquery源码——buildFragment
- 关于添加openwrt软件包的概述
- 文献阅读(8)
- 数据持久化
- LeetCode-----48. Rotate Image(二维矩阵旋转90度)
- SRM147_DIV2
- js的setAttribute的使用
- 位和字节
- JAVA实例一