aboutsummaryrefslogtreecommitdiffstats
path: root/src/core
diff options
context:
space:
mode:
authorTimmy Willison <timmywillisn@gmail.com>2013-08-15 14:15:49 -0400
committerTimmy Willison <timmywillisn@gmail.com>2013-08-15 14:15:49 -0400
commit6318ae6ab90d4b450dfadf32ab95fe52ed6331cb (patch)
tree50b247fed8569e909e380b281e9145bd1458a39e /src/core
parent7627b8b6d9ef6e57dbd20a55b946bd1991c1223e (diff)
downloadjquery-6318ae6ab90d4b450dfadf32ab95fe52ed6331cb.tar.gz
jquery-6318ae6ab90d4b450dfadf32ab95fe52ed6331cb.zip
AMD-ify jQuery sourcegit s! Woo! Fixes #14113, #14163.
Diffstat (limited to 'src/core')
-rw-r--r--src/core/ready.js92
-rw-r--r--src/core/swap.js29
2 files changed, 121 insertions, 0 deletions
diff --git a/src/core/ready.js b/src/core/ready.js
new file mode 100644
index 000000000..ab9f0801e
--- /dev/null
+++ b/src/core/ready.js
@@ -0,0 +1,92 @@
+define([
+ "../core",
+ "../deferred"
+], function( jQuery ) {
+
+// The deferred used on DOM ready
+var readyList;
+
+jQuery.fn.ready = function( fn ) {
+ // Add the callback
+ jQuery.ready.promise().done( fn );
+
+ return this;
+};
+
+jQuery.extend({
+ // Is the DOM ready to be used? Set to true once it occurs.
+ isReady: false,
+
+ // A counter to track how many items to wait for before
+ // the ready event fires. See #6781
+ readyWait: 1,
+
+ // Hold (or release) the ready event
+ holdReady: function( hold ) {
+ if ( hold ) {
+ jQuery.readyWait++;
+ } else {
+ jQuery.ready( true );
+ }
+ },
+
+ // Handle when the DOM is ready
+ ready: function( wait ) {
+
+ // Abort if there are pending holds or we're already ready
+ if ( wait === true ? --jQuery.readyWait : jQuery.isReady ) {
+ return;
+ }
+
+ // Remember that the DOM is ready
+ jQuery.isReady = true;
+
+ // If a normal DOM Ready event fired, decrement, and wait if need be
+ if ( wait !== true && --jQuery.readyWait > 0 ) {
+ return;
+ }
+
+ // If there are functions bound, to execute
+ readyList.resolveWith( document, [ jQuery ] );
+
+ // Trigger any bound ready events
+ if ( jQuery.fn.trigger ) {
+ jQuery( document ).trigger("ready").off("ready");
+ }
+ }
+});
+
+/**
+ * The ready event handler and self cleanup method
+ */
+function completed() {
+ document.removeEventListener( "DOMContentLoaded", completed, false );
+ window.removeEventListener( "load", completed, false );
+ jQuery.ready();
+}
+
+jQuery.ready.promise = function( obj ) {
+ if ( !readyList ) {
+
+ readyList = jQuery.Deferred();
+
+ // Catch cases where $(document).ready() is called after the browser event has already occurred.
+ // we once tried to use readyState "interactive" here, but it caused issues like the one
+ // discovered by ChrisS here: http://bugs.jquery.com/ticket/12282#comment:15
+ if ( document.readyState === "complete" ) {
+ // Handle it asynchronously to allow scripts the opportunity to delay ready
+ setTimeout( jQuery.ready );
+
+ } else {
+
+ // Use the handy event callback
+ document.addEventListener( "DOMContentLoaded", completed, false );
+
+ // A fallback to window.onload, that will always work
+ window.addEventListener( "load", completed, false );
+ }
+ }
+ return readyList.promise( obj );
+};
+
+});
diff --git a/src/core/swap.js b/src/core/swap.js
new file mode 100644
index 000000000..95f4e2c69
--- /dev/null
+++ b/src/core/swap.js
@@ -0,0 +1,29 @@
+define([
+ "../core"
+], function( jQuery ) {
+
+ // A method for quickly swapping in/out CSS properties to get correct calculations.
+ // Note: this method belongs to the css module but it's needed here for the support module.
+ // If support gets modularized, this method should be moved back to the css module.
+ jQuery.swap = function( elem, options, callback, args ) {
+ var ret, name,
+ old = {};
+
+ // Remember the old values, and insert the new ones
+ for ( name in options ) {
+ old[ name ] = elem.style[ name ];
+ elem.style[ name ] = options[ name ];
+ }
+
+ ret = callback.apply( elem, args || [] );
+
+ // Revert the old values
+ for ( name in options ) {
+ elem.style[ name ] = old[ name ];
+ }
+
+ return ret;
+ };
+
+ return jQuery.swap;
+});