Skip to content

Commit 87619fb

Browse files
committed
Refactor js
1 parent 835e79d commit 87619fb

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

readthedocs/core/static-src/core/js/doc-embed/search.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,12 @@ function attach_elastic_search_query_sphinx(data) {
8484
list_item.append(extra);
8585
}
8686

87-
for (var j = 0; j < blocks.length; j += 1) {
87+
for (var block_index = 0; block_index < blocks.length; block_index += 1) {
88+
var current_block = blocks[block_index];
8889

8990
var contents = $('<div class="context">');
9091

91-
var section_template = '' +
92+
var section_template =
9293
'<div>' +
9394
'<a href="<%= section_subtitle_link %>">' +
9495
'<%= section_subtitle %>' +
@@ -100,7 +101,7 @@ function attach_elastic_search_query_sphinx(data) {
100101
'</div>' +
101102
'<% } %>';
102103

103-
var domain_template = '' +
104+
var domain_template =
104105
'<div>' +
105106
'<a href="<%= domain_subtitle_link %>">' +
106107
'<%= domain_subtitle %>' +
@@ -111,8 +112,8 @@ function attach_elastic_search_query_sphinx(data) {
111112
'</div>';
112113

113114
// if the result is page section
114-
if (blocks[j].type === "section") {
115-
var section = blocks[j];
115+
if (current_block.type === "section") {
116+
var section = current_block;
116117
var section_subtitle = section.title;
117118
var section_subtitle_link = link + "#" + section.id;
118119
var section_content = [section.content.substr(0, MAX_SUBSTRING_LIMIT) + " ..."];
@@ -145,8 +146,8 @@ function attach_elastic_search_query_sphinx(data) {
145146
}
146147

147148
// if the result is a sphinx domain object
148-
if (blocks[j].type === "domain") {
149-
var domain = blocks[j];
149+
if (current_block.type === "domain") {
150+
var domain = current_block;
150151
var domain_role_name = domain.role;
151152
var domain_subtitle_link = link + "#" + domain.id;
152153
var domain_name = domain.name;
@@ -182,7 +183,7 @@ function attach_elastic_search_query_sphinx(data) {
182183

183184
// Create some spacing between the results.
184185
// Also, don't add this spacing in the last hit.
185-
if (j < blocks.length - 1) {
186+
if (block_index < blocks.length - 1) {
186187
list_item.append($("<div class='rtd_search_hits_spacing'></div>"));
187188
}
188189
}

0 commit comments

Comments
 (0)