10000 All: Remove usage of jQuery positional selectors by mgol · Pull Request #1904 · jquery/jquery-ui · GitHub
[go: up one dir, main page]

Skip to content

All: Remove usage of jQuery positional selectors #1904

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 22, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
All: Rewrite all :last usage to .last()
  • Loading branch information
mgol committed Dec 9, 2019
commit 33fba53c56e671c615ba2f5d3b464551fcc773ea
24 changes: 12 additions & 12 deletions tests/unit/datepicker/core.js
10000
Original file line number Diff line number Diff line change
Expand Up @@ -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" );
Expand All @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/datepicker/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,23 +247,23 @@ QUnit.test( "otherMonths", function( assert ) {
// In IE7/8 with jQuery <1.8, encoded spaces behave in strange ways
$( "<span>\u00a0123456789101112131415161718192021222324252627282930\u00a0\u00a0\u00a0\u00a0</span>" ).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(),

// Support: IE <9, jQuery <1.8
// In IE7/8 with jQuery <1.8, encoded spaces behave in strange ways
$( "<span>\u00a0123456789101112131415161718192021222324252627282930\u00a0\u00a0\u00a0\u00a0</span>" ).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 ) {
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/dialog/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ QUnit.test( "focus tabbable", function( assert ) {

function step1() {
checkFocus( "<div><input><input></div>", 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 ],
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/menu/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
}
} );

Expand Down Expand Up @@ -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() );
}
} );

Expand Down Expand Up @@ -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() );
}
} );

Expand Down
4 changes: 2 additions & 2 deletions tests/unit/menu/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -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( "<li><a href='#'>test item</a></li>" ).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( "<li>---</li>" ).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" );
} );

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/sortable/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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" );
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/sortable/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
} );

Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/spinner/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand All @@ -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" );
} );

Expand All @@ -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 ) {
Expand Down
2 changes: 1 addition & 1 deletion tests/visual/compound/draggable_resizable.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
minHeight: 13,
handles: "s"
});
$( ".draggable:last" ).addClass( "absolute" );
$( ".draggable" ).last().addClass( "absolute" );
</script>
</head>
<body>
Expand Down
0