From af54b60e349f902aecd3135a10c3048cb02b3f01 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Micha=C5=82=20Go=C5=82e=CC=A8biowski-Owczarek?=
Date: Mon, 9 Dec 2019 19:36:27 +0100
Subject: [PATCH 1/4] All: Rewrite all :first usage to .first()
---
tests/unit/datepicker/core.js | 46 +++++++++++++++++-----------------
tests/unit/menu/events.js | 6 ++---
tests/unit/menu/methods.js | 8 +++---
tests/unit/sortable/core.js | 4 +--
tests/unit/sortable/options.js | 2 +-
tests/unit/spinner/options.js | 6 ++---
ui/widgets/datepicker.js | 2 +-
ui/widgets/dialog.js | 4 +--
8 files changed, 39 insertions(+), 39 deletions(-)
diff --git a/tests/unit/datepicker/core.js b/tests/unit/datepicker/core.js
index 943a188b879..d3decbc6383 100644
--- a/tests/unit/datepicker/core.js
+++ b/tests/unit/datepicker/core.js
@@ -51,32 +51,32 @@ QUnit.test( "baseStructure", function( assert ) {
assert.ok( !dp.is( ".ui-datepicker-multi" ), "Structure - not multi-month" );
assert.equal( dp.children().length, 2, "Structure - child count" );
- header = dp.children( ":first" );
+ header = dp.children().first();
assert.ok( header.is( "div.ui-datepicker-header" ), "Structure - header division" );
assert.equal( header.children().length, 3, "Structure - header child count" );
- assert.ok( header.children( ":first" ).is( "a.ui-datepicker-prev" ) && header.children( ":first" ).html() !== "", "Structure - prev link" );
+ assert.ok( header.children().first().is( "a.ui-datepicker-prev" ) && header.children().first().html() !== "", "Structure - prev link" );
assert.ok( header.children( ":eq(1)" ).is( "a.ui-datepicker-next" ) && header.children( ":eq(1)" ).html() !== "", "Structure - next link" );
title = header.children( ":last" );
assert.ok( title.is( "div.ui-datepicker-title" ) && title.html() !== "", "Structure - title division" );
assert.equal( title.children().length, 2, "Structure - title child count" );
- assert.ok( title.children( ":first" ).is( "span.ui-datepicker-month" ) && title.children( ":first" ).text() !== "", "Structure - month text" );
+ assert.ok( title.children().first().is( "span.ui-datepicker-month" ) && title.children().first().text() !== "", "Structure - month text" );
assert.ok( title.children( ":last" ).is( "span.ui-datepicker-year" ) && title.children( ":last" ).text() !== "", "Structure - year text" );
table = dp.children( ":eq(1)" );
assert.ok( table.is( "table.ui-datepicker-calendar" ), "Structure - month table" );
- assert.ok( table.children( ":first" ).is( "thead" ), "Structure - month table thead" );
+ assert.ok( table.children().first().is( "thead" ), "Structure - month table thead" );
- thead = table.children( ":first" ).children( ":first" );
+ thead = table.children().first().children().first();
assert.ok( thead.is( "tr" ), "Structure - month table title row" );
assert.equal( thead.find( "th" ).length, 7, "Structure - month table title cells" );
assert.ok( table.children( ":eq(1)" ).is( "tbody" ), "Structure - month table body" );
assert.ok( table.children( ":eq(1)" ).children( "tr" ).length >= 4, "Structure - month table week count" );
- week = table.children( ":eq(1)" ).children( ":first" );
+ week = table.children( ":eq(1)" ).children().first();
assert.ok( week.is( "tr" ), "Structure - month table week row" );
assert.equal( week.children().length, 7, "Structure - week child count" );
- assert.ok( week.children( ":first" ).is( "td.ui-datepicker-week-end" ), "Structure - month table first day cell" );
+ assert.ok( week.children().first().is( "td.ui-datepicker-week-end" ), "Structure - month table first day cell" );
assert.ok( week.children( ":last" ).is( "td.ui-datepicker-week-end" ), "Structure - month table second day cell" );
inp.datepicker( "hide" ).datepicker( "destroy" );
@@ -94,13 +94,13 @@ QUnit.test( "baseStructure", function( assert ) {
} );
testHelper.onFocus( inp, function() {
title = dp.find( "div.ui-datepicker-title" );
- assert.ok( title.children( ":first" ).is( "select.ui-datepicker-month" ), "Structure - month selector" );
+ assert.ok( title.children().first().is( "select.ui-datepicker-month" ), "Structure - month selector" );
assert.ok( title.children( ":last" ).is( "select.ui-datepicker-year" ), "Structure - year selector" );
panel = dp.children( ":last" );
assert.ok( panel.is( "div.ui-datepicker-buttonpane" ), "Structure - button panel division" );
assert.equal( panel.children().length, 2, "Structure - button panel child count" );
- assert.ok( panel.children( ":first" ).is( "button.ui-datepicker-current" ), "Structure - today button" );
+ assert.ok( panel.children().first().is( "button.ui-datepicker-current" ), "Structure - today button" );
assert.ok( panel.children( ":last" ).is( "button.ui-datepicker-close" ), "Structure - close button" );
inp.datepicker( "hide" ).datepicker( "destroy" );
@@ -116,7 +116,7 @@ QUnit.test( "baseStructure", function( assert ) {
assert.ok( dp.is( ".ui-datepicker-multi" ), "Structure multi [2] - multi-month" );
assert.equal( dp.children().length, 3, "Structure multi [2] - child count" );
- child = dp.children( ":first" );
+ child = dp.children().first();
assert.ok( child.is( "div.ui-datepicker-group" ) && child.is( "div.ui-datepicker-group-first" ), "Structure multi [2] - first month division" );
child = dp.children( ":eq(1)" );
@@ -152,7 +152,7 @@ QUnit.test( "baseStructure", function( assert ) {
assert.ok( dp.is( ".ui-datepicker-multi" ), "Structure multi - multi-month" );
assert.equal( dp.children().length, 6, "Structure multi [2,2] - child count" );
- child = dp.children( ":first" );
+ child = dp.children().first();
assert.ok( child.is( "div.ui-datepicker-group" ) && child.is( "div.ui-datepicker-group-first" ), "Structure multi [2,2] - first month division" );
child = dp.children( ":eq(1)" );
@@ -181,13 +181,13 @@ QUnit.test( "baseStructure", function( assert ) {
assert.ok( !dp.is( ".ui-datepicker-multi" ), "Structure inline - not multi-month" );
assert.equal( dp.children().length, 2, "Structure inline - child count" );
- header = dp.children( ":first" );
+ header = dp.children().first();
assert.ok( header.is( "div.ui-datepicker-header" ), "Structure inline - header division" );
assert.equal( header.children().length, 3, "Structure inline - header child count" );
table = dp.children( ":eq(1)" );
assert.ok( table.is( "table.ui-datepicker-calendar" ), "Structure inline - month table" );
- assert.ok( table.children( ":first" ).is( "thead" ), "Structure inline - month table thead" );
+ assert.ok( table.children().first().is( "thead" ), "Structure inline - month table thead" );
assert.ok( table.children( ":eq(1)" ).is( "tbody" ), "Structure inline - month table body" );
inl.datepicker( "destroy" );
@@ -199,7 +199,7 @@ QUnit.test( "baseStructure", function( assert ) {
assert.ok( dp.is( ".ui-datepicker-inline" ) && dp.is( ".ui-datepicker-multi" ), "Structure inline multi - main div" );
assert.equal( dp.children().length, 3, "Structure inline multi - child count" );
- child = dp.children( ":first" );
+ child = dp.children().first();
assert.ok( child.is( "div.ui-datepicker-group" ) && child.is( "div.ui-datepicker-group-first" ), "Structure inline multi - first month division" );
child = dp.children( ":eq(1)" );
@@ -229,16 +229,16 @@ QUnit.test( "customStructure", function( assert ) {
testHelper.onFocus( inp, function() {
assert.ok( dp.is( ".ui-datepicker-rtl" ), "Structure RTL - right-to-left" );
- header = dp.children( ":first" );
+ header = dp.children().first();
assert.ok( header.is( "div.ui-datepicker-header" ), "Structure RTL - header division" );
assert.equal( header.children().length, 3, "Structure RTL - header child count" );
- assert.ok( header.children( ":first" ).is( "a.ui-datepicker-next" ), "Structure RTL - prev link" );
+ assert.ok( header.children().first().is( "a.ui-datepicker-next" ), "Structure RTL - prev link" );
assert.ok( header.children( ":eq(1)" ).is( "a.ui-datepicker-prev" ), "Structure RTL - next link" );
panel = dp.children( ":last" );
assert.ok( panel.is( "div.ui-datepicker-buttonpane" ), "Structure RTL - button division" );
assert.equal( panel.children().length, 2, "Structure RTL - button panel child count" );
- assert.ok( panel.children( ":first" ).is( "button.ui-datepicker-close" ), "Structure RTL - close button" );
+ assert.ok( panel.children().first().is( "button.ui-datepicker-close" ), "Structure RTL - close button" );
assert.ok( panel.children( ":last" ).is( "button.ui-datepicker-current" ), "Structure RTL - today button" );
inp.datepicker( "hide" ).datepicker( "destroy" );
@@ -256,10 +256,10 @@ QUnit.test( "customStructure", function( assert ) {
inp.val( "02/10/2008" );
testHelper.onFocus( inp, function() {
- header = dp.children( ":first" );
+ header = dp.children().first();
assert.ok( header.is( "div.ui-datepicker-header" ), "Structure hide prev/next - header division" );
assert.equal( header.children().length, 1, "Structure hide prev/next - links child count" );
- assert.ok( header.children( ":first" ).is( "div.ui-datepicker-title" ), "Structure hide prev/next - title division" );
+ assert.ok( header.children().first().is( "div.ui-datepicker-title" ), "Structure hide prev/next - title division" );
inp.datepicker( "hide" ).datepicker( "destroy" );
step3();
@@ -271,9 +271,9 @@ QUnit.test( "customStructure", function( assert ) {
inp = testHelper.initNewInput( { changeMonth: true } );
testHelper.onFocus( inp, function() {
- title = dp.children( ":first" ).children( ":last" );
+ title = dp.children().first().children( ":last" );
assert.equal( title.children().length, 2, "Structure changeable month - title child count" );
- assert.ok( title.children( ":first" ).is( "select.ui-datepicker-month" ), "Structure changeable month - month selector" );
+ assert.ok( title.children().first().is( "select.ui-datepicker-month" ), "Structure changeable month - month selector" );
assert.ok( title.children( ":last" ).is( "span.ui-datepicker-year" ), "Structure changeable month - read-only year" );
inp.datepicker( "hide" ).datepicker( "destroy" );
@@ -286,9 +286,9 @@ QUnit.test( "customStructure", function( assert ) {
inp = testHelper.initNewInput( { changeYear: true } );
testHelper.onFocus( inp, function() {
- title = dp.children( ":first" ).children( ":last" );
+ title = dp.children().first().children( ":last" );
assert.equal( title.children().length, 2, "Structure changeable year - title child count" );
- assert.ok( title.children( ":first" ).is( "span.ui-datepicker-month" ), "Structure changeable year - read-only month" );
+ assert.ok( title.children().first().is( "span.ui-datepicker-month" ), "Structure changeable year - read-only month" );
assert.ok( title.children( ":last" ).is( "select.ui-datepicker-year" ), "Structure changeable year - year selector" );
inp.datepicker( "hide" ).datepicker( "destroy" );
diff --git a/tests/unit/menu/events.js b/tests/unit/menu/events.js
index fd57373c182..c19b2119149 100644
--- a/tests/unit/menu/events.js
+++ b/tests/unit/menu/events.js
@@ -176,12 +176,12 @@ QUnit.test( "handle submenu auto collapse: mouseleave, default markup", function
function menumouseleave1() {
assert.equal( element.find( "ul[aria-expanded='true']" ).length, 1, "first submenu expanded" );
- element.menu( "focus", event, element.find( "li:nth-child(7) li:first" ) );
+ element.menu( "focus", event, element.find( "li:nth-child(7) li" ).first() );
setTimeout( menumouseleave2, 25 );
}
function menumouseleave2() {
assert.equal( element.find( "ul[aria-expanded='true']" ).length, 2, "second submenu expanded" );
- element.find( "ul[aria-expanded='true']:first" ).trigger( "mouseleave" );
+ element.find( "ul[aria-expanded='true']" ).first().trigger( "mouseleave" );
setTimeout( menumouseleave3, 25 );
}
function menumouseleave3() {
@@ -213,7 +213,7 @@ QUnit.test( "handle submenu auto collapse: mouseleave, custom markup", function(
}
function menumouseleave2() {
assert.equal( element.find( "div[aria-expanded='true']" ).length, 2, "second submenu expanded" );
- element.find( "div[aria-expanded='true']:first" ).trigger( "mouseleave" );
+ element.find( "div[aria-expanded='true']" ).first().trigger( "mouseleave" );
setTimeout( menumouseleave3, 25 );
}
function menumouseleave3() {
diff --git a/tests/unit/menu/methods.js b/tests/unit/menu/methods.js
index 48eaa33cd44..0cc9c13c9a8 100644
--- a/tests/unit/menu/methods.js
+++ b/tests/unit/menu/methods.js
@@ -62,22 +62,22 @@ QUnit.test( "refresh", function( assert ) {
QUnit.test( "refresh submenu", function( assert ) {
assert.expect( 2 );
var element = $( "#menu2" ).menu();
- assert.equal( element.find( "ul:first .ui-menu-item" ).length, 3 );
+ assert.equal( element.find( "ul" ).first().find( ".ui-menu-item" ).length, 3 );
element.find( "ul" ).addBack().append( "New Item" );
element.menu( "refresh" );
- assert.equal( element.find( "ul:first .ui-menu-item" ).length, 4 );
+ assert.equal( element.find( "ul" ).first().find( ".ui-menu-item" ).length, 4 );
} );
QUnit.test( "refresh icons (see #9377)", function( assert ) {
assert.expect( 3 );
var element = $( "#menu1" ).menu();
assert.lacksClasses( element, "ui-menu-icons" );
- element.find( "li:first .ui-menu-item-wrapper" )
+ element.find( "li" ).first().find( ".ui-menu-item-wrapper" )
.html( "Save" );
element.menu( "refresh" );
assert.hasClasses( element, "ui-menu-icons" );
- element.find( "li:first .ui-menu-item-wrapper" ).html( "Save" );
+ element.find( "li" ).first().find( ".ui-menu-item-wrapper" ).html( "Save" );
element.menu( "refresh" );
assert.lacksClasses( element, "ui-menu-icons" );
} );
diff --git a/tests/unit/sortable/core.js b/tests/unit/sortable/core.js
index 2bb11edbe2c..cd8645127dc 100644
--- a/tests/unit/sortable/core.js
+++ b/tests/unit/sortable/core.js
@@ -24,8 +24,8 @@ QUnit.test( "ui-sortable-handle applied to appropriate element", function( asser
.sortable()
.appendTo( "#qunit-fixture" );
- assert.hasClasses( el.find( "li:first" ), "ui-sortable-handle" );
- assert.hasClasses( el.find( "li:last" ), "ui-sortable-handle" );
+ assert.hasClasses( el.find( "li" ).first(), "ui-sortable-handle" );
+ assert.hasClasses( el.find( "li" ).last(), "ui-sortable-handle" );
el.sortable( "option", "handle", "p" );
assert.lacksClasses( el.find( "li" )[ 0 ], "ui-sortable-handle" );
diff --git a/tests/unit/sortable/options.js b/tests/unit/sortable/options.js
index 30929a501dc..f342b18c3e0 100644
--- a/tests/unit/sortable/options.js
+++ b/tests/unit/sortable/options.js
@@ -447,7 +447,7 @@ QUnit.test( "{ placholder: String } tbody", function( assert ) {
assert.equal( ui.placeholder.children( "tr" ).length, 1,
"placeholder's child is tr" );
assert.equal( ui.placeholder.find( "> tr" ).children().length,
- dragBody.find( "> tr:first" ).children().length,
+ dragBody.find( "> tr" ).first().children().length,
"placeholder's tr has correct number of cells" );
assert.equal( ui.placeholder.find( "> tr" ).children().html(),
$( " " ).html(),
diff --git a/tests/unit/spinner/options.js b/tests/unit/spinner/options.js
index 381e1b7fad6..5a4afecae48 100644
--- a/tests/unit/spinner/options.js
+++ b/tests/unit/spinner/options.js
@@ -13,7 +13,7 @@ QUnit.module( "spinner: options" );
QUnit.test( "icons: default ", function( assert ) {
assert.expect( 4 );
var element = $( "#spin" ).val( 0 ).spinner();
- assert.hasClasses( element.spinner( "widget" ).find( ".ui-icon:first" ),
+ assert.hasClasses( element.spinner( "widget" ).find( ".ui-icon" ).first(),
"ui-icon ui-icon-triangle-1-n" );
assert.hasClasses( element.spinner( "widget" ).find( ".ui-icon:last" ),
"ui-icon ui-icon-triangle-1-s" );
@@ -22,7 +22,7 @@ QUnit.test( "icons: default ", function( assert ) {
up: "ui-icon-caret-1-n",
down: "ui-icon-caret-1-s"
} );
- assert.hasClasses( element.spinner( "widget" ).find( ".ui-icon:first" ),
+ assert.hasClasses( element.spinner( "widget" ).find( ".ui-icon" ).first(),
"ui-icon ui-icon-caret-1-n" );
assert.hasClasses( element.spinner( "widget" ).find( ".ui-icon:last" ),
"ui-icon ui-icon-caret-1-s" );
@@ -36,7 +36,7 @@ QUnit.test( "icons: custom ", function( assert ) {
up: "custom-up"
}
} ).spinner( "widget" );
- assert.hasClasses( element.find( ".ui-icon:first" ), "ui-icon custom-up" );
+ assert.hasClasses( element.find( ".ui-icon" ).first(), "ui-icon custom-up" );
assert.hasClasses( element.find( ".ui-icon:last" ), "ui-icon custom-down" );
} );
diff --git a/ui/widgets/datepicker.js b/ui/widgets/datepicker.js
index c777a4b0edf..5e6321e1d44 100644
--- a/ui/widgets/datepicker.js
+++ b/ui/widgets/datepicker.js
@@ -858,7 +858,7 @@ $.extend( Datepicker.prototype, {
//assure that inst.yearshtml didn't change.
if ( origyearshtml === inst.yearshtml && inst.yearshtml ) {
- inst.dpDiv.find( "select.ui-datepicker-year:first" ).replaceWith( inst.yearshtml );
+ inst.dpDiv.find( "select.ui-datepicker-year" ).first().replaceWith( inst.yearshtml );
}
origyearshtml = inst.yearshtml = null;
}, 0 );
diff --git a/ui/widgets/dialog.js b/ui/widgets/dialog.js
index e4798e0d78c..c9feee48aae 100644
--- a/ui/widgets/dialog.js
+++ b/ui/widgets/dialog.js
@@ -369,8 +369,8 @@ $.widget( "ui.dialog", {
return;
}
var tabbables = this.uiDialog.find( ":tabbable" ),
- first = tabbables.filter( ":first" ),
- last = tabbables.filter( ":last" );
+ first = tabbables.first(),
+ last = tabbables.last();
if ( ( event.target === last[ 0 ] || event.target === this.uiDialog[ 0 ] ) &&
!event.shiftKey ) {
From 33fba53c56e671c615ba2f5d3b464551fcc773ea Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Micha=C5=82=20Go=C5=82e=CC=A8biowski-Owczarek?=
Date: Mon, 9 Dec 2019 19:41:52 +0100
Subject: [PATCH 2/4] All: Rewrite all :last usage to .last()
---
tests/unit/datepicker/core.js | 24 +++++++++----------
tests/unit/datepicker/options.js | 8 +++----
tests/unit/dialog/core.js | 2 +-
tests/unit/menu/events.js | 6 ++---
tests/unit/menu/methods.js | 4 ++--
tests/unit/sortable/core.js | 2 +-
tests/unit/sortable/events.js | 4 ++--
tests/unit/spinner/options.js | 6 ++---
.../visual/compound/draggable_resizable.html | 2 +-
9 files changed, 29 insertions(+), 29 deletions(-)
diff --git a/tests/unit/datepicker/core.js b/tests/unit/datepicker/core.js
index d3decbc6383..200f86b1e75 100644
--- a/tests/unit/datepicker/core.js
+++ b/tests/unit/datepicker/core.js
@@ -57,11 +57,11 @@ QUnit.test( "baseStructure", function( assert ) {
assert.ok( header.children().first().is( "a.ui-datepicker-prev" ) && header.children().first().html() !== "", "Structure - prev link" );
assert.ok( header.children( ":eq(1)" ).is( "a.ui-datepicker-next" ) && header.children( ":eq(1)" ).html() !== "", "Structure - next link" );
- title = header.children( ":last" );
+ title = header.children().last();
assert.ok( title.is( "div.ui-datepicker-title" ) && title.html() !== "", "Structure - title division" );
assert.equal( title.children().length, 2, "Structure - title child count" );
assert.ok( title.children().first().is( "span.ui-datepicker-month" ) && title.children().first().text() !== "", "Structure - month text" );
- assert.ok( title.children( ":last" ).is( "span.ui-datepicker-year" ) && title.children( ":last" ).text() !== "", "Structure - year text" );
+ assert.ok( title.children().last().is( "span.ui-datepicker-year" ) && title.children().last().text() !== "", "Structure - year text" );
table = dp.children( ":eq(1)" );
assert.ok( table.is( "table.ui-datepicker-calendar" ), "Structure - month table" );
@@ -77,7 +77,7 @@ QUnit.test( "baseStructure", function( assert ) {
assert.ok( week.is( "tr" ), "Structure - month table week row" );
assert.equal( week.children().length, 7, "Structure - week child count" );
assert.ok( week.children().first().is( "td.ui-datepicker-week-end" ), "Structure - month table first day cell" );
- assert.ok( week.children( ":last" ).is( "td.ui-datepicker-week-end" ), "Structure - month table second day cell" );
+ assert.ok( week.children().last().is( "td.ui-datepicker-week-end" ), "Structure - month table second day cell" );
inp.datepicker( "hide" ).datepicker( "destroy" );
step2();
@@ -95,13 +95,13 @@ QUnit.test( "baseStructure", function( assert ) {
testHelper.onFocus( inp, function() {
title = dp.find( "div.ui-datepicker-title" );
assert.ok( title.children().first().is( "select.ui-datepicker-month" ), "Structure - month selector" );
- assert.ok( title.children( ":last" ).is( "select.ui-datepicker-year" ), "Structure - year selector" );
+ assert.ok( title.children().last().is( "select.ui-datepicker-year" ), "Structure - year selector" );
- panel = dp.children( ":last" );
+ panel = dp.children().last();
assert.ok( panel.is( "div.ui-datepicker-buttonpane" ), "Structure - button panel division" );
assert.equal( panel.children().length, 2, "Structure - button panel child count" );
assert.ok( panel.children().first().is( "button.ui-datepicker-current" ), "Structure - today button" );
- assert.ok( panel.children( ":last" ).is( "button.ui-datepicker-close" ), "Structure - close button" );
+ assert.ok( panel.children().last().is( "button.ui-datepicker-close" ), "Structure - close button" );
inp.datepicker( "hide" ).datepicker( "destroy" );
step3();
@@ -235,11 +235,11 @@ QUnit.test( "customStructure", function( assert ) {
assert.ok( header.children().first().is( "a.ui-datepicker-next" ), "Structure RTL - prev link" );
assert.ok( header.children( ":eq(1)" ).is( "a.ui-datepicker-prev" ), "Structure RTL - next link" );
- panel = dp.children( ":last" );
+ panel = dp.children().last();
assert.ok( panel.is( "div.ui-datepicker-buttonpane" ), "Structure RTL - button division" );
assert.equal( panel.children().length, 2, "Structure RTL - button panel child count" );
assert.ok( panel.children().first().is( "button.ui-datepicker-close" ), "Structure RTL - close button" );
- assert.ok( panel.children( ":last" ).is( "button.ui-datepicker-current" ), "Structure RTL - today button" );
+ assert.ok( panel.children().last().is( "button.ui-datepicker-current" ), "Structure RTL - today button" );
inp.datepicker( "hide" ).datepicker( "destroy" );
step2();
@@ -271,10 +271,10 @@ QUnit.test( "customStructure", function( assert ) {
inp = testHelper.initNewInput( { changeMonth: true } );
testHelper.onFocus( inp, function() {
- title = dp.children().first().children( ":last" );
+ title = dp.children().first().children().last();
assert.equal( title.children().length, 2, "Structure changeable month - title child count" );
assert.ok( title.children().first().is( "select.ui-datepicker-month" ), "Structure changeable month - month selector" );
- assert.ok( title.children( ":last" ).is( "span.ui-datepicker-year" ), "Structure changeable month - read-only year" );
+ assert.ok( title.children().last().is( "span.ui-datepicker-year" ), "Structure changeable month - read-only year" );
inp.datepicker( "hide" ).datepicker( "destroy" );
step4();
@@ -286,10 +286,10 @@ QUnit.test( "customStructure", function( assert ) {
inp = testHelper.initNewInput( { changeYear: true } );
testHelper.onFocus( inp, function() {
- title = dp.children().first().children( ":last" );
+ title = dp.children().first().children().last();
assert.equal( title.children().length, 2, "Structure changeable year - title child count" );
assert.ok( title.children().first().is( "span.ui-datepicker-month" ), "Structure changeable year - read-only month" );
- assert.ok( title.children( ":last" ).is( "select.ui-datepicker-year" ), "Structure changeable year - year selector" );
+ assert.ok( title.children().last().is( "select.ui-datepicker-year" ), "Structure changeable year - year selector" );
inp.datepicker( "hide" ).datepicker( "destroy" );
step5();
diff --git a/tests/unit/datepicker/options.js b/tests/unit/datepicker/options.js
index 821852ed4a7..cbd5a33c032 100644
--- a/tests/unit/datepicker/options.js
+++ b/tests/unit/datepicker/options.js
@@ -247,15 +247,15 @@ QUnit.test( "otherMonths", function( assert ) {
// In IE7/8 with jQuery <1.8, encoded spaces behave in strange ways
$( "\u00a0123456789101112131415161718192021222324252627282930\u00a0\u00a0\u00a0\u00a0" ).text(),
"Other months - none" );
- assert.ok( pop.find( "td:last *" ).length === 0, "Other months - no content" );
+ assert.ok( pop.find( "td" ).last().find( "*" ).length === 0, "Other months - no content" );
inp.datepicker( "hide" ).datepicker( "option", "showOtherMonths", true ).datepicker( "show" );
assert.equal( pop.find( "tbody" ).text(), "311234567891011121314151617181920212223242526272829301234",
"Other months - show" );
- assert.ok( pop.find( "td:last span" ).length === 1, "Other months - span content" );
+ assert.ok( pop.find( "td" ).last().find( "span" ).length === 1, "Other months - span content" );
inp.datepicker( "hide" ).datepicker( "option", "selectOtherMonths", true ).datepicker( "show" );
assert.equal( pop.find( "tbody" ).text(), "311234567891011121314151617181920212223242526272829301234",
"Other months - select" );
- assert.ok( pop.find( "td:last a" ).length === 1, "Other months - link content" );
+ assert.ok( pop.find( "td" ).last().find( "a" ).length === 1, "Other months - link content" );
inp.datepicker( "hide" ).datepicker( "option", "showOtherMonths", false ).datepicker( "show" );
assert.equal( pop.find( "tbody" ).text(),
@@ -263,7 +263,7 @@ QUnit.test( "otherMonths", function( assert ) {
// In IE7/8 with jQuery <1.8, encoded spaces behave in strange ways
$( "\u00a0123456789101112131415161718192021222324252627282930\u00a0\u00a0\u00a0\u00a0" ).text(),
"Other months - none" );
- assert.ok( pop.find( "td:last *" ).length === 0, "Other months - no content" );
+ assert.ok( pop.find( "td" ).last().find( "*" ).length === 0, "Other months - no content" );
} );
QUnit.test( "defaultDate", function( assert ) {
diff --git a/tests/unit/dialog/core.js b/tests/unit/dialog/core.js
index 3b89a66388e..9e89eaa0f57 100644
--- a/tests/unit/dialog/core.js
+++ b/tests/unit/dialog/core.js
@@ -118,7 +118,7 @@ QUnit.test( "focus tabbable", function( assert ) {
function step1() {
checkFocus( "", options, function( done ) {
- var input = element.find( "input:last" ).trigger( "focus" ).trigger( "blur" );
+ var input = element.find( "input" ).last().trigger( "focus" ).trigger( "blur" );
element.dialog( "instance" )._focusTabbable();
setTimeout( function() {
assert.equal( document.activeElement, input[ 0 ],
diff --git a/tests/unit/menu/events.js b/tests/unit/menu/events.js
index c19b2119149..35eec7851eb 100644
--- a/tests/unit/menu/events.js
+++ b/tests/unit/menu/events.js
@@ -306,7 +306,7 @@ QUnit.test( "handle keyboard navigation on menu without scroll and with submenus
log( $( ui.item[ 0 ] ).text() );
},
focus: function( event ) {
- log( $( event.target ).find( ".ui-menu-item-wrapper.ui-state-active:last" ).parent().index() );
+ log( $( event.target ).find( ".ui-menu-item-wrapper.ui-state-active" ).last().parent().index() );
}
} );
@@ -427,7 +427,7 @@ QUnit.test( "handle keyboard navigation on menu with scroll and without submenus
log( $( ui.item[ 0 ] ).text() );
},
focus: function( event ) {
- log( $( event.target ).find( ".ui-menu-item-wrapper.ui-state-active:last" ).parent().index() );
+ log( $( event.target ).find( ".ui-menu-item-wrapper.ui-state-active" ).last().parent().index() );
}
} );
@@ -503,7 +503,7 @@ QUnit.test( "handle keyboard navigation on menu with scroll and with submenus",
log( $( ui.item[ 0 ] ).text() );
},
focus: function( event ) {
- log( $( event.target ).find( ".ui-menu-item-wrapper.ui-state-active:last" ).parent().index() );
+ log( $( event.target ).find( ".ui-menu-item-wrapper.ui-state-active" ).last().parent().index() );
}
} );
diff --git a/tests/unit/menu/methods.js b/tests/unit/menu/methods.js
index 0cc9c13c9a8..e0e942dd625 100644
--- a/tests/unit/menu/methods.js
+++ b/tests/unit/menu/methods.js
@@ -51,11 +51,11 @@ QUnit.test( "refresh", function( assert ) {
assert.equal( element.find( ".ui-menu-item" ).length, 5, "Incorrect number of menu items" );
element.append( "test item" ).menu( "refresh" );
assert.equal( element.find( ".ui-menu-item" ).length, 6, "Incorrect number of menu items" );
- element.find( ".ui-menu-item:last" ).remove().end().menu( "refresh" );
+ element.find( ".ui-menu-item" ).last().remove().end().end().menu( "refresh" );
assert.equal( element.find( ".ui-menu-item" ).length, 5, "Incorrect number of menu items" );
element.append( "---" ).menu( "refresh" );
assert.equal( element.find( ".ui-menu-item" ).length, 5, "Incorrect number of menu items" );
- element.children( ":last" ).remove().end().menu( "refresh" );
+ element.children().last().remove().end().end().menu( "refresh" );
assert.equal( element.find( ".ui-menu-item" ).length, 5, "Incorrect number of menu items" );
} );
diff --git a/tests/unit/sortable/core.js b/tests/unit/sortable/core.js
index cd8645127dc..b434e96f09b 100644
--- a/tests/unit/sortable/core.js
+++ b/tests/unit/sortable/core.js
@@ -34,7 +34,7 @@ QUnit.test( "ui-sortable-handle applied to appropriate element", function( asser
assert.hasClasses( el.find( "p" )[ 1 ], "ui-sortable-handle" );
el.append( item ).sortable( "refresh" );
- assert.hasClasses( el.find( "p:last" ), "ui-sortable-handle" );
+ assert.hasClasses( el.find( "p" ).last(), "ui-sortable-handle" );
el.sortable( "destroy" );
assert.equal( el.find( ".ui-sortable-handle" ).length, 0, "class name removed on destroy" );
diff --git a/tests/unit/sortable/events.js b/tests/unit/sortable/events.js
index 4973abef0bd..8ed46442520 100644
--- a/tests/unit/sortable/events.js
+++ b/tests/unit/sortable/events.js
@@ -329,7 +329,7 @@ QUnit.test( "out, with connected sortable", function( assert ) {
hash = ui;
outCount++;
} );
- $( "#sortable" ).find( "li:last" ).simulate( "drag", {
+ $( "#sortable" ).find( "li" ).last().simulate( "drag", {
dy: 40
} );
@@ -357,7 +357,7 @@ QUnit.test( "repeated out & over between connected sortables", function( assert
}
}
} );
- $( "#sortable" ).find( "li:last" ).simulate( "drag", {
+ $( "#sortable" ).find( "li" ).last().simulate( "drag", {
dy: 40
} ).simulate( "drag", {
dy: -40
diff --git a/tests/unit/spinner/options.js b/tests/unit/spinner/options.js
index 5a4afecae48..5b1e5db98f7 100644
--- a/tests/unit/spinner/options.js
+++ b/tests/unit/spinner/options.js
@@ -15,7 +15,7 @@ QUnit.test( "icons: default ", function( assert ) {
var element = $( "#spin" ).val( 0 ).spinner();
assert.hasClasses( element.spinner( "widget" ).find( ".ui-icon" ).first(),
"ui-icon ui-icon-triangle-1-n" );
- assert.hasClasses( element.spinner( "widget" ).find( ".ui-icon:last" ),
+ assert.hasClasses( element.spinner( "widget" ).find( ".ui-icon" ).last(),
"ui-icon ui-icon-triangle-1-s" );
element.spinner( "option", "icons", {
@@ -24,7 +24,7 @@ QUnit.test( "icons: default ", function( assert ) {
} );
assert.hasClasses( element.spinner( "widget" ).find( ".ui-icon" ).first(),
"ui-icon ui-icon-caret-1-n" );
- assert.hasClasses( element.spinner( "widget" ).find( ".ui-icon:last" ),
+ assert.hasClasses( element.spinner( "widget" ).find( ".ui-icon" ).last(),
"ui-icon ui-icon-caret-1-s" );
} );
@@ -37,7 +37,7 @@ QUnit.test( "icons: custom ", function( assert ) {
}
} ).spinner( "widget" );
assert.hasClasses( element.find( ".ui-icon" ).first(), "ui-icon custom-up" );
- assert.hasClasses( element.find( ".ui-icon:last" ), "ui-icon custom-down" );
+ assert.hasClasses( element.find( ".ui-icon" ).last(), "ui-icon custom-down" );
} );
QUnit.test( "incremental, false", function( assert ) {
diff --git a/tests/visual/compound/draggable_resizable.html b/tests/visual/compound/draggable_resizable.html
index 539091b7f4a..e2822ca199b 100644
--- a/tests/visual/compound/draggable_resizable.html
+++ b/tests/visual/compound/draggable_resizable.html
@@ -27,7 +27,7 @@
minHeight: 13,
handles: "s"
});
- $( ".draggable:last" ).addClass( "absolute" );
+ $( ".draggable" ).last().addClass( "absolute" );
From 52aff3ca2460478d6f98e0fe8a068d56cfe0a3a0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Micha=C5=82=20Go=C5=82e=CC=A8biowski-Owczarek?=
Date: Tue, 10 Dec 2019 00:38:20 +0100
Subject: [PATCH 3/4] All: Rewrite all :eq usage to .eq()
---
demos/position/cycler.html | 24 ++++++-------
tests/unit/accordion/core.js | 2 +-
tests/unit/datepicker/core.js | 34 +++++++++---------
tests/unit/datepicker/options.js | 48 ++++++++++++-------------
tests/unit/menu/core.js | 4 +--
tests/unit/menu/helper.js | 3 +-
tests/unit/sortable/events.js | 26 +++++++-------
tests/unit/sortable/options.js | 2 +-
tests/visual/effects/effects.js | 2 +-
tests/visual/selectmenu/selectmenu.html | 8 ++---
10 files changed, 77 insertions(+), 76 deletions(-)
diff --git a/demos/position/cycler.html b/demos/position/cycler.html
index 910b0050cfa..49616b3806a 100644
--- a/demos/position/cycler.html
+++ b/demos/position/cycler.html
@@ -49,24 +49,24 @@
});
}
- left( $( "img:eq(0)" ) );
- center( $( "img:eq(1)" ) );
- right( $( "img:eq(2)" ) );
+ left( $( "img" ).eq( 0 ) );
+ center( $( "img" ).eq( 1 ) );
+ right( $( "img" ).eq( 2 ) );
function animate( to ) {
$( this ).stop( true, false ).animate( to );
}
function next( event ) {
event.preventDefault();
- center( $( "img:eq(2)" ), animate );
- left( $( "img:eq(1)" ), animate );
- right( $( "img:eq(0)" ).appendTo( "#container" ) );
+ center( $( "img" ).eq( 2 ), animate );
+ left( $( "img" ).eq( 1 ), animate );
+ right( $( "img" ).eq( 0 ).appendTo( "#container" ) );
}
function previous( event ) {
event.preventDefault();
- center( $( "img:eq(0)" ), animate );
- right( $( "img:eq(1)" ), animate );
- left( $( "img:eq(2)" ).prependTo( "#container" ) );
+ center( $( "img" ).eq( 0 ), animate );
+ right( $( "img" ).eq( 1 ), animate );
+ left( $( "img" ).eq( 2 ).prependTo( "#container" ) );
}
$( "#previous" ).on( "click", previous );
$( "#next" ).on( "click", next );
@@ -76,9 +76,9 @@
});
$( window ).on( "resize", function() {
- left( $( "img:eq(0)" ), animate );
- center( $( "img:eq(1)" ), animate );
- right( $( "img:eq(2)" ), animate );
+ left( $( "img" ).eq( 0 ), animate );
+ center( $( "img" ).eq( 1 ), animate );
+ right( $( "img" ).eq( 2 ), animate );
});
diff --git a/tests/unit/accordion/core.js b/tests/unit/accordion/core.js
index 119280bc940..0b334c00cde 100644
--- a/tests/unit/accordion/core.js
+++ b/tests/unit/accordion/core.js
@@ -39,7 +39,7 @@ $.each( { div: "#list1", ul: "#navigation", dl: "#accordion-dl" }, function( typ
QUnit.test( "handle click on header-descendant", function( assert ) {
assert.expect( 1 );
var element = $( "#navigation" ).accordion();
- $( "#navigation h2:eq(1) a" ).trigger( "click" );
+ $( "#navigation h2" ).eq( 1 ).find( "a" ).trigger( "click" );
state( assert, element, 0, 1, 0 );
} );
diff --git a/tests/unit/datepicker/core.js b/tests/unit/datepicker/core.js
index 200f86b1e75..2cc89cd21b9 100644
--- a/tests/unit/datepicker/core.js
+++ b/tests/unit/datepicker/core.js
@@ -55,7 +55,7 @@ QUnit.test( "baseStructure", function( assert ) {
assert.ok( header.is( "div.ui-datepicker-header" ), "Structure - header division" );
assert.equal( header.children().length, 3, "Structure - header child count" );
assert.ok( header.children().first().is( "a.ui-datepicker-prev" ) && header.children().first().html() !== "", "Structure - prev link" );
- assert.ok( header.children( ":eq(1)" ).is( "a.ui-datepicker-next" ) && header.children( ":eq(1)" ).html() !== "", "Structure - next link" );
+ assert.ok( header.children().eq( 1 ).is( "a.ui-datepicker-next" ) && header.children().eq ( 1 ).html() !== "", "Structure - next link" );
title = header.children().last();
assert.ok( title.is( "div.ui-datepicker-title" ) && title.html() !== "", "Structure - title division" );
@@ -63,17 +63,17 @@ QUnit.test( "baseStructure", function( assert ) {
assert.ok( title.children().first().is( "span.ui-datepicker-month" ) && title.children().first().text() !== "", "Structure - month text" );
assert.ok( title.children().last().is( "span.ui-datepicker-year" ) && title.children().last().text() !== "", "Structure - year text" );
- table = dp.children( ":eq(1)" );
+ table = dp.children().eq( 1 );
assert.ok( table.is( "table.ui-datepicker-calendar" ), "Structure - month table" );
assert.ok( table.children().first().is( "thead" ), "Structure - month table thead" );
thead = table.children().first().children().first();
assert.ok( thead.is( "tr" ), "Structure - month table title row" );
assert.equal( thead.find( "th" ).length, 7, "Structure - month table title cells" );
- assert.ok( table.children( ":eq(1)" ).is( "tbody" ), "Structure - month table body" );
- assert.ok( table.children( ":eq(1)" ).children( "tr" ).length >= 4, "Structure - month table week count" );
+ assert.ok( table.children().eq( 1 ).is( "tbody" ), "Structure - month table body" );
+ assert.ok( table.children().eq( 1 ).children( "tr" ).length >= 4, "Structure - month table week count" );
- week = table.children( ":eq(1)" ).children().first();
+ week = table.children().eq( 1 ).children().first();
assert.ok( week.is( "tr" ), "Structure - month table week row" );
assert.equal( week.children().length, 7, "Structure - week child count" );
assert.ok( week.children().first().is( "td.ui-datepicker-week-end" ), "Structure - month table first day cell" );
@@ -119,10 +119,10 @@ QUnit.test( "baseStructure", function( assert ) {
child = dp.children().first();
assert.ok( child.is( "div.ui-datepicker-group" ) && child.is( "div.ui-datepicker-group-first" ), "Structure multi [2] - first month division" );
- child = dp.children( ":eq(1)" );
+ child = dp.children().eq( 1 );
assert.ok( child.is( "div.ui-datepicker-group" ) && child.is( "div.ui-datepicker-group-last" ), "Structure multi [2] - second month division" );
- child = dp.children( ":eq(2)" );
+ child = dp.children().eq( 2 );
assert.ok( child.is( "div.ui-datepicker-row-break" ), "Structure multi [2] - row break" );
assert.ok( dp.is( ".ui-datepicker-multi-2" ), "Structure multi [2] - multi-2" );
@@ -155,19 +155,19 @@ QUnit.test( "baseStructure", function( assert ) {
child = dp.children().first();
assert.ok( child.is( "div.ui-datepicker-group" ) && child.is( "div.ui-datepicker-group-first" ), "Structure multi [2,2] - first month division" );
- child = dp.children( ":eq(1)" );
+ child = dp.children().eq( 1 );
assert.ok( child.is( "div.ui-datepicker-group" ) && child.is( "div.ui-datepicker-group-last" ), "Structure multi [2,2] - second month division" );
- child = dp.children( ":eq(2)" );
+ child = dp.children().eq( 2 );
assert.ok( child.is( "div.ui-datepicker-row-break" ), "Structure multi [2,2] - row break" );
- child = dp.children( ":eq(3)" );
+ child = dp.children().eq( 3 );
assert.ok( child.is( "div.ui-datepicker-group" ) && child.is( "div.ui-datepicker-group-first" ), "Structure multi [2,2] - third month division" );
- child = dp.children( ":eq(4)" );
+ child = dp.children().eq( 4 );
assert.ok( child.is( "div.ui-datepicker-group" ) && child.is( "div.ui-datepicker-group-last" ), "Structure multi [2,2] - fourth month division" );
- child = dp.children( ":eq(5)" );
+ child = dp.children().eq( 5 );
assert.ok( child.is( "div.ui-datepicker-row-break" ), "Structure multi [2,2] - row break" );
inp.datepicker( "hide" ).datepicker( "destroy" );
@@ -185,10 +185,10 @@ QUnit.test( "baseStructure", function( assert ) {
assert.ok( header.is( "div.ui-datepicker-header" ), "Structure inline - header division" );
assert.equal( header.children().length, 3, "Structure inline - header child count" );
- table = dp.children( ":eq(1)" );
+ table = dp.children().eq( 1 );
assert.ok( table.is( "table.ui-datepicker-calendar" ), "Structure inline - month table" );
assert.ok( table.children().first().is( "thead" ), "Structure inline - month table thead" );
- assert.ok( table.children( ":eq(1)" ).is( "tbody" ), "Structure inline - month table body" );
+ assert.ok( table.children().eq( 1 ).is( "tbody" ), "Structure inline - month table body" );
inl.datepicker( "destroy" );
@@ -202,10 +202,10 @@ QUnit.test( "baseStructure", function( assert ) {
child = dp.children().first();
assert.ok( child.is( "div.ui-datepicker-group" ) && child.is( "div.ui-datepicker-group-first" ), "Structure inline multi - first month division" );
- child = dp.children( ":eq(1)" );
+ child = dp.children().eq( 1 );
assert.ok( child.is( "div.ui-datepicker-group" ) && child.is( "div.ui-datepicker-group-last" ), "Structure inline multi - second month division" );
- child = dp.children( ":eq(2)" );
+ child = dp.children().eq( 2 );
assert.ok( child.is( "div.ui-datepicker-row-break" ), "Structure inline multi - row break" );
inl.datepicker( "destroy" );
@@ -233,7 +233,7 @@ QUnit.test( "customStructure", function( assert ) {
assert.ok( header.is( "div.ui-datepicker-header" ), "Structure RTL - header division" );
assert.equal( header.children().length, 3, "Structure RTL - header child count" );
assert.ok( header.children().first().is( "a.ui-datepicker-next" ), "Structure RTL - prev link" );
- assert.ok( header.children( ":eq(1)" ).is( "a.ui-datepicker-prev" ), "Structure RTL - next link" );
+ assert.ok( header.children().eq( 1 ).is( "a.ui-datepicker-prev" ), "Structure RTL - next link" );
panel = dp.children().last();
assert.ok( panel.is( "div.ui-datepicker-buttonpane" ), "Structure RTL - button division" );
diff --git a/tests/unit/datepicker/options.js b/tests/unit/datepicker/options.js
index cbd5a33c032..7711e741233 100644
--- a/tests/unit/datepicker/options.js
+++ b/tests/unit/datepicker/options.js
@@ -710,82 +710,82 @@ QUnit.test( "daylightSaving", function( assert ) {
// Australia, Sydney - AM change, southern hemisphere
inp.val( "04/01/2008" ).datepicker( "show" );
- $( ".ui-datepicker-calendar td:eq(6) a", dp ).simulate( "click" );
+ $( ".ui-datepicker-calendar td", dp ).eq( 6 ).find( "a" ).simulate( "click" );
assert.equal( inp.val(), "04/05/2008", "Daylight saving - Australia 04/05/2008" );
inp.val( "04/01/2008" ).datepicker( "show" );
- $( ".ui-datepicker-calendar td:eq(7) a", dp ).simulate( "click" );
+ $( ".ui-datepicker-calendar td", dp ).eq( 7 ).find( "a" ).simulate( "click" );
assert.equal( inp.val(), "04/06/2008", "Daylight saving - Australia 04/06/2008" );
inp.val( "04/01/2008" ).datepicker( "show" );
- $( ".ui-datepicker-calendar td:eq(8) a", dp ).simulate( "click" );
+ $( ".ui-datepicker-calendar td", dp ).eq( 8 ).find( "a" ).simulate( "click" );
assert.equal( inp.val(), "04/07/2008", "Daylight saving - Australia 04/07/2008" );
inp.val( "10/01/2008" ).datepicker( "show" );
- $( ".ui-datepicker-calendar td:eq(6) a", dp ).simulate( "click" );
+ $( ".ui-datepicker-calendar td", dp ).eq( 6 ).find( "a" ).simulate( "click" );
assert.equal( inp.val(), "10/04/2008", "Daylight saving - Australia 10/04/2008" );
inp.val( "10/01/2008" ).datepicker( "show" );
- $( ".ui-datepicker-calendar td:eq(7) a", dp ).simulate( "click" );
+ $( ".ui-datepicker-calendar td", dp ).eq( 7 ).find( "a" ).simulate( "click" );
assert.equal( inp.val(), "10/05/2008", "Daylight saving - Australia 10/05/2008" );
inp.val( "10/01/2008" ).datepicker( "show" );
- $( ".ui-datepicker-calendar td:eq(8) a", dp ).simulate( "click" );
+ $( ".ui-datepicker-calendar td", dp ).eq( 8 ).find( "a" ).simulate( "click" );
assert.equal( inp.val(), "10/06/2008", "Daylight saving - Australia 10/06/2008" );
// Brasil, Brasilia - midnight change, southern hemisphere
inp.val( "02/01/2008" ).datepicker( "show" );
- $( ".ui-datepicker-calendar td:eq(20) a", dp ).simulate( "click" );
+ $( ".ui-datepicker-calendar td", dp ).eq( 20 ).find( "a" ).simulate( "click" );
assert.equal( inp.val(), "02/16/2008", "Daylight saving - Brasil 02/16/2008" );
inp.val( "02/01/2008" ).datepicker( "show" );
- $( ".ui-datepicker-calendar td:eq(21) a", dp ).simulate( "click" );
+ $( ".ui-datepicker-calendar td", dp ).eq( 21 ).find( "a" ).simulate( "click" );
assert.equal( inp.val(), "02/17/2008", "Daylight saving - Brasil 02/17/2008" );
inp.val( "02/01/2008" ).datepicker( "show" );
- $( ".ui-datepicker-calendar td:eq(22) a", dp ).simulate( "click" );
+ $( ".ui-datepicker-calendar td", dp ).eq( 22 ).find( "a" ).simulate( "click" );
assert.equal( inp.val(), "02/18/2008", "Daylight saving - Brasil 02/18/2008" );
inp.val( "10/01/2008" ).datepicker( "show" );
- $( ".ui-datepicker-calendar td:eq(13) a", dp ).simulate( "click" );
+ $( ".ui-datepicker-calendar td", dp ).eq( 13 ).find( "a" ).simulate( "click" );
assert.equal( inp.val(), "10/11/2008", "Daylight saving - Brasil 10/11/2008" );
inp.val( "10/01/2008" ).datepicker( "show" );
- $( ".ui-datepicker-calendar td:eq(14) a", dp ).simulate( "click" );
+ $( ".ui-datepicker-calendar td", dp ).eq( 14 ).find( "a" ).simulate( "click" );
assert.equal( inp.val(), "10/12/2008", "Daylight saving - Brasil 10/12/2008" );
inp.val( "10/01/2008" ).datepicker( "show" );
- $( ".ui-datepicker-calendar td:eq(15) a", dp ).simulate( "click" );
+ $( ".ui-datepicker-calendar td", dp ).eq( 15 ).find( "a" ).simulate( "click" );
assert.equal( inp.val(), "10/13/2008", "Daylight saving - Brasil 10/13/2008" );
// Lebanon, Beirut - midnight change, northern hemisphere
inp.val( "03/01/2008" ).datepicker( "show" );
- $( ".ui-datepicker-calendar td:eq(34) a", dp ).simulate( "click" );
+ $( ".ui-datepicker-calendar td", dp ).eq( 34 ).find( "a" ).simulate( "click" );
assert.equal( inp.val(), "03/29/2008", "Daylight saving - Lebanon 03/29/2008" );
inp.val( "03/01/2008" ).datepicker( "show" );
- $( ".ui-datepicker-calendar td:eq(35) a", dp ).simulate( "click" );
+ $( ".ui-datepicker-calendar td", dp ).eq( 35 ).find( "a" ).simulate( "click" );
assert.equal( inp.val(), "03/30/2008", "Daylight saving - Lebanon 03/30/2008" );
inp.val( "03/01/2008" ).datepicker( "show" );
- $( ".ui-datepicker-calendar td:eq(36) a", dp ).simulate( "click" );
+ $( ".ui-datepicker-calendar td", dp ).eq( 36 ).find( "a" ).simulate( "click" );
assert.equal( inp.val(), "03/31/2008", "Daylight saving - Lebanon 03/31/2008" );
inp.val( "10/01/2008" ).datepicker( "show" );
- $( ".ui-datepicker-calendar td:eq(27) a", dp ).simulate( "click" );
+ $( ".ui-datepicker-calendar td", dp ).eq( 27 ).find( "a" ).simulate( "click" );
assert.equal( inp.val(), "10/25/2008", "Daylight saving - Lebanon 10/25/2008" );
inp.val( "10/01/2008" ).datepicker( "show" );
- $( ".ui-datepicker-calendar td:eq(28) a", dp ).simulate( "click" );
+ $( ".ui-datepicker-calendar td", dp ).eq( 28 ).find( "a" ).simulate( "click" );
assert.equal( inp.val(), "10/26/2008", "Daylight saving - Lebanon 10/26/2008" );
inp.val( "10/01/2008" ).datepicker( "show" );
- $( ".ui-datepicker-calendar td:eq(29) a", dp ).simulate( "click" );
+ $( ".ui-datepicker-calendar td", dp ).eq( 29 ).find( "a" ).simulate( "click" );
assert.equal( inp.val(), "10/27/2008", "Daylight saving - Lebanon 10/27/2008" );
// US, Eastern - AM change, northern hemisphere
inp.val( "03/01/2008" ).datepicker( "show" );
- $( ".ui-datepicker-calendar td:eq(13) a", dp ).simulate( "click" );
+ $( ".ui-datepicker-calendar td", dp ).eq( 13 ).find( "a" ).simulate( "click" );
assert.equal( inp.val(), "03/08/2008", "Daylight saving - US 03/08/2008" );
inp.val( "03/01/2008" ).datepicker( "show" );
- $( ".ui-datepicker-calendar td:eq(14) a", dp ).simulate( "click" );
+ $( ".ui-datepicker-calendar td", dp ).eq( 14 ).find( "a" ).simulate( "click" );
assert.equal( inp.val(), "03/09/2008", "Daylight saving - US 03/09/2008" );
inp.val( "03/01/2008" ).datepicker( "show" );
- $( ".ui-datepicker-calendar td:eq(15) a", dp ).simulate( "click" );
+ $( ".ui-datepicker-calendar td", dp ).eq( 15 ).find( "a" ).simulate( "click" );
assert.equal( inp.val(), "03/10/2008", "Daylight saving - US 03/10/2008" );
inp.val( "11/01/2008" ).datepicker( "show" );
- $( ".ui-datepicker-calendar td:eq(6) a", dp ).simulate( "click" );
+ $( ".ui-datepicker-calendar td", dp ).eq( 6 ).find( "a" ).simulate( "click" );
assert.equal( inp.val(), "11/01/2008", "Daylight saving - US 11/01/2008" );
inp.val( "11/01/2008" ).datepicker( "show" );
- $( ".ui-datepicker-calendar td:eq(7) a", dp ).simulate( "click" );
+ $( ".ui-datepicker-calendar td", dp ).eq( 7 ).find( "a" ).simulate( "click" );
assert.equal( inp.val(), "11/02/2008", "Daylight saving - US 11/02/2008" );
inp.val( "11/01/2008" ).datepicker( "show" );
- $( ".ui-datepicker-calendar td:eq(8) a", dp ).simulate( "click" );
+ $( ".ui-datepicker-calendar td", dp ).eq( 8 ).find( "a" ).simulate( "click" );
assert.equal( inp.val(), "11/03/2008", "Daylight saving - US 11/03/2008" );
} );
diff --git a/tests/unit/menu/core.js b/tests/unit/menu/core.js
index 6742aa53e34..be68eddca13 100644
--- a/tests/unit/menu/core.js
+++ b/tests/unit/menu/core.js
@@ -87,8 +87,8 @@ QUnit.test( "active menu item styling", function( assert ) {
}
$.ui.menu.prototype.delay = 0;
var element = $( "#menu4" ).menu();
- var parentItem = element.children( "li:eq(1)" );
- var childItem = parentItem.find( "li:eq(0)" );
+ var parentItem = element.children( "li" ).eq( 1 );
+ var childItem = parentItem.find( "li" ).eq( 0 );
element.menu( "focus", null, parentItem );
setTimeout( function() {
isActive( parentItem );
diff --git a/tests/unit/menu/helper.js b/tests/unit/menu/helper.js
index 1e4a2148550..748dfe773c2 100644
--- a/tests/unit/menu/helper.js
+++ b/tests/unit/menu/helper.js
@@ -27,7 +27,8 @@ return $.extend( helper, {
click: function( menu, item ) {
lastItem = item;
- menu.children( ":eq(" + item + ")" )
+ menu.children()
+ .eq( item )
.children( ".ui-menu-item-wrapper" )
.trigger( "click" );
}
diff --git a/tests/unit/sortable/events.js b/tests/unit/sortable/events.js
index 8ed46442520..9df830e1654 100644
--- a/tests/unit/sortable/events.js
+++ b/tests/unit/sortable/events.js
@@ -16,7 +16,7 @@ QUnit.test( "start", function( assert ) {
start: function( e, ui ) {
hash = ui;
}
- } ).find( "li:eq(0)" ).simulate( "drag", {
+ } ).find( "li" ).eq( 0 ).simulate( "drag", {
dy: 10
} );
@@ -39,7 +39,7 @@ QUnit.test( "sort", function( assert ) {
sort: function( e, ui ) {
hash = ui;
}
- } ).find( "li:eq(0)" ).simulate( "drag", {
+ } ).find( "li" ).eq( 0 ).simulate( "drag", {
dy: 10
} );
@@ -61,7 +61,7 @@ QUnit.test( "change", function( assert ) {
change: function( e, ui ) {
hash = ui;
}
- } ).find( "li:eq(0)" ).simulate( "drag", {
+ } ).find( "li" ).eq( 0 ).simulate( "drag", {
dx: 1,
dy: 1
} );
@@ -72,7 +72,7 @@ QUnit.test( "change", function( assert ) {
change: function( e, ui ) {
hash = ui;
}
- } ).find( "li:eq(0)" ).simulate( "drag", {
+ } ).find( "li" ).eq( 0 ).simulate( "drag", {
dy: 22
} );
@@ -94,7 +94,7 @@ QUnit.test( "beforeStop", function( assert ) {
beforeStop: function( e, ui ) {
hash = ui;
}
- } ).find( "li:eq(0)" ).simulate( "drag", {
+ } ).find( "li" ).eq( 0 ).simulate( "drag", {
dy: 20
} );
@@ -116,7 +116,7 @@ QUnit.test( "stop", function( assert ) {
stop: function( e, ui ) {
hash = ui;
}
- } ).find( "li:eq(0)" ).simulate( "drag", {
+ } ).find( "li" ).eq( 0 ).simulate( "drag", {
dy: 20
} );
@@ -138,7 +138,7 @@ QUnit.test( "update", function( assert ) {
update: function( e, ui ) {
hash = ui;
}
- } ).find( "li:eq(0)" ).simulate( "drag", {
+ } ).find( "li" ).eq( 0 ).simulate( "drag", {
dx: 1,
dy: 1
} );
@@ -149,7 +149,7 @@ QUnit.test( "update", function( assert ) {
update: function( e, ui ) {
hash = ui;
}
- } ).find( "li:eq(0)" ).simulate( "drag", {
+ } ).find( "li" ).eq( 0 ).simulate( "drag", {
dy: 22
} );
@@ -203,13 +203,13 @@ QUnit.test( "#4752: link event firing on sortable with connect list", function(
fired.click = true;
} );
- $( "#sortable li:eq(0)" ).simulate( "click" );
+ $( "#sortable li" ).eq( 0 ).simulate( "click" );
assert.ok( !hasFired( "change" ), "Click only, change event should not have fired" );
assert.ok( hasFired( "click" ), "Click event should have fired" );
// Drag an item within the first list
fired = {};
- $( "#sortable li:eq(0)" ).simulate( "drag", { dx: 0, dy: 40 } );
+ $( "#sortable li" ).eq( 0 ).simulate( "drag", { dx: 0, dy: 40 } );
assert.ok( hasFired( "change" ), "40px drag, change event should have fired" );
assert.ok( !hasFired( "receive" ), "Receive event should not have fired" );
assert.ok( !hasFired( "remove" ), "Remove event should not have fired" );
@@ -217,7 +217,7 @@ QUnit.test( "#4752: link event firing on sortable with connect list", function(
// Drag an item from the first list to the second, connected list
fired = {};
- $( "#sortable li:eq(0)" ).simulate( "drag", { dx: 0, dy: 150 } );
+ $( "#sortable li" ).eq( 0 ).simulate( "drag", { dx: 0, dy: 150 } );
assert.ok( hasFired( "change" ), "150px drag, change event should have fired" );
assert.ok( hasFired( "receive" ), "Receive event should have fired" );
assert.ok( hasFired( "remove" ), "Remove event should have fired" );
@@ -245,7 +245,7 @@ QUnit.test( "over", function( assert ) {
hash = ui;
overCount++;
}
- } ).find( "li:eq(0)" ).simulate( "drag", {
+ } ).find( "li" ).eq( 0 ).simulate( "drag", {
dy: 20
} );
@@ -301,7 +301,7 @@ QUnit.test( "over, with connected sortable", function( assert ) {
hash = ui;
overCount++;
} );
- $( "#sortable" ).find( "li:eq(0)" ).simulate( "drag", {
+ $( "#sortable" ).find( "li" ).eq( 0 ).simulate( "drag", {
dy: 102
} );
diff --git a/tests/unit/sortable/options.js b/tests/unit/sortable/options.js
index f342b18c3e0..d157d2b779d 100644
--- a/tests/unit/sortable/options.js
+++ b/tests/unit/sortable/options.js
@@ -136,7 +136,7 @@ QUnit.test( "#8792: issues with floated items in connected lists", function( ass
}
} );
- element = $( "#qunit-fixture li:eq(0)" );
+ element = $( "#qunit-fixture li" ).eq( 0 );
// Move the first li to the right of the second li in the first ul
element.simulate( "drag", {
diff --git a/tests/visual/effects/effects.js b/tests/visual/effects/effects.js
index 6d36a55ead3..ebe3347f286 100644
--- a/tests/visual/effects/effects.js
+++ b/tests/visual/effects/effects.js
@@ -86,7 +86,7 @@ effect( "#slideRight", "slide", { direction: "right" } );
$( "#transfer" ).on( "click", function() {
$( this )
.addClass( "current" )
- .effect( "transfer", { to: "div:eq(0)" }, 1000, function() {
+ .effect( "transfer", { to: $( "div" ).eq( 0 ) }, 1000, function() {
$( this ).removeClass( "current" );
} );
} );
diff --git a/tests/visual/selectmenu/selectmenu.html b/tests/visual/selectmenu/selectmenu.html
index 693885d2506..0dbfc3882ad 100644
--- a/tests/visual/selectmenu/selectmenu.html
+++ b/tests/visual/selectmenu/selectmenu.html
@@ -89,10 +89,10 @@
$("#disable_option").on("click", function() {
if (disable_option) {
disable_option = false;
- disabled4.find("option:eq(0)").attr("disabled", "disabled");
+ disabled4.find( "option" ).eq( 0 ).attr("disabled", "disabled");
} else {
disable_option = true;
- disabled4.find("option:eq(0)").removeAttr("disabled");
+ disabled4.find( "option" ).eq( 0 ).removeAttr("disabled");
}
disabled4.selectmenu("refresh");
return false;
@@ -101,10 +101,10 @@
$("#disable_optgroup").on("click", function() {
if (disable_optgroup) {
disable_optgroup = false;
- disabled4.find("optgroup:eq(0)").attr("disabled", "disabled");
+ disabled4.find( "optgroup" ).eq( 0 ).attr("disabled", "disabled");
} else {
disable_optgroup = true;
- disabled4.find("optgroup:eq(0)").removeAttr("disabled");
+ disabled4.find( "optgroup" ).eq( 0 ).removeAttr("disabled");
}
disabled4.selectmenu("refresh");
return false;
From 777b068f4d86ec6324ec4c3aaf4dfb54dc163d4c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Micha=C5=82=20Go=C5=82e=CC=A8biowski-Owczarek?=
Date: Mon, 30 Dec 2019 23:56:16 +0100
Subject: [PATCH 4/4] Accordion: Rewrite all :even usage to .even()
The polyfill for `.even()` & `.odd()` is added for jQuery <3.5.0.
There was no usage of the :odd selector in the code but the `.odd()` method
is also polyfilled for completeness.
---
tests/lib/bootstrap.js | 5 ++++-
tests/unit/accordion/common.js | 4 +++-
tests/unit/accordion/options.js | 22 +++++++++++++++++++---
ui/jquery-1-7.js | 17 +++++++++++++++++
ui/widgets/accordion.js | 10 ++++++++--
5 files changed, 51 insertions(+), 7 deletions(-)
diff --git a/tests/lib/bootstrap.js b/tests/lib/bootstrap.js
index 27c1b610f9f..0134d1d03a9 100644
--- a/tests/lib/bootstrap.js
+++ b/tests/lib/bootstrap.js
@@ -172,8 +172,11 @@ function migrateUrl() {
}
}
+ var jQueryVersion = parseUrl().jquery;
+
// Load the jQuery fixes, if necessary
- if ( parseFloat( parseUrl().jquery ) < 3 ) {
+ if ( !jQueryVersion ||
+ ( jQueryVersion.indexOf( "git" ) === -1 && parseFloat( jQueryVersion ) < 4 ) ) {
modules.unshift( "ui/jquery-1-7" );
}
diff --git a/tests/unit/accordion/common.js b/tests/unit/accordion/common.js
index 453506dbdfe..926d5d9c36e 100644
--- a/tests/unit/accordion/common.js
+++ b/tests/unit/accordion/common.js
@@ -15,7 +15,9 @@ common.testWidget( "accordion", {
collapsible: false,
disabled: false,
event: "click",
- header: "> li > :first-child, > :not(li):even",
+ header: function( elem ) {
+ return elem.find( "> li > :first-child" ).add( elem.find( "> :not(li)" ).even() );
+ },
heightStyle: "auto",
icons: {
"activeHeader": "ui-icon-triangle-1-s",
diff --git a/tests/unit/accordion/options.js b/tests/unit/accordion/options.js
index 2dec303a97d..0fcaf5b7864 100644
--- a/tests/unit/accordion/options.js
+++ b/tests/unit/accordion/options.js
@@ -376,15 +376,15 @@ QUnit.test( "{ event: custom }", function( assert ) {
QUnit.test( "{ header: default }", function( assert ) {
assert.expect( 2 );
- // Default: > li > :first-child,> :not(li):even
- // > :not(li):even
+ // Default: elem.find( "> li > :first-child" ).add( elem.find( "> :not(li)" ).even() )
+ // elem.find( "> :not(li)" ).even()
state( assert, $( "#list1" ).accordion(), 1, 0, 0 );
// > li > :first-child
state( assert, $( "#navigation" ).accordion(), 1, 0, 0 );
} );
-QUnit.test( "{ header: custom }", function( assert ) {
+QUnit.test( "{ header: customString }", function( assert ) {
assert.expect( 6 );
var element = $( "#navigationWrapper" ).accordion( {
header: "h2"
@@ -398,6 +398,22 @@ QUnit.test( "{ header: custom }", function( assert ) {
state( assert, element, 0, 0, 1 );
} );
+QUnit.test( "{ header: customFunction }", function( assert ) {
+ assert.expect( 6 );
+ var element = $( "#navigationWrapper" ).accordion( {
+ header: function( elem ) {
+ return elem.find( "h2" );
+ }
+ } );
+ element.find( "h2" ).each( function() {
+ assert.hasClasses( this, "ui-accordion-header" );
+ } );
+ assert.equal( element.find( ".ui-accordion-header" ).length, 3 );
+ state( assert, element, 1, 0, 0 );
+ element.accordion( "option", "active", 2 );
+ state( assert, element, 0, 0, 1 );
+} );
+
QUnit.test( "{ heightStyle: 'auto' }", function( assert ) {
assert.expect( 3 );
var element = $( "#navigation" ).accordion( { heightStyle: "auto" } );
diff --git a/ui/jquery-1-7.js b/ui/jquery-1-7.js
index 5e7907a1591..3d0870f7cc3 100644
--- a/ui/jquery-1-7.js
+++ b/ui/jquery-1-7.js
@@ -98,4 +98,21 @@ if ( !$.uniqueSort ) {
$.uniqueSort = $.unique;
}
+// Support: jQuery 3.4.x or older
+// These methods have been defined in jQuery 3.5.0.
+if ( !$.fn.even || !$.fn.odd ) {
+ $.fn.extend( {
+ even: function() {
+ return this.filter( function( i ) {
+ return i % 2 === 0;
+ } );
+ },
+ odd: function() {
+ return this.filter( function( i ) {
+ return i % 2 === 1;
+ } );
+ }
+ } );
+}
+
} ) );
diff --git a/ui/widgets/accordion.js b/ui/widgets/accordion.js
index 530d7354340..59a6a7315d8 100644
--- a/ui/widgets/accordion.js
+++ b/ui/widgets/accordion.js
@@ -48,7 +48,9 @@ return $.widget( "ui.accordion", {
},
collapsible: false,
event: "click",
- header: "> li > :first-child, > :not(li):even",
+ header: function( elem ) {
+ return elem.find( "> li > :first-child" ).add( elem.find( "> :not(li)" ).even() );
+ },
heightStyle: "auto",
icons: {
activeHeader: "ui-icon-triangle-1-s",
@@ -279,7 +281,11 @@ return $.widget( "ui.accordion", {
var prevHeaders = this.headers,
prevPanels = this.panels;
- this.headers = this.element.find( this.options.header );
+ if ( typeof this.options.header === "function" ) {
+ this.headers = this.options.header( this.element );
+ } else {
+ this.headers = this.element.find( this.options.header );
+ }
this._addClass( this.headers, "ui-accordion-header ui-accordion-header-collapsed",
"ui-state-default" );