Skip to content
This repository has been archived by the owner on Oct 13, 2021. It is now read-only.

Commit

Permalink
Remove ES6-isms. Fixes bug 1283645.
Browse files Browse the repository at this point in the history
The latest Safari (9.1.1) and pre-44 versions of FF can't handle them, so search was broken.
  • Loading branch information
erikrose committed Jul 5, 2016
1 parent dfd2ebe commit 4f83ae7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 23 deletions.
2 changes: 1 addition & 1 deletion dxr/static_unhashed/js/code-highlighter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* jshint devel:true, esnext: true */
/* jshint devel:true */
/* globals nunjucks: true, $ */

/**
Expand Down
5 changes: 2 additions & 3 deletions dxr/static_unhashed/js/context_menu.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* jshint devel:true, esnext: true */
/* jshint devel:true */
/* globals nunjucks: true, $ */

$(function() {
Expand Down Expand Up @@ -30,8 +30,7 @@ $(function() {
// Only add highlights if the currentNode is not undefined or null and
// is an anchor link, as symbols will always be links.
if (currentNode && currentNode[0].tagName === 'A') {
let id = currentNode.data('id');
fileContainer.find('a[data-id=' + id + ']').addClass('clicking');
fileContainer.find('a[data-id=' + currentNode.data('id') + ']').addClass('clicking');
}
}

Expand Down
41 changes: 22 additions & 19 deletions dxr/static_unhashed/js/dxr.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* jshint devel:true, esnext: true */
/* jshint devel:true */
/* globals nunjucks: true, $ */

var htmlEscape;
Expand Down Expand Up @@ -237,16 +237,18 @@ $(function() {
* Add click listeners to the context buttons to load more contexts.
*/
function withContextListeners(renderedResults) {
const toJquery = $(renderedResults);
var toJquery = $(renderedResults);

// AJAX query as context lines after given row if after is true,
// otherwise before given row.
function getContextLines(row, query, after) {
$.ajax({
dataType: "json",
url: query,
success: function(data) {
var result;
if (data.lines.length > 0) {
const result = nunjucks.render('context_lines.html', {
result = nunjucks.render('context_lines.html', {
www_root: dxr.wwwRoot,
tree: dxr.tree,
result: data
Expand Down Expand Up @@ -275,13 +277,13 @@ $(function() {
{klass: ".ctx_up", start: -4, end: -1, after: false},
{klass: ".ctx_down", start: 1, end: 4, after: true}].forEach(
function(ctx) {
const c = ctx;
var c = ctx;
$(c.klass, toJquery).on('click', function() {
const $this = $(this),
path = $this.parents('.result').data('path'),
line = parseInt($this.parents(".result_line").data('line')),
queryString = (dxr.linesUrl + '?' +
$.param({path, start: line + c.start, end: line + c.end}));
var $this = $(this),
path = $this.parents('.result').data('path'),
line = parseInt($this.parents(".result_line").data('line')),
queryString = (dxr.linesUrl + '?' +
$.param({path, start: line + c.start, end: line + c.end}));
getContextLines($this.parents(".result_line"), queryString, c.after);
});
});
Expand All @@ -293,11 +295,12 @@ $(function() {
*/
function cleanupResults(result) {
// Construct {line: {contextEl, resultEl}}
const lineMap = {};
var lineMap = {};
var spaces, text, resultCode, lineNode, ctxSpan;
// Visit the lines and remove duplicates.
result.children('.result_line').each(function() {
const $this = $(this);
const line = parseInt($this.data("line"));
var $this = $(this);
var line = parseInt($this.data("line"));
lineMap[line] = lineMap[line] || {};
if (this.classList.contains("ctx_row")) {
if (lineMap[line].contextEl) {
Expand All @@ -316,23 +319,23 @@ $(function() {
}
});
// Now go through and fix some things.
for (let line in lineMap) {
for (var line in lineMap) {
if (!lineMap.hasOwnProperty(line)) continue;
// If some line has both context and result, then replace context line by result line.
// But since result strips trailing whitespace where context has it,
// we must bring that from the context line.
if (lineMap[line].contextEl && lineMap[line].resultEl) {
const text = lineMap[line].contextEl.querySelector("code").textContent;
const resultCode = lineMap[line].resultEl.querySelector("code");
let spaces = "";
for (let i = 0; i < text.length && /\s/.test(text[i]); i++) {
text = lineMap[line].contextEl.querySelector("code").textContent;
resultCode = lineMap[line].resultEl.querySelector("code");
spaces = "";
for (var i = 0; i < text.length && /\s/.test(text[i]); i++) {
spaces += text[i];
}
resultCode.innerHTML = spaces + resultCode.innerHTML;
$(lineMap[line].contextEl).replaceWith(lineMap[line].resultEl);
}
const lineNode = lineMap[line].resultEl || lineMap[line].contextEl,
ctxSpan = lineNode.querySelector(".leftmost-column > span");
lineNode = lineMap[line].resultEl || lineMap[line].contextEl;
ctxSpan = lineNode.querySelector(".leftmost-column > span");
line = parseInt(line);
// If previous line exists, remove ctx_up. If below line exists, remove ctx_down.
// If surrounded, remove ctx_full.
Expand Down

0 comments on commit 4f83ae7

Please sign in to comment.