Tabs js error fix, DevSite css issues fix, Search filtering
am: ebcf397
* commit 'ebcf3977a28477df6e6fdbad3bf425581d19ccc1':
Tabs js error fix, DevSite css issues fix, Search filtering
Change-Id: I0ce8101f73505fc9cd6ebbb87549171f0a27d0a1
This commit is contained in:
commit
7a697e73cb
2 changed files with 120 additions and 36 deletions
|
@ -9887,3 +9887,33 @@ a.video-shadowbox-button.white:hover::after {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: -4px;
|
top: -4px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** CSS Fixes for DevSite (akassay@) */
|
||||||
|
.dac-button-social,
|
||||||
|
.dac-fab:not('.dac-scroll-button') {
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dac-button-social .dac-sprite,
|
||||||
|
.dac-fab .dac-sprite,
|
||||||
|
.play-button .dac-sprite {
|
||||||
|
margin-top: -7px;
|
||||||
|
position: relative;
|
||||||
|
top: 50%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dac-fab .dac-sprite.dac-arrow-down-gray {
|
||||||
|
margin-top: -3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dac-button-social .dac-sprite.dac-gplus {
|
||||||
|
margin-top: -17px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.play-button .dac-sprite {
|
||||||
|
margin-top: -10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dac-nav-link-forward {
|
||||||
|
padding: 9px 0;
|
||||||
|
}
|
||||||
|
|
|
@ -15,7 +15,8 @@ $.ajaxSetup({
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
|
|
||||||
// prep nav expandos
|
// prep nav expandos
|
||||||
var pagePath = document.location.pathname;
|
var pagePath = devsite ?
|
||||||
|
location.href.replace(location.hash, '') : document.location.pathname;
|
||||||
// account for intl docs by removing the intl/*/ path
|
// account for intl docs by removing the intl/*/ path
|
||||||
if (pagePath.indexOf("/intl/") == 0) {
|
if (pagePath.indexOf("/intl/") == 0) {
|
||||||
pagePath = pagePath.substr(pagePath.indexOf("/", 6)); // start after intl/ to get last /
|
pagePath = pagePath.substr(pagePath.indexOf("/", 6)); // start after intl/ to get last /
|
||||||
|
@ -3378,12 +3379,22 @@ window.changeLangPref = changeLangPref;
|
||||||
})();
|
})();
|
||||||
var localeTarget = (function() {
|
var localeTarget = (function() {
|
||||||
var localeTarget = locale;
|
var localeTarget = locale;
|
||||||
if (location.pathname.substring(0,6) == "/intl/") {
|
if (window.devsite) {
|
||||||
var target = location.pathname.split('/')[2];
|
if (getQueryVariable('hl')) {
|
||||||
if (!(target === 0) || (LANGUAGES.indexOf(target) === -1)) {
|
var target = getQueryVariable('hl');
|
||||||
localeTarget = target;
|
if (!(target === 0) || (LANGUAGES.indexOf(target) === -1)) {
|
||||||
|
localeTarget = target;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (location.pathname.substring(0,6) == "/intl/") {
|
||||||
|
var target = location.pathname.split('/')[2];
|
||||||
|
if (!(target === 0) || (LANGUAGES.indexOf(target) === -1)) {
|
||||||
|
localeTarget = target;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return localeTarget;
|
return localeTarget;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
@ -5357,7 +5368,8 @@ window.metadata.search = (function() {
|
||||||
return $.get('https://content.googleapis.com/customsearch/v1?' + $.param(searchParams));
|
return $.get('https://content.googleapis.com/customsearch/v1?' + $.param(searchParams));
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderResults(el, results) {
|
function renderResults(el, results, searchAppliance) {
|
||||||
|
var referenceResults = searchAppliance.getReferenceResults();
|
||||||
if (!results.items) {
|
if (!results.items) {
|
||||||
el.append($('<div>').text('No results'));
|
el.append($('<div>').text('No results'));
|
||||||
return;
|
return;
|
||||||
|
@ -5365,27 +5377,37 @@ window.metadata.search = (function() {
|
||||||
|
|
||||||
for (var i = 0; i < results.items.length; i++) {
|
for (var i = 0; i < results.items.length; i++) {
|
||||||
var item = results.items[i];
|
var item = results.items[i];
|
||||||
var hasImage = item.pagemap && item.pagemap.cse_thumbnail;
|
var isDuplicate = false;
|
||||||
var sectionMatch = item.link.match(/developer\.android\.com\/(\w*)/);
|
$(referenceResults.android).each(function(index, result) {
|
||||||
var section = (sectionMatch && sectionMatch[1]) || 'blog';
|
if (item.link.indexOf(result.link) > -1) {
|
||||||
|
isDuplicate = true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
var entry = $('<div>').addClass('dac-custom-search-entry cols');
|
if (!isDuplicate) {
|
||||||
|
var hasImage = item.pagemap && item.pagemap.cse_thumbnail;
|
||||||
|
var sectionMatch = item.link.match(/developer\.android\.com\/(\w*)/);
|
||||||
|
var section = (sectionMatch && sectionMatch[1]) || 'blog';
|
||||||
|
|
||||||
if (hasImage) {
|
var entry = $('<div>').addClass('dac-custom-search-entry cols');
|
||||||
var image = item.pagemap.cse_thumbnail[0];
|
|
||||||
entry.append($('<div>').addClass('dac-custom-search-image-wrapper')
|
if (hasImage) {
|
||||||
.append($('<div>').addClass('dac-custom-search-image').css('background-image', 'url(' + image.src + ')')));
|
var image = item.pagemap.cse_thumbnail[0];
|
||||||
|
entry.append($('<div>').addClass('dac-custom-search-image-wrapper')
|
||||||
|
.append($('<div>').addClass('dac-custom-search-image').css('background-image', 'url(' + image.src + ')')));
|
||||||
|
}
|
||||||
|
|
||||||
|
entry.append($('<div>').addClass('dac-custom-search-text-wrapper')
|
||||||
|
.append($('<p>').addClass('dac-custom-search-section').text(section))
|
||||||
|
.append(
|
||||||
|
$('<a>').text(item.title).attr('href', item.link).wrap('<h2>').parent().addClass('dac-custom-search-title')
|
||||||
|
)
|
||||||
|
.append($('<p>').addClass('dac-custom-search-snippet').html(item.htmlSnippet.replace(/<br>/g, '')))
|
||||||
|
.append($('<a>').addClass('dac-custom-search-link').text(item.formattedUrl).attr('href', item.link)));
|
||||||
|
|
||||||
|
el.append(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
entry.append($('<div>').addClass('dac-custom-search-text-wrapper')
|
|
||||||
.append($('<p>').addClass('dac-custom-search-section').text(section))
|
|
||||||
.append(
|
|
||||||
$('<a>').text(item.title).attr('href', item.link).wrap('<h2>').parent().addClass('dac-custom-search-title')
|
|
||||||
)
|
|
||||||
.append($('<p>').addClass('dac-custom-search-snippet').html(item.htmlSnippet.replace(/<br>/g, '')))
|
|
||||||
.append($('<a>').addClass('dac-custom-search-link').text(item.formattedUrl).attr('href', item.link)));
|
|
||||||
|
|
||||||
el.append(entry);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (results.queries.nextPage) {
|
if (results.queries.nextPage) {
|
||||||
|
@ -5393,32 +5415,32 @@ window.metadata.search = (function() {
|
||||||
.addClass('dac-custom-search-load-more')
|
.addClass('dac-custom-search-load-more')
|
||||||
.text('Load more')
|
.text('Load more')
|
||||||
.click(function() {
|
.click(function() {
|
||||||
loadMoreResults(el, results);
|
loadMoreResults(el, results, searchAppliance);
|
||||||
});
|
});
|
||||||
|
|
||||||
el.append(loadMoreButton);
|
el.append(loadMoreButton);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
function loadMoreResults(el, results) {
|
function loadMoreResults(el, results, searchAppliance) {
|
||||||
var query = results.queries.request.searchTerms;
|
var query = results.queries.request[0].searchTerms;
|
||||||
var start = results.queries.nextPage.startIndex;
|
var start = results.queries.nextPage[0].startIndex;
|
||||||
var loadMoreButton = el.find('#dac-custom-search-load-more');
|
var loadMoreButton = el.find('#dac-custom-search-load-more');
|
||||||
|
|
||||||
loadMoreButton.text('Loading more...');
|
loadMoreButton.text('Loading more...');
|
||||||
|
|
||||||
customSearch(query, start).then(function(results) {
|
customSearch(query, start).then(function(results) {
|
||||||
loadMoreButton.remove();
|
loadMoreButton.remove();
|
||||||
renderResults(el, results);
|
renderResults(el, results, searchAppliance);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
$.fn.customSearch = function(query) {
|
$.fn.customSearch = function(query, searchAppliance) {
|
||||||
var el = $(this);
|
var el = $(this);
|
||||||
|
|
||||||
customSearch(query).then(function(results) {
|
customSearch(query).then(function(results) {
|
||||||
el.empty();
|
el.empty();
|
||||||
renderResults(el, results);
|
renderResults(el, results, searchAppliance);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
})(jQuery);
|
})(jQuery);
|
||||||
|
@ -5625,10 +5647,11 @@ window.metadata.search = (function() {
|
||||||
this.searchResultsHero = $('#dac-search-results-hero');
|
this.searchResultsHero = $('#dac-search-results-hero');
|
||||||
this.searchResultsReference = $('#dac-search-results-reference');
|
this.searchResultsReference = $('#dac-search-results-reference');
|
||||||
this.searchHeader = $('[data-search]').data('search-input.dac');
|
this.searchHeader = $('[data-search]').data('search-input.dac');
|
||||||
|
this.currQueryReferenceResults = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
Search.prototype.init = function() {
|
Search.prototype.init = function() {
|
||||||
if (this.checkRedirectToIndex()) { return; }
|
if (!devsite && this.checkRedirectToIndex()) { return; }
|
||||||
|
|
||||||
this.searchHistory = window.dacStore('search-history');
|
this.searchHistory = window.dacStore('search-history');
|
||||||
|
|
||||||
|
@ -5639,9 +5662,8 @@ window.metadata.search = (function() {
|
||||||
this.searchClose.click(this.close.bind(this));
|
this.searchClose.click(this.close.bind(this));
|
||||||
|
|
||||||
this.customSearch = $.fn.debounce(function(query) {
|
this.customSearch = $.fn.debounce(function(query) {
|
||||||
$('#dac-custom-search-results').customSearch(query);
|
$('#dac-custom-search-results').customSearch(query, this);
|
||||||
}, 1000);
|
}.bind(this), 1000);
|
||||||
|
|
||||||
// Start search shortcut (/)
|
// Start search shortcut (/)
|
||||||
$('body').keyup(function(event) {
|
$('body').keyup(function(event) {
|
||||||
if (event.which === 191 && $(event.target).is(':not(:input)')) {
|
if (event.which === 191 && $(event.target).is(':not(:input)')) {
|
||||||
|
@ -5764,6 +5786,10 @@ window.metadata.search = (function() {
|
||||||
return this.searchInput.val().replace(/(^ +)|( +$)/g, '');
|
return this.searchInput.val().replace(/(^ +)|( +$)/g, '');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Search.prototype.getReferenceResults = function() {
|
||||||
|
return this.currQueryReferenceResults;
|
||||||
|
};
|
||||||
|
|
||||||
Search.prototype.onSearchChanged = function() {
|
Search.prototype.onSearchChanged = function() {
|
||||||
var query = this.getQuery();
|
var query = this.getQuery();
|
||||||
|
|
||||||
|
@ -5780,10 +5806,19 @@ window.metadata.search = (function() {
|
||||||
|
|
||||||
this.lastQuery = query;
|
this.lastQuery = query;
|
||||||
this.searchResultsFor.text(query);
|
this.searchResultsFor.text(query);
|
||||||
|
|
||||||
|
// CSE results lag behind the metadata/reference results. We need to empty
|
||||||
|
// the CSE results and add 'Loading' text so user's aren't looking at two
|
||||||
|
// different sets of search results at one time.
|
||||||
|
var $loadingEl =
|
||||||
|
$('<div class="loadingCustomSearchResults">Loading Results...</div>');
|
||||||
|
$('#dac-custom-search-results').empty().prepend($loadingEl);
|
||||||
|
|
||||||
this.customSearch(query);
|
this.customSearch(query);
|
||||||
var metadataResults = metadata.search(query);
|
var metadataResults = metadata.search(query);
|
||||||
this.searchResultsResources.dacSearchRenderResources(metadataResults.resources, query);
|
this.searchResultsResources.dacSearchRenderResources(metadataResults.resources, query);
|
||||||
this.searchResultsReference.dacSearchRenderReferences(metadataResults, query);
|
this.searchResultsReference.dacSearchRenderReferences(metadataResults, query);
|
||||||
|
this.currQueryReferenceResults = metadataResults;
|
||||||
var hasHero = this.searchResultsHero.dacSearchRenderHero(metadataResults.resources, query);
|
var hasHero = this.searchResultsHero.dacSearchRenderHero(metadataResults.resources, query);
|
||||||
var hasQuery = !!query;
|
var hasQuery = !!query;
|
||||||
|
|
||||||
|
@ -6502,3 +6537,22 @@ window.dacStore = (function(window) {
|
||||||
initWideTable();
|
initWideTable();
|
||||||
});
|
});
|
||||||
})(jQuery);
|
})(jQuery);
|
||||||
|
|
||||||
|
/** Utilities */
|
||||||
|
|
||||||
|
/* returns the given string with all HTML brackets converted to entities
|
||||||
|
TODO: move this to the site's JS library */
|
||||||
|
function escapeHTML(string) {
|
||||||
|
return string.replace(/</g,"<")
|
||||||
|
.replace(/>/g,">");
|
||||||
|
};
|
||||||
|
|
||||||
|
function getQueryVariable(variable) {
|
||||||
|
var query = window.location.search.substring(1);
|
||||||
|
var vars = query.split("&");
|
||||||
|
for (var i=0;i<vars.length;i++) {
|
||||||
|
var pair = vars[i].split("=");
|
||||||
|
if(pair[0] == variable){return pair[1];}
|
||||||
|
}
|
||||||
|
return(false);
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in a new issue