Removed all inline documentation. The current version of all documentation is stored online, on the wiki: http://docs.jquery.com/

This commit is contained in:
John Resig 2007-09-04 01:57:35 +00:00
parent 1ce8006d48
commit 139393fe09
5 changed files with 10 additions and 2848 deletions

View file

@ -1,49 +1,9 @@
jQuery.fn.extend({
/**
* Load HTML from a remote file and inject it into the DOM, only if it's
* been modified by the server.
*
* @example $("#feeds").loadIfModified("feeds.html");
* @before <div id="feeds"></div>
* @result <div id="feeds"><b>45</b> feeds found.</div>
*
* @name loadIfModified
* @type jQuery
* @param String url The URL of the HTML file to load.
* @param Map params (optional) Key/value pairs that will be sent to the server.
* @param Function callback (optional) A function to be executed whenever the data is loaded (parameters: responseText, status and response itself).
* @cat Ajax
*/
// DEPRECATED
loadIfModified: function( url, params, callback ) {
this.load( url, params, callback, 1 );
},
/**
* Load HTML from a remote file and inject it into the DOM.
*
* Note: Avoid to use this to load scripts, instead use $.getScript.
* IE strips script tags when there aren't any other characters in front of it.
*
* @example $("#feeds").load("feeds.html");
* @before <div id="feeds"></div>
* @result <div id="feeds"><b>45</b> feeds found.</div>
*
* @example $("#feeds").load("feeds.html",
* {limit: 25},
* function() { alert("The last 25 entries in the feed have been loaded"); }
* );
* @desc Same as above, but with an additional parameter
* and a callback that is executed when the data was loaded.
*
* @name load
* @type jQuery
* @param String url The URL of the HTML file to load.
* @param Object params (optional) A set of key/value pairs that will be sent as data to the server.
* @param Function callback (optional) A function to be executed whenever the data is loaded (parameters: responseText, status and response itself).
* @cat Ajax
*/
load: function( url, params, callback, ifModified ) {
if ( jQuery.isFunction( url ) )
return this.bind("load", url);
@ -107,25 +67,6 @@ jQuery.fn.extend({
return this;
},
/**
* Serializes a set of input elements into a string of data.
* This will serialize all given elements.
*
* A serialization similar to the form submit of a browser is
* provided by the [http://www.malsup.com/jquery/form/ Form Plugin].
* It also takes multiple-selects
* into account, while this method recognizes only a single option.
*
* @example $("input[@type=text]").serialize();
* @before <input type='text' name='name' value='John'/>
* <input type='text' name='location' value='Boston'/>
* @after name=John&amp;location=Boston
* @desc Serialize a selection of input elements to a string
*
* @name serialize
* @type String
* @cat Ajax
*/
serialize: function() {
return jQuery.param( this );
},
@ -138,106 +79,6 @@ jQuery.fn.extend({
});
// Attach a bunch of functions for handling common AJAX events
/**
* Attach a function to be executed whenever an AJAX request begins
* and there is none already active.
*
* @example $("#loading").ajaxStart(function(){
* $(this).show();
* });
* @desc Show a loading message whenever an AJAX request starts
* (and none is already active).
*
* @name ajaxStart
* @type jQuery
* @param Function callback The function to execute.
* @cat Ajax
*/
/**
* Attach a function to be executed whenever all AJAX requests have ended.
*
* @example $("#loading").ajaxStop(function(){
* $(this).hide();
* });
* @desc Hide a loading message after all the AJAX requests have stopped.
*
* @name ajaxStop
* @type jQuery
* @param Function callback The function to execute.
* @cat Ajax
*/
/**
* Attach a function to be executed whenever an AJAX request completes.
*
* The XMLHttpRequest and settings used for that request are passed
* as arguments to the callback.
*
* @example $("#msg").ajaxComplete(function(request, settings){
* $(this).append("<li>Request Complete.</li>");
* });
* @desc Show a message when an AJAX request completes.
*
* @name ajaxComplete
* @type jQuery
* @param Function callback The function to execute.
* @cat Ajax
*/
/**
* Attach a function to be executed whenever an AJAX request completes
* successfully.
*
* The XMLHttpRequest and settings used for that request are passed
* as arguments to the callback.
*
* @example $("#msg").ajaxSuccess(function(request, settings){
* $(this).append("<li>Successful Request!</li>");
* });
* @desc Show a message when an AJAX request completes successfully.
*
* @name ajaxSuccess
* @type jQuery
* @param Function callback The function to execute.
* @cat Ajax
*/
/**
* Attach a function to be executed whenever an AJAX request fails.
*
* The XMLHttpRequest and settings used for that request are passed
* as arguments to the callback. A third argument, an exception object,
* is passed if an exception occured while processing the request.
*
* @example $("#msg").ajaxError(function(request, settings){
* $(this).append("<li>Error requesting page " + settings.url + "</li>");
* });
* @desc Show a message when an AJAX request fails.
*
* @name ajaxError
* @type jQuery
* @param Function callback The function to execute.
* @cat Ajax
*/
/**
* Attach a function to be executed before an AJAX request is sent.
*
* The XMLHttpRequest and settings used for that request are passed
* as arguments to the callback.
*
* @example $("#msg").ajaxSend(function(request, settings){
* $(this).append("<li>Starting request at " + settings.url + "</li>");
* });
* @desc Show a message before an AJAX request is sent.
*
* @name ajaxSend
* @type jQuery
* @param Function callback The function to execute.
* @cat Ajax
*/
jQuery.each( "ajaxStart,ajaxStop,ajaxComplete,ajaxError,ajaxSuccess,ajaxSend".split(","), function(i,o){
jQuery.fn[o] = function(f){
return this.bind(o, f);
@ -247,39 +88,6 @@ jQuery.each( "ajaxStart,ajaxStop,ajaxComplete,ajaxError,ajaxSuccess,ajaxSend".sp
var jsc = (new Date).getTime();
jQuery.extend({
/**
* Load a remote page using an HTTP GET request.
*
* This is an easy way to send a simple GET request to a server
* without having to use the more complex $.ajax function. It
* allows a single callback function to be specified that will
* be executed when the request is complete (and only if the response
* has a successful response code). If you need to have both error
* and success callbacks, you may want to use $.ajax.
*
* @example $.get("test.cgi");
*
* @example $.get("test.cgi", { name: "John", time: "2pm" } );
*
* @example $.get("test.cgi", function(data){
* alert("Data Loaded: " + data);
* });
*
* @example $.get("test.cgi",
* { name: "John", time: "2pm" },
* function(data){
* alert("Data Loaded: " + data);
* }
* );
*
* @name $.get
* @type XMLHttpRequest
* @param String url The URL of the page to load.
* @param Map params (optional) Key/value pairs that will be sent to the server.
* @param Function callback (optional) A function to be executed whenever the data is loaded successfully.
* @cat Ajax
*/
get: function( url, data, callback, type, ifModified ) {
// shift arguments if data argument was ommited
if ( jQuery.isFunction( data ) ) {
@ -297,110 +105,19 @@ jQuery.extend({
});
},
/**
* Load a remote page using an HTTP GET request, only if it hasn't
* been modified since it was last retrieved.
*
* @example $.getIfModified("test.html");
*
* @example $.getIfModified("test.html", { name: "John", time: "2pm" } );
*
* @example $.getIfModified("test.cgi", function(data){
* alert("Data Loaded: " + data);
* });
*
* @example $.getifModified("test.cgi",
* { name: "John", time: "2pm" },
* function(data){
* alert("Data Loaded: " + data);
* }
* );
*
* @name $.getIfModified
* @type XMLHttpRequest
* @param String url The URL of the page to load.
* @param Map params (optional) Key/value pairs that will be sent to the server.
* @param Function callback (optional) A function to be executed whenever the data is loaded successfully.
* @cat Ajax
*/
// DEPRECATED
getIfModified: function( url, data, callback, type ) {
return jQuery.get(url, data, callback, type, 1);
},
/**
* Loads, and executes, a remote JavaScript file using an HTTP GET request.
*
* Warning: Safari <= 2.0.x is unable to evaluate scripts in a global
* context synchronously. If you load functions via getScript, make sure
* to call them after a delay.
*
* @example $.getScript("test.js");
*
* @example $.getScript("test.js", function(){
* alert("Script loaded and executed.");
* });
*
* @name $.getScript
* @type XMLHttpRequest
* @param String url The URL of the page to load.
* @param Function callback (optional) A function to be executed whenever the data is loaded successfully.
* @cat Ajax
*/
getScript: function( url, callback ) {
return jQuery.get(url, null, callback, "script");
},
/**
* Load JSON data using an HTTP GET request.
*
* @example $.getJSON("test.js", function(json){
* alert("JSON Data: " + json.users[3].name);
* });
*
* @example $.getJSON("test.js",
* { name: "John", time: "2pm" },
* function(json){
* alert("JSON Data: " + json.users[3].name);
* }
* );
*
* @name $.getJSON
* @type XMLHttpRequest
* @param String url The URL of the page to load.
* @param Map params (optional) Key/value pairs that will be sent to the server.
* @param Function callback A function to be executed whenever the data is loaded successfully.
* @cat Ajax
*/
getJSON: function( url, data, callback ) {
return jQuery.get(url, data, callback, "json");
},
/**
* Load a remote page using an HTTP POST request.
*
* @example $.post("test.cgi");
*
* @example $.post("test.cgi", { name: "John", time: "2pm" } );
*
* @example $.post("test.cgi", function(data){
* alert("Data Loaded: " + data);
* });
*
* @example $.post("test.cgi",
* { name: "John", time: "2pm" },
* function(data){
* alert("Data Loaded: " + data);
* }
* );
*
* @name $.post
* @type XMLHttpRequest
* @param String url The URL of the page to load.
* @param Map params (optional) Key/value pairs that will be sent to the server.
* @param Function callback (optional) A function to be executed whenever the data is loaded successfully.
* @cat Ajax
*/
post: function( url, data, callback, type ) {
if ( jQuery.isFunction( data ) ) {
callback = data;
@ -416,51 +133,11 @@ jQuery.extend({
});
},
/**
* Set the timeout in milliseconds of all AJAX requests to a specific amount of time.
* This will make all future AJAX requests timeout after a specified amount
* of time.
*
* Set to null or 0 to disable timeouts (default).
*
* You can manually abort requests with the XMLHttpRequest's (returned by
* all ajax functions) abort() method.
*
* Deprecated. Use $.ajaxSetup instead.
*
* @example $.ajaxTimeout( 5000 );
* @desc Make all AJAX requests timeout after 5 seconds.
*
* @name $.ajaxTimeout
* @type undefined
* @param Number time How long before an AJAX request times out, in milliseconds.
* @cat Ajax
*/
// DEPRECATED
ajaxTimeout: function( timeout ) {
jQuery.ajaxSettings.timeout = timeout;
},
/**
* Setup global settings for AJAX requests.
*
* See $.ajax for a description of all available options.
*
* @example $.ajaxSetup( {
* url: "/xmlhttp/",
* global: false,
* type: "POST"
* } );
* $.ajax({ data: myData });
* @desc Sets the defaults for AJAX requests to the url "/xmlhttp/",
* disables global handlers and uses POST instead of GET. The following
* AJAX requests then sends some data without having to set anything else.
*
* @name $.ajaxSetup
* @type undefined
* @param Map settings Key/value pairs to use for all AJAX requests
* @cat Ajax
*/
ajaxSetup: function( settings ) {
jQuery.extend( jQuery.ajaxSettings, settings );
},
@ -478,128 +155,6 @@ jQuery.extend({
// Last-Modified header cache for next request
lastModified: {},
/**
* Load a remote page using an HTTP request.
*
* This is jQuery's low-level AJAX implementation. See $.get, $.post etc. for
* higher-level abstractions that are often easier to understand and use,
* but don't offer as much functionality (such as error callbacks).
*
* $.ajax() returns the XMLHttpRequest that it creates. In most cases you won't
* need that object to manipulate directly, but it is available if you need to
* abort the request manually.
*
* '''Note:''' If you specify the dataType option described below, make sure
* the server sends the correct MIME type in the response (eg. xml as "text/xml").
* Sending the wrong MIME type can lead to unexpected problems in your script.
* See [[Specifying the Data Type for AJAX Requests]] for more information.
*
* Supported datatypes are (see dataType option):
*
* "xml": Returns a XML document that can be processed via jQuery.
*
* "html": Returns HTML as plain text, included script tags are evaluated.
*
* "script": Evaluates the response as Javascript and returns it as plain text.
*
* "json": Evaluates the response as JSON and returns a Javascript Object
*
* $.ajax() takes one argument, an object of key/value pairs, that are
* used to initalize and handle the request. These are all the key/values that can
* be used:
*
* (String) url - The URL to request.
*
* (String) type - The type of request to make ("POST" or "GET"), default is "GET".
*
* (String) dataType - The type of data that you're expecting back from
* the server. No default: If the server sends xml, the responseXML, otherwise
* the responseText is passed to the success callback.
*
* (Boolean) ifModified - Allow the request to be successful only if the
* response has changed since the last request. This is done by checking the
* Last-Modified header. Default value is false, ignoring the header.
*
* (Number) timeout - Local timeout in milliseconds to override global timeout, eg. to give a
* single request a longer timeout while all others timeout after 1 second.
* See $.ajaxTimeout() for global timeouts.
*
* (Boolean) global - Whether to trigger global AJAX event handlers for
* this request, default is true. Set to false to prevent that global handlers
* like ajaxStart or ajaxStop are triggered.
*
* (Function) error - A function to be called if the request fails. The
* function gets passed tree arguments: The XMLHttpRequest object, a
* string describing the type of error that occurred and an optional
* exception object, if one occured.
*
* (Function) success - A function to be called if the request succeeds. The
* function gets passed one argument: The data returned from the server,
* formatted according to the 'dataType' parameter.
*
* (Function) complete - A function to be called when the request finishes. The
* function gets passed two arguments: The XMLHttpRequest object and a
* string describing the type of success of the request.
*
* (Object|String) data - Data to be sent to the server. Converted to a query
* string, if not already a string. Is appended to the url for GET-requests.
* See processData option to prevent this automatic processing.
*
* (String) contentType - When sending data to the server, use this content-type.
* Default is "application/x-www-form-urlencoded", which is fine for most cases.
*
* (Boolean) processData - By default, data passed in to the data option as an object
* other as string will be processed and transformed into a query string, fitting to
* the default content-type "application/x-www-form-urlencoded". If you want to send
* DOMDocuments, set this option to false.
*
* (Boolean) async - By default, all requests are sent asynchronous (set to true).
* If you need synchronous requests, set this option to false.
*
* (Function) beforeSend - A pre-callback to set custom headers etc., the
* XMLHttpRequest is passed as the only argument.
*
* @example $.ajax({
* type: "GET",
* url: "test.js",
* dataType: "script"
* })
* @desc Load and execute a JavaScript file.
*
* @example $.ajax({
* type: "POST",
* url: "some.php",
* data: "name=John&location=Boston",
* success: function(msg){
* alert( "Data Saved: " + msg );
* }
* });
* @desc Save some data to the server and notify the user once its complete.
*
* @example var html = $.ajax({
* url: "some.php",
* async: false
* }).responseText;
* @desc Loads data synchronously. Blocks the browser while the requests is active.
* It is better to block user interaction by other means when synchronization is
* necessary.
*
* @example var xmlDocument = [create xml document];
* $.ajax({
* url: "page.php",
* processData: false,
* data: xmlDocument,
* success: handleResponse
* });
* @desc Sends an xml document as data to the server. By setting the processData
* option to false, the automatic conversion of data to strings is prevented.
*
* @name $.ajax
* @type XMLHttpRequest
* @param Map properties Key/value pairs to initialize the request with.
* @cat Ajax
* @see ajaxSetup(Map)
*/
ajax: function( s ) {
var jsonp, jsre = /=(\?|%3F)/g, status, data;
@ -862,12 +417,6 @@ jQuery.extend({
return false;
},
/* Get the data out of an XMLHttpRequest.
* Return parsed XML if content-type header is "xml" and type is "xml" or omitted,
* otherwise return plain text.
* (String) data - The type of data that you're expecting back,
* (e.g. "xml", "html", "script")
*/
httpData: function( r, type ) {
var ct = r.getResponseHeader("content-type");
var xml = type == "xml" || !type && ct && ct.indexOf("xml") >= 0;

View file

@ -285,88 +285,12 @@ jQuery.event = {
};
jQuery.fn.extend({
/**
* Binds a handler to a particular event (like click) for each matched element.
* The event handler is passed an event object that you can use to prevent
* default behaviour. To stop both default action and event bubbling, your handler
* has to return false.
*
* In most cases, you can define your event handlers as anonymous functions
* (see first example). In cases where that is not possible, you can pass additional
* data as the second parameter (and the handler function as the third), see
* second example.
*
* Calling bind with an event type of "unload" will automatically
* use the one method instead of bind to prevent memory leaks.
*
* @example $("p").bind("click", function(){
* alert( $(this).text() );
* });
* @before <p>Hello</p>
* @result alert("Hello")
*
* @example function handler(event) {
* alert(event.data.foo);
* }
* $("p").bind("click", {foo: "bar"}, handler)
* @result alert("bar")
* @desc Pass some additional data to the event handler.
*
* @example $("form").bind("submit", function() { return false; })
* @desc Cancel a default action and prevent it from bubbling by returning false
* from your function.
*
* @example $("form").bind("submit", function(event){
* event.preventDefault();
* });
* @desc Cancel only the default action by using the preventDefault method.
*
*
* @example $("form").bind("submit", function(event){
* event.stopPropagation();
* });
* @desc Stop only an event from bubbling by using the stopPropagation method.
*
* @name bind
* @type jQuery
* @param String type An event type
* @param Object data (optional) Additional data passed to the event handler as event.data
* @param Function fn A function to bind to the event on each of the set of matched elements
* @cat Events
*/
bind: function( type, data, fn ) {
return type == "unload" ? this.one(type, data, fn) : this.each(function(){
jQuery.event.add( this, type, fn || data, fn && data );
});
},
/**
* Binds a handler to a particular event (like click) for each matched element.
* The handler is executed only once for each element. Otherwise, the same rules
* as described in bind() apply.
* The event handler is passed an event object that you can use to prevent
* default behaviour. To stop both default action and event bubbling, your handler
* has to return false.
*
* In most cases, you can define your event handlers as anonymous functions
* (see first example). In cases where that is not possible, you can pass additional
* data as the second paramter (and the handler function as the third), see
* second example.
*
* @example $("p").one("click", function(){
* alert( $(this).text() );
* });
* @before <p>Hello</p>
* @result alert("Hello")
*
* @name one
* @type jQuery
* @param String type An event type
* @param Object data (optional) Additional data passed to the event handler as event.data
* @param Function fn A function to bind to the event on each of the set of matched elements
* @cat Events
*/
one: function( type, data, fn ) {
return this.each(function(){
jQuery.event.add( this, type, function(event) {
@ -376,73 +300,12 @@ jQuery.fn.extend({
});
},
/**
* The opposite of bind, removes a bound event from each of the matched
* elements.
*
* Without any arguments, all bound events are removed.
*
* If the type is provided, all bound events of that type are removed.
*
* If the function that was passed to bind is provided as the second argument,
* only that specific event handler is removed.
*
* @example $("p").unbind()
* @before <p onclick="alert('Hello');">Hello</p>
* @result [ <p>Hello</p> ]
*
* @example $("p").unbind( "click" )
* @before <p onclick="alert('Hello');">Hello</p>
* @result [ <p>Hello</p> ]
*
* @example $("p").unbind( "click", function() { alert("Hello"); } )
* @before <p onclick="alert('Hello');">Hello</p>
* @result [ <p>Hello</p> ]
*
* @name unbind
* @type jQuery
* @param String type (optional) An event type
* @param Function fn (optional) A function to unbind from the event on each of the set of matched elements
* @cat Events
*/
unbind: function( type, fn ) {
return this.each(function(){
jQuery.event.remove( this, type, fn );
});
},
/**
* Trigger a type of event on every matched element. This will also cause
* the default action of the browser with the same name (if one exists)
* to be executed. For example, passing 'submit' to the trigger()
* function will also cause the browser to submit the form. This
* default action can be prevented by returning false from one of
* the functions bound to the event.
*
* You can also trigger custom events registered with bind.
*
* @example $("p").trigger("click")
* @before <p click="alert('hello')">Hello</p>
* @result alert('hello')
*
* @example $("p").click(function(event, a, b) {
* // when a normal click fires, a and b are undefined
* // for a trigger like below a refers too "foo" and b refers to "bar"
* }).trigger("click", ["foo", "bar"]);
* @desc Example of how to pass arbitrary data to an event
*
* @example $("p").bind("myEvent",function(event,message1,message2) {
* alert(message1 + ' ' + message2);
* });
* $("p").trigger("myEvent",["Hello","World"]);
* @result alert('Hello World') // One for each paragraph
*
* @name trigger
* @type jQuery
* @param String type An event type to trigger.
* @param Array data (optional) Additional data to pass as arguments (after the event object) to the event handler
* @cat Events
*/
trigger: function( type, data, fn ) {
return this.each(function(){
jQuery.event.trigger( type, data, this, true, fn );
@ -454,26 +317,6 @@ jQuery.fn.extend({
return jQuery.event.trigger( type, data, this[0], false, fn );
},
/**
* Toggle between two function calls every other click.
* Whenever a matched element is clicked, the first specified function
* is fired, when clicked again, the second is fired. All subsequent
* clicks continue to rotate through the two functions.
*
* Use unbind("click") to remove.
*
* @example $("p").toggle(function(){
* $(this).addClass("selected");
* },function(){
* $(this).removeClass("selected");
* });
*
* @name toggle
* @type jQuery
* @param Function even The function to execute on every even click.
* @param Function odd The function to execute on every odd click.
* @cat Events
*/
toggle: function() {
// Save reference to arguments for access in closure
var a = arguments;
@ -489,32 +332,7 @@ jQuery.fn.extend({
return a[this.lastToggle].apply( this, [e] ) || false;
});
},
/**
* A method for simulating hovering (moving the mouse on, and off,
* an object). This is a custom method which provides an 'in' to a
* frequent task.
*
* Whenever the mouse cursor is moved over a matched
* element, the first specified function is fired. Whenever the mouse
* moves off of the element, the second specified function fires.
* Additionally, checks are in place to see if the mouse is still within
* the specified element itself (for example, an image inside of a div),
* and if it is, it will continue to 'hover', and not move out
* (a common error in using a mouseout event handler).
*
* @example $("p").hover(function(){
* $(this).addClass("hover");
* },function(){
* $(this).removeClass("hover");
* });
*
* @name hover
* @type jQuery
* @param Function over The function to fire whenever the mouse is moved over a matched element.
* @param Function out The function to fire whenever the mouse is moved off of a matched element.
* @cat Events
*/
hover: function(f,g) {
// A private function for handling mouse 'hovering'
@ -536,43 +354,6 @@ jQuery.fn.extend({
return this.mouseover(handleHover).mouseout(handleHover);
},
/**
* Bind a function to be executed whenever the DOM is ready to be
* traversed and manipulated. This is probably the most important
* function included in the event module, as it can greatly improve
* the response times of your web applications.
*
* In a nutshell, this is a solid replacement for using window.onload,
* and attaching a function to that. By using this method, your bound function
* will be called the instant the DOM is ready to be read and manipulated,
* which is when what 99.99% of all JavaScript code needs to run.
*
* There is one argument passed to the ready event handler: A reference to
* the jQuery function. You can name that argument whatever you like, and
* can therefore stick with the $ alias without risk of naming collisions.
*
* Please ensure you have no code in your &lt;body&gt; onload event handler,
* otherwise $(document).ready() may not fire.
*
* You can have as many $(document).ready events on your page as you like.
* The functions are then executed in the order they were added.
*
* @example $(document).ready(function(){ Your code here... });
*
* @example jQuery(function($) {
* // Your code using failsafe $ alias here...
* });
* @desc Uses both the [[Core#.24.28_fn_.29|shortcut]] for $(document).ready() and the argument
* to write failsafe jQuery code using the $ alias, without relying on the
* global alias.
*
* @name ready
* @type jQuery
* @param Function fn The function to be executed when the DOM is ready.
* @cat Events
* @see $.noConflict()
* @see $(Function)
*/
ready: function(f) {
// Attach the listeners
bindReady();
@ -626,356 +407,16 @@ jQuery.extend({
}
});
/**
* Bind a function to the scroll event of each matched element.
*
* @example $("p").scroll( function() { alert("Hello"); } );
* @before <p>Hello</p>
* @result <p onscroll="alert('Hello');">Hello</p>
*
* @name scroll
* @type jQuery
* @param Function fn A function to bind to the scroll event on each of the matched elements.
* @cat Events
*/
/**
* Bind a function to the submit event of each matched element.
*
* @example $("#myform").submit( function() {
* return $("input", this).val().length > 0;
* } );
* @before <form id="myform"><input /></form>
* @desc Prevents the form submission when the input has no value entered.
*
* @name submit
* @type jQuery
* @param Function fn A function to bind to the submit event on each of the matched elements.
* @cat Events
*/
/**
* Trigger the submit event of each matched element. This causes all of the functions
* that have been bound to that submit event to be executed, and calls the browser's
* default submit action on the matching element(s). This default action can be prevented
* by returning false from one of the functions bound to the submit event.
*
* Note: This does not execute the submit method of the form element! If you need to
* submit the form via code, you have to use the DOM method, eg. $("form")[0].submit();
*
* @example $("form").submit();
* @desc Triggers all submit events registered to the matched form(s), and submits them.
*
* @name submit
* @type jQuery
* @cat Events
*/
/**
* Bind a function to the focus event of each matched element.
*
* @example $("p").focus( function() { alert("Hello"); } );
* @before <p>Hello</p>
* @result <p onfocus="alert('Hello');">Hello</p>
*
* @name focus
* @type jQuery
* @param Function fn A function to bind to the focus event on each of the matched elements.
* @cat Events
*/
/**
* Trigger the focus event of each matched element. This causes all of the functions
* that have been bound to thet focus event to be executed.
*
* Note: This does not execute the focus method of the underlying elements! If you need to
* focus an element via code, you have to use the DOM method, eg. $("#myinput")[0].focus();
*
* @example $("p").focus();
* @before <p onfocus="alert('Hello');">Hello</p>
* @result alert('Hello');
*
* @name focus
* @type jQuery
* @cat Events
*/
/**
* Bind a function to the keydown event of each matched element.
*
* @example $("p").keydown( function() { alert("Hello"); } );
* @before <p>Hello</p>
* @result <p onkeydown="alert('Hello');">Hello</p>
*
* @name keydown
* @type jQuery
* @param Function fn A function to bind to the keydown event on each of the matched elements.
* @cat Events
*/
/**
* Bind a function to the dblclick event of each matched element.
*
* @example $("p").dblclick( function() { alert("Hello"); } );
* @before <p>Hello</p>
* @result <p ondblclick="alert('Hello');">Hello</p>
*
* @name dblclick
* @type jQuery
* @param Function fn A function to bind to the dblclick event on each of the matched elements.
* @cat Events
*/
/**
* Bind a function to the keypress event of each matched element.
*
* @example $("p").keypress( function() { alert("Hello"); } );
* @before <p>Hello</p>
* @result <p onkeypress="alert('Hello');">Hello</p>
*
* @name keypress
* @type jQuery
* @param Function fn A function to bind to the keypress event on each of the matched elements.
* @cat Events
*/
/**
* Bind a function to the error event of each matched element.
*
* @example $("p").error( function() { alert("Hello"); } );
* @before <p>Hello</p>
* @result <p onerror="alert('Hello');">Hello</p>
*
* @name error
* @type jQuery
* @param Function fn A function to bind to the error event on each of the matched elements.
* @cat Events
*/
/**
* Bind a function to the blur event of each matched element.
*
* @example $("p").blur( function() { alert("Hello"); } );
* @before <p>Hello</p>
* @result <p onblur="alert('Hello');">Hello</p>
*
* @name blur
* @type jQuery
* @param Function fn A function to bind to the blur event on each of the matched elements.
* @cat Events
*/
/**
* Trigger the blur event of each matched element. This causes all of the functions
* that have been bound to that blur event to be executed, and calls the browser's
* default blur action on the matching element(s). This default action can be prevented
* by returning false from one of the functions bound to the blur event.
*
* Note: This does not execute the blur method of the underlying elements! If you need to
* blur an element via code, you have to use the DOM method, eg. $("#myinput")[0].blur();
*
* @example $("p").blur();
* @before <p onblur="alert('Hello');">Hello</p>
* @result alert('Hello');
*
* @name blur
* @type jQuery
* @cat Events
*/
/**
* Bind a function to the load event of each matched element.
*
* @example $("p").load( function() { alert("Hello"); } );
* @before <p>Hello</p>
* @result <p onload="alert('Hello');">Hello</p>
*
* @name load
* @type jQuery
* @param Function fn A function to bind to the load event on each of the matched elements.
* @cat Events
*/
/**
* Bind a function to the select event of each matched element.
*
* @example $("p").select( function() { alert("Hello"); } );
* @before <p>Hello</p>
* @result <p onselect="alert('Hello');">Hello</p>
*
* @name select
* @type jQuery
* @param Function fn A function to bind to the select event on each of the matched elements.
* @cat Events
*/
/**
* Trigger the select event of each matched element. This causes all of the functions
* that have been bound to that select event to be executed, and calls the browser's
* default select action on the matching element(s). This default action can be prevented
* by returning false from one of the functions bound to the select event.
*
* @example $("p").select();
* @before <p onselect="alert('Hello');">Hello</p>
* @result alert('Hello');
*
* @name select
* @type jQuery
* @cat Events
*/
/**
* Bind a function to the mouseup event of each matched element.
*
* @example $("p").mouseup( function() { alert("Hello"); } );
* @before <p>Hello</p>
* @result <p onmouseup="alert('Hello');">Hello</p>
*
* @name mouseup
* @type jQuery
* @param Function fn A function to bind to the mouseup event on each of the matched elements.
* @cat Events
*/
/**
* Bind a function to the unload event of each matched element.
*
* @example $("p").unload( function() { alert("Hello"); } );
* @before <p>Hello</p>
* @result <p onunload="alert('Hello');">Hello</p>
*
* @name unload
* @type jQuery
* @param Function fn A function to bind to the unload event on each of the matched elements.
* @cat Events
*/
/**
* Bind a function to the change event of each matched element.
*
* @example $("p").change( function() { alert("Hello"); } );
* @before <p>Hello</p>
* @result <p onchange="alert('Hello');">Hello</p>
*
* @name change
* @type jQuery
* @param Function fn A function to bind to the change event on each of the matched elements.
* @cat Events
*/
/**
* Bind a function to the mouseout event of each matched element.
*
* @example $("p").mouseout( function() { alert("Hello"); } );
* @before <p>Hello</p>
* @result <p onmouseout="alert('Hello');">Hello</p>
*
* @name mouseout
* @type jQuery
* @param Function fn A function to bind to the mouseout event on each of the matched elements.
* @cat Events
*/
/**
* Bind a function to the keyup event of each matched element.
*
* @example $("p").keyup( function() { alert("Hello"); } );
* @before <p>Hello</p>
* @result <p onkeyup="alert('Hello');">Hello</p>
*
* @name keyup
* @type jQuery
* @param Function fn A function to bind to the keyup event on each of the matched elements.
* @cat Events
*/
/**
* Bind a function to the click event of each matched element.
*
* @example $("p").click( function() { alert("Hello"); } );
* @before <p>Hello</p>
* @result <p onclick="alert('Hello');">Hello</p>
*
* @name click
* @type jQuery
* @param Function fn A function to bind to the click event on each of the matched elements.
* @cat Events
*/
/**
* Trigger the click event of each matched element. This causes all of the functions
* that have been bound to thet click event to be executed.
*
* @example $("p").click();
* @before <p onclick="alert('Hello');">Hello</p>
* @result alert('Hello');
*
* @name click
* @type jQuery
* @cat Events
*/
/**
* Bind a function to the resize event of each matched element.
*
* @example $("p").resize( function() { alert("Hello"); } );
* @before <p>Hello</p>
* @result <p onresize="alert('Hello');">Hello</p>
*
* @name resize
* @type jQuery
* @param Function fn A function to bind to the resize event on each of the matched elements.
* @cat Events
*/
/**
* Bind a function to the mousemove event of each matched element.
*
* @example $("p").mousemove( function() { alert("Hello"); } );
* @before <p>Hello</p>
* @result <p onmousemove="alert('Hello');">Hello</p>
*
* @name mousemove
* @type jQuery
* @param Function fn A function to bind to the mousemove event on each of the matched elements.
* @cat Events
*/
/**
* Bind a function to the mousedown event of each matched element.
*
* @example $("p").mousedown( function() { alert("Hello"); } );
* @before <p>Hello</p>
* @result <p onmousedown="alert('Hello');">Hello</p>
*
* @name mousedown
* @type jQuery
* @param Function fn A function to bind to the mousedown event on each of the matched elements.
* @cat Events
*/
/**
* Bind a function to the mouseover event of each matched element.
*
* @example $("p").mouseover( function() { alert("Hello"); } );
* @before <p>Hello</p>
* @result <p onmouseover="alert('Hello');">Hello</p>
*
* @name mouseover
* @type jQuery
* @param Function fn A function to bind to the mousedown event on each of the matched elements.
* @cat Events
*/
jQuery.each( ("blur,focus,load,resize,scroll,unload,click,dblclick," +
"mousedown,mouseup,mousemove,mouseover,mouseout,change,select," +
"submit,keydown,keypress,keyup,error").split(","), function(i,o){
// Handle event binding
jQuery.fn[o] = function(f){
return f ? this.bind(o, f) : this.trigger(o);
};
});
jQuery.each( ("blur,focus,load,resize,scroll,unload,click,dblclick," +
"mousedown,mouseup,mousemove,mouseover,mouseout,change,select," +
"submit,keydown,keypress,keyup,error").split(","), function(i,o){
// Handle event binding
jQuery.fn[o] = function(f){
return f ? this.bind(o, f) : this.trigger(o);
};
});
var readyBound = false;

View file

@ -1,37 +1,4 @@
jQuery.fn.extend({
/**
* Displays each of the set of matched elements if they are hidden.
*
* @example $("p").show()
* @before <p style="display: none">Hello</p>
* @result [ <p style="display: block">Hello</p> ]
*
* @name show
* @type jQuery
* @cat Effects
*/
/**
* Show all matched elements using a graceful animation and firing an
* optional callback after completion.
*
* The height, width, and opacity of each of the matched elements
* are changed dynamically according to the specified speed.
*
* @example $("p").show("slow");
*
* @example $("p").show("slow",function(){
* alert("Animation Done.");
* });
*
* @name show
* @type jQuery
* @param String|Number speed A string representing one of the three predefined speeds ("slow", "normal", or "fast") or the number of milliseconds to run the animation (e.g. 1000).
* @param Function callback (optional) A function to be executed whenever the animation completes.
* @cat Effects
* @see hide(String|Number,Function)
*/
show: function(speed,callback){
return speed ?
this.animate({
@ -45,38 +12,6 @@ jQuery.fn.extend({
}).end();
},
/**
* Hides each of the set of matched elements if they are shown.
*
* @example $("p").hide()
* @before <p>Hello</p>
* @result [ <p style="display: none">Hello</p> ]
*
* @name hide
* @type jQuery
* @cat Effects
*/
/**
* Hide all matched elements using a graceful animation and firing an
* optional callback after completion.
*
* The height, width, and opacity of each of the matched elements
* are changed dynamically according to the specified speed.
*
* @example $("p").hide("slow");
*
* @example $("p").hide("slow",function(){
* alert("Animation Done.");
* });
*
* @name hide
* @type jQuery
* @param String|Number speed A string representing one of the three predefined speeds ("slow", "normal", or "fast") or the number of milliseconds to run the animation (e.g. 1000).
* @param Function callback (optional) A function to be executed whenever the animation completes.
* @cat Effects
* @see show(String|Number,Function)
*/
hide: function(speed,callback){
return speed ?
this.animate({
@ -94,19 +29,6 @@ jQuery.fn.extend({
// Save the old toggle function
_toggle: jQuery.fn.toggle,
/**
* Toggles each of the set of matched elements. If they are shown,
* toggle makes them hidden. If they are hidden, toggle
* makes them shown.
*
* @example $("p").toggle()
* @before <p>Hello</p><p style="display: none">Hello Again</p>
* @result [ <p style="display: none">Hello</p>, <p style="display: block">Hello Again</p> ]
*
* @name toggle
* @type jQuery
* @cat Effects
*/
toggle: function( fn, fn2 ){
return jQuery.isFunction(fn) && jQuery.isFunction(fn2) ?
this._toggle( fn, fn2 ) :
@ -119,196 +41,30 @@ jQuery.fn.extend({
});
},
/**
* Reveal all matched elements by adjusting their height and firing an
* optional callback after completion.
*
* Only the height is adjusted for this animation, causing all matched
* elements to be revealed in a "sliding" manner.
*
* @example $("p").slideDown("slow");
*
* @example $("p").slideDown("slow",function(){
* alert("Animation Done.");
* });
*
* @name slideDown
* @type jQuery
* @param String|Number speed (optional) A string representing one of the three predefined speeds ("slow", "normal", or "fast") or the number of milliseconds to run the animation (e.g. 1000).
* @param Function callback (optional) A function to be executed whenever the animation completes.
* @cat Effects
* @see slideUp(String|Number,Function)
* @see slideToggle(String|Number,Function)
*/
slideDown: function(speed,callback){
return this.animate({height: "show"}, speed, callback);
},
/**
* Hide all matched elements by adjusting their height and firing an
* optional callback after completion.
*
* Only the height is adjusted for this animation, causing all matched
* elements to be hidden in a "sliding" manner.
*
* @example $("p").slideUp("slow");
*
* @example $("p").slideUp("slow",function(){
* alert("Animation Done.");
* });
*
* @name slideUp
* @type jQuery
* @param String|Number speed (optional) A string representing one of the three predefined speeds ("slow", "normal", or "fast") or the number of milliseconds to run the animation (e.g. 1000).
* @param Function callback (optional) A function to be executed whenever the animation completes.
* @cat Effects
* @see slideDown(String|Number,Function)
* @see slideToggle(String|Number,Function)
*/
slideUp: function(speed,callback){
return this.animate({height: "hide"}, speed, callback);
},
/**
* Toggle the visibility of all matched elements by adjusting their height and firing an
* optional callback after completion.
*
* Only the height is adjusted for this animation, causing all matched
* elements to be hidden in a "sliding" manner.
*
* @example $("p").slideToggle("slow");
*
* @example $("p").slideToggle("slow",function(){
* alert("Animation Done.");
* });
*
* @name slideToggle
* @type jQuery
* @param String|Number speed (optional) A string representing one of the three predefined speeds ("slow", "normal", or "fast") or the number of milliseconds to run the animation (e.g. 1000).
* @param Function callback (optional) A function to be executed whenever the animation completes.
* @cat Effects
* @see slideDown(String|Number,Function)
* @see slideUp(String|Number,Function)
*/
slideToggle: function(speed, callback){
return this.animate({height: "toggle"}, speed, callback);
},
/**
* Fade in all matched elements by adjusting their opacity and firing an
* optional callback after completion.
*
* Only the opacity is adjusted for this animation, meaning that
* all of the matched elements should already have some form of height
* and width associated with them.
*
* @example $("p").fadeIn("slow");
*
* @example $("p").fadeIn("slow",function(){
* alert("Animation Done.");
* });
*
* @name fadeIn
* @type jQuery
* @param String|Number speed (optional) A string representing one of the three predefined speeds ("slow", "normal", or "fast") or the number of milliseconds to run the animation (e.g. 1000).
* @param Function callback (optional) A function to be executed whenever the animation completes.
* @cat Effects
* @see fadeOut(String|Number,Function)
* @see fadeTo(String|Number,Number,Function)
*/
fadeIn: function(speed, callback){
return this.animate({opacity: "show"}, speed, callback);
},
/**
* Fade out all matched elements by adjusting their opacity and firing an
* optional callback after completion.
*
* Only the opacity is adjusted for this animation, meaning that
* all of the matched elements should already have some form of height
* and width associated with them.
*
* @example $("p").fadeOut("slow");
*
* @example $("p").fadeOut("slow",function(){
* alert("Animation Done.");
* });
*
* @name fadeOut
* @type jQuery
* @param String|Number speed (optional) A string representing one of the three predefined speeds ("slow", "normal", or "fast") or the number of milliseconds to run the animation (e.g. 1000).
* @param Function callback (optional) A function to be executed whenever the animation completes.
* @cat Effects
* @see fadeIn(String|Number,Function)
* @see fadeTo(String|Number,Number,Function)
*/
fadeOut: function(speed, callback){
return this.animate({opacity: "hide"}, speed, callback);
},
/**
* Fade the opacity of all matched elements to a specified opacity and firing an
* optional callback after completion.
*
* Only the opacity is adjusted for this animation, meaning that
* all of the matched elements should already have some form of height
* and width associated with them.
*
* @example $("p").fadeTo("slow", 0.5);
*
* @example $("p").fadeTo("slow", 0.5, function(){
* alert("Animation Done.");
* });
*
* @name fadeTo
* @type jQuery
* @param String|Number speed A string representing one of the three predefined speeds ("slow", "normal", or "fast") or the number of milliseconds to run the animation (e.g. 1000).
* @param Number opacity The opacity to fade to (a number from 0 to 1).
* @param Function callback (optional) A function to be executed whenever the animation completes.
* @cat Effects
* @see fadeIn(String|Number,Function)
* @see fadeOut(String|Number,Function)
*/
fadeTo: function(speed,to,callback){
return this.animate({opacity: to}, speed, callback);
},
/**
* A function for making your own, custom animations. The key aspect of
* this function is the object of style properties that will be animated,
* and to what end. Each key within the object represents a style property
* that will also be animated (for example: "height", "top", or "opacity").
*
* Note that properties should be specified using camel case
* eg. marginLeft instead of margin-left.
*
* The value associated with the key represents to what end the property
* will be animated. If a number is provided as the value, then the style
* property will be transitioned from its current state to that new number.
* Otherwise if the string "hide", "show", or "toggle" is provided, a default
* animation will be constructed for that property.
*
* @example $("p").animate({
* height: 'toggle', opacity: 'toggle'
* }, "slow");
*
* @example $("p").animate({
* left: 50, opacity: 'show'
* }, 500);
*
* @example $("p").animate({
* opacity: 'show'
* }, "slow", "easein");
* @desc An example of using an 'easing' function to provide a different style of animation. This will only work if you have a plugin that provides this easing function (Only "swing" and "linear" are provided by default, with jQuery).
*
* @name animate
* @type jQuery
* @param Hash params A set of style attributes that you wish to animate, and to what end.
* @param String|Number speed (optional) A string representing one of the three predefined speeds ("slow", "normal", or "fast") or the number of milliseconds to run the animation (e.g. 1000).
* @param String easing (optional) The name of the easing effect that you want to use (e.g. "swing" or "linear"). Defaults to "swing".
* @param Function callback (optional) A function to be executed whenever the animation completes.
* @cat Effects
*/
animate: function( prop, speed, easing, callback ) {
return this.queue(function(){
var hidden = jQuery(this).is(":hidden"),
@ -346,10 +102,6 @@ jQuery.fn.extend({
});
},
/**
*
* @private
*/
queue: function(type,fn){
if ( !fn ) {
fn = type;

1544
src/jquery/jquery.js vendored

File diff suppressed because it is too large Load diff

View file

@ -94,12 +94,6 @@ jQuery.extend({
return cur;
},
/**
* @name $.find
* @type Array<Element>
* @private
* @cat Core
*/
find: function( t, context ) {
// Quickly handle non-string expressions
if ( typeof t != "string" )
@ -427,15 +421,6 @@ jQuery.extend({
return { r: r, t: t };
},
/**
* All ancestors of a given element.
*
* @private
* @name $.parents
* @type Array<Element>
* @param Element elem The element to find the ancestors of.
* @cat DOM/Traversing
*/
parents: function( elem ){
var matched = [];
var cur = elem.parentNode;
@ -446,18 +431,6 @@ jQuery.extend({
return matched;
},
/**
* A handy, and fast, way to traverse in a particular direction and find
* a specific element.
*
* @private
* @name $.nth
* @type DOMElement
* @param DOMElement cur The element to search from.
* @param String|Number num The Nth result to match. Can be a number or a string (like 'even' or 'odd').
* @param String dir The direction to move in (pass in something like 'previousSibling' or 'nextSibling').
* @cat DOM/Traversing
*/
nth: function(cur,result,dir,elem){
result = result || 1;
var num = 0;
@ -469,15 +442,6 @@ jQuery.extend({
return cur;
},
/**
* All elements on a specified axis.
*
* @private
* @name $.sibling
* @type Array
* @param Element elem The element to find all the siblings of (including itself).
* @cat DOM/Traversing
*/
sibling: function( n, elem ) {
var r = [];