зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1396855 - about:telemetry : Added search terms in the URL fragment. r=chutten
Implementation of the search terms in the url fragment was done as concisely as possible(considering the various conditions required, with the underscore when other hash terms are present). To implement search through hashes in URL, the function urlStateRestore() was changed. To make the changes more aesthetic, another function urlSectionRestore() performs the tasks earlier performed by urlStateRestore(), and urlStateRestore() now implements the search parsing and a call to urlSectionRestore(). MozReview-Commit-ID: 9vgjNUpJkQG --HG-- extra : rebase_source : c2cdb79e74faffa50bfd6636f0877f541f4f6ddf
This commit is contained in:
Родитель
b8af9874fd
Коммит
ecc5186a64
|
@ -1275,6 +1275,8 @@ var Histogram = {
|
||||||
|
|
||||||
var Search = {
|
var Search = {
|
||||||
|
|
||||||
|
HASH_SEARCH: "search=",
|
||||||
|
|
||||||
// A list of ids of sections that do not support search.
|
// A list of ids of sections that do not support search.
|
||||||
blacklist: [
|
blacklist: [
|
||||||
"raw-payload-section"
|
"raw-payload-section"
|
||||||
|
@ -1419,6 +1421,8 @@ var Search = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
changeUrlSearch(text);
|
||||||
|
|
||||||
if (!sectionParam) { // If we are not searching in all section.
|
if (!sectionParam) { // If we are not searching in all section.
|
||||||
this.updateNoResults(text, noSearchResults);
|
this.updateNoResults(text, noSearchResults);
|
||||||
}
|
}
|
||||||
|
@ -1452,6 +1456,7 @@ var Search = {
|
||||||
},
|
},
|
||||||
|
|
||||||
homeSearch(text) {
|
homeSearch(text) {
|
||||||
|
changeUrlSearch(text);
|
||||||
if (text === "") {
|
if (text === "") {
|
||||||
this.resetHome();
|
this.resetHome();
|
||||||
return;
|
return;
|
||||||
|
@ -1917,6 +1922,29 @@ function changeUrlPath(selectedSection, subSection) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Change the url according to the current search text
|
||||||
|
*/
|
||||||
|
function changeUrlSearch(searchText) {
|
||||||
|
let currentHash = window.location.hash;
|
||||||
|
let hashWithoutSearch = currentHash.split(Search.HASH_SEARCH)[0];
|
||||||
|
let hash = "";
|
||||||
|
|
||||||
|
if (!currentHash && !searchText) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!currentHash.includes(Search.HASH_SEARCH) && hashWithoutSearch) {
|
||||||
|
hashWithoutSearch += "_";
|
||||||
|
}
|
||||||
|
if (searchText) {
|
||||||
|
hash = hashWithoutSearch + Search.HASH_SEARCH + searchText.replace(/ /g, "+");
|
||||||
|
} else if (hashWithoutSearch) {
|
||||||
|
hash = hashWithoutSearch.slice(0, hashWithoutSearch.length - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
window.location.hash = hash;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Change the section displayed
|
* Change the section displayed
|
||||||
*/
|
*/
|
||||||
|
@ -2072,10 +2100,10 @@ function setupListeners() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Restore sections states
|
// Restores the sections states
|
||||||
function urlStateRestore() {
|
function urlSectionRestore(hash) {
|
||||||
if (window.location.hash) {
|
if (hash) {
|
||||||
let section = window.location.hash.slice(1).replace("-tab", "-section");
|
let section = hash.replace("-tab", "-section");
|
||||||
let subsection = section.split("_")[1];
|
let subsection = section.split("_")[1];
|
||||||
section = section.split("_")[0];
|
section = section.split("_")[0];
|
||||||
let category = document.querySelector(".category[value=" + section + "]");
|
let category = document.querySelector(".category[value=" + section + "]");
|
||||||
|
@ -2090,6 +2118,24 @@ function urlStateRestore() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Restore sections states and search terms
|
||||||
|
function urlStateRestore() {
|
||||||
|
let hash = window.location.hash;
|
||||||
|
let searchQuery = "";
|
||||||
|
if (hash) {
|
||||||
|
hash = hash.slice(1);
|
||||||
|
if (hash.includes(Search.HASH_SEARCH)) {
|
||||||
|
searchQuery = hash.split(Search.HASH_SEARCH)[1].replace(/[+]/g, " ");
|
||||||
|
hash = hash.split(Search.HASH_SEARCH)[0];
|
||||||
|
}
|
||||||
|
urlSectionRestore(hash);
|
||||||
|
}
|
||||||
|
if (searchQuery) {
|
||||||
|
let search = document.getElementById("search");
|
||||||
|
search.value = searchQuery;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function openJsonInFirefoxJsonViewer(json) {
|
function openJsonInFirefoxJsonViewer(json) {
|
||||||
json = unescape(encodeURIComponent(json));
|
json = unescape(encodeURIComponent(json));
|
||||||
try {
|
try {
|
||||||
|
|
Загрузка…
Ссылка в новой задаче