From 78b5378b57211101083168b43aaf9fefd8b4f4d2 Mon Sep 17 00:00:00 2001 From: Chris Church Date: Thu, 1 May 2014 19:33:46 -0400 Subject: [PATCH] AC-1235 Speed up JS for inventory script view in browsable API. --- awx/templates/rest_framework/api.html | 48 +++++++++------------------ 1 file changed, 15 insertions(+), 33 deletions(-) diff --git a/awx/templates/rest_framework/api.html b/awx/templates/rest_framework/api.html index abfa8fe027..d811e2b45a 100644 --- a/awx/templates/rest_framework/api.html +++ b/awx/templates/rest_framework/api.html @@ -207,45 +207,27 @@ html body .dropdown-submenu:hover>a { $(function() { // Make links from relative URLs to resources. $('span.str').each(function() { - // Remove REST API links within data. - if ($(this).parent('a').size()) { - $(this).unwrap(); - } var s = $(this).html(); if (s.match(/^\"\/.+\/\"$/) || s.match(/^\"\/.+\/\?.*\"$/)) { $(this).html('"' + s.replace(/\"/g, '') + '"'); } }); // Make links for all inventory script hosts. - $('.request-info .pln:contains("script")').each(function() { - $('.response-info span.str:contains("hosts")').each(function() { - if ($(this).text() != '"hosts"') { - return; - } - var hosts_state = 0; - $(this).find('~ span').each(function() { - if (hosts_state == 0) { - if ($(this).is('span.pun') && $(this).text() == '[') { - hosts_state = 1; - } - } - else if (hosts_state == 1) { - if ($(this).is('span.pun') && ($(this).text() == ']' || $(this).text() == '],')) { - hosts_state = 2; - } - else if ($(this).is('span.str')) { - if ($(this).text() == '"') { - } - else if ($(this).text().match(/^\".+\"$/)) { - var s = $(this).text().replace(/\"/g, ''); - $(this).html('"' + s + '"'); - } - else { - var s = $(this).text(); - $(this).html('' + s + ''); - } - } - } + $('.request-info .pln').filter(function() { + return $(this).text() === 'script'; + }).each(function() { + $('.response-info span.str').filter(function() { + return $(this).text() === '"hosts"'; + }).each(function() { + $(this).nextUntil('span.pun:contains("]")').filter('span.str').each(function() { + if ($(this).text().match(/^\".+\"$/)) { + var s = $(this).text().replace(/\"/g, ''); + $(this).html('"' + s + '"'); + } + else if ($(this).text() !== '"') { + var s = $(this).text(); + $(this).html('' + s + ''); + } }); }); });