Skip to content

Commit

Permalink
Preparing for jQuery 3: size() -> length (elastic#15648) (elastic#15671)
Browse files Browse the repository at this point in the history
Per https://api.jquery.com/size/ - .size() is deprecated,
and should be changed to .length

Making this change alone already makes Kibana run with jQuery master.
  • Loading branch information
nyurik authored Dec 18, 2017
1 parent 7173053 commit 492a15e
Show file tree
Hide file tree
Showing 15 changed files with 55 additions and 55 deletions.
10 changes: 5 additions & 5 deletions src/core_plugins/kibana/public/field_formats/__tests__/_url.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ describe('Url Format', function () {

const $a = unwrap($(url.convert('http://elastic.co', 'html')));
expect($a.is('a')).to.be(true);
expect($a.size()).to.be(1);
expect($a.length).to.be(1);
expect($a.attr('href')).to.be('http://elastic.co');
expect($a.attr('target')).to.be('_blank');
expect($a.children().size()).to.be(0);
expect($a.children().length).to.be(0);
});

it('outputs a <a> link with target=_self if "open link in current tab" is checked', function () {
Expand All @@ -55,10 +55,10 @@ describe('Url Format', function () {
const url = new Url({ urlTemplate: 'http://{{ value }}' });
const $a = unwrap($(url.convert('url', 'html')));
expect($a.is('a')).to.be(true);
expect($a.size()).to.be(1);
expect($a.length).to.be(1);
expect($a.attr('href')).to.be('http://url');
expect($a.attr('target')).to.be('_blank');
expect($a.children().size()).to.be(0);
expect($a.children().length).to.be(0);
});

it('only outputs the url if the contentType === "text"', function () {
Expand All @@ -72,7 +72,7 @@ describe('Url Format', function () {
const url = new Url({ labelTemplate: 'extension: {{ value }}', urlTemplate: 'http://www.{{value}}.com' });
const $a = unwrap($(url.convert('php', 'html')));
expect($a.is('a')).to.be(true);
expect($a.size()).to.be(1);
expect($a.length).to.be(1);
expect($a.attr('href')).to.be('http://www.php.com');
expect($a.html()).to.be('extension: php');
});
Expand Down
10 changes: 5 additions & 5 deletions src/core_plugins/table_vis/public/__tests__/_table_vis.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ describe('Integration', function () {

$rootScope.$on('renderComplete', () => {
const $atg = $el.find('kbn-agg-table-group').first();
expect($atg.size()).to.be(1);
expect($atg.length).to.be(1);
expect($atg.attr('group')).to.be('tableGroups');
expect($atg.isolateScope().group).to.be($atg.scope().tableGroups);
});
Expand All @@ -103,10 +103,10 @@ describe('Integration', function () {
init(new OneRangeVis(), { hits: { total: 0, hits: [] } });

$rootScope.$on('renderComplete', () => {
expect($el.find('kbn-agg-table-group').size()).to.be(0);
expect($el.find('kbn-agg-table-group').length).to.be(0);

const $err = $el.find('.table-vis-error');
expect($err.size()).to.be(1);
expect($err.length).to.be(1);
expect($err.text().trim()).to.be('No results found');
});
});
Expand All @@ -128,10 +128,10 @@ describe('Integration', function () {
init(new ThreeTermVis(visParams), resp);

$rootScope.$on('renderComplete', () => {
expect($el.find('kbn-agg-table-group').size()).to.be(0);
expect($el.find('kbn-agg-table-group').length).to.be(0);

const $err = $el.find('.table-vis-error');
expect($err.size()).to.be(1);
expect($err.length).to.be(1);
expect($err.text().trim()).to.be('No results found');
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe('tooltipFormatter', function () {
const event = _.cloneDeep(baseEvent);
const $el = $(tooltipFormatter(event));
const $rows = $el.find('tr');
expect($rows.size()).to.be(3);
expect($rows.length).to.be(3);

const $row1 = $rows.eq(0).find('td');
expect(cell($row1, 0)).to.be('inner');
Expand Down
8 changes: 4 additions & 4 deletions src/ui/public/agg_table/__tests__/_group.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('AggTableGroup Directive', function () {
$scope.$digest();

// should create one sub-tbale
expect($el.find('kbn-agg-table').size()).to.be(1);
expect($el.find('kbn-agg-table').length).to.be(1);
});

it('renders nothing if the table list is empty', function () {
Expand All @@ -59,7 +59,7 @@ describe('AggTableGroup Directive', function () {
$scope.$digest();

const $subTables = $el.find('kbn-agg-table');
expect($subTables.size()).to.be(0);
expect($subTables.length).to.be(0);
});

it('renders a complex response properly', function () {
Expand All @@ -82,10 +82,10 @@ describe('AggTableGroup Directive', function () {
$scope.$digest();

const $subTables = $el.find('kbn-agg-table');
expect($subTables.size()).to.be(3);
expect($subTables.length).to.be(3);

const $subTableHeaders = $el.find('.agg-table-group-header');
expect($subTableHeaders.size()).to.be(3);
expect($subTableHeaders.length).to.be(3);

$subTableHeaders.each(function (i) {
expect($(this).text()).to.be(group.tables[i].title);
Expand Down
18 changes: 9 additions & 9 deletions src/ui/public/agg_table/__tests__/_table.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ describe('AggTable Directive', function () {
const $el = $compile('<kbn-agg-table table="table"></kbn-agg-table>')($scope);
$scope.$digest();

expect($el.find('tbody').size()).to.be(1);
expect($el.find('td').size()).to.be(1);
expect($el.find('tbody').length).to.be(1);
expect($el.find('td').length).to.be(1);
expect($el.find('td').text()).to.eql(1000);
});

Expand All @@ -54,7 +54,7 @@ describe('AggTable Directive', function () {
const $el = $compile('<kbn-agg-table table="table"></kbn-agg-table>')($scope);
$scope.$digest();

expect($el.find('tbody').size()).to.be(0);
expect($el.find('tbody').length).to.be(0);
});

it('renders a complex response properly', function () {
Expand All @@ -76,10 +76,10 @@ describe('AggTable Directive', function () {
$compile($el)($scope);
$scope.$digest();

expect($el.find('tbody').size()).to.be(1);
expect($el.find('tbody').length).to.be(1);

const $rows = $el.find('tbody tr');
expect($rows.size()).to.be.greaterThan(0);
expect($rows.length).to.be.greaterThan(0);

function validBytes(str) {
expect(str).to.match(/^\d+$/);
Expand All @@ -90,7 +90,7 @@ describe('AggTable Directive', function () {
$rows.each(function () {
// 6 cells in every row
const $cells = $(this).find('td');
expect($cells.size()).to.be(6);
expect($cells.length).to.be(6);

const txts = $cells.map(function () {
return $(this).text().trim();
Expand Down Expand Up @@ -144,13 +144,13 @@ describe('AggTable Directive', function () {
$compile($el)($scope);
$scope.$digest();

expect($el.find('tfoot').size()).to.be(1);
expect($el.find('tfoot').length).to.be(1);

const $rows = $el.find('tfoot tr');
expect($rows.size()).to.be(1);
expect($rows.length).to.be(1);

const $cells = $($rows[0]).find('th');
expect($cells.size()).to.be(6);
expect($cells.length).to.be(6);

for (let i = 0; i < 6; i++) {
expect($($cells[i]).text()).to.be(expected[i]);
Expand Down
4 changes: 2 additions & 2 deletions src/ui/public/directives/paginate.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ uiModules.get('kibana')
link: {
pre: function ($scope, $el, attrs) {
if (_.isUndefined(attrs.bottomControls)) attrs.bottomControls = true;
if ($el.find('paginate-controls.paginate-bottom').size() === 0 && attrs.bottomControls) {
if ($el.find('paginate-controls.paginate-bottom').length === 0 && attrs.bottomControls) {
$el.append($compile('<paginate-controls class="paginate-bottom">')($scope));
}
},
post: function ($scope, $el, attrs) {
if (_.isUndefined(attrs.topControls)) attrs.topControls = false;
if ($el.find('paginate-controls.paginate-top').size() === 0 && attrs.topControls) {
if ($el.find('paginate-controls.paginate-top').length === 0 && attrs.topControls) {
$el.prepend($compile('<paginate-controls class="paginate-top">')($scope));
}

Expand Down
2 changes: 1 addition & 1 deletion src/ui/public/doc_table/components/table_row.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ module.directive('kbnTableRow', function ($compile, $httpParamSerializer, kbnUrl
const $target = reuse ? $(reuse).detach() : $(html);
$target.data('discover:html', html);
const $before = $cells.eq(i - 1);
if ($before.size()) {
if ($before.length) {
$before.after($target);
} else {
$el.append($target);
Expand Down
10 changes: 5 additions & 5 deletions src/ui/public/jquery/__tests__/find_test_subject.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ describe('jQuery.findTestSubject', function () {
const $otherMatch = $make('subject').appendTo($container);

const $found = $container.findTestSubject('subject');
expect($found.filter($match).size()).to.be(1);
expect($found.filter($otherMatch).size()).to.be(1);
expect($found.filter($match).length).to.be(1);
expect($found.filter($otherMatch).length).to.be(1);
});

it('finds all of the elements with either subject', function () {
Expand All @@ -33,9 +33,9 @@ describe('jQuery.findTestSubject', function () {
const $noMatch = $make('notSubject').appendTo($container);

const $found = $container.findTestSubject('subject', 'alsoSubject');
expect($found.filter($match1).size()).to.be(1);
expect($found.filter($match2).size()).to.be(1);
expect($found.filter($noMatch).size()).to.be(0);
expect($found.filter($match1).length).to.be(1);
expect($found.filter($match2).length).to.be(1);
expect($found.filter($noMatch).length).to.be(0);
});

it('finds all of the elements with a decendant selector', function () {
Expand Down
2 changes: 1 addition & 1 deletion src/ui/public/notify/notifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ Notifier.prototype._showFatal = function (err) {

let $container = $('#fatal-splash-screen');

if (!$container.size()) {
if (!$container.length) {
$(document.body)
// in case the app has not completed boot
.removeAttr('ng-cloak')
Expand Down
2 changes: 1 addition & 1 deletion src/ui/public/number_list/number_list_input.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ uiModules
function go(dir) {
return function () {
const $to = $get(dir);
if ($to.size()) $to.focus();
if ($to.length) $to.focus();
else return false;
};
}
Expand Down
34 changes: 17 additions & 17 deletions src/ui/public/paginated_table/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ describe('paginated table', function () {
const rows = [];

renderTable(cols, rows);
expect($el.children().size()).to.be(0);
expect($el.children().length).to.be(0);
});

it('should render columns and rows', function () {
Expand All @@ -89,10 +89,10 @@ describe('paginated table', function () {
const rows = data.rows;

renderTable(cols, rows);
expect($el.children().size()).to.be(1);
expect($el.children().length).to.be(1);
const tableRows = $el.find('tbody tr');
// should pad rows
expect(tableRows.size()).to.be(defaultPerPage);
expect(tableRows.length).to.be(defaultPerPage);
// should contain the row data
expect(tableRows.eq(0).find('td').eq(0).text()).to.be(rows[0][0]);
expect(tableRows.eq(0).find('td').eq(1).text()).to.be(rows[0][1]);
Expand All @@ -109,9 +109,9 @@ describe('paginated table', function () {

renderTable(data.columns, data.rows, perPageCount);
const tableRows = $el.find('tbody tr');
expect(tableRows.size()).to.be(perPageCount);
expect(tableRows.length).to.be(perPageCount);
// add 2 for the first and last page links
expect($el.find('paginate-controls button').size()).to.be(pageCount + 2);
expect($el.find('paginate-controls button').length).to.be(pageCount + 2);
});

it('should not show blank rows on last page when so specified', function () {
Expand All @@ -121,23 +121,23 @@ describe('paginated table', function () {

renderTable(data.columns, data.rows, perPageCount, null, false);
const tableRows = $el.find('tbody tr');
expect(tableRows.size()).to.be(rowCount);
expect(tableRows.length).to.be(rowCount);
});

it('should not show link to top when not set', function () {
const data = makeData(5, 5);
renderTable(data.columns, data.rows, 10, null, false);

const linkToTop = $el.find('[data-test-subj="paginateControlsLinkToTop"]');
expect(linkToTop.size()).to.be(0);
expect(linkToTop.length).to.be(0);
});

it('should show link to top when set', function () {
const data = makeData(5, 5);
renderTable(data.columns, data.rows, 10, null, false, true);

const linkToTop = $el.find('[data-test-subj="paginateControlsLinkToTop"]');
expect(linkToTop.size()).to.be(1);
expect(linkToTop.length).to.be(1);
});

});
Expand Down Expand Up @@ -367,27 +367,27 @@ describe('paginated table', function () {

it('should append object markup', function () {
const tableRows = $el.find('tbody tr');
expect(tableRows.eq(0).find('h1').size()).to.be(0);
expect(tableRows.eq(1).find('h1').size()).to.be(1);
expect(tableRows.eq(2).find('h1').size()).to.be(0);
expect(tableRows.eq(0).find('h1').length).to.be(0);
expect(tableRows.eq(1).find('h1').length).to.be(1);
expect(tableRows.eq(2).find('h1').length).to.be(0);
});

it('should sort using object value', function () {
paginatedTable.sortColumn(0);
$scope.$digest();
let tableRows = $el.find('tbody tr');
expect(tableRows.eq(0).find('h1').size()).to.be(0);
expect(tableRows.eq(1).find('h1').size()).to.be(0);
expect(tableRows.eq(0).find('h1').length).to.be(0);
expect(tableRows.eq(1).find('h1').length).to.be(0);
// html row should be the last row
expect(tableRows.eq(2).find('h1').size()).to.be(1);
expect(tableRows.eq(2).find('h1').length).to.be(1);

paginatedTable.sortColumn(0);
$scope.$digest();
tableRows = $el.find('tbody tr');
// html row should be the first row
expect(tableRows.eq(0).find('h1').size()).to.be(1);
expect(tableRows.eq(1).find('h1').size()).to.be(0);
expect(tableRows.eq(2).find('h1').size()).to.be(0);
expect(tableRows.eq(0).find('h1').length).to.be(1);
expect(tableRows.eq(1).find('h1').length).to.be(0);
expect(tableRows.eq(2).find('h1').length).to.be(0);
});
});
});
2 changes: 1 addition & 1 deletion src/ui/public/resize_checker/resize_checker.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function ResizeCheckerProvider(Private) {
// so we wrap in jQuery then extract the element
const $el = $(el);

if ($el.size() !== 1) {
if ($el.length !== 1) {
throw new TypeError('ResizeChecker must be constructed with a single DOM element.');
}

Expand Down
2 changes: 1 addition & 1 deletion src/ui/public/vis/components/tooltip/position_tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function positionTooltip(opts, html) {
const prev = $chart.data('previousPlacement') || {};
const event = opts.event;

if (!$chart.size() || !$el.size()) return;
if (!$chart.length || !$el.length) return;

const size = getTtSize(html || $el.html(), $sizer);
const pos = getBasePosition(size, event);
Expand Down
2 changes: 1 addition & 1 deletion src/ui/public/vis/components/tooltip/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ Tooltip.prototype.hide = function () {
*/
Tooltip.prototype.$getChart = function () {
const chart = $(this.container && this.container.node());
return chart.size() ? chart : false;
return chart.length ? chart : false;
};

/**
Expand Down
2 changes: 1 addition & 1 deletion src/ui/public/visualize/visualization.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ uiModules
function jQueryGetter(selector) {
return function () {
const $sel = $el.find(selector);
if ($sel.size()) return $sel;
if ($sel.length) return $sel;
};
}
}
Expand Down

0 comments on commit 492a15e

Please sign in to comment.