先重这里开始翻译,发现前面某些地方翻译。只是新的1.10.1把顺序打乱了,还得慢慢整理,所以就从这里开始了。还望高手们多多指点。 jQuery.support = (function( support ) { var all, a, input, select, fragment, opt, eventName, isSupported, i, div = document.createElement("div"); // Setup // 计划 div.setAttribute( "className", "t" ); div.innerHTML = " <link/><table></table><a href='/a'>a</a><input type='checkbox'/>"; // Finish early in limited (non-browser) environments // 在被限制的(无浏览程序)环境中尽早完成 all = div.getElementsByTagName("*") || []; a = div.getElementsByTagName("a")[ 0 ]; if ( !a || !a.style || !all.length ) { return support; } // First batch of tests // 第一批测试 select = document.createElement("select"); opt = select.appendChild( document.createElement("option") ); input = div.getElementsByTagName("input")[ 0 ]; a.style.cssText = "top:1px;float:left;opacity:.5"; // Test setAttribute on camelCase class. If it works, we need attrFixes when doing get/setAttribute (ie6/7) // 尝试设置属性在骆驼拼写法类上。如果邮箱,我们需要attrFixes当正在得到或者设置属性(ie6/7) // setAttribute()方法:创建或改变某个新属性。 // getAttribute()方法:通过名称获取属性的值。 // attrFixes暂时不会翻译 support.getSetAttribute = div.className !== "t"; // IE strips leading whitespace when .innerHTML is used // 当.innerHTML被使用,IE删除前置空格 support.leadingWhitespace = div.firstChild.nodeType === 3; // Make sure that tbody elements aren't automatically inserted // 确认tbody元素不是自动被添加 // IE will insert them into empty tables // IE将会添加他们到空白的表格中 support.tbody = !div.getElementsByTagName("tbody").length; // Make sure that link elements get serialized correctly by innerHTML // 确认用innerHTML让关联元素得到正确的序列 // This requires a wrapper element in IE // 这个需要一个在IE内的封装元素 support.htmlSerialize = !!div.getElementsByTagName("link").length; // Get the style information from getAttribute // 从getAttribute得到风格信息 // (IE uses .cssText instead) // (IE使用.cssText代替) support.style = /top/.test( a.getAttribute("style") ); // Make sure that URLs aren't manipulated // 确认URLs没有被操作 // (IE normalizes it by default) support.hrefNormalized = a.getAttribute("href") === "/a"; // Make sure that element opacity exists // 确认元素不透明性存在 // (IE uses filter instead) // (IE使用滤镜代替) // Use a regex to work around a WebKit issue. See #5145 support.opacity = /^0.5/.test( a.style.opacity ); // Verify style float existence // 核实格式浮动存在 // (IE uses styleFloat instead of cssFloat) // (IE使用styleFloat代替cssFloat) support.cssFloat = !!a.style.cssFloat; // Check the default checkbox/radio value ("" on WebKit; "on" elsewhere) // 检测默认复选框与单选框的值(在WebKit上为"";其他地方为"on" support.checkOn = !!input.value; // Make sure that a selected-by-default option has a working selected property. // 确认一个被选定为默认的选项有一个有效的被选择特性 // (WebKit defaults to false instead of true, IE too, if it's in an optgroup) // (WebKit默认为假代替真,IE也一样,如果他在optgroup内) // optgroup元素用于组合选项。当您使用一个长的选项列表时,对相关的选项进行组合会使处理更加容易。 support.optSelected = opt.selected; // Tests for enctype support on a form (#6743) // 测试一个表单enctype属性的支持 // enctype属性:规定在发送到服务器之前应该如何对表单数据进行编码。 support.enctype = !!document.createElement("form").enctype; // Makes sure cloning an html5 element does not cause problems // 确认克隆一个html5元素不会引起问题 // Where outerHTML is undefined, this still works // 在outerHTML没被规定的地方仍然工作 support.html5Clone = document.createElement("nav").cloneNode( true ).outerHTML !== "<:nav></:nav>"; // Will be defined later // 稍后将会被规定 support.inlineBlockNeedsLayout = false; support.shrinkWrapBlocks = false; support.pixelPosition = false; support.deleteExpando = true; support.noCloneEvent = true; support.reliableMarginRight = true; support.boxSizingReliable = true; // Make sure checked status is properly cloned // 确保被检测的状态被正常复制
连接01层的翻译input.checked = true; support.noCloneChecked = input.cloneNode( true ).checked; // Make sure that the options inside disabled selects aren't ed as disabled // 确保在禁用的选择中选项没有被标记为已禁用 // (WebKit s them as disabled) // (WebKit 标记他们为被禁用) // WebKit是开源的Web浏览器引擎,苹果的Safari、谷歌的Chrome浏览器都是基于这个框架来开发的。 // WebKit 还支持移动设备和手机,包括iPhone和Android手机都是使用WebKit做为浏览器的核心。 select.disabled = true; support.optDisabled = !opt.disabled; // Support: IE<9 // 支持: IE<9 try { delete div.test; } catch( e ) { support.deleteExpando = false; } // Check if we can trust getAttribute("value") // 检测我们是否能够相信getAttribute("value") input = document.createElement("input"); input.setAttribute( "value", "" ); support.input = input.getAttribute( "value" ) === ""; // Check if an input maintains its value after becoming a radio // 检测一个input在成为一个radio后是否还保持它的值 input.value = "t"; input.setAttribute( "type", "radio" ); support.radioValue = input.value === "t"; // #11217 - WebKit loses check when the name is after the checked attribute // #11217 - WebKit 丢失检测当名字是检测后的属性 input.setAttribute( "checked", "t" ); input.setAttribute( "name", "t" ); fragment = document.createDocumentFragment(); fragment.appendChild( input ); // Check if a disconnected checkbox will retain its checked // 检测一个断开的复选框是否仍然保留它为真的选择值 // value of true after appended to the DOM (IE6/7) // 在被添加到DOM后(IE6/7) support.appendChecked = input.checked; // WebKit doesn't clone checked state correctly in fragments // WebKit 不会正确地复制被检测的状态在fragments中 support.checkClone = fragment.cloneNode( true ).cloneNode( true ).lastChild.checked; // Support: IE<9 // 支持: IE<9 // Opera does not clone events (and typeof div.attachEvent === undefined). // Opera不会克隆事件(并且div.attachEvent的类型未定义) // IE9-10 clones events bound via attachEvent, but they don't trigger with .click() // IE9-10复制绑定经过attachEvent的事件,但是他们不会用.click()触发 if ( div.attachEvent ) { div.attachEvent( "onclick", function() { support.noCloneEvent = false; }); div.cloneNode( true ).click(); } // Support: IE<9 (lack submit/change bubble), Firefox 17+ (lack focusin event) // 支持: IE<9(缺少提交/改变冒泡)Firefox 17+ // 上面这句估计翻译不准 // Beware of CSP restrictions (https://developer.mozilla.org/en/Security/CSP) // 提防CSP限制 // CSP:连接安全措施,网上介绍这个的资料很少,网址上的全英文文章是介绍这个的。简短介绍就是防止被攻击的安全机制 for ( i in { submit: true, change: true, focusin: true }) { div.setAttribute( eventName = "on" + i, "t" ); support[ i + "Bubbles" ] = eventName in window || div.attributes[ eventName ].expando === false; } div.style.backgroundClip = "content-box"; div.cloneNode( true ).style.backgroundClip = ""; support.clearCloneStyle = div.style.backgroundClip === "content-box"; // Support: IE<9 // 支持:IE<9 // Iteration over object's inherited properties before its own. // 在对象的继承的属性之前自己迭代 // 迭代语句又叫循环语句,声明一组要反复执行的命令,直到满足了某些条件为止。 for ( i in jQuery( support ) ) { break; } support.ownLast = i !== "0"; // Run tests that need a body at doc ready // 运行测试需要一个在文档准备时的body(这句话不太会翻译) jQuery(function() { var container, marginDiv, tds, divReset = "padding:0;margin:0;border:0;display:block;box-sizing:content-box;-moz-box-sizing:content-box;-webkit-box-sizing:content-box;", body = document.getElementsByTagName("body")[0]; if ( !body ) { // Return for frameset docs that don't have a body // 返回给不要body的frameset文档 // frameset元素可定义一个框架集。它被用来组织多个窗口(框架)。 return; } container = document.createElement("div"); container.style.cssText = "border:0;width:0;height:0;position:absolute;top:0;left:-9999px;margin-top:1px"; body.appendChild( container ).appendChild( div ); // Support: IE8 // 支持: IE8
连接第02层翻译加入一点学到的知识// Support: IE8 // 支持: IE8 // Check if table cells still have offsetWidth/Height when they are set // 检测表格单元是否仍旧有offsetWidth/Height属性 // to display:none and there are still other visible table cells in a // 当他们被设置为显示none状态,并且他们仍然是其他可见表格单元在一个表格行内 // table row; if so, offsetWidth/Height are not reliable for use when // 如果如此,offsetWidth/Height对于使用不是可靠的 // determining if an element has been hidden directly using // 当决定一个元素是否已被隐藏直接使用显示为none // display:none (it is still safe to use offsets if a parent element is // (如果一个父元素被隐藏,对于使用offsets他仍旧安全的 // hidden; don safety goggles and see bug #4512 for more information). // don safety goggles然后看bug #4512获取更多的信息 // don safety goggles如果直接翻译就是:带上护目眼睛,不知道这里怎么理解这句,暂时不会翻译,有会翻译麻烦告诉一下 div.innerHTML = "<table><tr><td></td><td>t</td></tr></table>"; tds = div.getElementsByTagName("td"); tds[ 0 ].style.cssText = "padding:0;margin:0;border:0;display:none"; isSupported = ( tds[ 0 ].offsetHeight === 0 ); tds[ 0 ].style.display = ""; tds[ 1 ].style.display = "none"; // Support: IE8 // 支持:IE8 // Check if empty table cells still have offsetWidth/Height // 检测空单元格是否仍旧有返回元素宽度与高度 // offsetWidth注释:返回元素宽度,以像素为单位。 support.reliableHiddenOffsets = isSupported && ( tds[ 0 ].offsetHeight === 0 ); // Check box-sizing and margin behavior. // 检测盒子大小和外边距状态 // margin注释:在一个声明中设置所有外边距属性 div.innerHTML = ""; div.style.cssText = "box-sizing:border-box;-moz-box-sizing:border-box;-webkit-box-sizing:border-box;padding:1px;border:1px;display:block;width:4px;margin-top:1%;position:absolute;top:1%;"; // Workaround failing boxSizing test due to offsetWidth returning wrong value // 由于返回宽度返回错误值,执行失败盒子大小测试 // workaround在IT行业里指:应急方案、替代方案、规避措施,也指工作区,运行环境 // with some non-1 values of body zoom, ticket #13543 // 用一些本体zoom的non-1值,标签#13543 // zoom属性:IE浏览器的专有属性,Firefox等浏览器不支持。它可以设置或检索对象的缩放比例。 // 除此之外,它还有其他一些小作用,比如触发ie的hasLayout属性,清除浮动、清除margin的重叠等。 jQuery.swap( body, body.style.zoom != null ? { zoom: 1 } : {}, function() { support.boxSizing = div.offsetWidth === 4; }); // Use window.getComputedStyle because jsdom on node.js will break without it. // 使用window.getComputedStyle因为没有他在node.js中的jsdom将会被破坏
回复一下楼上的各位,我查阅了很多关于jQuery的相关资料,网上的很乱。 也有人翻译,我看到的没有一个完整的,基本都是翻译一小部分简单的句子,然后就是无限期拖置了。 也有对jQuery代码进行解释的,不过用的版本确实有点老。 而且JQ的更新速度很快要求翻译需要很快的速度,英文还得好,老实说我应该也就勉强能及格,不算高手。 所以基本都是从零开始,需要理解代码才能翻译明白,注释也不能乱写误导别人。 估计在这个大版本更新前能翻译完,希望那帮高手别再用那神速更新了。 这个版本大部分翻译完的时候,我那个1.9.1的估计也能完成了。谢谢楼上的veryhunger有些翻译多次的句子我不翻译了一层加入太多代码需要加载很长时间,所以每一层还是少放点代码现在开始说说==和===区别,以前还以为没区别第一个是相等符(等于);第二个全等符(严格等于);== 两边值类型不同的时候,要先进行类型转换,再比较。 === 不做类型转换,类型不同的一定不等。例: var a = 3; var b = "3"; a==b 返回 true a===b 返回 false 因为a,b的类型不一样 ===用来进行严格的比较判断,结果为false 以下连接05层代码翻译 // gets computed margin-right based on width of container. (#3333) // 得到基于容器宽度的计算出的margin-right // margin-right属性设置元素的右外边距 // Fails in WebKit before Feb 2011 nightlies // WebKit失败在2011年2月nightlies前 // nightlies 这个不会翻译,也没查到相关资料 // WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right // WebKit Bug 13343 - getComputedStyle 返回错误值给margin-right marginDiv = div.appendChild( document.createElement("div") ); marginDiv.style.cssText = div.style.cssText = divReset; marginDiv.style.marginRight = marginDiv.style.width = "0"; div.style.width = "1px"; support.reliableMarginRight = !parseFloat( ( window.getComputedStyle( marginDiv, null ) || {} ).marginRight ); } if ( typeof div.style.zoom !== core_strundefined ) { // Support: IE<8 // 支持:IE8以下的版本 // Check if natively block-level elements act like inline-block // 检测本地的块级元素是否像内联块级元素一样起作用 // elements when setting their display to 'inline' and giving // 当设置他们的显示为内联并且 // them layout // 给予他们安置 div.innerHTML = ""; div.style.cssText = divReset + "width:1px;padding:1px;display:inline;zoom:1"; support.inlineBlockNeedsLayout = ( div.offsetWidth === 3 ); // Support: IE6 // 支持:IE6 // Check if elements with layout shrink-wrap their children // 检测带有布局的元素是否收缩包装他们的资源(这句我不是很理解怎么翻译) div.style.display = "block"; div.innerHTML = "<div></div>"; div.firstChild.style.width = "5px"; support.shrinkWrapBlocks = ( div.offsetWidth !== 3 ); if ( support.inlineBlockNeedsLayout ) { // Prevent IE 6 from affecting layout for positioned elements #11048 // 阻止IE6影响对于位置元素的布局#11048 // Prevent IE from shrinking the body in IE 7 mode #12869 // 阻止IE收缩body在IE7的风格中 // Support: IE<8 body.style.zoom = 1; } } body.removeChild( container ); // Null elements to avoid leaks in IE container = div = tds = marginDiv = null; }); // Null elements to avoid leaks in IE // Null元素阻止在IE内的泄漏 all = select = fragment = opt = a = input = null; return support; })({});var rbrace = /(?:\{[\s\S]*\}|\[[\s\S]*\])$/, rmultiDash = /([A-Z])/g;function internalData( elem, name, data, pvt /* Internal Use Only */ ){ if ( !jQuery.acceptData( elem ) ) { return; } // Internal Use Only翻译:仅能在内部使用 var ret, thisCache, internalKey = jQuery.expando, // We have to handle DOM nodes and JS objects differently because IE6-7 // 我们必须用不同方式管理DOM节点和JS对象 // can't GC object references properly across the DOM-JS boundary // 因为IE6-7越过DOM-JS范围正确地回收对象引用 // GC:计算机术语Garbage Collection简写,垃圾回收的意思,比较高深的东西 isNode = elem.nodeType, // Only DOM nodes need the global jQuery cache; JS object data is // 只有DOM节点需要全局的jQuery缓冲存储器 // attached directly to the object so GC can occur automatically // JS对象数据直接与对象项链所以GC能够自动地发生
谢谢提醒,关于window代表浏览器窗口昨天才弄明白,以前一直以为是系统Window 对象表示浏览器中打开的窗口。如果文档包含框架(frame 或 iframe 标签),浏览器会为 HTML 文档创建一个 window 对象,并为每个框架创建一个额外的 window 对象。注释:没有应用于 window 对象的公开标准,不过所有浏览器都支持该对象。再分享一个今天学习的CSS clear 属性(这个以前没见过,今天第一次见到,我是没用过)定义和用法clear 属性规定元素的哪一侧不允许其他浮动元素。图像的左侧和右侧均不允许出现浮动元素:img { float:left; clear:both; }以下连接24层的翻译// attached directly to the object so GC can occur automatically // JS对象数据直接与对象项链所以GC能够自动地发生 cache = isNode ? jQuery.cache : elem, // Only defining an ID for JS objects if its cache already exists allows // 只有规定一个ID给JS对象如果他的缓存已经存在,才能允许 // the code to shortcut on the same path as a DOM node with no cache // 一段在同样路径作为没有缓存的DOM节点创造捷径的代码 // 上面这两句太长了,估计翻译不是很准确 id = isNode ? elem[ internalKey ] : elem[ internalKey ] && internalKey; // Avoid doing any more work than we need to when trying to get data on an // 避免做任何比我们需要多的工作,当尝试去得到数据在一个 // object that has no data at all // 根本没有数据的对象上 if ( (!id || !cache[id] || (!pvt && !cache[id].data)) && data === undefined && typeof name === "string" ) { return; } if ( !id ) { // Only DOM nodes need a new unique ID for each element since their data // 仅有DOM节点需要一个新的唯一ID // ends up in the global cache // 由于他们的数据在全局缓存中结束 if ( isNode ) { id = elem[ internalKey ] = core_deletedIds.pop() || jQuery.guid++; } else { id = internalKey; } } if ( !cache[ id ] ) { // Avoid exposing jQuery metadata on plain JS objects when the object // 避免暴露在完全的JS对象上的jQuery元数据当对象 // is serialized using JSON.stringify // 正连续使用JSON.stringify // 关于JSON.stringify就是说把原来是对象的类型转换成字符串类型(或者更确切的说是json类型的) // 打个比方说,你有一个类,那么你可以通过这个方法转换成相应的json类型的。 cache[ id ] = isNode ? {} : { toJSON: jQuery.noop }; } // An object can be passed to jQuery.data instead of a key/value pair; this gets // 一个对象可以通过jQuery.data代替一个键位/数值对 // shallow copied over onto the existing cache // 这将得到浅复制在存在的缓存上 // over onto 这两个英文单词在一起连用不知道怎么翻译,暂时翻译为:在……上 if ( typeof name === "object" || typeof name === "function" ) { if ( pvt ) { cache[ id ] = jQuery.extend( cache[ id ], name ); } else { cache[ id ].data = jQuery.extend( cache[ id ].data, name ); } } thisCache = cache[ id ]; // jQuery data() is stored in a separate object inside the object's internal data // jQuery data() 被存储在一个分开的对象中,这个对象的内部他的内部数据 // cache in order to avoid key collisions between internal data and user-defined // 缓存是为了阻止键位冲突在内部数据和使用者规定的 // data. // 数据中 if ( !pvt ) { if ( !thisCache.data ) { thisCache.data = {}; } thisCache = thisCache.data; } if ( data !== undefined ) { thisCache[ jQuery.camelCase( name ) ] = data; } // Check for both converted-to-camel and non-converted data property names // 核实converted-to-camel与non-converted数据属性名字 // If a data property was specified // 如果数据属性是被制定的 if ( typeof name === "string" ) { // First Try to find as-is property data // 首先尝试找到as-is属性数据 ret = thisCache[ name ]; // Test for null|undefined property data // 尝试没有或者违背定义属性数据 if ( ret == null ) { // Try to find the camelCased property // 尝试找到骆驼拼写法属性 ret = thisCache[ jQuery.camelCase( name ) ]; } } else { ret = thisCache; } return ret; }function internalRemoveData( elem, name, pvt ) { if ( !jQuery.acceptData( elem ) ) { return; } var thisCache, i, isNode = elem.nodeType, // See jQuery.data for more information // 查阅jQuery.data 获得更多的信息 cache = isNode ? jQuery.cache : elem, id = isNode ? elem[ jQuery.expando ] : jQuery.expando; // If there is already no cache entry for this object, there is no // purpose in continuing // 如果已经没有缓冲入口给这个对象,也没有继续的目的
温馨提示,想只看代码的建议右上角设置成【只显示楼主】回复昨天楼上的。如果翻译机能翻译出一般人能看懂的中文其实我也不愿意翻译,不知道什么翻译器 能把这些具有专业术语的英文翻译成比较好的中文语句,麻烦介绍给我,谢谢。至于翻译有没有必要,应该是有,不是所有人都是英语高手,看到大量的英文注释都能明白意思。 这样让一些人往往不看注释了,其实注释还有一些注意的东西,所以翻译出来对阅读有帮助。其实翻译这个很不容易,对代码一无所知就翻译基本就翻译不准,不知道哪个机器可以像人脑这样 需要查阅资料和理解才翻译成句子,虽然我脑子笨,不过好歹我也想了想怎么准确的翻译因为jQuery涉及到不单单就是代码,也同时涉及到许多其他方面的网络知识,所以再翻译过程中, 我也尽可能把一些其他方面知识尽我所能解释下,老实说有更好的教学内容,我也更想看,写其实很累人, 尤其现在还是大夏天。今天说说【AJAX】感觉JQ里面用到了这个现在很常用的技术了,不会用代表了过时。 我理解他就是:点击一个按钮,无需刷新就是能改变网页上的某些内容 感觉学习【AJAX】不当需要了解js代码,还需要了解服务器语言比如PHP什么的以下连接25层翻译,欢迎回复,大家多多支持,谢了。 // 如果已经没有缓冲入口给这个对象,也没有继续的目的 if ( !cache[ id ] ) { return; } if ( name ) { thisCache = pvt ? cache[ id ] : cache[ id ].data; if ( thisCache ) { // Support array or space separated string names for data keys // 支持数值或者空格隔开的字符串名字对于数据键位 if ( !jQuery.isArray( name ) ) { // try the string as a key before any manipulation // 尝试把字符串当成键位在任何操作 if ( name in thisCache ) { name = [ name ]; } else { // split the camel cased version by spaces unless a key with the spaces exists // 用空格分割骆驼事例的版本,除非有一个空格键存在 name = jQuery.camelCase( name ); if ( name in thisCache ) { name = [ name ]; } else { name = name.split(" "); } } } else { // If "name" is an array of keys... // 如果"name"是键位组…… // When data is initially created, via ("key", "val") signature, // 当数据最初被创建,经过("key", "val")识别标志 // keys will be converted to camelCase. // 键位将会被转换为骆驼拼写法 // Since there is no way to tell _how_ a key was added, remove // 由于没有途径告诉键位如何被添加,移除 // both plain key and camelCase key. #12786 // 清晰键位和骆驼拼写法键位#12786 // This will only penalize the array argument path. // 这将仅仅惩罚数值参数路径 name = name.concat( jQuery.map( name, jQuery.camelCase ) ); } i = name.length; while ( i-- ) { delete thisCache[ name[i] ]; } // If there is no data left in the cache, we want to continue // 如果没有数据在缓存中留下,我们想要继续 // and let the cache object itself get destroyed // 并且让缓存对象自己破坏自己 if ( pvt ? !isEmptyDataObject(thisCache) : !jQuery.isEmptyObject(thisCache) ) { return; } } } // See jQuery.data for more information if ( !pvt ) { delete cache[ id ].data; // Don't destroy the parent cache unless the internal data object // 不要破坏父缓存除非内部数据对象 // had been the only thing left in it // 是唯一被留下的 if ( !isEmptyDataObject( cache[ id ] ) ) { return; } } // Destroy the cache // 破坏缓存 if ( isNode ) { jQuery.cleanData( [ elem ], true ); // Use delete when supported for expandos or `cache` is not a window per isWindow (#10080) // 使用删除当被支持对于expandos属性或者缓存不是window按照惯例isWindow (#10080) // 这句翻译的不是很准备,见谅 // expandos我理解一个属性的命名 // isWindow用于测试是否为一个window对象 /* jshint eqeqeq: false */ // JSHint介绍 // 翻译自www.jshint.com // JSHint是一个由javascript社区驱动开发的用于检查javascript代码错误和问题的工具, // 有了他,可以使你保持一个良好的编码风格。你可以很简单的配置它以适应你目前的一个编码风格。 // 目前JSHint的源码可以在github上面找到。 } else if ( jQuery.support.deleteExpando || cache != cache.window ) { /* jshint eqeqeq: true */ delete cache[ id ]; // When all else fails, null // 当其他的所有失败,空值 } else { cache[ id ] = null; } }jQuery.extend({ cache: {}, // The following elements throw uncatchable exceptions if you // 接下来的元素扔出不可捕捉的例外如果你 // attempt to add expando properties to them. // 试图添加expando属性给他们 // expando我不知道什么意思 noData: { "applet": true, "embed": true, // Ban all objects except for Flash (which handle expandos) // 禁止所用对象除了Flash (管理expandos属性) "object": "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" }, hasData: function( elem ) { elem = elem.nodeType ? jQuery.cache[ elem[jQuery.expando] ] : elem[ jQuery.expando ]; return !!elem && !isEmptyDataObject( elem ); }, data: function( elem, name, data ) { return internalData( elem, name, data ); }, removeData: function( elem, name ) { return internalRemoveData( elem, name ); }, // For internal use only. _data: function( elem, name, data ) { return internalData( elem, name, data, true ); }, _removeData: function( elem, name ) { return internalRemoveData( elem, name, true ); }, // A method for determining if a DOM node can handle the data expando // 一个方法决定DOM节点能否操作数据expando属性
关于翻译像机器翻译的问题,今天想想估计也有可能是直接按照原英文单词原意翻译的。 因为有的单词确实不知道该如何翻译比较好,才按原意翻译的。说说代码这东西,假如今天你把某些代码理解得还可以,如果长期不用这些代码,一段时间后估计还得重学。 不过只是下次重学的时间要快些而已,所以把一些重要知识记录在帖子中,也方便大家学习。今天说说JQ代码中常用到写法类似这样 say:function(){alert('hello word!');}; 其实就相当于 var say = function(){alert('hello word!');};var p=function(){}()表示的什么意思?var p = function(){return 'abc';}(); alert(p);//abc alert(typeof p); //stringvar p = (function(){return 'abc';})(); alert(p);//abc alert(typeof p); //string定义了一个变量,后面函数的返回值赋值给这个变量如果把最后的()去掉后 var p = function(){return 'abc';}; alert(p);//function(){return 'abc';} alert(typeof p); //function 就是将这个函数赋值给变量,今天第一次学到的。如果这个翻译会把完整版的下载地址给出,估计到时候自己的水平能有一些提高连接40层的翻译,介绍了一点关于HTML5的内容 // 一个方法决定DOM节点能否操作数据expando属性 acceptData: function( elem ) { // Do not set data on non-element because it will not be cleared (#8335). // 不要设置数据在non-element上面因为它将不会被清除(#8335) if ( elem.nodeType && elem.nodeType !== 1 && elem.nodeType !== 9 ) { return false; } var noData = elem.nodeName && jQuery.noData[ elem.nodeName.toLowerCase() ]; // nodes accept data unless otherwise specified; rejection can be conditional // 节点接受数据除非有其他的规定;拒绝可以是有条件的 return !noData || noData !== true && elem.getAttribute("classid") === noData; } });jQuery.fn.extend({ data: function( key, value ) { var attrs, name, data = null, i = 0, elem = this[0]; // Special expections of .data basically thwart jQuery.access, // 关于.data的特别例外基本阻碍jQuery.access // so implement the relevant behavior ourselves // 所以我们自己执行相关行为 // Gets all values // 得到全部值 if ( key === undefined ) { if ( this.length ) { data = jQuery.data( elem ); if ( elem.nodeType === 1 && !jQuery._data( elem, "parsedAttrs" ) ) { attrs = elem.attributes; for ( ; i < attrs.length; i++ ) { name = attrs[i].name; if ( name.indexOf("data-") === 0 ) { name = jQuery.camelCase( name.slice(5) ); dataAttr( elem, name, data[ name ] ); } } jQuery._data( elem, "parsedAttrs", true ); } } return data; } // Sets multiple values // 设置多个值 if ( typeof key === "object" ) { return this.each(function() { jQuery.data( this, key ); }); } return arguments.length > 1 ? // Sets one value // 设置数值 this.each(function() { jQuery.data( this, key, value ); }) : // Gets one value // Try to fetch any internally stored data first // 首先尝试拿取任意内部被存储的数据 elem ? dataAttr( elem, key, jQuery.data( elem, key ) ) : null; }, removeData: function( key ) { return this.each(function() { jQuery.removeData( this, key ); }); } });function dataAttr( elem, key, data ) { // If nothing was found internally, try to fetch any // 如果在内部什么也没找到,尝试拿取任意 // data from the HTML5 data-* attribute // 数据从 HTML5 data-* 属性 // 关于 HTML5 data-* 属性的相关介绍:HTML5中支持用户自定义的data-*特性,例如data-length,它可以附加在input的标签上。 // 本人对HTML5还不太属性,所以不多介绍了。 if ( data === undefined && elem.nodeType === 1 ) { var name = "data-" + key.replace( rmultiDash, "-$1" ).toLowerCase(); data = elem.getAttribute( name ); if ( typeof data === "string" ) { try { data = data === "true" ? true : data === "false" ? false : data === "null" ? null : // Only convert to a number if it doesn't change the string // 仅仅转换成数字如果他不是字符串 +data + "" === data ? +data : rbrace.test( data ) ? jQuery.parseJSON( data ) : data; } catch( e ) {} // Make sure we set the data so it isn't changed later // 确认我们设置了数据以便他稍后不会被改变 jQuery.data( elem, key, data ); } else { data = undefined; } } return data; }// checks a cache object for emptiness // 核实缓存对象为空 function isEmptyDataObject( obj ) { var name; for ( name in obj ) { // if the public data object is empty, the private is still empty // 如果公有数据对象为空,那么私有也为空。 if ( name === "data" && jQuery.isEmptyObject( obj[name] ) ) { continue; } if ( name !== "toJSON" ) { return false; } } return true; } jQuery.extend({ queue: function( elem, type, data ) { var queue; if ( elem ) { type = ( type || "fx" ) + "queue"; queue = jQuery._data( elem, type ); // Speed up dequeue by getting out quickly if this is just a lookup // 以退出的方式加速离开队列如果只是查找 if ( data ) { if ( !queue || jQuery.isArray(data) ) { queue = jQuery._data( elem, type, jQuery.makeArray(data) ); } else { queue.push( data ); } } return queue || []; } }, dequeue: function( elem, type ) { type = type || "fx"; var queue = jQuery.queue( elem, type ), startLength = queue.length, fn = queue.shift(), hooks = jQuery._queueHooks( elem, type ), next = function() { jQuery.dequeue( elem, type ); }; // If the fx queue is dequeued, always remove the progress sentinel // 如果fx队列被终止,经常移除进行前哨 // sentinel不知道怎么翻译 // jQuery中dequeue()方法:终止一个自定义的队列函数 if ( fn === "inprogress" ) { fn = queue.shift(); startLength--; } if ( fn ) { // Add a progress sentinel to prevent the fx queue from being // automatically dequeued // 添加进程前哨阻止fx队列自动出列 if ( type === "fx" ) { queue.unshift( "inprogress" ); } // clear up the last queue stop function // 处理最后队列停止功能
jQuery.support = (function( support ) { var all, a, input, select, fragment, opt, eventName, isSupported, i,
div = document.createElement("div"); // Setup
// 计划
div.setAttribute( "className", "t" );
div.innerHTML = " <link/><table></table><a href='/a'>a</a><input type='checkbox'/>"; // Finish early in limited (non-browser) environments
// 在被限制的(无浏览程序)环境中尽早完成
all = div.getElementsByTagName("*") || [];
a = div.getElementsByTagName("a")[ 0 ];
if ( !a || !a.style || !all.length ) {
return support;
} // First batch of tests
// 第一批测试
select = document.createElement("select");
opt = select.appendChild( document.createElement("option") );
input = div.getElementsByTagName("input")[ 0 ]; a.style.cssText = "top:1px;float:left;opacity:.5"; // Test setAttribute on camelCase class. If it works, we need attrFixes when doing get/setAttribute (ie6/7)
// 尝试设置属性在骆驼拼写法类上。如果邮箱,我们需要attrFixes当正在得到或者设置属性(ie6/7)
// setAttribute()方法:创建或改变某个新属性。
// getAttribute()方法:通过名称获取属性的值。
// attrFixes暂时不会翻译
support.getSetAttribute = div.className !== "t"; // IE strips leading whitespace when .innerHTML is used
// 当.innerHTML被使用,IE删除前置空格
support.leadingWhitespace = div.firstChild.nodeType === 3; // Make sure that tbody elements aren't automatically inserted
// 确认tbody元素不是自动被添加
// IE will insert them into empty tables
// IE将会添加他们到空白的表格中
support.tbody = !div.getElementsByTagName("tbody").length; // Make sure that link elements get serialized correctly by innerHTML
// 确认用innerHTML让关联元素得到正确的序列
// This requires a wrapper element in IE
// 这个需要一个在IE内的封装元素
support.htmlSerialize = !!div.getElementsByTagName("link").length; // Get the style information from getAttribute
// 从getAttribute得到风格信息
// (IE uses .cssText instead)
// (IE使用.cssText代替)
support.style = /top/.test( a.getAttribute("style") ); // Make sure that URLs aren't manipulated
// 确认URLs没有被操作
// (IE normalizes it by default)
support.hrefNormalized = a.getAttribute("href") === "/a"; // Make sure that element opacity exists
// 确认元素不透明性存在
// (IE uses filter instead)
// (IE使用滤镜代替)
// Use a regex to work around a WebKit issue. See #5145
support.opacity = /^0.5/.test( a.style.opacity ); // Verify style float existence
// 核实格式浮动存在
// (IE uses styleFloat instead of cssFloat)
// (IE使用styleFloat代替cssFloat)
support.cssFloat = !!a.style.cssFloat; // Check the default checkbox/radio value ("" on WebKit; "on" elsewhere)
// 检测默认复选框与单选框的值(在WebKit上为"";其他地方为"on"
support.checkOn = !!input.value; // Make sure that a selected-by-default option has a working selected property.
// 确认一个被选定为默认的选项有一个有效的被选择特性
// (WebKit defaults to false instead of true, IE too, if it's in an optgroup)
// (WebKit默认为假代替真,IE也一样,如果他在optgroup内)
// optgroup元素用于组合选项。当您使用一个长的选项列表时,对相关的选项进行组合会使处理更加容易。
support.optSelected = opt.selected; // Tests for enctype support on a form (#6743)
// 测试一个表单enctype属性的支持
// enctype属性:规定在发送到服务器之前应该如何对表单数据进行编码。
support.enctype = !!document.createElement("form").enctype; // Makes sure cloning an html5 element does not cause problems
// 确认克隆一个html5元素不会引起问题
// Where outerHTML is undefined, this still works
// 在outerHTML没被规定的地方仍然工作
support.html5Clone = document.createElement("nav").cloneNode( true ).outerHTML !== "<:nav></:nav>"; // Will be defined later
// 稍后将会被规定
support.inlineBlockNeedsLayout = false;
support.shrinkWrapBlocks = false;
support.pixelPosition = false;
support.deleteExpando = true;
support.noCloneEvent = true;
support.reliableMarginRight = true;
support.boxSizingReliable = true; // Make sure checked status is properly cloned
// 确保被检测的状态被正常复制
support.noCloneChecked = input.cloneNode( true ).checked; // Make sure that the options inside disabled selects aren't ed as disabled
// 确保在禁用的选择中选项没有被标记为已禁用
// (WebKit s them as disabled)
// (WebKit 标记他们为被禁用)
// WebKit是开源的Web浏览器引擎,苹果的Safari、谷歌的Chrome浏览器都是基于这个框架来开发的。
// WebKit 还支持移动设备和手机,包括iPhone和Android手机都是使用WebKit做为浏览器的核心。
select.disabled = true;
support.optDisabled = !opt.disabled; // Support: IE<9
// 支持: IE<9
try {
delete div.test;
} catch( e ) {
support.deleteExpando = false;
} // Check if we can trust getAttribute("value")
// 检测我们是否能够相信getAttribute("value")
input = document.createElement("input");
input.setAttribute( "value", "" );
support.input = input.getAttribute( "value" ) === ""; // Check if an input maintains its value after becoming a radio
// 检测一个input在成为一个radio后是否还保持它的值
input.value = "t";
input.setAttribute( "type", "radio" );
support.radioValue = input.value === "t"; // #11217 - WebKit loses check when the name is after the checked attribute
// #11217 - WebKit 丢失检测当名字是检测后的属性
input.setAttribute( "checked", "t" );
input.setAttribute( "name", "t" ); fragment = document.createDocumentFragment();
fragment.appendChild( input ); // Check if a disconnected checkbox will retain its checked
// 检测一个断开的复选框是否仍然保留它为真的选择值
// value of true after appended to the DOM (IE6/7)
// 在被添加到DOM后(IE6/7)
support.appendChecked = input.checked; // WebKit doesn't clone checked state correctly in fragments
// WebKit 不会正确地复制被检测的状态在fragments中
support.checkClone = fragment.cloneNode( true ).cloneNode( true ).lastChild.checked; // Support: IE<9
// 支持: IE<9
// Opera does not clone events (and typeof div.attachEvent === undefined).
// Opera不会克隆事件(并且div.attachEvent的类型未定义)
// IE9-10 clones events bound via attachEvent, but they don't trigger with .click()
// IE9-10复制绑定经过attachEvent的事件,但是他们不会用.click()触发
if ( div.attachEvent ) {
div.attachEvent( "onclick", function() {
support.noCloneEvent = false;
}); div.cloneNode( true ).click();
} // Support: IE<9 (lack submit/change bubble), Firefox 17+ (lack focusin event)
// 支持: IE<9(缺少提交/改变冒泡)Firefox 17+
// 上面这句估计翻译不准
// Beware of CSP restrictions (https://developer.mozilla.org/en/Security/CSP)
// 提防CSP限制
// CSP:连接安全措施,网上介绍这个的资料很少,网址上的全英文文章是介绍这个的。简短介绍就是防止被攻击的安全机制 for ( i in { submit: true, change: true, focusin: true }) {
div.setAttribute( eventName = "on" + i, "t" ); support[ i + "Bubbles" ] = eventName in window || div.attributes[ eventName ].expando === false;
} div.style.backgroundClip = "content-box";
div.cloneNode( true ).style.backgroundClip = "";
support.clearCloneStyle = div.style.backgroundClip === "content-box"; // Support: IE<9
// 支持:IE<9
// Iteration over object's inherited properties before its own.
// 在对象的继承的属性之前自己迭代
// 迭代语句又叫循环语句,声明一组要反复执行的命令,直到满足了某些条件为止。
for ( i in jQuery( support ) ) {
break;
}
support.ownLast = i !== "0"; // Run tests that need a body at doc ready
// 运行测试需要一个在文档准备时的body(这句话不太会翻译)
jQuery(function() {
var container, marginDiv, tds,
divReset = "padding:0;margin:0;border:0;display:block;box-sizing:content-box;-moz-box-sizing:content-box;-webkit-box-sizing:content-box;",
body = document.getElementsByTagName("body")[0]; if ( !body ) {
// Return for frameset docs that don't have a body
// 返回给不要body的frameset文档
// frameset元素可定义一个框架集。它被用来组织多个窗口(框架)。
return;
} container = document.createElement("div");
container.style.cssText = "border:0;width:0;height:0;position:absolute;top:0;left:-9999px;margin-top:1px"; body.appendChild( container ).appendChild( div ); // Support: IE8
// 支持: IE8
// 支持: IE8
// Check if table cells still have offsetWidth/Height when they are set
// 检测表格单元是否仍旧有offsetWidth/Height属性
// to display:none and there are still other visible table cells in a
// 当他们被设置为显示none状态,并且他们仍然是其他可见表格单元在一个表格行内
// table row; if so, offsetWidth/Height are not reliable for use when
// 如果如此,offsetWidth/Height对于使用不是可靠的
// determining if an element has been hidden directly using
// 当决定一个元素是否已被隐藏直接使用显示为none
// display:none (it is still safe to use offsets if a parent element is
// (如果一个父元素被隐藏,对于使用offsets他仍旧安全的
// hidden; don safety goggles and see bug #4512 for more information).
// don safety goggles然后看bug #4512获取更多的信息
// don safety goggles如果直接翻译就是:带上护目眼睛,不知道这里怎么理解这句,暂时不会翻译,有会翻译麻烦告诉一下
div.innerHTML = "<table><tr><td></td><td>t</td></tr></table>";
tds = div.getElementsByTagName("td");
tds[ 0 ].style.cssText = "padding:0;margin:0;border:0;display:none";
isSupported = ( tds[ 0 ].offsetHeight === 0 ); tds[ 0 ].style.display = "";
tds[ 1 ].style.display = "none"; // Support: IE8
// 支持:IE8
// Check if empty table cells still have offsetWidth/Height
// 检测空单元格是否仍旧有返回元素宽度与高度
// offsetWidth注释:返回元素宽度,以像素为单位。
support.reliableHiddenOffsets = isSupported && ( tds[ 0 ].offsetHeight === 0 ); // Check box-sizing and margin behavior.
// 检测盒子大小和外边距状态
// margin注释:在一个声明中设置所有外边距属性
div.innerHTML = "";
div.style.cssText = "box-sizing:border-box;-moz-box-sizing:border-box;-webkit-box-sizing:border-box;padding:1px;border:1px;display:block;width:4px;margin-top:1%;position:absolute;top:1%;"; // Workaround failing boxSizing test due to offsetWidth returning wrong value
// 由于返回宽度返回错误值,执行失败盒子大小测试
// workaround在IT行业里指:应急方案、替代方案、规避措施,也指工作区,运行环境
// with some non-1 values of body zoom, ticket #13543
// 用一些本体zoom的non-1值,标签#13543
// zoom属性:IE浏览器的专有属性,Firefox等浏览器不支持。它可以设置或检索对象的缩放比例。
// 除此之外,它还有其他一些小作用,比如触发ie的hasLayout属性,清除浮动、清除margin的重叠等。
jQuery.swap( body, body.style.zoom != null ? { zoom: 1 } : {}, function() {
support.boxSizing = div.offsetWidth === 4;
}); // Use window.getComputedStyle because jsdom on node.js will break without it.
// 使用window.getComputedStyle因为没有他在node.js中的jsdom将会被破坏
// 关于getComputedStyle这里多废话几句,我也在学习中,把学到的分享下
// 样式表有三种方式
// 内嵌样式(inline Style) :是写在Tag里面的,内嵌样式只对所有的Tag有效。
// 内部样式(internal Style Sheet):是写在HTML的<head></head>里面的,内部样式只对所在的网页有效。
// 外部样式表(External StyleSheet):如果很多网页需要用到同样的样式(Styles),
// 将样式(Styles)写在一个以.css为后缀的CSS文件里,然后在每个需要用到这些样式(Styles)的网页里引用这个CSS文件。
// 最常用的是style属性,在JavaScript中,通过document.getElementById(id).style.XXX就可以获取到XXX的值,
// 但意外的是,这样做只能取到通过内嵌方式设置的样式值,即style属性里面设置的值。
// 解决方案:引入currentStyle,runtimeStyle,getComputedStyle
//style 标准的样式。可能是由style属性指定的。
//runtimeStyle 运行时的样式。如果与style的属性重叠,将覆盖style的属性。
//currentStyle 指 style 和 runtimeStyle 的结合。
//通过currentStyle就可以获取到通过内联或外部引用的CSS样式的值了(仅限IE)
//如:document.getElementById("test").currentStyle.top
//要兼容FF,就得需要getComputedStyle 出马了
//注意:getComputedStyle是firefox中的,currentStyle是ie中的。 if ( window.getComputedStyle ) {
support.pixelPosition = ( window.getComputedStyle( div, null ) || {} ).top !== "1%";
support.boxSizingReliable = ( window.getComputedStyle( div, null ) || { width: "4px" } ).width === "4px"; // Check if div with explicit width and no margin-right incorrectly
// 检查带有明确的宽度和没有右外边距的div是否错误地
// gets computed margin-right based on width of container. (#3333)
// 得到基于容器宽度的计算出的margin-right
// margin-right属性设置元素的右外边距
window.close();
翻译:
窗体.关闭();
和我理解的一样 呵呵,我感觉不要理会jquery注释,直接按自己理解的jquery源码翻译较好,而且不要为了翻译而翻译,有些简单的没必要翻译,抓住一些关键地方,精华的地方理解了,并且吸收成自己的知识,让自己能从中提高,再给大家分享下较好,个人看法, 本人认为楼主精神可嘉,有上进心
也有人翻译,我看到的没有一个完整的,基本都是翻译一小部分简单的句子,然后就是无限期拖置了。
也有对jQuery代码进行解释的,不过用的版本确实有点老。
而且JQ的更新速度很快要求翻译需要很快的速度,英文还得好,老实说我应该也就勉强能及格,不算高手。
所以基本都是从零开始,需要理解代码才能翻译明白,注释也不能乱写误导别人。
估计在这个大版本更新前能翻译完,希望那帮高手别再用那神速更新了。
这个版本大部分翻译完的时候,我那个1.9.1的估计也能完成了。谢谢楼上的veryhunger有些翻译多次的句子我不翻译了一层加入太多代码需要加载很长时间,所以每一层还是少放点代码现在开始说说==和===区别,以前还以为没区别第一个是相等符(等于);第二个全等符(严格等于);== 两边值类型不同的时候,要先进行类型转换,再比较。
=== 不做类型转换,类型不同的一定不等。例:
var a = 3;
var b = "3"; a==b 返回 true
a===b 返回 false 因为a,b的类型不一样 ===用来进行严格的比较判断,结果为false
以下连接05层代码翻译
// gets computed margin-right based on width of container. (#3333)
// 得到基于容器宽度的计算出的margin-right
// margin-right属性设置元素的右外边距
// Fails in WebKit before Feb 2011 nightlies
// WebKit失败在2011年2月nightlies前
// nightlies 这个不会翻译,也没查到相关资料
// WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right
// WebKit Bug 13343 - getComputedStyle 返回错误值给margin-right
marginDiv = div.appendChild( document.createElement("div") );
marginDiv.style.cssText = div.style.cssText = divReset;
marginDiv.style.marginRight = marginDiv.style.width = "0";
div.style.width = "1px"; support.reliableMarginRight =
!parseFloat( ( window.getComputedStyle( marginDiv, null ) || {} ).marginRight );
} if ( typeof div.style.zoom !== core_strundefined ) {
// Support: IE<8
// 支持:IE8以下的版本
// Check if natively block-level elements act like inline-block
// 检测本地的块级元素是否像内联块级元素一样起作用
// elements when setting their display to 'inline' and giving
// 当设置他们的显示为内联并且
// them layout
// 给予他们安置
div.innerHTML = "";
div.style.cssText = divReset + "width:1px;padding:1px;display:inline;zoom:1";
support.inlineBlockNeedsLayout = ( div.offsetWidth === 3 ); // Support: IE6
// 支持:IE6
// Check if elements with layout shrink-wrap their children
// 检测带有布局的元素是否收缩包装他们的资源(这句我不是很理解怎么翻译)
div.style.display = "block";
div.innerHTML = "<div></div>";
div.firstChild.style.width = "5px";
support.shrinkWrapBlocks = ( div.offsetWidth !== 3 ); if ( support.inlineBlockNeedsLayout ) {
// Prevent IE 6 from affecting layout for positioned elements #11048
// 阻止IE6影响对于位置元素的布局#11048
// Prevent IE from shrinking the body in IE 7 mode #12869
// 阻止IE收缩body在IE7的风格中
// Support: IE<8
body.style.zoom = 1;
}
} body.removeChild( container ); // Null elements to avoid leaks in IE
container = div = tds = marginDiv = null;
}); // Null elements to avoid leaks in IE
// Null元素阻止在IE内的泄漏
all = select = fragment = opt = a = input = null; return support;
})({});var rbrace = /(?:\{[\s\S]*\}|\[[\s\S]*\])$/,
rmultiDash = /([A-Z])/g;function internalData( elem, name, data, pvt /* Internal Use Only */ ){
if ( !jQuery.acceptData( elem ) ) {
return;
}
// Internal Use Only翻译:仅能在内部使用
var ret, thisCache,
internalKey = jQuery.expando, // We have to handle DOM nodes and JS objects differently because IE6-7
// 我们必须用不同方式管理DOM节点和JS对象
// can't GC object references properly across the DOM-JS boundary
// 因为IE6-7越过DOM-JS范围正确地回收对象引用
// GC:计算机术语Garbage Collection简写,垃圾回收的意思,比较高深的东西
isNode = elem.nodeType, // Only DOM nodes need the global jQuery cache; JS object data is
// 只有DOM节点需要全局的jQuery缓冲存储器
// attached directly to the object so GC can occur automatically
// JS对象数据直接与对象项链所以GC能够自动地发生
{
float:left;
clear:both;
}以下连接24层的翻译// attached directly to the object so GC can occur automatically
// JS对象数据直接与对象项链所以GC能够自动地发生
cache = isNode ? jQuery.cache : elem, // Only defining an ID for JS objects if its cache already exists allows
// 只有规定一个ID给JS对象如果他的缓存已经存在,才能允许
// the code to shortcut on the same path as a DOM node with no cache
// 一段在同样路径作为没有缓存的DOM节点创造捷径的代码
// 上面这两句太长了,估计翻译不是很准确
id = isNode ? elem[ internalKey ] : elem[ internalKey ] && internalKey; // Avoid doing any more work than we need to when trying to get data on an
// 避免做任何比我们需要多的工作,当尝试去得到数据在一个
// object that has no data at all
// 根本没有数据的对象上
if ( (!id || !cache[id] || (!pvt && !cache[id].data)) && data === undefined && typeof name === "string" ) {
return;
} if ( !id ) {
// Only DOM nodes need a new unique ID for each element since their data
// 仅有DOM节点需要一个新的唯一ID
// ends up in the global cache
// 由于他们的数据在全局缓存中结束
if ( isNode ) {
id = elem[ internalKey ] = core_deletedIds.pop() || jQuery.guid++;
} else {
id = internalKey;
}
} if ( !cache[ id ] ) {
// Avoid exposing jQuery metadata on plain JS objects when the object
// 避免暴露在完全的JS对象上的jQuery元数据当对象
// is serialized using JSON.stringify
// 正连续使用JSON.stringify
// 关于JSON.stringify就是说把原来是对象的类型转换成字符串类型(或者更确切的说是json类型的)
// 打个比方说,你有一个类,那么你可以通过这个方法转换成相应的json类型的。
cache[ id ] = isNode ? {} : { toJSON: jQuery.noop };
} // An object can be passed to jQuery.data instead of a key/value pair; this gets
// 一个对象可以通过jQuery.data代替一个键位/数值对
// shallow copied over onto the existing cache
// 这将得到浅复制在存在的缓存上
// over onto 这两个英文单词在一起连用不知道怎么翻译,暂时翻译为:在……上
if ( typeof name === "object" || typeof name === "function" ) {
if ( pvt ) {
cache[ id ] = jQuery.extend( cache[ id ], name );
} else {
cache[ id ].data = jQuery.extend( cache[ id ].data, name );
}
} thisCache = cache[ id ]; // jQuery data() is stored in a separate object inside the object's internal data
// jQuery data() 被存储在一个分开的对象中,这个对象的内部他的内部数据
// cache in order to avoid key collisions between internal data and user-defined
// 缓存是为了阻止键位冲突在内部数据和使用者规定的
// data.
// 数据中
if ( !pvt ) {
if ( !thisCache.data ) {
thisCache.data = {};
} thisCache = thisCache.data;
} if ( data !== undefined ) {
thisCache[ jQuery.camelCase( name ) ] = data;
} // Check for both converted-to-camel and non-converted data property names
// 核实converted-to-camel与non-converted数据属性名字
// If a data property was specified
// 如果数据属性是被制定的
if ( typeof name === "string" ) { // First Try to find as-is property data
// 首先尝试找到as-is属性数据
ret = thisCache[ name ]; // Test for null|undefined property data
// 尝试没有或者违背定义属性数据
if ( ret == null ) { // Try to find the camelCased property
// 尝试找到骆驼拼写法属性
ret = thisCache[ jQuery.camelCase( name ) ];
}
} else {
ret = thisCache;
} return ret;
}function internalRemoveData( elem, name, pvt ) {
if ( !jQuery.acceptData( elem ) ) {
return;
} var thisCache, i,
isNode = elem.nodeType, // See jQuery.data for more information
// 查阅jQuery.data 获得更多的信息
cache = isNode ? jQuery.cache : elem,
id = isNode ? elem[ jQuery.expando ] : jQuery.expando; // If there is already no cache entry for this object, there is no
// purpose in continuing
// 如果已经没有缓冲入口给这个对象,也没有继续的目的
能把这些具有专业术语的英文翻译成比较好的中文语句,麻烦介绍给我,谢谢。至于翻译有没有必要,应该是有,不是所有人都是英语高手,看到大量的英文注释都能明白意思。
这样让一些人往往不看注释了,其实注释还有一些注意的东西,所以翻译出来对阅读有帮助。其实翻译这个很不容易,对代码一无所知就翻译基本就翻译不准,不知道哪个机器可以像人脑这样
需要查阅资料和理解才翻译成句子,虽然我脑子笨,不过好歹我也想了想怎么准确的翻译因为jQuery涉及到不单单就是代码,也同时涉及到许多其他方面的网络知识,所以再翻译过程中,
我也尽可能把一些其他方面知识尽我所能解释下,老实说有更好的教学内容,我也更想看,写其实很累人,
尤其现在还是大夏天。今天说说【AJAX】感觉JQ里面用到了这个现在很常用的技术了,不会用代表了过时。
我理解他就是:点击一个按钮,无需刷新就是能改变网页上的某些内容
感觉学习【AJAX】不当需要了解js代码,还需要了解服务器语言比如PHP什么的以下连接25层翻译,欢迎回复,大家多多支持,谢了。
// 如果已经没有缓冲入口给这个对象,也没有继续的目的
if ( !cache[ id ] ) {
return;
} if ( name ) { thisCache = pvt ? cache[ id ] : cache[ id ].data; if ( thisCache ) { // Support array or space separated string names for data keys
// 支持数值或者空格隔开的字符串名字对于数据键位
if ( !jQuery.isArray( name ) ) { // try the string as a key before any manipulation
// 尝试把字符串当成键位在任何操作
if ( name in thisCache ) {
name = [ name ];
} else { // split the camel cased version by spaces unless a key with the spaces exists
// 用空格分割骆驼事例的版本,除非有一个空格键存在
name = jQuery.camelCase( name );
if ( name in thisCache ) {
name = [ name ];
} else {
name = name.split(" ");
}
}
} else {
// If "name" is an array of keys...
// 如果"name"是键位组……
// When data is initially created, via ("key", "val") signature,
// 当数据最初被创建,经过("key", "val")识别标志
// keys will be converted to camelCase.
// 键位将会被转换为骆驼拼写法
// Since there is no way to tell _how_ a key was added, remove
// 由于没有途径告诉键位如何被添加,移除
// both plain key and camelCase key. #12786
// 清晰键位和骆驼拼写法键位#12786
// This will only penalize the array argument path.
// 这将仅仅惩罚数值参数路径
name = name.concat( jQuery.map( name, jQuery.camelCase ) );
} i = name.length;
while ( i-- ) {
delete thisCache[ name[i] ];
} // If there is no data left in the cache, we want to continue
// 如果没有数据在缓存中留下,我们想要继续
// and let the cache object itself get destroyed
// 并且让缓存对象自己破坏自己
if ( pvt ? !isEmptyDataObject(thisCache) : !jQuery.isEmptyObject(thisCache) ) {
return;
}
}
} // See jQuery.data for more information
if ( !pvt ) {
delete cache[ id ].data; // Don't destroy the parent cache unless the internal data object
// 不要破坏父缓存除非内部数据对象
// had been the only thing left in it
// 是唯一被留下的
if ( !isEmptyDataObject( cache[ id ] ) ) {
return;
}
} // Destroy the cache
// 破坏缓存
if ( isNode ) {
jQuery.cleanData( [ elem ], true ); // Use delete when supported for expandos or `cache` is not a window per isWindow (#10080)
// 使用删除当被支持对于expandos属性或者缓存不是window按照惯例isWindow (#10080)
// 这句翻译的不是很准备,见谅
// expandos我理解一个属性的命名
// isWindow用于测试是否为一个window对象
/* jshint eqeqeq: false */
// JSHint介绍
// 翻译自www.jshint.com
// JSHint是一个由javascript社区驱动开发的用于检查javascript代码错误和问题的工具,
// 有了他,可以使你保持一个良好的编码风格。你可以很简单的配置它以适应你目前的一个编码风格。
// 目前JSHint的源码可以在github上面找到。 } else if ( jQuery.support.deleteExpando || cache != cache.window ) {
/* jshint eqeqeq: true */
delete cache[ id ]; // When all else fails, null
// 当其他的所有失败,空值
} else {
cache[ id ] = null;
}
}jQuery.extend({
cache: {}, // The following elements throw uncatchable exceptions if you
// 接下来的元素扔出不可捕捉的例外如果你
// attempt to add expando properties to them.
// 试图添加expando属性给他们
// expando我不知道什么意思
noData: {
"applet": true,
"embed": true,
// Ban all objects except for Flash (which handle expandos)
// 禁止所用对象除了Flash (管理expandos属性)
"object": "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
}, hasData: function( elem ) {
elem = elem.nodeType ? jQuery.cache[ elem[jQuery.expando] ] : elem[ jQuery.expando ];
return !!elem && !isEmptyDataObject( elem );
}, data: function( elem, name, data ) {
return internalData( elem, name, data );
}, removeData: function( elem, name ) {
return internalRemoveData( elem, name );
}, // For internal use only.
_data: function( elem, name, data ) {
return internalData( elem, name, data, true );
}, _removeData: function( elem, name ) {
return internalRemoveData( elem, name, true );
}, // A method for determining if a DOM node can handle the data expando
// 一个方法决定DOM节点能否操作数据expando属性
因为有的单词确实不知道该如何翻译比较好,才按原意翻译的。说说代码这东西,假如今天你把某些代码理解得还可以,如果长期不用这些代码,一段时间后估计还得重学。
不过只是下次重学的时间要快些而已,所以把一些重要知识记录在帖子中,也方便大家学习。今天说说JQ代码中常用到写法类似这样
say:function(){alert('hello word!');};
其实就相当于
var say = function(){alert('hello word!');};var p=function(){}()表示的什么意思?var p = function(){return 'abc';}();
alert(p);//abc
alert(typeof p); //stringvar p = (function(){return 'abc';})();
alert(p);//abc
alert(typeof p); //string定义了一个变量,后面函数的返回值赋值给这个变量如果把最后的()去掉后
var p = function(){return 'abc';};
alert(p);//function(){return 'abc';}
alert(typeof p); //function
就是将这个函数赋值给变量,今天第一次学到的。如果这个翻译会把完整版的下载地址给出,估计到时候自己的水平能有一些提高连接40层的翻译,介绍了一点关于HTML5的内容
// 一个方法决定DOM节点能否操作数据expando属性
acceptData: function( elem ) {
// Do not set data on non-element because it will not be cleared (#8335).
// 不要设置数据在non-element上面因为它将不会被清除(#8335)
if ( elem.nodeType && elem.nodeType !== 1 && elem.nodeType !== 9 ) {
return false;
} var noData = elem.nodeName && jQuery.noData[ elem.nodeName.toLowerCase() ]; // nodes accept data unless otherwise specified; rejection can be conditional
// 节点接受数据除非有其他的规定;拒绝可以是有条件的
return !noData || noData !== true && elem.getAttribute("classid") === noData;
}
});jQuery.fn.extend({
data: function( key, value ) {
var attrs, name,
data = null,
i = 0,
elem = this[0]; // Special expections of .data basically thwart jQuery.access,
// 关于.data的特别例外基本阻碍jQuery.access
// so implement the relevant behavior ourselves
// 所以我们自己执行相关行为 // Gets all values
// 得到全部值
if ( key === undefined ) {
if ( this.length ) {
data = jQuery.data( elem ); if ( elem.nodeType === 1 && !jQuery._data( elem, "parsedAttrs" ) ) {
attrs = elem.attributes;
for ( ; i < attrs.length; i++ ) {
name = attrs[i].name; if ( name.indexOf("data-") === 0 ) {
name = jQuery.camelCase( name.slice(5) ); dataAttr( elem, name, data[ name ] );
}
}
jQuery._data( elem, "parsedAttrs", true );
}
} return data;
} // Sets multiple values
// 设置多个值
if ( typeof key === "object" ) {
return this.each(function() {
jQuery.data( this, key );
});
} return arguments.length > 1 ? // Sets one value
// 设置数值
this.each(function() {
jQuery.data( this, key, value );
}) : // Gets one value
// Try to fetch any internally stored data first
// 首先尝试拿取任意内部被存储的数据
elem ? dataAttr( elem, key, jQuery.data( elem, key ) ) : null;
}, removeData: function( key ) {
return this.each(function() {
jQuery.removeData( this, key );
});
}
});function dataAttr( elem, key, data ) {
// If nothing was found internally, try to fetch any
// 如果在内部什么也没找到,尝试拿取任意
// data from the HTML5 data-* attribute
// 数据从 HTML5 data-* 属性
// 关于 HTML5 data-* 属性的相关介绍:HTML5中支持用户自定义的data-*特性,例如data-length,它可以附加在input的标签上。
// 本人对HTML5还不太属性,所以不多介绍了。
if ( data === undefined && elem.nodeType === 1 ) { var name = "data-" + key.replace( rmultiDash, "-$1" ).toLowerCase(); data = elem.getAttribute( name ); if ( typeof data === "string" ) {
try {
data = data === "true" ? true :
data === "false" ? false :
data === "null" ? null :
// Only convert to a number if it doesn't change the string
// 仅仅转换成数字如果他不是字符串
+data + "" === data ? +data :
rbrace.test( data ) ? jQuery.parseJSON( data ) :
data;
} catch( e ) {} // Make sure we set the data so it isn't changed later
// 确认我们设置了数据以便他稍后不会被改变
jQuery.data( elem, key, data ); } else {
data = undefined;
}
} return data;
}// checks a cache object for emptiness
// 核实缓存对象为空
function isEmptyDataObject( obj ) {
var name;
for ( name in obj ) { // if the public data object is empty, the private is still empty
// 如果公有数据对象为空,那么私有也为空。
if ( name === "data" && jQuery.isEmptyObject( obj[name] ) ) {
continue;
}
if ( name !== "toJSON" ) {
return false;
}
} return true;
}
jQuery.extend({
queue: function( elem, type, data ) {
var queue; if ( elem ) {
type = ( type || "fx" ) + "queue";
queue = jQuery._data( elem, type ); // Speed up dequeue by getting out quickly if this is just a lookup
// 以退出的方式加速离开队列如果只是查找
if ( data ) {
if ( !queue || jQuery.isArray(data) ) {
queue = jQuery._data( elem, type, jQuery.makeArray(data) );
} else {
queue.push( data );
}
}
return queue || [];
}
}, dequeue: function( elem, type ) {
type = type || "fx"; var queue = jQuery.queue( elem, type ),
startLength = queue.length,
fn = queue.shift(),
hooks = jQuery._queueHooks( elem, type ),
next = function() {
jQuery.dequeue( elem, type );
}; // If the fx queue is dequeued, always remove the progress sentinel
// 如果fx队列被终止,经常移除进行前哨
// sentinel不知道怎么翻译
// jQuery中dequeue()方法:终止一个自定义的队列函数
if ( fn === "inprogress" ) {
fn = queue.shift();
startLength--;
} if ( fn ) { // Add a progress sentinel to prevent the fx queue from being
// automatically dequeued
// 添加进程前哨阻止fx队列自动出列
if ( type === "fx" ) {
queue.unshift( "inprogress" );
} // clear up the last queue stop function
// 处理最后队列停止功能