Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 45 additions & 6 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ <h1><a href="https://threejs.org">three.js</a></h1>


// Functionality for search/filter input field

filterInput.onfocus = function () {

panel.classList.add( 'searchFocused' );
Expand All @@ -149,17 +150,17 @@ <h1><a href="https://threejs.org">three.js</a></h1>

};

exitSearchButton.onclick = function () {
filterInput.oninput = function () {

filterInput.value = '';
updateFilter();
panel.classList.remove( 'searchFocused' );

};

filterInput.oninput = function () {
exitSearchButton.onclick = function () {

filterInput.value = '';
updateFilter();
panel.classList.remove( 'searchFocused' );

};

Expand All @@ -172,6 +173,18 @@ <h1><a href="https://threejs.org">three.js</a></h1>
createNavigation( list, language );
createNewIframe();

// Handle search query

filterInput.value = extractQuery();

if ( filterInput.value !== '' ) {

panel.classList.add( 'searchFocused' );

}

updateFilter();

}

// Navigation Panel
Expand Down Expand Up @@ -305,10 +318,36 @@ <h1><a href="https://threejs.org">three.js</a></h1>

// Filtering

function extractQuery() {

const search = window.location.search;

if ( search.indexOf( '?q=' ) !== - 1 ) {

return decodeURI( search.substr( 3 ) );

}

return '';

}

function updateFilter() {

// (uncomment the following line and the "Query strings" section, if you want query strings):
// updateQueryString();
let v = filterInput.value.trim();
v = v.replace( /\s+/gi, ' ' ); // replace multiple whitespaces with a single one

if ( v !== '' ) {

window.history.replaceState( {}, '', '?q=' + v + window.location.hash );

} else {

window.history.replaceState( {}, '', window.location.pathname + window.location.hash );

}

//

const regExp = new RegExp( filterInput.value, 'gi' );

Expand Down
7 changes: 3 additions & 4 deletions examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -342,19 +342,18 @@ <h1><a href="https://threejs.org">three.js</a></h1>

function extractQuery() {

const p = window.location.search.indexOf( '?q=' );
const search = window.location.search;

if ( p !== - 1 ) {
if ( search.indexOf( '?q=' ) !== - 1 ) {

return decodeURI( window.location.search.substr( 3 ) );
return decodeURI( search.substr( 3 ) );

}

return '';

}


function createElementFromHTML( htmlString ) {

const div = document.createElement( 'div' );
Expand Down