jQuery-1.9.1 Source Analysis Series (14) Some jquery tools

Source: Internet
Author: User
Tags rtrim jquery library javascript eval

To prepare for the next chapter in analyzing animation, take a look at some tools. Where the queue tool is used frequently in animation processing.

Jquery.fn. Queue ([QueueName] [, Newqueue]) | | ([QueueName,] Pager Back )) (Gets or sets the function queue to be executed on the currently matched element.) If the current jquery object matches multiple elements: when the queue is fetched, only the queue on the first matching element is fetched; When the queue (replace queue, append function) is set, each matching element is set separately. If you need to remove and execute the first function in a queue, use the Dequeue () function. You can also use the Clearqueue () function to empty the specified queue)

Jquery.fn. Dequeue ([Dequeuename])(removes the first function in the specified queue for each matching element and executes the removed function.) You can also use the Clearqueue () function to empty the specified queue (no function is performed))

Jquery.fn. Clearqueue ([Dequeuename])(clears all outstanding items in the specified queue for each matching element)

jquery.error (msg)(throws an exception that contains the specified string information.) )

Jquery.each (object, callback)(iterates through the specified objects and arrays, and iterates through the specified function as a context for each property of the object (or each member of the array). The so-called context, meaning that the this pointer inside the function refers to the element. The function belongs to the global jquery object. Note that this is different from the each () function of the jquery object (instance), but the each () implementation of the JQuery object (instance) is also called Jquery.each)

Jquery.proxy ()(changes the context of the function. You can pass the specified function into the function, which returns a new function whose execution code is unchanged, but the context within the function (this) has been changed to the specified value

  Usage One:

Jquery.proxy (function, context [, additionalarguments])

Changes the function context object of the function to the specified context .

  Usage Two:

Jquery.proxy (context, name [, Additionalarguments])

Changes the context of the function named to the name specified context . namethe function should be context a property of the object.

Jquery.map (object, callback)(uses the specified function to process each element in the array (or each property of an object) and encapsulates the result of the processing as a new array return. There is also an instance method JQuery.fn.map () with the same name in the jquery library, which is used only to traverse the elements that match the current jquery object)

jQuery.fn.data ([key [, value]])(Access data on all elements matching the current JQuery object)

jQuery.fn.removeData (keys)(removes data items for the specified key name stored on each element that matches the current JQuery object)

Jquery.support(returns the feature or bug information for the browser that the user is currently using.) This property is an object. The properties of this object are not immutable, and jquery does not guarantee that the specified properties will be available in future releases, which are primarily used by plug-ins or kernel developers.

Jquery.contains (container, contained)(determines whether another element is contained within the specified element.) In short, this function is used to determine whether another DOM element is a descendant of a specified DOM element)

jquery.extend ([deep], Target, Object1 [, objectn ...]) (Merges the contents of one or more objects into the target object.) The function can copy the member properties and methods of one or more objects onto the specified object, and the parameter deep is used to indicate whether depth is recursively merged)

JQuery.fn.extend (object)(extends one or more instance properties and methods for JQuery (primarily for extension methods))

jquery.globaleval (code), which performs a piece of JavaScript code globally, is similar to the regular JavaScript eval () function. The difference is that the scope of the Jquery.globaleval () execution code is global scope)

jquery.grep (array, function [, invert])(uses the specified function to filter the elements in the array and returns the filtered array.) The source array is not affected and the filtered results are reflected only in the returned result array.

Jquery.inarray (value, array [, FromIndex])(searches the array for the specified value and returns its index value.) Returns 1 if the value does not exist in the array)

Jquery.isarray (object)(determines whether the specified argument is an array)

Jquery.isemptyobject (object), which determines whether the specified argument is an empty object. The so-called "empty object", that is, does not include any enumerable (custom) properties. In short, the object has no properties that can be iterated by for...in)

Jquery.isplainobject (object) (Determines whether the specified parameter is a purely object.) The so-called "pure object" is the object created by "{}" or "New object"

jquery.isfunction (object)(determines whether the specified argument is a function)

jquery.isnumeric (value)(determines whether the specified parameter is a numeric value)

Jquery.iswindow (object)(determines whether the specified parameter is a window)

jquery.isxmldoc (node) (Determines whether a DOM node is in an XML document, or is itself an XML document.) This function is primarily used to determine whether the specified document is an XML document or an HTML (or XHTML) document)

Jquery.makearray(object) (Converts a class array object to a true array object.) The so-called "class Array Object" is a regular object object, but it is very similar to and array objects: With the Length property, and with 0, 1, 2, 3 ... Equal number as the property name. However, it is not an array after all, there is no built-in method inherited from the array's prototype object (for example: push (), sort (), etc.))

Jquery.noop ()(is an empty function, it does nothing.) When you need to pass in a function parameter at some point, and you want it to do nothing, you can use the function, and you don't need to create a new empty function.

Jquery.now ()(returns the number of milliseconds that have elapsed since midnight January 1, 1970. The function acts like the new Date (). GetTime ())

jquery.parsehtml (htmlstring [, Context] [, keepscripts])(parses an HTML string into an array of corresponding DOM nodes.) The function uses the native DOM element creation function to convert the HTML string into a collection of DOM elements that you can insert into the document.

Jquery.parsejson (jsonstring)(converts a well-formed JSON string to its corresponding JavaScript object.) The so-called "well-formed" requirement is that the specified string must conform to a strict JSON format, for example: attribute names must be double-quoted, string values must also be double-quoted. If you pass in a JSON string that is not well formed, a JS exception will be thrown)

jquery.parsexml (xmlstring)(parses the string into the corresponding XML document.) The function uses the browser's built-in parsing function to create a valid XML document that can be passed into the jquery () function to create a typical jquery object to traverse or otherwise manipulate)

Jquery.trim (str)(removes whitespace characters at both ends of the string.) This function removes whitespace characters at the beginning and end of the string (until the first non-whitespace string is encountered). It clears common whitespace characters including line breaks, spaces, tabs, and so on)

Jquery.type (object)(determines the type of JavaScript built-in object and returns the type name in lowercase form.) JavaScript also comes with a typeof operator that can determine the type of data. However, for most objects, the typeof operator returns "Object" and cannot distinguish between specific types. Jquery.type () can more precisely determine the type of JS built-in object. For example: for new number (5), TypeOf returns "Object", Jquery.type () returns "number", and for New Date (), TypeOf returns "Object", and Jquery.type () returns "Date". The returned result of type has the lowercase "Boolean number String Function Array Date RegExp Object Error" )

jquery.unique (Array), which sorts the array of DOM elements according to the order in which the elements appear in the document, and removes the duplicate elements.

  Note : This function is used only for DOM element arrays, not numbers, strings, or other types. In addition , the repetition here refers to the fact that two elements are actually the same element (judged by the congruent "= = ="), not the same element as the two attribute.

  warning : The actual test found that the function did not return the correct results as expected. In different browsers, in different versions of jquery, the return result may be inconsistent (see Demo code below))

jQuery.fn.promise ([type,] obj)(Gets the promise of the resolved deferred object and merges it with the Obj object.) And when the queue of the specified type is emptied (the default type is FX) add resolution Processing)

A.jquery.trim Source Detailed

The TRIM function has two branches, and the first branch is: if the browser supports the TRIM function, the local trim function of the browser is used, otherwise the second branch uses a regular blank to remove the front and back edges.

//use the TRIM function supported by the browser if you can//Core_version.trimJQuery.trim:core_trim &&!core_trim.call ("\ufeff\xa0")?function(text) {returnText = =NULL? "": Core_trim.call (text);} ://Otherwise, use a regular to remove whitespace from the front and back ends//RTrim =/^[\s\ufeff\xa0]+| [\s\ufeff\xa0]+$/g,function(text) {returnText = =NULL? "": (Text+ ""). Replace (RTrim, "" );},

  

B. Queuing (queue) detailed

JQuery.fn.queue (type, data)

  The process steps are as follows:

The default queue is the standard animation effect queue for the FX type. If the queue type is not a string, you need to adjust the data by default type.

if typeof Type!== "string" ) {    = type;     = "FX";    Setter--;}

Determines whether to get or set the queue of the specified type, depending on the parameter.

If it is a queue that gets the first element of the element that directly gets the current jquery match, the corresponding type;

// gets the queue of the specified type if (Arguments.length < setter) {    returnthis [0], type);}

If it is set, it iterates through the current jquery-matched elements, sets a queue of the specified type for each element, and sets the corresponding hooks for each element (used for extension processing, such as the final purge queue)

returndata = = = undefined? This ://each jquery element is added to a queue This. each (function() {    varQueue = Jquery.queue ( This, type, data); //Make sure that the queue has a hooks. After executing this code, a function empty queue is saved.Jquery._queuehooks ( This, type); //if "FX" (which represents the standard animation effect queue in jquery), and the first function in the queue is not executing    //executes the first function in a queue. Visible animation queue is animated when added    if(Type = = = "FX" && Queue[0]!== "InProgress") {Jquery.dequeue ( This, type); }})

The function uses the low-level API Jquery.queue function, is the basic interface to get/set the queue, the source code is as follows

Queuefunction(Elem, type, data) {varqueue; if(elem) {//get the queue of the appropriate type firstType = (Type | | "FX") + "queue"; Queue=jquery._data (Elem, type); //Add a function at the end of a queue        if(data) {if(!queue | |Jquery.isarray (data)) {Queue=jquery._data (Elem, type, Jquery.makearray (data)); } Else{queue.push (data); }        }        returnQueue | | []; }}
View Code

  

C.jquery.fn.dequeue

Removes the first function in the specified queue for each matching element and executes the removed function. Internally called Jquery.dequeue to implement. Jquery.dequeue source code is as follows

Special attention in Jquery.dequeue is the processing of FX animation queues

Dequeuefunction(Elem, type) {type= Type | | "FX"; varQueue =jquery.queue (Elem, type), Startlength=queue.length, FN= Queue.shift (),//Take out the first function in a queueHooks =jquery._queuehooks (Elem, type), Next=function() {Jquery.dequeue (elem, type);    }; //always remove progress points if the FX queue is queued    if(fn = = = "InProgress")) {fn=Queue.shift (); Startlength--; } hooks.cur=fn; if(FN) {//add a progress point to prevent the FX queue from automatically dequeue        if(Type = = = "FX") {Queue.unshift ("InProgress" ); }        //clean up the last queue stop function        DeleteHooks.stop; //Next and hooks will pass to the callbackFn.call (Elem, Next, hooks); }    //Queue Length is 0 and hooks exists, delete queue    if(!startlength &&hooks)    {Hooks.empty.fire (); }}

Note the parameters of the function passing in the execution queue (Elem, Next, hooks).

Subsequent detailed analysis of the animation queue

  If you feel this article is good, please click on the bottom right "recommended"!

jQuery-1.9.1 Source Analysis Series (14) Some jquery tools

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.