From c252c5fac2a25869524c2eba2e93d4230e6af25c Mon Sep 17 00:00:00 2001 From: Timmy Willison Date: Wed, 6 May 2015 10:47:07 -0700 Subject: [PATCH] Core: remove custom ready event Fixes gh-2264 Close gh-2265 --- src/core/ready.js | 7 ------ test/unit/ready.js | 63 ++++++++++++++++++++++------------------------ 2 files changed, 30 insertions(+), 40 deletions(-) diff --git a/src/core/ready.js b/src/core/ready.js index c9ffdd749..bea0496da 100644 --- a/src/core/ready.js +++ b/src/core/ready.js @@ -1,7 +1,6 @@ define([ "../core", "../var/document", - "../core/init", "../deferred" ], function( jQuery, document ) { @@ -50,12 +49,6 @@ jQuery.extend({ // If there are functions bound, to execute readyList.resolveWith( document, [ jQuery ] ); - - // Trigger any bound ready events - if ( jQuery.fn.triggerHandler ) { - jQuery( document ).triggerHandler( "ready" ); - jQuery( document ).off( "ready" ); - } } }); diff --git a/test/unit/ready.js b/test/unit/ready.js index 5cea77447..27d451936 100644 --- a/test/unit/ready.js +++ b/test/unit/ready.js @@ -1,73 +1,70 @@ -module("event"); +module( "event" ); -(function(){ +(function() { var notYetReady, noEarlyExecution, order = [], args = {}; notYetReady = !jQuery.isReady; - test("jQuery.isReady", function() { - expect(2); + test( "jQuery.isReady", function() { + expect( 2 ); - equal(notYetReady, true, "jQuery.isReady should not be true before DOM ready"); - equal(jQuery.isReady, true, "jQuery.isReady should be true once DOM is ready"); + equal( notYetReady, true, "jQuery.isReady should not be true before DOM ready" ); + equal( jQuery.isReady, true, "jQuery.isReady should be true once DOM is ready" ); }); // Create an event handler. function makeHandler( testId ) { + // When returned function is executed, push testId onto `order` array // to ensure execution order. Also, store event handler arg to ensure // the correct arg is being passed into the event handler. return function( arg ) { - order.push(testId); + order.push( testId ); args[testId] = arg; }; } // Bind to the ready event in every possible way. - jQuery(makeHandler("a")); - jQuery(document).ready(makeHandler("b")); - jQuery(document).on("ready.readytest", makeHandler("c")); + jQuery( makeHandler( "a" ) ); + jQuery( document ).ready( makeHandler( "b" ) ); // Do it twice, just to be sure. - jQuery(makeHandler("d")); - jQuery(document).ready(makeHandler("e")); - jQuery(document).on("ready.readytest", makeHandler("f")); + jQuery( makeHandler( "c" ) ); + jQuery( document ).ready( makeHandler( "d" ) ); noEarlyExecution = order.length === 0; // This assumes that QUnit tests are run on DOM ready! - test("jQuery ready", function() { - expect(10); + test( "jQuery ready", function() { + expect( 8 ); - ok(noEarlyExecution, "Handlers bound to DOM ready should not execute before DOM ready"); + ok( noEarlyExecution, + "Handlers bound to DOM ready should not execute before DOM ready" ); // Ensure execution order. - deepEqual(order, ["a", "b", "d", "e", "c", "f"], "Bound DOM ready handlers should execute in on-order, but those bound with jQuery(document).on( 'ready', fn ) will always execute last"); + deepEqual( order, [ "a", "b", "c", "d" ], + "Bound DOM ready handlers should execute in on-order" ); // Ensure handler argument is correct. - equal(args["a"], jQuery, "Argument passed to fn in jQuery( fn ) should be jQuery"); - equal(args["b"], jQuery, "Argument passed to fn in jQuery(document).ready( fn ) should be jQuery"); - ok(args["c"] instanceof jQuery.Event, "Argument passed to fn in jQuery(document).on( 'ready', fn ) should be an event object"); + equal( args.a, jQuery, + "Argument passed to fn in jQuery( fn ) should be jQuery" ); + equal( args.b, jQuery, + "Argument passed to fn in jQuery(document).ready( fn ) should be jQuery" ); order = []; // Now that the ready event has fired, again bind to the ready event // in every possible way. These event handlers should execute immediately. - jQuery(makeHandler("g")); - equal(order.pop(), "g", "Event handler should execute immediately"); - equal(args["g"], jQuery, "Argument passed to fn in jQuery( fn ) should be jQuery"); - - jQuery(document).ready(makeHandler("h")); - equal(order.pop(), "h", "Event handler should execute immediately"); - equal(args["h"], jQuery, "Argument passed to fn in jQuery(document).ready( fn ) should be jQuery"); - - jQuery(document).on("ready.readytest", makeHandler("never")); - equal(order.length, 0, "Event handler should never execute since DOM ready has already passed"); - - // Cleanup. - jQuery(document).off("ready.readytest"); + jQuery( makeHandler( "g" ) ); + equal( order.pop(), "g", "Event handler should execute immediately" ); + equal( args.g, jQuery, "Argument passed to fn in jQuery( fn ) should be jQuery" ); + + jQuery( document ).ready( makeHandler( "h" ) ); + equal( order.pop(), "h", "Event handler should execute immediately" ); + equal( args.h, jQuery, + "Argument passed to fn in jQuery(document).ready( fn ) should be jQuery" ); }); })(); -- 2.39.5