From 3363e6795f06ef80267f7b09f561585dbc8d3641 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Thu, 1 Sep 2016 18:07:19 +0200 Subject: [PATCH] JS: use $(parent).find(child) instead of $(child, parent) refs #10704 Signed-off-by: Eric Lippmann --- modules/doc/public/js/module.js | 2 +- public/js/icinga/behavior/actiontable.js | 8 +++---- public/js/icinga/behavior/navigation.js | 6 ++--- public/js/icinga/behavior/tooltip.js | 10 ++++----- public/js/icinga/events.js | 18 +++++++-------- public/js/icinga/loader.js | 28 ++++++++++++------------ public/js/icinga/ui.js | 2 +- 7 files changed, 37 insertions(+), 37 deletions(-) diff --git a/modules/doc/public/js/module.js b/modules/doc/public/js/module.js index d5571eedd..f187be503 100644 --- a/modules/doc/public/js/module.js +++ b/modules/doc/public/js/module.js @@ -18,7 +18,7 @@ rendered: function(event) { var $container = $(event.currentTarget); - if ($('> .content.styleguide', $container).length) { + if ($($container).find('> .content.styleguide').length) { $container.removeClass('module-doc'); } } diff --git a/public/js/icinga/behavior/actiontable.js b/public/js/icinga/behavior/actiontable.js index 8d8424999..63175eef8 100644 --- a/public/js/icinga/behavior/actiontable.js +++ b/public/js/icinga/behavior/actiontable.js @@ -417,11 +417,11 @@ var self = evt.data.self; // initialize all rows with the correct row action - $('table.action tr, table.table-row-selectable tr', container).each(function(idx, el) { + $(container).find('table.action tr, table.table-row-selectable tr').each(function(idx, el) { // decide which row action to use: links declared with the class rowaction take // the highest precedence before hrefs defined in the tr itself and regular links - var $a = $('a[href].rowaction', el).first(); + var $a = $(el).find('a[href].rowaction').first(); if ($a.length) { // TODO: Find out whether we leak memory on IE with this: $(el).attr('href', $a.attr('href')); @@ -430,14 +430,14 @@ if ($(el).attr('href') && $(el).attr('href').length) { return; } - $a = $('a[href]', el).first(); + $a = $(el).find('a[href]').first(); if ($a.length) { $(el).attr('href', $a.attr('href')); } }); // IE will not ignore user-select unless we cancel selectstart - $('table.action.multiselect tr, table.table-row-selectable.multiselect tr', container).each(function(idx, el) { + $(container).find('table.action.multiselect tr, table.table-row-selectable.multiselect tr').each(function(idx, el) { $(el).on('selectstart', false); }); diff --git a/public/js/icinga/behavior/navigation.js b/public/js/icinga/behavior/navigation.js index 539639685..48f192347 100644 --- a/public/js/icinga/behavior/navigation.js +++ b/public/js/icinga/behavior/navigation.js @@ -56,7 +56,7 @@ // of the navigation after the page has been opened. // initialise the menu selected by the backend as active. - var $menus = $('#menu li.active', e.target); + var $menus = $(e.target).find('#menu li.active'); if ($menus.length) { $menus.each(function() { _this.setActive($(this)); @@ -179,10 +179,10 @@ */ Navigation.prototype.clear = function() { // menu items - $('#menu li.active', this.element).removeClass('active'); + $(this.element).find('#menu li.active').removeClass('active'); // search fields - $('#menu input.active', this.element).removeClass('active'); + $(this.element).find('#menu input.active').removeClass('active'); }; /** diff --git a/public/js/icinga/behavior/tooltip.js b/public/js/icinga/behavior/tooltip.js index 98cc1ff59..9ee369e1c 100644 --- a/public/js/icinga/behavior/tooltip.js +++ b/public/js/icinga/behavior/tooltip.js @@ -23,13 +23,13 @@ Tooltip.prototype.onRendered = function(evt) { var self = evt.data.self, icinga = evt.data.icinga, el = evt.target; - $('[title]', el).each(function () { + $(el).find('[title]').each(function () { var $el = $(this); $el.attr('title', $el.data('title-rich') || $el.attr('title')); }); - $('svg .chart-data', el).tipsy({ gravity: 'se', html: true }); - $('i[title]', el).tipsy({ gravity: $.fn.tipsy.autoNS, offset: 2 }); - $('[title]', el).each(function (i, el) { + $(el).find('svg .chart-data').tipsy({ gravity: 'se', html: true }); + $(el).find('i[title]').tipsy({ gravity: $.fn.tipsy.autoNS, offset: 2 }); + $(el).find('[title]').each(function (i, el) { var $el = $(el); var delay, gravity; if ($el.data('tooltip-delay') !== undefined) { @@ -54,7 +54,7 @@ // migrate or remove all orphaned tooltips $('.tipsy').each(function () { - var arrow = $('.tipsy-arrow', this)[0]; + var arrow = $(this).find('.tipsy-arrow')[0]; if (!icinga.utils.elementsOverlap(arrow, $('#main')[0])) { $(this).remove(); return; diff --git a/public/js/icinga/events.js b/public/js/icinga/events.js index aeca60db4..b5c1e36f8 100644 --- a/public/js/icinga/events.js +++ b/public/js/icinga/events.js @@ -51,7 +51,7 @@ } } - $('.icinga-module', $target).each(function(idx, mod) { + $target.find('.icinga-module').each(function(idx, mod) { moduleName = $(mod).data('icingaModule'); if (icinga.hasModule(moduleName) && !icinga.isLoadedModule(moduleName)) { loaded |= icinga.loadModule(moduleName); @@ -82,7 +82,7 @@ self.initializeModules = true; } - $('.dashboard > div', $target).each(function(idx, el) { + $target.find('.dashboard > div').each(function(idx, el) { var $element = $(el); var $url = $element.data('icingaUrl'); if (typeof $url !== 'undefined') { @@ -90,7 +90,7 @@ } }); - var $searchField = $('#menu input.search', $target); + var $searchField = $target.find('#menu input.search'); // Remember initial search field value if any if ($searchField.length && $searchField.val().length) { self.searchValue = $searchField.val(); @@ -154,7 +154,7 @@ treeNodeToggle: function () { var $parent = $(this).closest('li'); if ($parent.hasClass('collapsed')) { - $('li', $parent).addClass('collapsed'); + $parent.find('li').addClass('collapsed'); $parent.removeClass('collapsed'); } else { $parent.addClass('collapsed'); @@ -219,7 +219,7 @@ var url = $form.attr('action'); var method = $form.attr('method'); var encoding = $form.attr('enctype'); - var $button = $('input[type=submit]:focus', $form).add('button[type=submit]:focus', $form); + var $button = $form.find('input[type=submit]:focus').add('button[type=submit]:focus', $form); var progressTimer; var $target; var data; @@ -268,7 +268,7 @@ } if ($button.length === 0) { - $button = $('input[type=submit]', $form).add('button[type=submit]', $form).first(); + $button = $form.find('input[type=submit]').add('button[type=submit]', $form).first(); } if ($button.length) { @@ -389,14 +389,14 @@ } }, null, 100); } else if ($button.length && $button.next().hasClass('spinner')) { - $('i', $button.next()).addClass('active'); + $button.next().find('i').addClass('active'); } else if ($form.attr('data-progress-element')) { var $progressElement = $('#' + $form.attr('data-progress-element')); if ($progressElement.length) { if ($progressElement.hasClass('spinner')) { - $('i', $progressElement).addClass('active'); + $progressElement.find('i').addClass('active'); } else { - $('i.spinner', $progressElement).addClass('active'); + $progressElement.find('i.spinner').addClass('active'); } } } diff --git a/public/js/icinga/loader.js b/public/js/icinga/loader.js index 2ff4d7f6f..f1695da90 100644 --- a/public/js/icinga/loader.js +++ b/public/js/icinga/loader.js @@ -407,7 +407,7 @@ return; var self = this; - $('img.icon', $container).each(function(idx, img) { + $container.find('img.icon').each(function(idx, img) { var src = $(img).attr('src'); if (typeof self.iconCache[src] !== 'undefined') { return; @@ -453,7 +453,7 @@ if (req.autorefresh) { // TODO: next container url - active = $('[href].active', req.$target).attr('href'); + active = req.$target.find('[href].active').attr('href'); } var target = req.getResponseHeader('X-Icinga-Container'); @@ -519,26 +519,26 @@ // Handle search requests, still hardcoded. if (req.url.match(/^\/search/) && req.$target.data('icingaUrl').match(/^\/search/) && - $('.dashboard', $resp).length > 0 && - $('.dashboard .container', req.$target).length > 0) + $resp.find('.dashboard').length > 0 && + req.$target.find('.dashboard .container').length > 0) { // TODO: We need dashboard pane and container identifiers (not ids) var targets = []; - $('.dashboard .container', req.$target).each(function (idx, el) { + req.$target.find('.dashboard .container').each(function (idx, el) { targets.push($(el)); }); var i = 0; // Searching for '.dashboard .container' in $resp doesn't dork?! - $('.dashboard .container', $resp).each(function (idx, el) { + $resp.find('.dashboard .container').each(function (idx, el) { var $el = $(el); if ($el.hasClass('dashboard')) { return; } var url = $el.data('icingaUrl'); targets[i].data('icingaUrl', url); - var title = $('h1', $el).first(); - $('h1', targets[i]).first().replaceWith(title); + var title = $el.find('h1').first(); + $(targets[i]).find('h1').first().replaceWith(title); self.loadUrl(url, targets[i]); i++; @@ -595,7 +595,7 @@ var $el = $(el); if ($el.closest('#menu').length) { if ($el.is('form')) { - $('input', $el).addClass('active'); + $el.find('input').addClass('active'); } // Interrupt .each, only one menu item shall be active return false; @@ -797,20 +797,20 @@ // event.preventDefault(); // }); - $('.container', $container).each(function() { + $container.find('.container').each(function() { self.stopPendingRequestsFor($(this)); }); if (false && - $('.dashboard', $content).length > 0 && - $('.dashboard', $container).length === 0 + $content.find('.dashboard').length > 0 && + $container.find('.dashboard').length === 0 ) { - // $('.dashboard', $content) + // $content.find('.dashboard') // $container.html(content); } else { if ($container.closest('.dashboard').length) { - var title = $('h1', $container).first().detach(); + var title = $container.find('h1').first().detach(); $container.html(title).append(content); } else if (action === 'replace') { $container.html(content); diff --git a/public/js/icinga/ui.js b/public/js/icinga/ui.js index af60a3ce9..fce1a6257 100644 --- a/public/js/icinga/ui.js +++ b/public/js/icinga/ui.js @@ -459,7 +459,7 @@ */ initializeTriStates: function ($html) { var self = this; - $('div.tristate', $html).each(function(index, item) { + $html.find('div.tristate').each(function(index, item) { var $target = $(item); // hide input boxess and remove text nodes