/* * this file has been commented to support visual studio intellisense. * you should not use this file at runtime inside the browser--it is only * intended to be used only for design-time intellisense. please use the * standard jquery library for all production use. * * comment version: 1.4.1a */ /*! * jquery javascript library v1.4.1 * http://jquery.com/ * * distributed in whole under the terms of the mit * * copyright 2010, john resig * * permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "software"), to deal in the software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the software, and to * permit persons to whom the software is furnished to do so, subject to * the following conditions: * * the above copyright notice and this permission notice shall be * included in all copies or substantial portions of the software. * * the software is provided "as is", without warranty of any kind, * express or implied, including but not limited to the warranties of * merchantability, fitness for a particular purpose and * noninfringement. in no event shall the authors or copyright holders be * liable for any claim, damages or other liability, whether in an action * of contract, tort or otherwise, arising from, out of or in connection * with the software or the use or other dealings in the software. * * includes sizzle.js * http://sizzlejs.com/ * copyright 2010, the dojo foundation * released under the mit, bsd, and gpl licenses. * * date: mon jan 25 19:43:33 2010 -0500 */ (function( window, undefined ) { // define a local copy of jquery var jquery = function( selector, context ) { /// /// 1: $(expression, context) - 此函数接受一个包含 css 选择器的字符串,随后将使用该选择器匹配一组元素。 /// 2: $(html) - 基于提供的原始 html 字符串动态创建 dom 元素。 /// 3: $(elements) - 围绕单个或多个 dom 元素包装 jquery 功能。 /// 4: $(callback) - $(document).ready() 的简写形式。 /// 5: $() - 从 jquery 1.4 开始,如果未向 jquery()方法传递任何参数,则将返回空的 jquery 集。 /// /// /// 1: expression - 要用于搜索的表达式。 /// 2: html - 要动态创建的 html 字符串。 /// 3: elements - 将由 jquery 对象封装的 dom 元素。 /// 4: callback - 当 dom 就绪时要执行的函数。 /// /// /// 1: context - 要用作上下文的 dom 元素、文档或 jquery。 /// /// // the jquery object is actually just the init constructor 'enhanced' return new jquery.fn.init( selector, context ); }, // map over jquery in case of overwrite _jquery = window.jquery, // map over the $ in case of overwrite _$ = window.$, // use the correct document accordingly with window argument (sandbox) document = window.document, // a central reference to the root jquery(document) rootjquery, // a simple way to check for html strings or id strings // (both of which we optimize for) quickexpr = /^[^<]*(<[\w\w]+>)[^>]*$|^#([\w-]+)$/, // is it a simple selector issimple = /^.[^:#\[\.,]*$/, // check if a string has a non-whitespace character in it rnotwhite = /\s/, // used for trimming whitespace rtrim = /^(\s|\u00a0)+|(\s|\u00a0)+$/g, // match a standalone tag rsingletag = /^<(\w+)\s*\/?>(?:<\/\1>)?$/, // keep a useragent string for use with jquery.browser useragent = navigator.useragent, // for matching the engine and version of the browser browsermatch, // has the ready events already been bound? readybound = false, // the functions to execute on dom ready readylist = [], // the ready event handler domcontentloaded, // save a reference to some core methods tostring = object.prototype.tostring, hasownproperty = object.prototype.hasownproperty, push = array.prototype.push, slice = array.prototype.slice, indexof = array.prototype.indexof; jquery.fn = jquery.prototype = { init: function( selector, context ) { var match, elem, ret, doc; // handle $(""), $(null), or $(undefined) if ( !selector ) { return this; } // handle $(domelement) if ( selector.nodetype ) { this.context = this[0] = selector; this.length = 1; return this; } // handle html strings if ( typeof selector === "string" ) { // are we dealing with html string or an id? match = quickexpr.exec( selector ); // verify a match, and that no context was specified for #id if ( match && (match[1] || !context) ) { // handle: $(html) -> $(array) if ( match[1] ) { doc = (context ? context.ownerdocument || context : document); // if a single string is passed in and it's a single tag // just do a createelement and skip the rest ret = rsingletag.exec( selector ); if ( ret ) { if ( jquery.isplainobject( context ) ) { selector = [ document.createelement( ret[1] ) ]; jquery.fn.attr.call( selector, context, true ); } else { selector = [ doc.createelement( ret[1] ) ]; } } else { ret = buildfragment( [ match[1] ], [ doc ] ); selector = (ret.cacheable ? ret.fragment.clonenode(true) : ret.fragment).childnodes; } // handle: $("#id") } else { elem = document.getelementbyid( match[2] ); if ( elem ) { // handle the case where ie and opera return items // by name instead of id if ( elem.id !== match[2] ) { return rootjquery.find( selector ); } // otherwise, we inject the element directly into the jquery object this.length = 1; this[0] = elem; } this.context = document; this.selector = selector; return this; } // handle: $("tag") } else if ( !context && /^\w+$/.test( selector ) ) { this.selector = selector; this.context = document; selector = document.getelementsbytagname( selector ); // handle: $(expr, $(...)) } else if ( !context || context.jquery ) { return (context || rootjquery).find( selector ); // handle: $(expr, context) // (which is just equivalent to: $(context).find(expr) } else { return jquery( context ).find( selector ); } // handle: $(function) // shortcut for document ready } else if ( jquery.isfunction( selector ) ) { return rootjquery.ready( selector ); } if (selector.selector !== undefined) { this.selector = selector.selector; this.context = selector.context; } return jquery.isarray( selector ) ? this.setarray( selector ) : jquery.makearray( selector, this ); }, // start with an empty selector selector: "", // the current version of jquery being used jquery: "1.4.1", // the default length of a jquery object is 0 length: 0, // the number of elements contained in the matched element set size: function() { /// /// 当前匹配的元素的数目。 /// 核心部分 /// /// return this.length; }, toarray: function() { /// /// 以数组的形式检索 jquery 集中包含的所有 dom 元素。 /// /// return slice.call( this, 0 ); }, // get the nth element in the matched element set or // get the whole matched element set as a clean array get: function( num ) { /// /// 访问单个匹配的元素。num 用于访问 /// 匹配的第 n 个元素。 /// 核心部分 /// /// /// /// 访问处于第 n 个位置的元素。 /// return num == null ? // return a 'clean' array this.toarray() : // return just the object ( num < 0 ? this.slice(num)[ 0 ] : this[ num ] ); }, // take an array of elements and push it onto the stack // (returning the new matched element set) pushstack: function( elems, name, selector ) { /// /// 将 jquery 对象设置为一个元素数组,同时对 /// 堆栈进行维护。 /// 核心部分 /// /// /// /// 元素数组 /// // build a new jquery matched element set var ret = jquery( elems || null ); // add the old object onto the stack (as a reference) ret.prevobject = this; ret.context = this.context; if ( name === "find" ) { ret.selector = this.selector + (this.selector ? " " : "") + selector; } else if ( name ) { ret.selector = this.selector + "." + name + "(" + selector + ")"; } // return the newly-formed element set return ret; }, // force the current matched set of elements to become // the specified array of elements (destroying the stack in the process) // you should use pushstack() in order to do this, but maintain the stack setarray: function( elems ) { /// /// 将 jquery 对象设置为一个元素数组。此操作具有十足的 /// 破坏性 - 如果您希望维护 jquery 堆栈, /// 请务必使用 .pushstack()。 /// 核心部分 /// /// /// /// 元素数组 /// // resetting the length to 0, then using the native array push // is a super-fast way to populate an object with array-like properties this.length = 0; push.apply( this, elems ); return this; }, // execute a callback for every element in the matched set. // (you can seed the arguments with an array of args, but this is // only used internally.) each: function( callback, args ) { /// /// 在每个匹配元素的上下文中执行函数。 /// 这意味着每次执行传入的函数 /// (为每个匹配的元素执行一次)时,“this”关键字 /// 将指向特定元素。 /// 此外,在执行该函数时,还会为其传递一个参数, /// 用于表示元素在匹配集中的位置 /// 。 /// 核心部分 /// /// /// /// 要执行的函数 /// return jquery.each( this, callback, args ); }, ready: function( fn ) { /// /// 绑定一个每当准备好遍历和操作 dom 时就要执行的函数。 /// /// 当 dom 就绪时要执行的函数。 // attach the listeners jquery.bindready(); // if the dom is already ready if ( jquery.isready ) { // execute the function immediately fn.call( document, jquery ); // otherwise, remember the function for later } else if ( readylist ) { // add the function to the wait list readylist.push( fn ); } return this; }, eq: function( i ) { /// /// 将匹配元素集简化为单个元素。 /// 元素在匹配元素集中的位置 /// 从 0 开始,直至 length - 1。 /// 核心部分 /// /// /// /// pos 希望限制为的元素索引。 /// return i === -1 ? this.slice( i ) : this.slice( i, +i + 1 ); }, first: function() { /// /// 将匹配元素集精简为集合中的第一个元素。 /// /// return this.eq( 0 ); }, last: function() { /// /// 将匹配元素集精简为集合中的最后一个元素。 /// /// return this.eq( -1 ); }, slice: function() { /// /// 选择匹配元素的子集。行为方式与内置的 array 切片方法完全一样。 /// /// 开始子集的位置(从 0 开始)。 /// 结束子集的位置(不包括结束元素本身)。 /// 如果省略,则在选择结束时结束 /// 切片元素 return this.pushstack( slice.apply( this, arguments ), "slice", slice.call(arguments).join(",") ); }, map: function( callback ) { /// /// 此成员为内部成员。 /// /// /// return this.pushstack( jquery.map(this, function( elem, i ) { return callback.call( elem, i, elem ); })); }, end: function() { /// /// 结束最新的“破坏性”操作,并将匹配元素的列表 /// 还原回以前的状态。执行结束操作之后,匹配元素的列表将还原为 /// 匹配元素的最后状态。 /// 如果前面没有出现过破坏性操作,则将返回一个空集。 /// dom/遍历部分 /// /// return this.prevobject || jquery(null); }, // 仅供内部使用。 // 行为方式与数组的方法类似,而与 jquery 方法不类似。 push: push, sort: [].sort, splice: [].splice }; // 为 init 函数指定 jquery 原型以用于以后的实例化 jquery.fn.init.prototype = jquery.fn; jquery.extend = jquery.fn.extend = function() { /// /// 用一个或多个对象扩展另一个对象,并返回已修改的 /// 原始对象。这对于简单继承是一个非常有用的实用工具。 /// jquery.extend(settings, options); /// var settings = jquery.extend({}, defaults, options); /// javascript 部分 /// /// /// 要扩展的对象 /// /// /// 将合并到第一个对象的对象。 /// /// /// (可选)要合并到第一个对象的多个对象 /// /// // copy reference to target object var target = arguments[0] || {}, i = 1, length = arguments.length, deep = false, options, name, src, copy; // handle a deep copy situation if ( typeof target === "boolean" ) { deep = target; target = arguments[1] || {}; // skip the boolean and the target i = 2; } // handle case when target is a string or something (possible in deep copy) if ( typeof target !== "object" && !jquery.isfunction(target) ) { target = {}; } // extend jquery itself if only one argument is passed if ( length === i ) { target = this; --i; } for ( ; i < length; i++ ) { // only deal with non-null/undefined values if ( (options = arguments[ i ]) != null ) { // extend the base object for ( name in options ) { src = target[ name ]; copy = options[ name ]; // prevent never-ending loop if ( target === copy ) { continue; } // recurse if we're merging object literal values or arrays if ( deep && copy && ( jquery.isplainobject(copy) || jquery.isarray(copy) ) ) { var clone = src && ( jquery.isplainobject(src) || jquery.isarray(src) ) ? src : jquery.isarray(copy) ? [] : {}; // never move original objects, clone them target[ name ] = jquery.extend( deep, clone, copy ); // don't bring in undefined values } else if ( copy !== undefined ) { target[ name ] = copy; } } } } // return the modified object return target; }; jquery.extend({ noconflict: function( deep ) { /// /// 运行此函数以将 $ 变量的控制权交还给 /// 任何首先实现它的库。这可帮助确保 /// jquery 不会与其他库的 $ 对象 /// 冲突。 /// 通过使用此函数,您将只能够使用“jquery”变量 /// 来访问 jquery。例如,在执行 /// $("div p") 的位置,您现在必须执行 jquery("div p")。 /// 核心部分 /// /// window.$ = _$; if ( deep ) { window.jquery = _jquery; } return jquery; }, // 是否准备好使用 dom? 一旦准备好,请设置为 true。 isready: false, // 当 dom 就绪时处理 ready: function() { /// /// 此方法为内部方法。 /// /// // make sure that the dom is not already loaded if ( !jquery.isready ) { // make sure body exists, at least, in case ie gets a little overzealous (ticket #5443). if ( !document.body ) { return settimeout( jquery.ready, 13 ); } // remember that the dom is ready jquery.isready = true; // if there are functions bound, to execute if ( readylist ) { // execute all of them var fn, i = 0; while ( (fn = readylist[ i++ ]) ) { fn.call( document, jquery ); } // reset the list of functions readylist = null; } // trigger any bound ready events if ( jquery.fn.triggerhandler ) { jquery( document ).triggerhandler( "ready" ); } } }, bindready: function() { if ( readybound ) { return; } readybound = true; // catch cases where $(document).ready() is called after the // browser event has already occurred. if ( document.readystate === "complete" ) { return jquery.ready(); } // mozilla, opera and webkit nightlies currently support this event if ( document.addeventlistener ) { // use the handy event callback document.addeventlistener( "domcontentloaded", domcontentloaded, false ); // a fallback to window.onload, that will always work window.addeventlistener( "load", jquery.ready, false ); // if ie event model is used } else if ( document.attachevent ) { // ensure firing before onload, // maybe late but safe also for iframes document.attachevent("onreadystatechange", domcontentloaded); // a fallback to window.onload, that will always work window.attachevent( "onload", jquery.ready ); // if ie and not a frame // continually check to see if the document is ready var toplevel = false; try { toplevel = window.frameelement == null; } catch(e) {} if ( document.documentelement.doscroll && toplevel ) { doscrollcheck(); } } }, // see test/unit/core.js for details concerning isfunction. // since version 1.3, dom methods and functions like alert // aren't supported. they return false on ie (#2968). isfunction: function( obj ) { /// /// 确定传递的参数是否为函数。 /// /// 要检查的对象 /// 如果该参数为函数,则为 true;否则为 false。 return tostring.call(obj) === "[object function]"; }, isarray: function( obj ) { /// /// 确定传递的参数是否为数组。 /// /// 要测试其是否为数组的对象。 /// 如果该参数为函数,则为 true;否则为 false。 return tostring.call(obj) === "[object array]"; }, isplainobject: function( obj ) { /// /// check to see if an object is a plain object (created using "{}" or "new object"). /// /// /// 将检查其是否为纯对象的对象。 /// /// // must be an object. // because of ie, we also have to check the presence of the constructor property. // make sure that dom nodes and window objects don't pass through, as well if ( !obj || tostring.call(obj) !== "[object object]" || obj.nodetype || obj.setinterval ) { return false; } // not own constructor property must be object if ( obj.constructor && !hasownproperty.call(obj, "constructor") && !hasownproperty.call(obj.constructor.prototype, "isprototypeof") ) { return false; } // own properties are enumerated firstly, so to speed up, // if last one is own, then all properties are own. var key; for ( key in obj ) {} return key === undefined || hasownproperty.call( obj, key ); }, isemptyobject: function( obj ) { /// /// 检查某个对象是否为空(不包含任何属性)。 /// /// /// 将检查其是否为空的对象。 /// /// for ( var name in obj ) { return false; } return true; }, error: function( msg ) { throw msg; }, parsejson: function( data ) { if ( typeof data !== "string" || !data ) { return null; } // make sure the incoming data is actual json // logic borrowed from http://json.org/json2.js if ( /^[\],:{}\s]*$/.test(data.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fa-f]{4})/g, "@") .replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[ee][+\-]?\d+)?/g, "]") .replace(/(?:^|:|,)(?:\s*\[)+/g, "")) ) { // try to use the native json parser first return window.json && window.json.parse ? window.json.parse( data ) : (new function("return " + data))(); } else { jquery.error( "invalid json: " + data ); } }, noop: function() { /// /// 一个空函数。 /// /// }, // 计算全局上下文中的脚本 globaleval: function( data ) { /// /// 在内部计算全局上下文中的脚本。 /// /// if ( data && rnotwhite.test(data) ) { // inspired by code by andrea giammarchi // http://webreflection.blogspot.com/2007/08/global-scope-evaluation-and-dom.html var head = document.getelementsbytagname("head")[0] || document.documentelement, script = document.createelement("script"); script.type = "text/javascript"; if ( jquery.support.scripteval ) { script.appendchild( document.createtextnode( data ) ); } else { script.text = data; } // use insertbefore instead of appendchild to circumvent an ie6 bug. // this arises when a base node is used (#2709). head.insertbefore( script, head.firstchild ); head.removechild( script ); } }, nodename: function( elem, name ) { /// /// 检查指定的元素是否具有指定的 dom 节点名称。 /// /// 要检查的元素 /// 要检查的节点名称 /// 如果指定的节点名称与节点的 dom 节点名称匹配,则为 true;否则为 false return elem.nodename && elem.nodename.touppercase() === name.touppercase(); }, // args is for internal usage only each: function( object, callback, args ) { /// /// 一个泛型迭代器函数,它可用于无缝地 /// 循环访问对象和数组。此函数不同于 /// $().each(),该函数用于以独占方式循环访问 jquery /// 对象。此函数可用于循环访问任何内容。 /// 该回调具有两个参数: key (对象)或 index (数组)作为 /// 第一个参数,value 作为第二个参数。 /// javascript 部分 /// /// /// 要循环访问的对象或数组。 /// /// /// 将针对每个对象执行的函数。 /// /// var name, i = 0, length = object.length, isobj = length === undefined || jquery.isfunction(object); if ( args ) { if ( isobj ) { for ( name in object ) { if ( callback.apply( object[ name ], args ) === false ) { break; } } } else { for ( ; i < length; ) { if ( callback.apply( object[ i++ ], args ) === false ) { break; } } } // a special, fast, case for the most common use of each } else { if ( isobj ) { for ( name in object ) { if ( callback.call( object[ name ], name, object[ name ] ) === false ) { break; } } } else { for ( var value = object[0]; i < length && callback.call( value, i, value ) !== false; value = object[++i] ) {} } } return object; }, trim: function( text ) { /// /// 移除字符串开始和结尾处的空白。 /// javascript 部分 /// /// /// /// 要修整的字符串。 /// return (text || "").replace( rtrim, "" ); }, // results is for internal usage only makearray: function( array, results ) { /// /// 将任何内容转换为一个真正的数组。这是一个内部方法。 /// /// 要转换为实际数组的任何内容 /// /// var ret = results || []; if ( array != null ) { // the window, strings (and functions) also have 'length' // the extra typeof function check is to prevent crashes // in safari 2 (see: #3039) if ( array.length == null || typeof array === "string" || jquery.isfunction(array) || (typeof array !== "function" && array.setinterval) ) { push.call( ret, array ); } else { jquery.merge( ret, array ); } } return ret; }, inarray: function( elem, array ) { if ( array.indexof ) { return array.indexof( elem ); } for ( var i = 0, length = array.length; i < length; i++ ) { if ( array[ i ] === elem ) { return i; } } return -1; }, merge: function( first, second ) { /// /// 将两个数组合并在一起并移除所有重复项。 /// 新数组是: 第一个数组中的所有结果, /// 后跟第二个数组中的唯一结果。 /// javascript 部分 /// /// /// /// 要合并的第一个数组。 /// /// /// 要合并的第二个数组。 /// var i = first.length, j = 0; if ( typeof second.length === "number" ) { for ( var l = second.length; j < l; j++ ) { first[ i++ ] = second[ j ]; } } else { while ( second[j] !== undefined ) { first[ i++ ] = second[ j++ ]; } } first.length = i; return first; }, grep: function( elems, callback, inv ) { /// /// 使用筛选器函数从数组中筛选出项。 /// 将向指定的函数传递两个参数: /// 当前数组项和该项在数组中的索引。 /// 该函数必须返回“true”以将该项保留在数组中, /// 若返回 false 则将移除该项。 /// }); /// javascript 部分 /// /// /// /// array 要在其中查找项的数组。 /// /// /// 要用于处理每一项的函数。 /// /// /// 反转选择 - 选择函数的反函数。 /// var ret = []; // go through the array, only saving the items // that pass the validator function for ( var i = 0, length = elems.length; i < length; i++ ) { if ( !inv !== !callback( elems[ i ], i ) ) { ret.push( elems[ i ] ); } } return ret; }, // arg is for internal usage only map: function( elems, callback, arg ) { /// /// 将一个数组中的所有项转换为另一个项数组。 /// 针对数组中每一项调用提供给此方法的转换函数, /// 并向该函数传递一个参数: /// 要转换的项。 /// 然后,该函数可以返回转换后的值、“null” /// (以移除相应项)或值数组 - 这些数据将 /// 会修整到完整的数组中。 /// javascript 部分 /// /// /// /// array 要转换的数组。 /// /// /// 要用于处理每一项的函数。 /// var ret = [], value; // 遍历数组,并将每个项转换为 // 一个或多个新值。 for ( var i = 0, length = elems.length; i < length; i++ ) { value = callback( elems[ i ], i, arg ); if ( value != null ) { ret[ ret.length ] = value; } } return ret.concat.apply( [], ret ); }, // 用于对象的全局 guid 计数器 guid: 1, proxy: function( fn, proxy, thisobject ) { /// /// 采用一个函数,并返回一个将始终具有特定范围的新函数。 /// /// /// 将更改其范围的函数。 /// /// /// 应将其设置为函数的范围的对象。 /// /// if ( arguments.length === 2 ) { if ( typeof proxy === "string" ) { thisobject = fn; fn = thisobject[ proxy ]; proxy = undefined; } else if ( proxy && !jquery.isfunction( proxy ) ) { thisobject = proxy; proxy = undefined; } } if ( !proxy && fn ) { proxy = function() { return fn.apply( thisobject || this, arguments ); }; } // set the guid of unique handler to the same of original handler, so it can be removed if ( fn ) { proxy.guid = fn.guid = fn.guid || proxy.guid || jquery.guid++; } // so proxy can be declared as an argument return proxy; }, // use of jquery.browser is frowned upon. // more details: http://docs.jquery.com/utilities/jquery.browser uamatch: function( ua ) { ua = ua.tolowercase(); var match = /(webkit)[ \/]([\w.]+)/.exec( ua ) || /(opera)(?:.*version)?[ \/]([\w.]+)/.exec( ua ) || /(msie) ([\w.]+)/.exec( ua ) || !/compatible/.test( ua ) && /(mozilla)(?:.*? rv:([\w.]+))?/.exec( ua ) || []; return { browser: match[1] || "", version: match[2] || "0" }; }, browser: {} }); browsermatch = jquery.uamatch( useragent ); if ( browsermatch.browser ) { jquery.browser[ browsermatch.browser ] = true; jquery.browser.version = browsermatch.version; } // deprecated, use jquery.browser.webkit instead if ( jquery.browser.webkit ) { jquery.browser.safari = true; } if ( indexof ) { jquery.inarray = function( elem, array ) { /// /// 确定数组中第一个参数的索引。 /// /// 要检查数组中是否存在的值。 /// 要在其中浏览查找值的数组 /// 项的从 0 开始的索引(如果找到);否则为 -1。 return indexof.call( array, elem ); }; } // all jquery objects should point back to these rootjquery = jquery(document); // cleanup functions for the document ready method if ( document.addeventlistener ) { domcontentloaded = function() { document.removeeventlistener( "domcontentloaded", domcontentloaded, false ); jquery.ready(); }; } else if ( document.attachevent ) { domcontentloaded = function() { // make sure body exists, at least, in case ie gets a little overzealous (ticket #5443). if ( document.readystate === "complete" ) { document.detachevent( "onreadystatechange", domcontentloaded ); jquery.ready(); } }; } // the dom ready check for internet explorer function doscrollcheck() { if ( jquery.isready ) { return; } try { // if ie is used, use the trick by diego perini // http://javascript.nwbox.com/iecontentloaded/ document.documentelement.doscroll("left"); } catch( error ) { settimeout( doscrollcheck, 1 ); return; } // and execute any waiting functions jquery.ready(); } function evalscript( i, elem ) { /// /// 此方法为内部方法。 /// /// if ( elem.src ) { jquery.ajax({ url: elem.src, async: false, datatype: "script" }); } else { jquery.globaleval( elem.text || elem.textcontent || elem.innerhtml || "" ); } if ( elem.parentnode ) { elem.parentnode.removechild( elem ); } } // mutifunctional method to get and set values to a collection // the value/s can be optionally by executed if its a function function access( elems, key, value, exec, fn, pass ) { var length = elems.length; // setting many attributes if ( typeof key === "object" ) { for ( var k in key ) { access( elems, k, key[k], exec, fn, value ); } return elems; } // setting one attribute if ( value !== undefined ) { // optionally, function values get executed if exec is true exec = !pass && exec && jquery.isfunction(value); for ( var i = 0; i < length; i++ ) { fn( elems[i], key, exec ? value.call( elems[i], i, fn( elems[i], key ) ) : value, pass ); } return elems; } // getting an attribute return length ? fn( elems[0], key ) : null; } function now() { /// /// 获取当前日期。 /// /// 当前日期。 return (new date).gettime(); } // [vsdoc] the following function has been modified for intellisense. // [vsdoc] stubbing support properties to "false" for intellisense compat. (function() { jquery.support = {}; // var root = document.documentelement, // script = document.createelement("script"), // div = document.createelement("div"), // id = "script" + now(); // div.style.display = "none"; // div.innerhtml = "
a"; // var all = div.getelementsbytagname("*"), // a = div.getelementsbytagname("a")[0]; // // can't get basic test support // if ( !all || !all.length || !a ) { // return; // } jquery.support = { // ie strips leading whitespace when .innerhtml is used leadingwhitespace: false, // make sure that tbody elements aren't automatically inserted // ie will insert them into empty tables tbody: false, // make sure that link elements get serialized correctly by innerhtml // this requires a wrapper element in ie htmlserialize: false, // get the style information from getattribute // (ie uses .csstext insted) style: false, // make sure that urls aren't manipulated // (ie normalizes it by default) hrefnormalized: false, // make sure that element opacity exists // (ie uses filter instead) // use a regex to work around a webkit issue. see #5145 opacity: false, // verify style float existence // (ie uses stylefloat instead of cssfloat) cssfloat: false, // make sure that if no value is specified for a checkbox // that it defaults to "on". // (webkit defaults to "" instead) checkon: false, // 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) optselected: false, // will be defined later checkclone: false, scripteval: false, nocloneevent: false, boxmodel: false }; // script.type = "text/javascript"; // try { // script.appendchild( document.createtextnode( "window." + id + "=1;" ) ); // } catch(e) {} // root.insertbefore( script, root.firstchild ); // // make sure that the execution of code works by injecting a script // // tag with appendchild/createtextnode // // (ie doesn't support this, fails, and uses .text instead) // if ( window[ id ] ) { // jquery.support.scripteval = true; // delete window[ id ]; // } // root.removechild( script ); // if ( div.attachevent && div.fireevent ) { // div.attachevent("onclick", function click() { // // cloning a node shouldn't copy over any // // bound event handlers (ie does this) // jquery.support.nocloneevent = false; // div.detachevent("onclick", click); // }); // div.clonenode(true).fireevent("onclick"); // } // div = document.createelement("div"); // div.innerhtml = ""; // var fragment = document.createdocumentfragment(); // fragment.appendchild( div.firstchild ); // // webkit doesn't clone checked state correctly in fragments // jquery.support.checkclone = fragment.clonenode(true).clonenode(true).lastchild.checked; // // figure out if the w3c box model works as expected // // document.body must exist before we can do this // jquery(function() { // var div = document.createelement("div"); // div.style.width = div.style.paddingleft = "1px"; // document.body.appendchild( div ); // jquery.boxmodel = jquery.support.boxmodel = div.offsetwidth === 2; // document.body.removechild( div ).style.display = 'none'; // div = null; // }); // // technique from juriy zaytsev // // http://thinkweb2.com/projects/prototype/detecting-event-support-without-browser-sniffing/ // var eventsupported = function( eventname ) { // var el = document.createelement("div"); // eventname = "on" + eventname; // var issupported = (eventname in el); // if ( !issupported ) { // el.setattribute(eventname, "return;"); // issupported = typeof el[eventname] === "function"; // } // el = null; // return issupported; // }; jquery.support.submitbubbles = false; jquery.support.changebubbles = false; // // release memory in ie // root = script = div = all = a = null; })(); jquery.props = { "for": "htmlfor", "class": "classname", readonly: "readonly", maxlength: "maxlength", cellspacing: "cellspacing", rowspan: "rowspan", colspan: "colspan", tabindex: "tabindex", usemap: "usemap", frameborder: "frameborder" }; var expando = "jquery" + now(), uuid = 0, windowdata = {}; var emptyobject = {}; jquery.extend({ cache: {}, expando:expando, // the following elements throw uncatchable exceptions if you // attempt to add expando properties to them. nodata: { "embed": true, "object": true, "applet": true }, data: function( elem, name, data ) { /// /// 存储与指定元素关联的任意数据。 /// /// /// 要与数据关联的 dom 元素。 /// /// /// 用于指定要设置的数据块的字符串。 /// /// /// 新的数据值。 /// /// if ( elem.nodename && jquery.nodata[elem.nodename.tolowercase()] ) { return; } elem = elem == window ? windowdata : elem; var id = elem[ expando ], cache = jquery.cache, thiscache; // handle the case where there's no name immediately if ( !name && !id ) { return null; } // compute a unique id for the element if ( !id ) { id = ++uuid; } // avoid generating a new cache unless none exists and we // want to manipulate it. if ( typeof name === "object" ) { elem[ expando ] = id; thiscache = cache[ id ] = jquery.extend(true, {}, name); } else if ( cache[ id ] ) { thiscache = cache[ id ]; } else if ( typeof data === "undefined" ) { thiscache = emptyobject; } else { thiscache = cache[ id ] = {}; } // prevent overriding the named cache with undefined values if ( data !== undefined ) { elem[ expando ] = id; thiscache[ name ] = data; } return typeof name === "string" ? thiscache[ name ] : thiscache; }, removedata: function( elem, name ) { if ( elem.nodename && jquery.nodata[elem.nodename.tolowercase()] ) { return; } elem = elem == window ? windowdata : elem; var id = elem[ expando ], cache = jquery.cache, thiscache = cache[ id ]; // if we want to remove a specific section of the element's data if ( name ) { if ( thiscache ) { // remove the section of cache data delete thiscache[ name ]; // if we've removed all the data, remove the element's cache if ( jquery.isemptyobject(thiscache) ) { jquery.removedata( elem ); } } // otherwise, we want to remove all of the element's data } else { // clean up the element expando try { delete elem[ expando ]; } catch( e ) { // ie has trouble directly removing the expando // but it's ok with using removeattribute if ( elem.removeattribute ) { elem.removeattribute( expando ); } } // completely remove the data cache delete cache[ id ]; } } }); jquery.fn.extend({ data: function( key, value ) { /// /// 存储与匹配元素关联的任意数据。 /// /// /// 用于指定要设置的数据块的字符串。 /// /// /// 新的数据值。 /// /// if ( typeof key === "undefined" && this.length ) { return jquery.data( this[0] ); } else if ( typeof key === "object" ) { return this.each(function() { jquery.data( this, key ); }); } var parts = key.split("."); parts[1] = parts[1] ? "." + parts[1] : ""; if ( value === undefined ) { var data = this.triggerhandler("getdata" + parts[1] + "!", [parts[0]]); if ( data === undefined && this.length ) { data = jquery.data( this[0], key ); } return data === undefined && parts[1] ? this.data( parts[0] ) : data; } else { return this.trigger("setdata" + parts[1] + "!", [parts[0], value]).each(function() { jquery.data( this, key, value ); }); } }, removedata: function( key ) { return this.each(function() { jquery.removedata( this, key ); }); } }); jquery.extend({ queue: function( elem, type, data ) { if ( !elem ) { return; } type = (type || "fx") + "queue"; var q = jquery.data( elem, type ); // speed up dequeue by getting out quickly if this is just a lookup if ( !data ) { return q || []; } if ( !q || jquery.isarray(data) ) { q = jquery.data( elem, type, jquery.makearray(data) ); } else { q.push( data ); } return q; }, dequeue: function( elem, type ) { type = type || "fx"; var queue = jquery.queue( elem, type ), fn = queue.shift(); // if the fx queue is dequeued, always remove the progress sentinel if ( fn === "inprogress" ) { fn = queue.shift(); } if ( fn ) { // add a progress sentinel to prevent the fx queue from being // automatically dequeued if ( type === "fx" ) { queue.unshift("inprogress"); } fn.call(elem, function() { jquery.dequeue(elem, type); }); } } }); jquery.fn.extend({ queue: function( type, data ) { /// /// 1: queue() - 返回对第一个元素的队列的引用(这是一个函数数组)。 /// 2: queue(callback) - 在所有匹配元素的队列结尾处添加一个将要执行的新函数。 /// 3: queue(queue) - 将所有匹配元素的队列替换为此新队列(函数组成的数组)。 /// /// 要添加到队列中的函数。 /// if ( typeof type !== "string" ) { data = type; type = "fx"; } if ( data === undefined ) { return jquery.queue( this[0], type ); } return this.each(function( i, elem ) { var queue = jquery.queue( this, type, data ); if ( type === "fx" && queue[0] !== "inprogress" ) { jquery.dequeue( this, type ); } }); }, dequeue: function( type ) { /// /// 从队列的前面移除一个排队函数并执行该函数。 /// /// 要访问的队列的类型。 /// return this.each(function() { jquery.dequeue( this, type ); }); }, // based off of the plugin by clint helfers, with permission. // http://blindsignals.com/index.php/2009/07/jquery-delay/ delay: function( time, type ) { /// /// 设置计时器以延迟执行队列中的后续项。 /// /// /// 一个整数,它指示延迟执行队列中下一项的毫秒数。 /// /// /// 一个包含队列名称的字符串。默认设置为 fx (标准效果队列)。 /// /// time = jquery.fx ? jquery.fx.speeds[time] || time : time; type = type || "fx"; return this.queue( type, function() { var elem = this; settimeout(function() { jquery.dequeue( elem, type ); }, time ); }); }, clearqueue: function( type ) { /// /// 从队列中移除尚未运行的所有项。 /// /// /// 一个包含队列名称的字符串。默认设置为 fx (标准效果队列)。 /// /// return this.queue( type || "fx", [] ); } }); var rclass = /[\n\t]/g, rspace = /\s+/, rreturn = /\r/g, rspecialurl = /href|src|style/, rtype = /(button|input)/i, rfocusable = /(button|input|object|select|textarea)/i, rclickable = /^(a|area)$/i, rradiocheck = /radio|checkbox/; jquery.fn.extend({ attr: function( name, value ) { /// /// 将所有匹配元素的单个属性设置为计算值。 /// 提供用于计算值的函数,而不是值。 /// dom/特性部分 /// /// /// /// 要设置的属性的名称。 /// /// /// 返回要设置的值的函数。 /// return access( this, name, value, true, jquery.attr ); }, removeattr: function( name, fn ) { /// /// 从每个匹配元素中移除某个特性。 /// dom/特性部分 /// /// /// 要移除的特性。 /// /// return this.each(function(){ jquery.attr( this, name, "" ); if ( this.nodetype === 1 ) { this.removeattribute( name ); } }); }, addclass: function( value ) { /// /// 将指定的类添加到每个匹配元素集中。 /// dom/特性部分 /// /// /// 要添加到每个匹配元素的类特性中的一个或多个类名称。 /// /// if ( jquery.isfunction(value) ) { return this.each(function(i) { var self = jquery(this); self.addclass( value.call(this, i, self.attr("class")) ); }); } if ( value && typeof value === "string" ) { var classnames = (value || "").split( rspace ); for ( var i = 0, l = this.length; i < l; i++ ) { var elem = this[i]; if ( elem.nodetype === 1 ) { if ( !elem.classname ) { elem.classname = value; } else { var classname = " " + elem.classname + " "; for ( var c = 0, cl = classnames.length; c < cl; c++ ) { if ( classname.indexof( " " + classnames[c] + " " ) < 0 ) { elem.classname += " " + classnames[c]; } } } } } } return this; }, removeclass: function( value ) { /// /// 从匹配元素集中移除所有的或指定的类。 /// dom/特性部分 /// /// /// (可选)将从每个匹配元素的类特性中移除的类名称。 /// /// if ( jquery.isfunction(value) ) { return this.each(function(i) { var self = jquery(this); self.removeclass( value.call(this, i, self.attr("class")) ); }); } if ( (value && typeof value === "string") || value === undefined ) { var classnames = (value || "").split(rspace); for ( var i = 0, l = this.length; i < l; i++ ) { var elem = this[i]; if ( elem.nodetype === 1 && elem.classname ) { if ( value ) { var classname = (" " + elem.classname + " ").replace(rclass, " "); for ( var c = 0, cl = classnames.length; c < cl; c++ ) { classname = classname.replace(" " + classnames[c] + " ", " "); } elem.classname = classname.substring(1, classname.length - 1); } else { elem.classname = ""; } } } } return this; }, toggleclass: function( value, stateval ) { /// /// 在匹配元素集的每个元素中添加或移除某个类,具体取决于 /// 该类是否存在或开关参数的值。 /// /// /// 要针对匹配集中的每个元素进行切换的类名称。 /// /// /// 一个用于确定是应添加还是应移除类的布尔值。 /// /// var type = typeof value, isbool = typeof stateval === "boolean"; if ( jquery.isfunction( value ) ) { return this.each(function(i) { var self = jquery(this); self.toggleclass( value.call(this, i, self.attr("class"), stateval), stateval ); }); } return this.each(function() { if ( type === "string" ) { // toggle individual class names var classname, i = 0, self = jquery(this), state = stateval, classnames = value.split( rspace ); while ( (classname = classnames[ i++ ]) ) { // check each classname given, space seperated list state = isbool ? state : !self.hasclass( classname ); self[ state ? "addclass" : "removeclass" ]( classname ); } } else if ( type === "undefined" || type === "boolean" ) { if ( this.classname ) { // store classname if set jquery.data( this, "__classname__", this.classname ); } // toggle whole classname this.classname = this.classname || value === false ? "" : jquery.data( this, "__classname__" ) || ""; } }); }, hasclass: function( selector ) { /// /// 根据某个类检查当前选择,并返回是否至少有一个选择具有给定的类。 /// /// 要作为检查依据的类 /// 如果选择中至少有一个元素具有给定的类,则返回 true;否则返回 false。 var classname = " " + selector + " "; for ( var i = 0, l = this.length; i < l; i++ ) { if ( (" " + this[i].classname + " ").replace(rclass, " ").indexof( classname ) > -1 ) { return true; } } return false; }, val: function( value ) { /// /// 设置每个匹配元素的值。 /// dom/特性部分 /// /// /// /// 要设置为每个匹配元素的值属性的文本字符串或 /// 字符串数组。 /// if ( value === undefined ) { var elem = this[0]; if ( elem ) { if ( jquery.nodename( elem, "option" ) ) { return (elem.attributes.value || {}).specified ? elem.value : elem.text; } // we need to handle select boxes special if ( jquery.nodename( elem, "select" ) ) { var index = elem.selectedindex, values = [], options = elem.options, one = elem.type === "select-one"; // nothing was selected if ( index < 0 ) { return null; } // loop through all the selected options for ( var i = one ? index : 0, max = one ? index + 1 : options.length; i < max; i++ ) { var option = options[ i ]; if ( option.selected ) { // get the specifc value for the option value = jquery(option).val(); // we don't need an array for one selects if ( one ) { return value; } // multi-selects return an array values.push( value ); } } return values; } // handle the case where in webkit "" is returned instead of "on" if a value isn't specified if ( rradiocheck.test( elem.type ) && !jquery.support.checkon ) { return elem.getattribute("value") === null ? "on" : elem.value; } // everything else, we just grab the value return (elem.value || "").replace(rreturn, ""); } return undefined; } var isfunction = jquery.isfunction(value); return this.each(function(i) { var self = jquery(this), val = value; if ( this.nodetype !== 1 ) { return; } if ( isfunction ) { val = value.call(this, i, self.val()); } // typecast each time if the value is a function and the appended // value is therefore different each time. if ( typeof val === "number" ) { val += ""; } if ( jquery.isarray(val) && rradiocheck.test( this.type ) ) { this.checked = jquery.inarray( self.val(), val ) >= 0; } else if ( jquery.nodename( this, "select" ) ) { var values = jquery.makearray(val); jquery( "option", this ).each(function() { this.selected = jquery.inarray( jquery(this).val(), values ) >= 0; }); if ( !values.length ) { this.selectedindex = -1; } } else { this.value = val; } }); } }); jquery.extend({ attrfn: { val: true, css: true, html: true, text: true, data: true, width: true, height: true, offset: true }, attr: function( elem, name, value, pass ) { /// /// 此方法为内部方法。 /// /// // don't set attributes on text and comment nodes if ( !elem || elem.nodetype === 3 || elem.nodetype === 8 ) { return undefined; } if ( pass && name in jquery.attrfn ) { return jquery(elem)[name](value); } var notxml = elem.nodetype !== 1 || !jquery.isxmldoc( elem ), // whether we are setting (or getting) set = value !== undefined; // try to normalize/fix the name name = notxml && jquery.props[ name ] || name; // only do all the following if this is a node (faster for style) if ( elem.nodetype === 1 ) { // these attributes require special treatment var special = rspecialurl.test( name ); // safari mis-reports the default selected property of an option // accessing the parent's selectedindex property fixes it if ( name === "selected" && !jquery.support.optselected ) { var parent = elem.parentnode; if ( parent ) { parent.selectedindex; // make sure that it also works with optgroups, see #5701 if ( parent.parentnode ) { parent.parentnode.selectedindex; } } } // if applicable, access the attribute via the dom 0 way if ( name in elem && notxml && !special ) { if ( set ) { // we can't allow the type property to be changed (since it causes problems in ie) if ( name === "type" && rtype.test( elem.nodename ) && elem.parentnode ) { jquery.error( "type property can't be changed" ); } elem[ name ] = value; } // browsers index elements by id/name on forms, give priority to attributes. if ( jquery.nodename( elem, "form" ) && elem.getattributenode(name) ) { return elem.getattributenode( name ).nodevalue; } // elem.tabindex doesn't always return the correct value when it hasn't been explicitly set // http://fluidproject.org/blog/2008/01/09/getting-setting-and-removing-tabindex-values-with-javascript/ if ( name === "tabindex" ) { var attributenode = elem.getattributenode( "tabindex" ); return attributenode && attributenode.specified ? attributenode.value : rfocusable.test( elem.nodename ) || rclickable.test( elem.nodename ) && elem.href ? 0 : undefined; } return elem[ name ]; } if ( !jquery.support.style && notxml && name === "style" ) { if ( set ) { elem.style.csstext = "" + value; } return elem.style.csstext; } if ( set ) { // convert the value to a string (all browsers do this but ie) see #1070 elem.setattribute( name, "" + value ); } var attr = !jquery.support.hrefnormalized && notxml && special ? // some attributes require a special call on ie elem.getattribute( name, 2 ) : elem.getattribute( name ); // non-existent attributes return null, we normalize to undefined return attr === null ? undefined : attr; } // elem is actually elem.style ... set the style // using attr for specific style information is now deprecated. use style insead. return jquery.style( elem, name, value ); } }); var fcleanup = function( nm ) { return nm.replace(/[^\w\s\.\|`]/g, function( ch ) { return "\\" + ch; }); }; /* * a number of helper functions used for managing events. * many of the ideas behind this code originated from * dean edwards' addevent library. */ jquery.event = { // bind an event to an element // original by dean edwards add: function( elem, types, handler, data ) { /// /// 此方法为内部方法。 /// /// if ( elem.nodetype === 3 || elem.nodetype === 8 ) { return; } // for whatever reason, ie has trouble passing the window object // around, causing it to be cloned in the process if ( elem.setinterval && ( elem !== window && !elem.frameelement ) ) { elem = window; } // make sure that the function being executed has a unique id if ( !handler.guid ) { handler.guid = jquery.guid++; } // if data is passed, bind to handler if ( data !== undefined ) { // create temporary function pointer to original handler var fn = handler; // create unique handler function, wrapped around original handler handler = jquery.proxy( fn ); // store data in unique handler handler.data = data; } // init the element's event structure var events = jquery.data( elem, "events" ) || jquery.data( elem, "events", {} ), handle = jquery.data( elem, "handle" ), eventhandle; if ( !handle ) { eventhandle = function() { // handle the second event of a trigger and when // an event is called after a page has unloaded return typeof jquery !== "undefined" && !jquery.event.triggered ? jquery.event.handle.apply( eventhandle.elem, arguments ) : undefined; }; handle = jquery.data( elem, "handle", eventhandle ); } // if no handle is found then we must be trying to bind to one of the // banned nodata elements if ( !handle ) { return; } // add elem as a property of the handle function // this is to prevent a memory leak with non-native // event in ie. handle.elem = elem; // handle multiple events separated by a space // jquery(...).bind("mouseover mouseout", fn); types = types.split( /\s+/ ); var type, i = 0; while ( (type = types[ i++ ]) ) { // namespaced event handlers var namespaces = type.split("."); type = namespaces.shift(); if ( i > 1 ) { handler = jquery.proxy( handler ); if ( data !== undefined ) { handler.data = data; } } handler.type = namespaces.slice(0).sort().join("."); // get the current list of functions bound to this event var handlers = events[ type ], special = this.special[ type ] || {}; // init the event handler queue if ( !handlers ) { handlers = events[ type ] = {}; // check for a special event handler // only use addeventlistener/attachevent if the special // events handler returns false if ( !special.setup || special.setup.call( elem, data, namespaces, handler) === false ) { // bind the global event handler to the element if ( elem.addeventlistener ) { elem.addeventlistener( type, handle, false ); } else if ( elem.attachevent ) { elem.attachevent( "on" + type, handle ); } } } if ( special.add ) { var modifiedhandler = special.add.call( elem, handler, data, namespaces, handlers ); if ( modifiedhandler && jquery.isfunction( modifiedhandler ) ) { modifiedhandler.guid = modifiedhandler.guid || handler.guid; modifiedhandler.data = modifiedhandler.data || handler.data; modifiedhandler.type = modifiedhandler.type || handler.type; handler = modifiedhandler; } } // add the function to the element's handler list handlers[ handler.guid ] = handler; // keep track of which events have been used, for global triggering this.global[ type ] = true; } // nullify elem to prevent memory leaks in ie elem = null; }, global: {}, // detach an event or set of events from an element remove: function( elem, types, handler ) { /// /// 此方法为内部方法。 /// /// // don't do events on text and comment nodes if ( elem.nodetype === 3 || elem.nodetype === 8 ) { return; } var events = jquery.data( elem, "events" ), ret, type, fn; if ( events ) { // unbind all events for the element if ( types === undefined || (typeof types === "string" && types.charat(0) === ".") ) { for ( type in events ) { this.remove( elem, type + (types || "") ); } } else { // types is actually an event object here if ( types.type ) { handler = types.handler; types = types.type; } // handle multiple events separated by a space // jquery(...).unbind("mouseover mouseout", fn); types = types.split(/\s+/); var i = 0; while ( (type = types[ i++ ]) ) { // namespaced event handlers var namespaces = type.split("."); type = namespaces.shift(); var all = !namespaces.length, cleaned = jquery.map( namespaces.slice(0).sort(), fcleanup ), namespace = new regexp("(^|\\.)" + cleaned.join("\\.(?:.*\\.)?") + "(\\.|$)"), special = this.special[ type ] || {}; if ( events[ type ] ) { // remove the given handler for the given type if ( handler ) { fn = events[ type ][ handler.guid ]; delete events[ type ][ handler.guid ]; // remove all handlers for the given type } else { for ( var handle in events[ type ] ) { // handle the removal of namespaced events if ( all || namespace.test( events[ type ][ handle ].type ) ) { delete events[ type ][ handle ]; } } } if ( special.remove ) { special.remove.call( elem, namespaces, fn); } // remove generic event handler if no more handlers exist for ( ret in events[ type ] ) { break; } if ( !ret ) { if ( !special.teardown || special.teardown.call( elem, namespaces ) === false ) { if ( elem.removeeventlistener ) { elem.removeeventlistener( type, jquery.data( elem, "handle" ), false ); } else if ( elem.detachevent ) { elem.detachevent( "on" + type, jquery.data( elem, "handle" ) ); } } ret = null; delete events[ type ]; } } } } // remove the expando if it's no longer used for ( ret in events ) { break; } if ( !ret ) { var handle = jquery.data( elem, "handle" ); if ( handle ) { handle.elem = null; } jquery.removedata( elem, "events" ); jquery.removedata( elem, "handle" ); } } }, // bubbling is internal trigger: function( event, data, elem /*, bubbling */ ) { /// /// this method is internal. /// /// // event object or event type var type = event.type || event, bubbling = arguments[3]; if ( !bubbling ) { event = typeof event === "object" ? // jquery.event object event[expando] ? event : // object literal jquery.extend( jquery.event(type), event ) : // just the event type (string) jquery.event(type); if ( type.indexof("!") >= 0 ) { event.type = type = type.slice(0, -1); event.exclusive = true; } // handle a global trigger if ( !elem ) { // don't bubble custom events when global (to avoid too much overhead) event.stoppropagation(); // only trigger if we've ever bound an event for it if ( this.global[ type ] ) { jquery.each( jquery.cache, function() { if ( this.events && this.events[type] ) { jquery.event.trigger( event, data, this.handle.elem ); } }); } } // handle triggering a single element // don't do events on text and comment nodes if ( !elem || elem.nodetype === 3 || elem.nodetype === 8 ) { return undefined; } // clean up in case it is reused event.result = undefined; event.target = elem; // clone the incoming data, if any data = jquery.makearray( data ); data.unshift( event ); } event.currenttarget = elem; // trigger the event, it is assumed that "handle" is a function var handle = jquery.data( elem, "handle" ); if ( handle ) { handle.apply( elem, data ); } var parent = elem.parentnode || elem.ownerdocument; // trigger an inline bound script try { if ( !(elem && elem.nodename && jquery.nodata[elem.nodename.tolowercase()]) ) { if ( elem[ "on" + type ] && elem[ "on" + type ].apply( elem, data ) === false ) { event.result = false; } } // prevent ie from throwing an error for some elements with some event types, see #3533 } catch (e) {} if ( !event.ispropagationstopped() && parent ) { jquery.event.trigger( event, data, parent, true ); } else if ( !event.isdefaultprevented() ) { var target = event.target, old, isclick = jquery.nodename(target, "a") && type === "click"; if ( !isclick && !(target && target.nodename && jquery.nodata[target.nodename.tolowercase()]) ) { try { if ( target[ type ] ) { // make sure that we don't accidentally re-trigger the onfoo events old = target[ "on" + type ]; if ( old ) { target[ "on" + type ] = null; } this.triggered = true; target[ type ](); } // prevent ie from throwing an error for some elements with some event types, see #3533 } catch (e) {} if ( old ) { target[ "on" + type ] = old; } this.triggered = false; } } }, handle: function( event ) { /// /// 此方法为内部方法。 /// /// // returned undefined or false var all, handlers; event = arguments[0] = jquery.event.fix( event || window.event ); event.currenttarget = this; // namespaced event handlers var namespaces = event.type.split("."); event.type = namespaces.shift(); // cache this now, all = true means, any handler all = !namespaces.length && !event.exclusive; var namespace = new regexp("(^|\\.)" + namespaces.slice(0).sort().join("\\.(?:.*\\.)?") + "(\\.|$)"); handlers = ( jquery.data(this, "events") || {} )[ event.type ]; for ( var j in handlers ) { var handler = handlers[ j ]; // filter the functions by class if ( all || namespace.test(handler.type) ) { // pass in a reference to the handler function itself // so that we can later remove it event.handler = handler; event.data = handler.data; var ret = handler.apply( this, arguments ); if ( ret !== undefined ) { event.result = ret; if ( ret === false ) { event.preventdefault(); event.stoppropagation(); } } if ( event.isimmediatepropagationstopped() ) { break; } } } return event.result; }, props: "altkey attrchange attrname bubbles button cancelable charcode clientx clienty ctrlkey currenttarget data detail eventphase fromelement handler keycode layerx layery metakey newvalue offsetx offsety originaltarget pagex pagey prevvalue relatednode relatedtarget screenx screeny shiftkey srcelement target toelement view wheeldelta which".split(" "), fix: function( event ) { /// /// 此方法为内部方法。 /// /// if ( event[ expando ] ) { return event; } // store a copy of the original event object // and "clone" to set read-only properties var originalevent = event; event = jquery.event( originalevent ); for ( var i = this.props.length, prop; i; ) { prop = this.props[ --i ]; event[ prop ] = originalevent[ prop ]; } // fix target property, if necessary if ( !event.target ) { event.target = event.srcelement || document; // fixes #1925 where srcelement might not be defined either } // check if target is a textnode (safari) if ( event.target.nodetype === 3 ) { event.target = event.target.parentnode; } // add relatedtarget, if necessary if ( !event.relatedtarget && event.fromelement ) { event.relatedtarget = event.fromelement === event.target ? event.toelement : event.fromelement; } // calculate pagex/y if missing and clientx/y available if ( event.pagex == null && event.clientx != null ) { var doc = document.documentelement, body = document.body; event.pagex = event.clientx + (doc && doc.scrollleft || body && body.scrollleft || 0) - (doc && doc.clientleft || body && body.clientleft || 0); event.pagey = event.clienty + (doc && doc.scrolltop || body && body.scrolltop || 0) - (doc && doc.clienttop || body && body.clienttop || 0); } // add which for key events if ( !event.which && ((event.charcode || event.charcode === 0) ? event.charcode : event.keycode) ) { event.which = event.charcode || event.keycode; } // add metakey to non-mac browsers (use ctrl for pc's and meta for macs) if ( !event.metakey && event.ctrlkey ) { event.metakey = event.ctrlkey; } // add which for click: 1 === left; 2 === middle; 3 === right // note: button is not normalized, so don't use it if ( !event.which && event.button !== undefined ) { event.which = (event.button & 1 ? 1 : ( event.button & 2 ? 3 : ( event.button & 4 ? 2 : 0 ) )); } return event; }, // deprecated, use jquery.guid instead guid: 1e8, // deprecated, use jquery.proxy instead proxy: jquery.proxy, special: { ready: { // make sure the ready event is setup setup: jquery.bindready, teardown: jquery.noop }, live: { add: function( proxy, data, namespaces, live ) { jquery.extend( proxy, data || {} ); proxy.guid += data.selector + data.live; data.liveproxy = proxy; jquery.event.add( this, data.live, livehandler, data ); }, remove: function( namespaces ) { if ( namespaces.length ) { var remove = 0, name = new regexp("(^|\\.)" + namespaces[0] + "(\\.|$)"); jquery.each( (jquery.data(this, "events").live || {}), function() { if ( name.test(this.type) ) { remove++; } }); if ( remove < 1 ) { jquery.event.remove( this, namespaces[0], livehandler ); } } }, special: {} }, beforeunload: { setup: function( data, namespaces, fn ) { // we only want to do this special case on windows if ( this.setinterval ) { this.onbeforeunload = fn; } return false; }, teardown: function( namespaces, fn ) { if ( this.onbeforeunload === fn ) { this.onbeforeunload = null; } } } } }; jquery.event = function( src ) { // allow instantiation without the 'new' keyword if ( !this.preventdefault ) { return new jquery.event( src ); } // event object if ( src && src.type ) { this.originalevent = src; this.type = src.type; // event type } else { this.type = src; } // timestamp is buggy for some events on firefox(#3843) // so we won't rely on the native value this.timestamp = now(); // mark it as fixed this[ expando ] = true; }; function returnfalse() { return false; } function returntrue() { return true; } // jquery.event is based on dom3 events as specified by the ecmascript language binding // http://www.w3.org/tr/2003/wd-dom-level-3-events-20030331/ecma-script-binding.html jquery.event.prototype = { preventdefault: function() { this.isdefaultprevented = returntrue; var e = this.originalevent; if ( !e ) { return; } // if preventdefault exists run it on the original event if ( e.preventdefault ) { e.preventdefault(); } // otherwise set the returnvalue property of the original event to false (ie) e.returnvalue = false; }, stoppropagation: function() { this.ispropagationstopped = returntrue; var e = this.originalevent; if ( !e ) { return; } // if stoppropagation exists run it on the original event if ( e.stoppropagation ) { e.stoppropagation(); } // otherwise set the cancelbubble property of the original event to true (ie) e.cancelbubble = true; }, stopimmediatepropagation: function() { this.isimmediatepropagationstopped = returntrue; this.stoppropagation(); }, isdefaultprevented: returnfalse, ispropagationstopped: returnfalse, isimmediatepropagationstopped: returnfalse }; // checks if an event happened on an element within another element // used in jquery.event.special.mouseenter and mouseleave handlers var withinelement = function( event ) { // check if mouse(over|out) are still within the same parent element var parent = event.relatedtarget; // traverse up the tree while ( parent && parent !== this ) { // firefox sometimes assigns relatedtarget a xul element // which we cannot access the parentnode property of try { parent = parent.parentnode; // assuming we've left the element since we most likely mousedover a xul element } catch(e) { break; } } if ( parent !== this ) { // set the correct event type event.type = event.data; // handle event if we actually just moused on to a non sub-element jquery.event.handle.apply( this, arguments ); } }, // in case of event delegation, we only need to rename the event.type, // livehandler will take care of the rest. delegate = function( event ) { event.type = event.data; jquery.event.handle.apply( this, arguments ); }; // create mouseenter and mouseleave events jquery.each({ mouseenter: "mouseover", mouseleave: "mouseout" }, function( orig, fix ) { jquery.event.special[ orig ] = { setup: function( data ) { jquery.event.add( this, fix, data && data.selector ? delegate : withinelement, orig ); }, teardown: function( data ) { jquery.event.remove( this, fix, data && data.selector ? delegate : withinelement ); } }; }); // submit delegation if ( !jquery.support.submitbubbles ) { jquery.event.special.submit = { setup: function( data, namespaces, fn ) { if ( this.nodename.tolowercase() !== "form" ) { jquery.event.add(this, "click.specialsubmit." + fn.guid, function( e ) { var elem = e.target, type = elem.type; if ( (type === "submit" || type === "image") && jquery( elem ).closest("form").length ) { return trigger( "submit", this, arguments ); } }); jquery.event.add(this, "keypress.specialsubmit." + fn.guid, function( e ) { var elem = e.target, type = elem.type; if ( (type === "text" || type === "password") && jquery( elem ).closest("form").length && e.keycode === 13 ) { return trigger( "submit", this, arguments ); } }); } else { return false; } }, remove: function( namespaces, fn ) { jquery.event.remove( this, "click.specialsubmit" + (fn ? "."+fn.guid : "") ); jquery.event.remove( this, "keypress.specialsubmit" + (fn ? "."+fn.guid : "") ); } }; } // change delegation, happens here so we have bind. if ( !jquery.support.changebubbles ) { var formelems = /textarea|input|select/i; function getval( elem ) { var type = elem.type, val = elem.value; if ( type === "radio" || type === "checkbox" ) { val = elem.checked; } else if ( type === "select-multiple" ) { val = elem.selectedindex > -1 ? jquery.map( elem.options, function( elem ) { return elem.selected; }).join("-") : ""; } else if ( elem.nodename.tolowercase() === "select" ) { val = elem.selectedindex; } return val; } function testchange( e ) { var elem = e.target, data, val; if ( !formelems.test( elem.nodename ) || elem.readonly ) { return; } data = jquery.data( elem, "_change_data" ); val = getval(elem); // the current data will be also retrieved by beforeactivate if ( e.type !== "focusout" || elem.type !== "radio" ) { jquery.data( elem, "_change_data", val ); } if ( data === undefined || val === data ) { return; } if ( data != null || val ) { e.type = "change"; return jquery.event.trigger( e, arguments[1], elem ); } } jquery.event.special.change = { filters: { focusout: testchange, click: function( e ) { var elem = e.target, type = elem.type; if ( type === "radio" || type === "checkbox" || elem.nodename.tolowercase() === "select" ) { return testchange.call( this, e ); } }, // change has to be called before submit // keydown will be called before keypress, which is used in submit-event delegation keydown: function( e ) { var elem = e.target, type = elem.type; if ( (e.keycode === 13 && elem.nodename.tolowercase() !== "textarea") || (e.keycode === 32 && (type === "checkbox" || type === "radio")) || type === "select-multiple" ) { return testchange.call( this, e ); } }, // beforeactivate happens also before the previous element is blurred // with this event you can't trigger a change event, but you can store // information/focus[in] is not needed anymore beforeactivate: function( e ) { var elem = e.target; if ( elem.nodename.tolowercase() === "input" && elem.type === "radio" ) { jquery.data( elem, "_change_data", getval(elem) ); } } }, setup: function( data, namespaces, fn ) { for ( var type in changefilters ) { jquery.event.add( this, type + ".specialchange." + fn.guid, changefilters[type] ); } return formelems.test( this.nodename ); }, remove: function( namespaces, fn ) { for ( var type in changefilters ) { jquery.event.remove( this, type + ".specialchange" + (fn ? "."+fn.guid : ""), changefilters[type] ); } return formelems.test( this.nodename ); } }; var changefilters = jquery.event.special.change.filters; } function trigger( type, elem, args ) { args[0].type = type; return jquery.event.handle.apply( elem, args ); } // create "bubbling" focus and blur events if ( document.addeventlistener ) { jquery.each({ focus: "focusin", blur: "focusout" }, function( orig, fix ) { jquery.event.special[ fix ] = { setup: function() { /// /// 此方法为内部方法。 /// /// this.addeventlistener( orig, handler, true ); }, teardown: function() { /// /// 此方法为内部方法。 /// /// this.removeeventlistener( orig, handler, true ); } }; function handler( e ) { e = jquery.event.fix( e ); e.type = fix; return jquery.event.handle.call( this, e ); } }); } // jquery.each(["bind", "one"], function( i, name ) { // jquery.fn[ name ] = function( type, data, fn ) { // // handle object literals // if ( typeof type === "object" ) { // for ( var key in type ) { // this[ name ](key, data, type[key], fn); // } // return this; // } // // if ( jquery.isfunction( data ) ) { // fn = data; // data = undefined; // } // // var handler = name === "one" ? jquery.proxy( fn, function( event ) { // jquery( this ).unbind( event, handler ); // return fn.apply( this, arguments ); // }) : fn; // // return type === "unload" && name !== "one" ? // this.one( type, data, fn ) : // this.each(function() { // jquery.event.add( this, type, handler, data ); // }); // }; // }); jquery.fn[ "bind" ] = function( type, data, fn ) { /// /// 将处理程序绑定到每个匹配元素的一个或多个事件。也可以绑定自定义事件。 /// /// 由空格分隔的一个或多个事件类型。内置事件类型值有: blur、focus、load、resize、scroll、unload、click、dblclick、mousedown、mouseup、mousemove、mouseover、mouseout、mouseenter、mouseleave、change、select、submit、keydown、keypress、keyup、error。 /// 作为 event.data 传递给事件处理程序的其他数据 /// 要绑定到每个匹配元素集上的事件的函数。例如 callback(eventobject)这样的函数对应于 dom 元素。 // 处理对象文本 if ( typeof type === "object" ) { for ( var key in type ) { this[ "bind" ](key, data, type[key], fn); } return this; } if ( jquery.isfunction( data ) ) { fn = data; data = undefined; } var handler = "bind" === "one" ? jquery.proxy( fn, function( event ) { jquery( this ).unbind( event, handler ); return fn.apply( this, arguments ); }) : fn; return type === "unload" && "bind" !== "one" ? this.one( type, data, fn ) : this.each(function() { jquery.event.add( this, type, handler, data ); }); }; jquery.fn[ "one" ] = function( type, data, fn ) { /// /// 将处理程序绑定到将为每个匹配元素执行一次的一个或多个事件。 /// /// 由空格分隔的一个或多个事件类型。内置事件类型值有: blur、focus、load、resize、scroll、unload、click、dblclick、mousedown、mouseup、mousemove、mouseover、mouseout、mouseenter、mouseleave、change、select、submit、keydown、keypress、keyup、error。 /// 作为 event.data 传递给事件处理程序的其他数据 /// 要绑定到每个匹配元素集上的事件的函数。例如 callback(eventobject)这样的函数对应于 dom 元素。 // handle object literals if ( typeof type === "object" ) { for ( var key in type ) { this[ "one" ](key, data, type[key], fn); } return this; } if ( jquery.isfunction( data ) ) { fn = data; data = undefined; } var handler = "one" === "one" ? jquery.proxy( fn, function( event ) { jquery( this ).unbind( event, handler ); return fn.apply( this, arguments ); }) : fn; return type === "unload" && "one" !== "one" ? this.one( type, data, fn ) : this.each(function() { jquery.event.add( this, type, handler, data ); }); }; jquery.fn.extend({ unbind: function( type, fn ) { /// /// 从每个匹配元素的一个或多个事件取消绑定处理程序。 /// /// 由空格分隔的一个或多个事件类型。内置事件类型值有: blur、focus、load、resize、scroll、unload、click、dblclick、mousedown、mouseup、mousemove、mouseover、mouseout、mouseenter、mouseleave、change、select、submit、keydown、keypress、keyup、error。 /// 要绑定到每个匹配元素集上的事件的函数。例如 callback(eventobject)这样的函数对应于 dom 元素。 // handle object literals if ( typeof type === "object" && !type.preventdefault ) { for ( var key in type ) { this.unbind(key, type[key]); } return this; } return this.each(function() { jquery.event.remove( this, type, fn ); }); }, trigger: function( type, data ) { /// /// 针对每个匹配元素触发一种事件类型。 /// /// 由空格分隔的一个或多个事件类型。内置事件类型值有: blur、focus、load、resize、scroll、unload、click、dblclick、mousedown、mouseup、mousemove、mouseover、mouseout、mouseenter、mouseleave、change、select、submit、keydown、keypress、keyup、error。 /// 作为附加参数传递给事件处理程序的其他数据。 /// 未记录此参数。 return this.each(function() { jquery.event.trigger( type, data, this ); }); }, triggerhandler: function( type, data ) { /// /// 为特定事件类型触发元素上绑定的所有事件处理程序,但不执行浏览器的默认操作。 /// /// 由空格分隔的一个或多个事件类型。内置事件类型值有: blur、focus、load、resize、scroll、unload、click、dblclick、mousedown、mouseup、mousemove、mouseover、mouseout、mouseenter、mouseleave、change、select、submit、keydown、keypress、keyup、error。 /// 作为附加参数传递给事件处理程序的其他数据。 /// 未记录此参数。 if ( this[0] ) { var event = jquery.event( type ); event.preventdefault(); event.stoppropagation(); jquery.event.trigger( event, data, this[0] ); return event.result; } }, toggle: function( fn ) { /// /// 每隔一次单击在两个或两个以上的函数调用中切换一次。 /// /// 要切换执行的函数 // save reference to arguments for access in closure var args = arguments, i = 1; // link all the functions, so any of them can unbind this click handler while ( i < args.length ) { jquery.proxy( fn, args[ i++ ] ); } return this.click( jquery.proxy( fn, function( event ) { // figure out which function to execute var lasttoggle = ( jquery.data( this, "lasttoggle" + fn.guid ) || 0 ) % i; jquery.data( this, "lasttoggle" + fn.guid, lasttoggle + 1 ); // make sure that clicks stop event.preventdefault(); // and execute the function return args[ lasttoggle ].apply( this, arguments ) || false; })); }, hover: function( fnover, fnout ) { /// /// 模拟悬停事件(将鼠标移到对象上或移离对象)。 /// /// 当鼠标移到某个匹配元素上时要激发的函数。 /// 当鼠标离开某个匹配元素时要激发的函数。 return this.mouseenter( fnover ).mouseleave( fnout || fnover ); } }); // jquery.each(["live", "die"], function( i, name ) { // jquery.fn[ name ] = function( types, data, fn ) { // var type, i = 0; // // if ( jquery.isfunction( data ) ) { // fn = data; // data = undefined; // } // // types = (types || "").split( /\s+/ ); // // while ( (type = types[ i++ ]) != null ) { // type = type === "focus" ? "focusin" : // focus --> focusin // type === "blur" ? "focusout" : // blur --> focusout // type === "hover" ? types.push("mouseleave") && "mouseenter" : // hover support // type; // // if ( name === "live" ) { // // bind live handler // jquery( this.context ).bind( liveconvert( type, this.selector ), { // data: data, selector: this.selector, live: type // }, fn ); // // } else { // // unbind live handler // jquery( this.context ).unbind( liveconvert( type, this.selector ), fn ? { guid: fn.guid + this.selector + type } : null ); // } // } // // return this; // } // }); jquery.fn[ "live" ] = function( types, data, fn ) { /// /// 为现在或将来匹配当前选择器的所有元素的事件 /// 附加一个处理程序。 /// /// /// 一个包含 javascript 事件类型(如“click”或“keydown”)的字符串。 /// /// /// 将传递给事件处理程序的数据映射。 /// /// /// 要在触发事件时执行的函数。 /// /// var type, i = 0; if ( jquery.isfunction( data ) ) { fn = data; data = undefined; } types = (types || "").split( /\s+/ ); while ( (type = types[ i++ ]) != null ) { type = type === "focus" ? "focusin" : // focus --> focusin type === "blur" ? "focusout" : // blur --> focusout type === "hover" ? types.push("mouseleave") && "mouseenter" : // hover support type; if ( "live" === "live" ) { // bind live handler jquery( this.context ).bind( liveconvert( type, this.selector ), { data: data, selector: this.selector, live: type }, fn ); } else { // unbind live handler jquery( this.context ).unbind( liveconvert( type, this.selector ), fn ? { guid: fn.guid + this.selector + type } : null ); } } return this; } jquery.fn[ "die" ] = function( types, data, fn ) { /// /// 使用 .live()从元素中移除以前附加的所有事件处理程序。 /// /// /// 一个包含 javascript 事件类型(如 click 或 keydown)的字符串。 /// /// /// 不会再执行的函数。 /// /// var type, i = 0; if ( jquery.isfunction( data ) ) { fn = data; data = undefined; } types = (types || "").split( /\s+/ ); while ( (type = types[ i++ ]) != null ) { type = type === "focus" ? "focusin" : // focus --> focusin type === "blur" ? "focusout" : // blur --> focusout type === "hover" ? types.push("mouseleave") && "mouseenter" : // hover support type; if ( "die" === "live" ) { // bind live handler jquery( this.context ).bind( liveconvert( type, this.selector ), { data: data, selector: this.selector, live: type }, fn ); } else { // unbind live handler jquery( this.context ).unbind( liveconvert( type, this.selector ), fn ? { guid: fn.guid + this.selector + type } : null ); } } return this; } function livehandler( event ) { var stop, elems = [], selectors = [], args = arguments, related, match, fn, elem, j, i, l, data, live = jquery.extend({}, jquery.data( this, "events" ).live); // make sure we avoid non-left-click bubbling in firefox (#3861) if ( event.button && event.type === "click" ) { return; } for ( j in live ) { fn = live[j]; if ( fn.live === event.type || fn.altlive && jquery.inarray(event.type, fn.altlive) > -1 ) { data = fn.data; if ( !(data.beforefilter && data.beforefilter[event.type] && !data.beforefilter[event.type](event)) ) { selectors.push( fn.selector ); } } else { delete live[j]; } } match = jquery( event.target ).closest( selectors, event.currenttarget ); for ( i = 0, l = match.length; i < l; i++ ) { for ( j in live ) { fn = live[j]; elem = match[i].elem; related = null; if ( match[i].selector === fn.selector ) { // those two events require additional checking if ( fn.live === "mouseenter" || fn.live === "mouseleave" ) { related = jquery( event.relatedtarget ).closest( fn.selector )[0]; } if ( !related || related !== elem ) { elems.push({ elem: elem, fn: fn }); } } } } for ( i = 0, l = elems.length; i < l; i++ ) { match = elems[i]; event.currenttarget = match.elem; event.data = match.fn.data; if ( match.fn.apply( match.elem, args ) === false ) { stop = false; break; } } return stop; } function liveconvert( type, selector ) { return "live." + (type ? type + "." : "") + selector.replace(/\./g, "`").replace(/ /g, "&"); } // jquery.each( ("blur focus focusin focusout load resize scroll unload click dblclick " + // "mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave " + // "change select submit keydown keypress keyup error").split(" "), function( i, name ) { // // // handle event binding // jquery.fn[ name ] = function( fn ) { // return fn ? this.bind( name, fn ) : this.trigger( name ); // }; // // if ( jquery.attrfn ) { // jquery.attrfn[ name ] = true; // } // }); jquery.fn[ "blur" ] = function( fn ) { /// /// 1: blur() - 触发每个匹配元素的 blur 事件。 /// 2: blur(fn) - 将函数绑定到每个匹配元素的 blur 事件。 /// /// 要执行的函数。 /// return fn ? this.bind( "blur", fn ) : this.trigger( "blur" ); }; jquery.fn[ "focus" ] = function( fn ) { /// /// 1: focus() - 触发每个匹配元素的 focus 事件。 /// 2: focus(fn) - 将函数绑定到每个匹配元素的 focus 事件。 /// /// 要执行的函数。 /// return fn ? this.bind( "focus", fn ) : this.trigger( "focus" ); }; jquery.fn[ "focusin" ] = function( fn ) { /// /// 将事件处理程序绑定到“focusin”javascript 事件。 /// /// /// 要在每次触发该事件时执行的函数。 /// /// return fn ? this.bind( "focusin", fn ) : this.trigger( "focusin" ); }; jquery.fn[ "focusout" ] = function( fn ) { /// /// 将事件处理程序绑定到“focusout”javascript 事件。 /// /// /// 要在每次触发该事件时执行的函数。 /// /// return fn ? this.bind( "focusout", fn ) : this.trigger( "focusout" ); }; jquery.fn[ "load" ] = function( fn ) { /// /// 1: load() - 触发每个匹配元素的 load 事件。 /// 2: load(fn) - 将函数绑定到每个匹配元素的 load 事件。 /// /// 要执行的函数。 /// return fn ? this.bind( "load", fn ) : this.trigger( "load" ); }; jquery.fn[ "resize" ] = function( fn ) { /// /// 1: resize() - 触发每个匹配元素的 resize 事件。 /// 2: resize(fn) - 将函数绑定到每个匹配元素的 resize 事件。 /// /// 要执行的函数。 /// return fn ? this.bind( "resize", fn ) : this.trigger( "resize" ); }; jquery.fn[ "scroll" ] = function( fn ) { /// /// 1: scroll() - 触发每个匹配元素的 scroll 事件。 /// 2: scroll(fn) - 将函数绑定到每个匹配元素的 scroll 事件。 /// /// 要执行的函数。 /// return fn ? this.bind( "scroll", fn ) : this.trigger( "scroll" ); }; jquery.fn[ "unload" ] = function( fn ) { /// /// 1: unload() - 触发每个匹配元素的 unload 事件。 /// 2: unload(fn) - 将函数绑定到每个匹配元素的 unload 事件。 /// /// 要执行的函数。 /// return fn ? this.bind( "unload", fn ) : this.trigger( "unload" ); }; jquery.fn[ "click" ] = function( fn ) { /// /// 1: click() - 触发每个匹配元素的 click 事件。 /// 2: click(fn) - 将函数绑定到每个匹配元素的 click 事件。 /// /// 要执行的函数。 /// return fn ? this.bind( "click", fn ) : this.trigger( "click" ); }; jquery.fn[ "dblclick" ] = function( fn ) { /// /// 1: dblclick() - 触发每个匹配元素的 dblclick 事件。 /// 2: dblclick(fn) - 将函数绑定到每个匹配元素的 dblclick 事件。 /// /// 要执行的函数。 /// return fn ? this.bind( "dblclick", fn ) : this.trigger( "dblclick" ); }; jquery.fn[ "mousedown" ] = function( fn ) { /// /// 将函数绑定到每个匹配元素的 mousedown 事件。 /// /// 要执行的函数。 /// return fn ? this.bind( "mousedown", fn ) : this.trigger( "mousedown" ); }; jquery.fn[ "mouseup" ] = function( fn ) { /// /// 将函数绑定到每个匹配元素的 mouseup 事件。 /// /// 要执行的函数。 /// return fn ? this.bind( "mouseup", fn ) : this.trigger( "mouseup" ); }; jquery.fn[ "mousemove" ] = function( fn ) { /// /// 将函数绑定到每个匹配元素的 mousemove 事件。 /// /// 要执行的函数。 /// return fn ? this.bind( "mousemove", fn ) : this.trigger( "mousemove" ); }; jquery.fn[ "mouseover" ] = function( fn ) { /// /// 将函数绑定到每个匹配元素的 mouseover 事件。 /// /// 要执行的函数。 /// return fn ? this.bind( "mouseover", fn ) : this.trigger( "mouseover" ); }; jquery.fn[ "mouseout" ] = function( fn ) { /// /// 将函数绑定到每个匹配元素的 mouseout 事件。 /// /// 要执行的函数。 /// return fn ? this.bind( "mouseout", fn ) : this.trigger( "mouseout" ); }; jquery.fn[ "mouseenter" ] = function( fn ) { /// /// 将函数绑定到每个匹配元素的 mouseenter 事件。 /// /// 要执行的函数。 /// return fn ? this.bind( "mouseenter", fn ) : this.trigger( "mouseenter" ); }; jquery.fn[ "mouseleave" ] = function( fn ) { /// /// 将函数绑定到每个匹配元素的 mouseleave 事件。 /// /// 要执行的函数。 /// return fn ? this.bind( "mouseleave", fn ) : this.trigger( "mouseleave" ); }; jquery.fn[ "change" ] = function( fn ) { /// /// 1: change() - 触发每个匹配元素的 change 事件。 /// 2: change(fn) - 将函数绑定到每个匹配元素的 change 事件。 /// /// 要执行的函数。 /// return fn ? this.bind( "change", fn ) : this.trigger( "change" ); }; jquery.fn[ "select" ] = function( fn ) { /// /// 1: select() - 触发每个匹配元素的 select 事件。 /// 2: select(fn) - 将函数绑定到每个匹配元素的 select 事件。 /// /// 要执行的函数。 /// return fn ? this.bind( "select", fn ) : this.trigger( "select" ); }; jquery.fn[ "submit" ] = function( fn ) { /// /// 1: submit() - 触发每个匹配元素的 submit 事件。 /// 2: submit(fn) - 将函数绑定到每个匹配元素的 submit 事件。 /// /// 要执行的函数。 /// return fn ? this.bind( "submit", fn ) : this.trigger( "submit" ); }; jquery.fn[ "keydown" ] = function( fn ) { /// /// 1: keydown() - 触发每个匹配元素的 keydown 事件。 /// 2: keydown(fn) - 将函数绑定到每个匹配元素的 keydown 事件。 /// /// 要执行的函数。 /// return fn ? this.bind( "keydown", fn ) : this.trigger( "keydown" ); }; jquery.fn[ "keypress" ] = function( fn ) { /// /// 1: keypress() - 触发每个匹配元素的 keypress 事件。 /// 2: keypress(fn) - 将函数绑定到每个匹配元素的 keypress 事件。 /// /// 要执行的函数。 /// return fn ? this.bind( "keypress", fn ) : this.trigger( "keypress" ); }; jquery.fn[ "keyup" ] = function( fn ) { /// /// 1: keyup() - 触发每个匹配元素的 keyup 事件。 /// 2: keyup(fn) - 将函数绑定到每个匹配元素的 keyup 事件。 /// /// 要执行的函数。 /// return fn ? this.bind( "keyup", fn ) : this.trigger( "keyup" ); }; jquery.fn[ "error" ] = function( fn ) { /// /// 1: error() - 触发每个匹配元素的 error 事件。 /// 2: error(fn) - 将函数绑定到每个匹配元素的 error 事件。 /// /// 要执行的函数。 /// return fn ? this.bind( "error", fn ) : this.trigger( "error" ); }; // prevent memory leaks in ie // window isn't included so as not to unbind existing unload events // more info: // - http://isaacschlueter.com/2006/10/msie-memory-leaks/ if ( window.attachevent && !window.addeventlistener ) { window.attachevent("onunload", function() { for ( var id in jquery.cache ) { if ( jquery.cache[ id ].handle ) { // try/catch is to handle iframes being unloaded, see #4280 try { jquery.event.remove( jquery.cache[ id ].handle.elem ); } catch(e) {} } } }); } /*! * sizzle css selector engine - v1.0 * copyright 2009, the dojo foundation * released under the mit, bsd, and gpl licenses. * more information: http://sizzlejs.com/ */ (function(){ var chunker = /((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^[\]]*\]|['"][^'"]*['"]|[^[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?((?:.|\r|\n)*)/g, done = 0, tostring = object.prototype.tostring, hasduplicate = false, basehasduplicate = true; // here we check if the javascript engine is using some sort of // optimization where it does not always call our comparision // function. if that is the case, discard the hasduplicate value. // thus far that includes google chrome. [0, 0].sort(function(){ basehasduplicate = false; return 0; }); var sizzle = function(selector, context, results, seed) { results = results || []; var origcontext = context = context || document; if ( context.nodetype !== 1 && context.nodetype !== 9 ) { return []; } if ( !selector || typeof selector !== "string" ) { return results; } var parts = [], m, set, checkset, extra, prune = true, contextxml = isxml(context), sofar = selector; // reset the position of the chunker regexp (start from head) while ( (chunker.exec(""), m = chunker.exec(sofar)) !== null ) { sofar = m[3]; parts.push( m[1] ); if ( m[2] ) { extra = m[3]; break; } } if ( parts.length > 1 && origpos.exec( selector ) ) { if ( parts.length === 2 && expr.relative[ parts[0] ] ) { set = posprocess( parts[0] + parts[1], context ); } else { set = expr.relative[ parts[0] ] ? [ context ] : sizzle( parts.shift(), context ); while ( parts.length ) { selector = parts.shift(); if ( expr.relative[ selector ] ) { selector += parts.shift(); } set = posprocess( selector, set ); } } } else { // take a shortcut and set the context if the root selector is an id // (but not if it'll be faster if the inner selector is an id) if ( !seed && parts.length > 1 && context.nodetype === 9 && !contextxml && expr.match.id.test(parts[0]) && !expr.match.id.test(parts[parts.length - 1]) ) { var ret = sizzle.find( parts.shift(), context, contextxml ); context = ret.expr ? sizzle.filter( ret.expr, ret.set )[0] : ret.set[0]; } if ( context ) { var ret = seed ? { expr: parts.pop(), set: makearray(seed) } : sizzle.find( parts.pop(), parts.length === 1 && (parts[0] === "~" || parts[0] === "+") && context.parentnode ? context.parentnode : context, contextxml ); set = ret.expr ? sizzle.filter( ret.expr, ret.set ) : ret.set; if ( parts.length > 0 ) { checkset = makearray(set); } else { prune = false; } while ( parts.length ) { var cur = parts.pop(), pop = cur; if ( !expr.relative[ cur ] ) { cur = ""; } else { pop = parts.pop(); } if ( pop == null ) { pop = context; } expr.relative[ cur ]( checkset, pop, contextxml ); } } else { checkset = parts = []; } } if ( !checkset ) { checkset = set; } if ( !checkset ) { sizzle.error( cur || selector ); } if ( tostring.call(checkset) === "[object array]" ) { if ( !prune ) { results.push.apply( results, checkset ); } else if ( context && context.nodetype === 1 ) { for ( var i = 0; checkset[i] != null; i++ ) { if ( checkset[i] && (checkset[i] === true || checkset[i].nodetype === 1 && contains(context, checkset[i])) ) { results.push( set[i] ); } } } else { for ( var i = 0; checkset[i] != null; i++ ) { if ( checkset[i] && checkset[i].nodetype === 1 ) { results.push( set[i] ); } } } } else { makearray( checkset, results ); } if ( extra ) { sizzle( extra, origcontext, results, seed ); sizzle.uniquesort( results ); } return results; }; sizzle.uniquesort = function(results){ /// /// 从元素数组中移除所有的重复元素。 /// /// 要转换的数组 /// 转换后的数组。 if ( sortorder ) { hasduplicate = basehasduplicate; results.sort(sortorder); if ( hasduplicate ) { for ( var i = 1; i < results.length; i++ ) { if ( results[i] === results[i-1] ) { results.splice(i--, 1); } } } } return results; }; sizzle.matches = function(expr, set){ return sizzle(expr, null, null, set); }; sizzle.find = function(expr, context, isxml){ var set, match; if ( !expr ) { return []; } for ( var i = 0, l = expr.order.length; i < l; i++ ) { var type = expr.order[i], match; if ( (match = expr.leftmatch[ type ].exec( expr )) ) { var left = match[1]; match.splice(1,1); if ( left.substr( left.length - 1 ) !== "\\" ) { match[1] = (match[1] || "").replace(/\\/g, ""); set = expr.find[ type ]( match, context, isxml ); if ( set != null ) { expr = expr.replace( expr.match[ type ], "" ); break; } } } } if ( !set ) { set = context.getelementsbytagname("*"); } return {set: set, expr: expr}; }; sizzle.filter = function(expr, set, inplace, not){ var old = expr, result = [], curloop = set, match, anyfound, isxmlfilter = set && set[0] && isxml(set[0]); while ( expr && set.length ) { for ( var type in expr.filter ) { if ( (match = expr.leftmatch[ type ].exec( expr )) != null && match[2] ) { var filter = expr.filter[ type ], found, item, left = match[1]; anyfound = false; match.splice(1,1); if ( left.substr( left.length - 1 ) === "\\" ) { continue; } if ( curloop === result ) { result = []; } if ( expr.prefilter[ type ] ) { match = expr.prefilter[ type ]( match, curloop, inplace, result, not, isxmlfilter ); if ( !match ) { anyfound = found = true; } else if ( match === true ) { continue; } } if ( match ) { for ( var i = 0; (item = curloop[i]) != null; i++ ) { if ( item ) { found = filter( item, match, i, curloop ); var pass = not ^ !!found; if ( inplace && found != null ) { if ( pass ) { anyfound = true; } else { curloop[i] = false; } } else if ( pass ) { result.push( item ); anyfound = true; } } } } if ( found !== undefined ) { if ( !inplace ) { curloop = result; } expr = expr.replace( expr.match[ type ], "" ); if ( !anyfound ) { return []; } break; } } } // improper expression if ( expr === old ) { if ( anyfound == null ) { sizzle.error( expr ); } else { break; } } old = expr; } return curloop; }; sizzle.error = function( msg ) { throw "syntax error, unrecognized expression: " + msg; }; var expr = sizzle.selectors = { order: [ "id", "name", "tag" ], match: { id: /#((?:[\w\u00c0-\uffff-]|\\.)+)/, class: /\.((?:[\w\u00c0-\uffff-]|\\.)+)/, name: /\[name=['"]*((?:[\w\u00c0-\uffff-]|\\.)+)['"]*\]/, attr: /\[\s*((?:[\w\u00c0-\uffff-]|\\.)+)\s*(?:(\s?=)\s*(['"]*)(.*?)\3|)\s*\]/, tag: /^((?:[\w\u00c0-\uffff\*-]|\\.)+)/, child: /:(only|nth|last|first)-child(?:\((even|odd|[\dn+-]*)\))?/, pos: /:(nth|eq|gt|lt|first|last|even|odd)(?:\((\d*)\))?(?=[^-]|$)/, pseudo: /:((?:[\w\u00c0-\uffff-]|\\.)+)(?:\((['"]?)((?:\([^\)]+\)|[^\(\)]*)+)\2\))?/ }, leftmatch: {}, attrmap: { "class": "classname", "for": "htmlfor" }, attrhandle: { href: function(elem){ return elem.getattribute("href"); } }, relative: { "+": function(checkset, part){ var ispartstr = typeof part === "string", istag = ispartstr && !/\w/.test(part), ispartstrnottag = ispartstr && !istag; if ( istag ) { part = part.tolowercase(); } for ( var i = 0, l = checkset.length, elem; i < l; i++ ) { if ( (elem = checkset[i]) ) { while ( (elem = elem.previoussibling) && elem.nodetype !== 1 ) {} checkset[i] = ispartstrnottag || elem && elem.nodename.tolowercase() === part ? elem || false : elem === part; } } if ( ispartstrnottag ) { sizzle.filter( part, checkset, true ); } }, ">": function(checkset, part){ var ispartstr = typeof part === "string"; if ( ispartstr && !/\w/.test(part) ) { part = part.tolowercase(); for ( var i = 0, l = checkset.length; i < l; i++ ) { var elem = checkset[i]; if ( elem ) { var parent = elem.parentnode; checkset[i] = parent.nodename.tolowercase() === part ? parent : false; } } } else { for ( var i = 0, l = checkset.length; i < l; i++ ) { var elem = checkset[i]; if ( elem ) { checkset[i] = ispartstr ? elem.parentnode : elem.parentnode === part; } } if ( ispartstr ) { sizzle.filter( part, checkset, true ); } } }, "": function(checkset, part, isxml){ var donename = done++, checkfn = dircheck; if ( typeof part === "string" && !/\w/.test(part) ) { var nodecheck = part = part.tolowercase(); checkfn = dirnodecheck; } checkfn("parentnode", part, donename, checkset, nodecheck, isxml); }, "~": function(checkset, part, isxml){ var donename = done++, checkfn = dircheck; if ( typeof part === "string" && !/\w/.test(part) ) { var nodecheck = part = part.tolowercase(); checkfn = dirnodecheck; } checkfn("previoussibling", part, donename, checkset, nodecheck, isxml); } }, find: { id: function(match, context, isxml){ if ( typeof context.getelementbyid !== "undefined" && !isxml ) { var m = context.getelementbyid(match[1]); return m ? [m] : []; } }, name: function(match, context){ if ( typeof context.getelementsbyname !== "undefined" ) { var ret = [], results = context.getelementsbyname(match[1]); for ( var i = 0, l = results.length; i < l; i++ ) { if ( results[i].getattribute("name") === match[1] ) { ret.push( results[i] ); } } return ret.length === 0 ? null : ret; } }, tag: function(match, context){ return context.getelementsbytagname(match[1]); } }, prefilter: { class: function(match, curloop, inplace, result, not, isxml){ match = " " + match[1].replace(/\\/g, "") + " "; if ( isxml ) { return match; } for ( var i = 0, elem; (elem = curloop[i]) != null; i++ ) { if ( elem ) { if ( not ^ (elem.classname && (" " + elem.classname + " ").replace(/[\t\n]/g, " ").indexof(match) >= 0) ) { if ( !inplace ) { result.push( elem ); } } else if ( inplace ) { curloop[i] = false; } } } return false; }, id: function(match){ return match[1].replace(/\\/g, ""); }, tag: function(match, curloop){ return match[1].tolowercase(); }, child: function(match){ if ( match[1] === "nth" ) { // parse equations like 'even', 'odd', '5', '2n', '3n+2', '4n-1', '-n+6' var test = /(-?)(\d*)n((?:\+|-)?\d*)/.exec( match[2] === "even" && "2n" || match[2] === "odd" && "2n+1" || !/\d/.test( match[2] ) && "0n+" + match[2] || match[2]); // calculate the numbers (first)n+(last) including if they are negative match[2] = (test[1] + (test[2] || 1)) - 0; match[3] = test[3] - 0; } // todo: move to normal caching system match[0] = done++; return match; }, attr: function(match, curloop, inplace, result, not, isxml){ var name = match[1].replace(/\\/g, ""); if ( !isxml && expr.attrmap[name] ) { match[1] = expr.attrmap[name]; } if ( match[2] === "~=" ) { match[4] = " " + match[4] + " "; } return match; }, pseudo: function(match, curloop, inplace, result, not){ if ( match[1] === "not" ) { // if we're dealing with a complex expression, or a simple one if ( ( chunker.exec(match[3]) || "" ).length > 1 || /^\w/.test(match[3]) ) { match[3] = sizzle(match[3], null, null, curloop); } else { var ret = sizzle.filter(match[3], curloop, inplace, true ^ not); if ( !inplace ) { result.push.apply( result, ret ); } return false; } } else if ( expr.match.pos.test( match[0] ) || expr.match.child.test( match[0] ) ) { return true; } return match; }, pos: function(match){ match.unshift( true ); return match; } }, filters: { enabled: function(elem){ return elem.disabled === false && elem.type !== "hidden"; }, disabled: function(elem){ return elem.disabled === true; }, checked: function(elem){ return elem.checked === true; }, selected: function(elem){ // accessing this property makes selected-by-default // options in safari work properly elem.parentnode.selectedindex; return elem.selected === true; }, parent: function(elem){ return !!elem.firstchild; }, empty: function(elem){ return !elem.firstchild; }, has: function(elem, i, match){ /// /// 仅供内部使用;请使用 hasclass('class') /// /// return !!sizzle( match[3], elem ).length; }, header: function(elem){ return /h\d/i.test( elem.nodename ); }, text: function(elem){ return "text" === elem.type; }, radio: function(elem){ return "radio" === elem.type; }, checkbox: function(elem){ return "checkbox" === elem.type; }, file: function(elem){ return "file" === elem.type; }, password: function(elem){ return "password" === elem.type; }, submit: function(elem){ return "submit" === elem.type; }, image: function(elem){ return "image" === elem.type; }, reset: function(elem){ return "reset" === elem.type; }, button: function(elem){ return "button" === elem.type || elem.nodename.tolowercase() === "button"; }, input: function(elem){ return /input|select|textarea|button/i.test(elem.nodename); } }, setfilters: { first: function(elem, i){ return i === 0; }, last: function(elem, i, match, array){ return i === array.length - 1; }, even: function(elem, i){ return i % 2 === 0; }, odd: function(elem, i){ return i % 2 === 1; }, lt: function(elem, i, match){ return i < match[3] - 0; }, gt: function(elem, i, match){ return i > match[3] - 0; }, nth: function(elem, i, match){ return match[3] - 0 === i; }, eq: function(elem, i, match){ return match[3] - 0 === i; } }, filter: { pseudo: function(elem, match, i, array){ var name = match[1], filter = expr.filters[ name ]; if ( filter ) { return filter( elem, i, match, array ); } else if ( name === "contains" ) { return (elem.textcontent || elem.innertext || gettext([ elem ]) || "").indexof(match[3]) >= 0; } else if ( name === "not" ) { var not = match[3]; for ( var i = 0, l = not.length; i < l; i++ ) { if ( not[i] === elem ) { return false; } } return true; } else { sizzle.error( "syntax error, unrecognized expression: " + name ); } }, child: function(elem, match){ var type = match[1], node = elem; switch (type) { case 'only': case 'first': while ( (node = node.previoussibling) ) { if ( node.nodetype === 1 ) { return false; } } if ( type === "first" ) { return true; } node = elem; case 'last': while ( (node = node.nextsibling) ) { if ( node.nodetype === 1 ) { return false; } } return true; case 'nth': var first = match[2], last = match[3]; if ( first === 1 && last === 0 ) { return true; } var donename = match[0], parent = elem.parentnode; if ( parent && (parent.sizcache !== donename || !elem.nodeindex) ) { var count = 0; for ( node = parent.firstchild; node; node = node.nextsibling ) { if ( node.nodetype === 1 ) { node.nodeindex = ++count; } } parent.sizcache = donename; } var diff = elem.nodeindex - last; if ( first === 0 ) { return diff === 0; } else { return ( diff % first === 0 && diff / first >= 0 ); } } }, id: function(elem, match){ return elem.nodetype === 1 && elem.getattribute("id") === match; }, tag: function(elem, match){ return (match === "*" && elem.nodetype === 1) || elem.nodename.tolowercase() === match; }, class: function(elem, match){ return (" " + (elem.classname || elem.getattribute("class")) + " ") .indexof( match ) > -1; }, attr: function(elem, match){ var name = match[1], result = expr.attrhandle[ name ] ? expr.attrhandle[ name ]( elem ) : elem[ name ] != null ? elem[ name ] : elem.getattribute( name ), value = result + "", type = match[2], check = match[4]; return result == null ? type === "!=" : type === "=" ? value === check : type === "*=" ? value.indexof(check) >= 0 : type === "~=" ? (" " + value + " ").indexof(check) >= 0 : !check ? value && result !== false : type === "!=" ? value !== check : type === "^=" ? value.indexof(check) === 0 : type === "$=" ? value.substr(value.length - check.length) === check : type === "|=" ? value === check || value.substr(0, check.length + 1) === check + "-" : false; }, pos: function(elem, match, i, array){ var name = match[2], filter = expr.setfilters[ name ]; if ( filter ) { return filter( elem, i, match, array ); } } } }; var origpos = expr.match.pos; for ( var type in expr.match ) { expr.match[ type ] = new regexp( expr.match[ type ].source + /(?![^\[]*\])(?![^\(]*\))/.source ); expr.leftmatch[ type ] = new regexp( /(^(?:.|\r|\n)*?)/.source + expr.match[ type ].source.replace(/\\(\d+)/g, function(all, num){ return "\\" + (num - 0 + 1); })); } var makearray = function(array, results) { array = array.prototype.slice.call( array, 0 ); if ( results ) { results.push.apply( results, array ); return results; } return array; }; // perform a simple check to determine if the browser is capable of // converting a nodelist to an array using builtin methods. try { array.prototype.slice.call( document.documentelement.childnodes, 0 ); // provide a fallback method if it does not work } catch(e){ makearray = function(array, results) { var ret = results || []; if ( tostring.call(array) === "[object array]" ) { array.prototype.push.apply( ret, array ); } else { if ( typeof array.length === "number" ) { for ( var i = 0, l = array.length; i < l; i++ ) { ret.push( array[i] ); } } else { for ( var i = 0; array[i]; i++ ) { ret.push( array[i] ); } } } return ret; }; } var sortorder; if ( document.documentelement.comparedocumentposition ) { sortorder = function( a, b ) { if ( !a.comparedocumentposition || !b.comparedocumentposition ) { if ( a == b ) { hasduplicate = true; } return a.comparedocumentposition ? -1 : 1; } var ret = a.comparedocumentposition(b) & 4 ? -1 : a === b ? 0 : 1; if ( ret === 0 ) { hasduplicate = true; } return ret; }; } else if ( "sourceindex" in document.documentelement ) { sortorder = function( a, b ) { if ( !a.sourceindex || !b.sourceindex ) { if ( a == b ) { hasduplicate = true; } return a.sourceindex ? -1 : 1; } var ret = a.sourceindex - b.sourceindex; if ( ret === 0 ) { hasduplicate = true; } return ret; }; } else if ( document.createrange ) { sortorder = function( a, b ) { if ( !a.ownerdocument || !b.ownerdocument ) { if ( a == b ) { hasduplicate = true; } return a.ownerdocument ? -1 : 1; } var arange = a.ownerdocument.createrange(), brange = b.ownerdocument.createrange(); arange.setstart(a, 0); arange.setend(a, 0); brange.setstart(b, 0); brange.setend(b, 0); var ret = arange.compareboundarypoints(range.start_to_end, brange); if ( ret === 0 ) { hasduplicate = true; } return ret; }; } // utility function for retreiving the text value of an array of dom nodes function gettext( elems ) { var ret = "", elem; for ( var i = 0; elems[i]; i++ ) { elem = elems[i]; // get the text from text nodes and cdata nodes if ( elem.nodetype === 3 || elem.nodetype === 4 ) { ret += elem.nodevalue; // traverse everything else, except comment nodes } else if ( elem.nodetype !== 8 ) { ret += gettext( elem.childnodes ); } } return ret; } // [vsdoc] the following function has been modified for intellisense. // check to see if the browser returns elements by name when // querying by getelementbyid (and provide a workaround) (function(){ // we're going to inject a fake input element with a specified name // var form = document.createelement("div"), // id = "script" + (new date).gettime(); // form.innerhtml = ""; // // inject it into the root element, check its status, and remove it quickly // var root = document.documentelement; // root.insertbefore( form, root.firstchild ); // the workaround has to do additional checks after a getelementbyid // which slows things down for other browsers (hence the branching) // if ( document.getelementbyid( id ) ) { expr.find.id = function(match, context, isxml){ if ( typeof context.getelementbyid !== "undefined" && !isxml ) { var m = context.getelementbyid(match[1]); return m ? m.id === match[1] || typeof m.getattributenode !== "undefined" && m.getattributenode("id").nodevalue === match[1] ? [m] : undefined : []; } }; expr.filter.id = function(elem, match){ var node = typeof elem.getattributenode !== "undefined" && elem.getattributenode("id"); return elem.nodetype === 1 && node && node.nodevalue === match; }; // } // root.removechild( form ); root = form = null; // release memory in ie })(); // [vsdoc] the following function has been modified for intellisense. (function(){ // check to see if the browser returns only elements // when doing getelementsbytagname("*") // create a fake element // var div = document.createelement("div"); // div.appendchild( document.createcomment("") ); // make sure no comments are found // if ( div.getelementsbytagname("*").length > 0 ) { expr.find.tag = function(match, context){ var results = context.getelementsbytagname(match[1]); // filter out possible comments if ( match[1] === "*" ) { var tmp = []; for ( var i = 0; results[i]; i++ ) { if ( results[i].nodetype === 1 ) { tmp.push( results[i] ); } } results = tmp; } return results; }; // } // check to see if an attribute returns normalized href attributes // div.innerhtml = ""; // if ( div.firstchild && typeof div.firstchild.getattribute !== "undefined" && // div.firstchild.getattribute("href") !== "#" ) { expr.attrhandle.href = function(elem){ return elem.getattribute("href", 2); }; // } div = null; // release memory in ie })(); if ( document.queryselectorall ) { (function(){ var oldsizzle = sizzle, div = document.createelement("div"); div.innerhtml = "

"; // safari can't handle uppercase or unicode characters when // in quirks mode. if ( div.queryselectorall && div.queryselectorall(".test").length === 0 ) { return; } sizzle = function(query, context, extra, seed){ context = context || document; // only use queryselectorall on non-xml documents // (id selectors don't work in non-html documents) if ( !seed && context.nodetype === 9 && !isxml(context) ) { try { return makearray( context.queryselectorall(query), extra ); } catch(e){} } return oldsizzle(query, context, extra, seed); }; for ( var prop in oldsizzle ) { sizzle[ prop ] = oldsizzle[ prop ]; } div = null; // release memory in ie })(); } (function(){ var div = document.createelement("div"); div.innerhtml = "
"; // opera can't find a second classname (in 9.6) // also, make sure that getelementsbyclassname actually exists if ( !div.getelementsbyclassname || div.getelementsbyclassname("e").length === 0 ) { return; } // safari caches class attributes, doesn't catch changes (in 3.2) div.lastchild.classname = "e"; if ( div.getelementsbyclassname("e").length === 1 ) { return; } expr.order.splice(1, 0, "class"); expr.find.class = function(match, context, isxml) { if ( typeof context.getelementsbyclassname !== "undefined" && !isxml ) { return context.getelementsbyclassname(match[1]); } }; div = null; // release memory in ie })(); function dirnodecheck( dir, cur, donename, checkset, nodecheck, isxml ) { for ( var i = 0, l = checkset.length; i < l; i++ ) { var elem = checkset[i]; if ( elem ) { elem = elem[dir]; var match = false; while ( elem ) { if ( elem.sizcache === donename ) { match = checkset[elem.sizset]; break; } if ( elem.nodetype === 1 && !isxml ){ elem.sizcache = donename; elem.sizset = i; } if ( elem.nodename.tolowercase() === cur ) { match = elem; break; } elem = elem[dir]; } checkset[i] = match; } } } function dircheck( dir, cur, donename, checkset, nodecheck, isxml ) { for ( var i = 0, l = checkset.length; i < l; i++ ) { var elem = checkset[i]; if ( elem ) { elem = elem[dir]; var match = false; while ( elem ) { if ( elem.sizcache === donename ) { match = checkset[elem.sizset]; break; } if ( elem.nodetype === 1 ) { if ( !isxml ) { elem.sizcache = donename; elem.sizset = i; } if ( typeof cur !== "string" ) { if ( elem === cur ) { match = true; break; } } else if ( sizzle.filter( cur, [elem] ).length > 0 ) { match = elem; break; } } elem = elem[dir]; } checkset[i] = match; } } } var contains = document.comparedocumentposition ? function(a, b){ /// /// 检查某个 dom 节点是否位于另一个 dom 节点中。 /// /// /// 可能包含其他元素的 dom 元素。 /// /// /// 可能包含于其他元素中的 dom 节点。 /// /// return a.comparedocumentposition(b) & 16; } : function(a, b){ /// /// 检查某个 dom 节点是否位于另一个 dom 节点中。 /// /// /// 可能包含其他元素的 dom 元素。 /// /// /// 可能包含于其他元素中的 dom 节点。 /// /// return a !== b && (a.contains ? a.contains(b) : true); }; var isxml = function(elem){ /// /// 确定传递的参数是否为 xml 文档。 /// /// 要测试的对象 /// 如果该参数为 xml 文档,则为 true;否则为 false。 // documentelement is verified for cases where it doesn't yet exist // (such as loading iframes in ie - #4833) var documentelement = (elem ? elem.ownerdocument || elem : 0).documentelement; return documentelement ? documentelement.nodename !== "html" : false; }; var posprocess = function(selector, context){ var tmpset = [], later = "", match, root = context.nodetype ? [context] : context; // position selectors must be done after the filter // and so must :not(positional) so we move all pseudos to the end while ( (match = expr.match.pseudo.exec( selector )) ) { later += match[0]; selector = selector.replace( expr.match.pseudo, "" ); } selector = expr.relative[selector] ? selector + "*" : selector; for ( var i = 0, l = root.length; i < l; i++ ) { sizzle( selector, root[i], tmpset ); } return sizzle.filter( later, tmpset ); }; // expose jquery.find = sizzle; jquery.expr = sizzle.selectors; jquery.expr[":"] = jquery.expr.filters; jquery.unique = sizzle.uniquesort; jquery.gettext = gettext; jquery.isxmldoc = isxml; jquery.contains = contains; return; window.sizzle = sizzle; })(); var runtil = /until$/, rparentsprev = /^(?:parents|prevuntil|prevall)/, // note: this regexp should be improved, or likely pulled from sizzle rmultiselector = /,/, slice = array.prototype.slice; // implement the identical functionality for filter and not var winnow = function( elements, qualifier, keep ) { if ( jquery.isfunction( qualifier ) ) { return jquery.grep(elements, function( elem, i ) { return !!qualifier.call( elem, i, elem ) === keep; }); } else if ( qualifier.nodetype ) { return jquery.grep(elements, function( elem, i ) { return (elem === qualifier) === keep; }); } else if ( typeof qualifier === "string" ) { var filtered = jquery.grep(elements, function( elem ) { return elem.nodetype === 1; }); if ( issimple.test( qualifier ) ) { return jquery.filter(qualifier, filtered, !keep); } else { qualifier = jquery.filter( qualifier, filtered ); } } return jquery.grep(elements, function( elem, i ) { return (jquery.inarray( elem, qualifier ) >= 0) === keep; }); }; jquery.fn.extend({ find: function( selector ) { /// /// 搜索与指定的表达式匹配的所有元素。 /// 此方法是查找其他要进行处理的子代 /// 元素的好方法。 /// 所有搜索都是使用 jquery 表达式来完成的。可以使用 /// css 1-3 选择器语法或基本 xpath 来编写该表达式。 /// dom/遍历部分 /// /// /// /// 要用于搜索的表达式。 /// /// var ret = this.pushstack( "", "find", selector ), length = 0; for ( var i = 0, l = this.length; i < l; i++ ) { length = ret.length; jquery.find( selector, this[i], ret ); if ( i > 0 ) { // 确保结果的唯一性 for ( var n = length; n < ret.length; n++ ) { for ( var r = 0; r < length; r++ ) { if ( ret[r] === ret[n] ) { ret.splice(n--, 1); break; } } } } } return ret; }, has: function( target ) { /// /// 将匹配元素集精简为具有子代匹配选择器或 /// dom 元素的那些元素。 /// /// /// 一个包含要与其匹配元素的选择器表达式的字符串。 /// /// var targets = jquery( target ); return this.filter(function() { for ( var i = 0, l = targets.length; i < l; i++ ) { if ( jquery.contains( this, targets[i] ) ) { return true; } } }); }, not: function( selector ) { /// /// 从匹配元素集中移除元素数组内部的 /// 任何元素。此方法用于从 jquery 对象中 /// 移除一个或多个元素。 /// dom/遍历部分 /// /// /// 要从匹配元素的 jquery 集中移除的一组元素。 /// /// return this.pushstack( winnow(this, selector, false), "not", selector); }, filter: function( selector ) { /// /// 从未通过指定筛选器的匹配元素集中 /// 移除所有元素。此方法用于缩小搜索的 /// 结果。 /// }) /// dom/遍历部分 /// /// /// /// 要用于进行筛选的函数 /// /// return this.pushstack( winnow(this, selector, true), "filter", selector ); }, is: function( selector ) { /// /// 针对表达式检查当前选择,如果至少有一个选择的 /// 元素符合给定的表达式,则返回 true。 /// 如果没有元素符合表达式或表达式无效,则返回 false。 /// filter(string) 在内部使用,因此在别处应用的所有规则 /// 在此处同样适用。 /// dom/遍历部分 /// /// /// /// 要用于进行筛选的表达式 /// return !!selector && jquery.filter( selector, this ).length > 0; }, closest: function( selectors, context ) { /// /// 获取一组包含匹配指定筛选器的最接近的父元素的元素(包括起始元素)。 /// /// /// 一个包含要与其匹配元素的选择器表达式的字符串。 /// /// /// 可能会在其中找到匹配元素的 dom 元素。如果未传入上下文, /// 则将改为使用 jquery 集的上下文。 /// /// if ( jquery.isarray( selectors ) ) { var ret = [], cur = this[0], match, matches = {}, selector; if ( cur && selectors.length ) { for ( var i = 0, l = selectors.length; i < l; i++ ) { selector = selectors[i]; if ( !matches[selector] ) { matches[selector] = jquery.expr.match.pos.test( selector ) ? jquery( selector, context || this.context ) : selector; } } while ( cur && cur.ownerdocument && cur !== context ) { for ( selector in matches ) { match = matches[selector]; if ( match.jquery ? match.index(cur) > -1 : jquery(cur).is(match) ) { ret.push({ selector: selector, elem: cur }); delete matches[selector]; } } cur = cur.parentnode; } } return ret; } var pos = jquery.expr.match.pos.test( selectors ) ? jquery( selectors, context || this.context ) : null; return this.map(function( i, cur ) { while ( cur && cur.ownerdocument && cur !== context ) { if ( pos ? pos.index(cur) > -1 : jquery(cur).is(selectors) ) { return cur; } cur = cur.parentnode; } return null; }); }, // determine the position of an element within // the matched set of elements index: function( elem ) { /// /// 在每个匹配的元素中搜索该对象,如果找到,则返回 /// 相应元素的索引(从零开始)。 /// 如果未找到该对象,则返回 -1。 /// 核心部分 /// /// /// /// 要搜索的对象 /// if ( !elem || typeof elem === "string" ) { return jquery.inarray( this[0], // if it receives a string, the selector is used // if it receives nothing, the siblings are used elem ? jquery( elem ) : this.parent().children() ); } // locate the position of the desired element return jquery.inarray( // if it receives a jquery object, the first element is used elem.jquery ? elem[0] : elem, this ); }, add: function( selector, context ) { /// /// 向匹配元素的集合中添加一个或多个元素。 /// dom/遍历部分 /// /// /// 一个包含要与其匹配其他元素的选择器表达式的字符串。 /// /// /// 添加一些以指定上下文为根的元素。 /// /// var set = typeof selector === "string" ? jquery( selector, context || this.context ) : jquery.makearray( selector ), all = jquery.merge( this.get(), set ); return this.pushstack( isdisconnected( set[0] ) || isdisconnected( all[0] ) ? all : jquery.unique( all ) ); }, andself: function() { /// /// 将以前的选择添加到当前选择。 /// /// return this.add( this.prevobject ); } }); // a painfully simple check to see if an element is disconnected // from a document (should be improved, where feasible). function isdisconnected( node ) { return !node || !node.parentnode || node.parentnode.nodetype === 11; } jquery.each({ parent: function( elem ) { var parent = elem.parentnode; return parent && parent.nodetype !== 11 ? parent : null; }, parents: function( elem ) { return jquery.dir( elem, "parentnode" ); }, next: function( elem ) { return jquery.nth( elem, 2, "nextsibling" ); }, prev: function( elem ) { return jquery.nth( elem, 2, "previoussibling" ); }, nextall: function( elem ) { return jquery.dir( elem, "nextsibling" ); }, prevall: function( elem ) { return jquery.dir( elem, "previoussibling" ); }, siblings: function( elem ) { return jquery.sibling( elem.parentnode.firstchild, elem ); }, children: function( elem ) { return jquery.sibling( elem.firstchild ); }, contents: function( elem ) { return jquery.nodename( elem, "iframe" ) ? elem.contentdocument || elem.contentwindow.document : jquery.makearray( elem.childnodes ); } }, function( name, fn ) { jquery.fn[ name ] = function( until, selector ) { var ret = jquery.map( this, fn, until ); if ( !runtil.test( name ) ) { selector = until; } if ( selector && typeof selector === "string" ) { ret = jquery.filter( selector, ret ); } ret = this.length > 1 ? jquery.unique( ret ) : ret; if ( (this.length > 1 || rmultiselector.test( selector )) && rparentsprev.test( name ) ) { ret = ret.reverse(); } return this.pushstack( ret, name, slice.call(arguments).join(",") ); }; }); jquery.fn[ "parentsuntil" ] = function( until, selector ) { /// /// 获取当前匹配元素集中每个元素的上级,直到但不包括 /// 由选择器匹配的元素。 /// /// /// 一个字符串,它包含用于指示在何处停止匹配上级元素的 /// 选择器表达式。 /// /// var fn = function( elem, i, until ) { return jquery.dir( elem, "parentnode", until ); } var ret = jquery.map( this, fn, until ); if ( !runtil.test( "parentsuntil" ) ) { selector = until; } if ( selector && typeof selector === "string" ) { ret = jquery.filter( selector, ret ); } ret = this.length > 1 ? jquery.unique( ret ) : ret; if ( (this.length > 1 || rmultiselector.test( selector )) && rparentsprev.test( "parentsuntil" ) ) { ret = ret.reverse(); } return this.pushstack( ret, "parentsuntil", slice.call(arguments).join(",") ); }; jquery.fn[ "nextuntil" ] = function( until, selector ) { /// /// 获取每个元素的所有后续同级元素,直到但不包括由选择器匹配的 /// 元素。 /// /// /// 一个字符串,它包含用于指示在何处停止匹配后续同级元素的 /// 选择器表达式。 /// /// var fn = function( elem, i, until ) { return jquery.dir( elem, "nextsibling", until ); } var ret = jquery.map( this, fn, until ); if ( !runtil.test( "nextuntil" ) ) { selector = until; } if ( selector && typeof selector === "string" ) { ret = jquery.filter( selector, ret ); } ret = this.length > 1 ? jquery.unique( ret ) : ret; if ( (this.length > 1 || rmultiselector.test( selector )) && rparentsprev.test( "nextuntil" ) ) { ret = ret.reverse(); } return this.pushstack( ret, "nextuntil", slice.call(arguments).join(",") ); }; jquery.fn[ "prevuntil" ] = function( until, selector ) { /// /// 获取每个元素的所有前面的同级元素,直到但不包括由选择器匹配的 /// 元素。 /// /// /// 一个字符串,它包含用于指示在何处停止匹配前面的同级元素的 /// 选择器表达式。 /// /// var fn = function( elem, i, until ) { return jquery.dir( elem, "previoussibling", until ); } var ret = jquery.map( this, fn, until ); if ( !runtil.test( "prevuntil" ) ) { selector = until; } if ( selector && typeof selector === "string" ) { ret = jquery.filter( selector, ret ); } ret = this.length > 1 ? jquery.unique( ret ) : ret; if ( (this.length > 1 || rmultiselector.test( selector )) && rparentsprev.test( "prevuntil" ) ) { ret = ret.reverse(); } return this.pushstack( ret, "prevuntil", slice.call(arguments).join(",") ); }; jquery.extend({ filter: function( expr, elems, not ) { if ( not ) { expr = ":not(" + expr + ")"; } return jquery.find.matches(expr, elems); }, dir: function( elem, dir, until ) { /// /// 此成员仅供内部使用。 /// /// var matched = [], cur = elem[dir]; while ( cur && cur.nodetype !== 9 && (until === undefined || cur.nodetype !== 1 || !jquery( cur ).is( until )) ) { if ( cur.nodetype === 1 ) { matched.push( cur ); } cur = cur[dir]; } return matched; }, nth: function( cur, result, dir, elem ) { /// /// 此成员仅供内部使用。 /// /// result = result || 1; var num = 0; for ( ; cur; cur = cur[dir] ) { if ( cur.nodetype === 1 && ++num === result ) { break; } } return cur; }, sibling: function( n, elem ) { /// /// 此成员仅供内部使用。 /// /// var r = []; for ( ; n; n = n.nextsibling ) { if ( n.nodetype === 1 && n !== elem ) { r.push( n ); } } return r; } }); var rinlinejquery = / jquery\d+="(?:\d+|null)"/g, rleadingwhitespace = /^\s+/, rxhtmltag = /(<([\w:]+)[^>]*?)\/>/g, rselfclosing = /^(?:area|br|col|embed|hr|img|input|link|meta|param)$/i, rtagname = /<([\w:]+)/, rtbody = /"; }, wrapmap = { option: [ 1, "" ], legend: [ 1, "
", "
" ], thead: [ 1, "", "
" ], tr: [ 2, "", "
" ], td: [ 3, "", "
" ], col: [ 2, "", "
" ], area: [ 1, "", "" ], _default: [ 0, "", "" ] }; wrapmap.optgroup = wrapmap.option; wrapmap.tbody = wrapmap.tfoot = wrapmap.colgroup = wrapmap.caption = wrapmap.thead; wrapmap.th = wrapmap.td; // ie can't serialize and