提交 c780cc1b 编写于 作者: M munrocket@pm.me

Examples: refactor index.html

上级 4a0dce9d
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
<div id="contentWrapper"> <div id="contentWrapper">
<div id="inputWrapper"> <div id="inputWrapper">
<input placeholder="" type="text" id="filter" autocorrect="off" autocapitalize="off" spellcheck="false" /> <input placeholder="" type="text" id="filterInput" autocorrect="off" autocapitalize="off" spellcheck="false" />
<div id="exitSearchButton"></div> <div id="exitSearchButton"></div>
<select id="language"> <select id="language">
<option value="en">en</option> <option value="en">en</option>
...@@ -94,7 +94,7 @@ ...@@ -94,7 +94,7 @@
var expandButton = document.getElementById( 'expandButton' ); var expandButton = document.getElementById( 'expandButton' );
var exitSearchButton = document.getElementById( 'exitSearchButton' ); var exitSearchButton = document.getElementById( 'exitSearchButton' );
var panelScrim = document.getElementById( 'panelScrim' ); var panelScrim = document.getElementById( 'panelScrim' );
var filterInput = document.getElementById( 'filter' ); var filterInput = document.getElementById( 'filterInput' );
var iframe = document.querySelector( 'iframe' ); var iframe = document.querySelector( 'iframe' );
var pageProperties = {}; var pageProperties = {};
......
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
<div id="contentWrapper"> <div id="contentWrapper">
<div id="inputWrapper"> <div id="inputWrapper">
<input placeholder="" type="text" id="filter" autocorrect="off" autocapitalize="off" spellcheck="false" /> <input placeholder="" type="text" id="filterInput" autocorrect="off" autocapitalize="off" spellcheck="false" />
<div id="exitSearchButton"></div> <div id="exitSearchButton"></div>
</div> </div>
...@@ -49,103 +49,143 @@ ...@@ -49,103 +49,143 @@
<script> <script>
function extractQuery() { var panel = document.getElementById( 'panel' );
var content = document.getElementById( 'content' );
var viewer = document.getElementById( 'viewer' );
var filterInput = document.getElementById( 'filterInput' );
var exitSearchButton = document.getElementById( 'exitSearchButton' );
var expandButton = document.getElementById( 'expandButton' );
var viewSrcButton = document.getElementById( 'button' );
var panelScrim = document.getElementById( 'panelScrim' );
var p = window.location.search.indexOf( '?q=' ); var links = {};
var selected = null;
var container = document.createElement( 'div' );
if ( p !== - 1 ) { init();
return window.location.search.substr( 3 ); function init() {
content.appendChild( container );
viewSrcButton.style.display = 'none';
for ( var key in files ) {
var section = files[ key ];
var header = document.createElement( 'h2' );
header.textContent = key;
header.setAttribute( 'data-category', key );
container.appendChild( header );
for ( var i = 0; i < section.length; i ++ ) {
var file = section[ i ];
var link = createLink( file );
container.appendChild( link );
links[ file ] = link;
}
} }
return ''; if ( window.location.hash !== '' && links[ window.location.hash.substring( 1 ) ] ) {
} loadFile( window.location.hash.substring( 1 ) );
var panel = document.getElementById( 'panel' ); }
var content = document.getElementById( 'content' );
var viewer = document.getElementById( 'viewer' );
var filterInput = document.getElementById( 'filter' ); filterInput.value = extractQuery();
var exitSearchButton = document.getElementById( 'exitSearchButton' );
var expandButton = document.getElementById( 'expandButton' ); if ( filterInput.value !== '' ) {
expandButton.addEventListener( 'click', function ( event ) {
event.preventDefault(); panel.classList.add( 'searchFocused' );
panel.classList.toggle( 'open' );
} ); }
var panelScrim = document.getElementById( 'panelScrim' ); updateFilter();
panelScrim.onclick = function ( event ) {
event.preventDefault(); // Events
panel.classList.toggle( 'open' );
}; filterInput.onfocus = function ( event ) {
// iOS iframe auto-resize workaround panel.classList.add( 'searchFocused' );
if ( /(iPad|iPhone|iPod)/g.test( navigator.userAgent ) ) { };
viewer.style.width = getComputedStyle( viewer ).width; filterInput.onblur = function ( event ) {
viewer.style.height = getComputedStyle( viewer ).height;
viewer.setAttribute( 'scrolling', 'no' );
} if ( filterInput.value === '' ) {
var container = document.createElement( 'div' ); panel.classList.remove( 'searchFocused' );
content.appendChild( container );
var viewSrcButton = document.getElementById( 'button' ); }
viewSrcButton.style.display = 'none';
var links = {}; };
var selected = null;
function createLink( file ) { exitSearchButton.onclick = function ( event ) {
var link = document.createElement( 'a' ); filterInput.value = '';
link.className = 'link'; updateFilter();
link.href = file + '.html'; panel.classList.remove( 'searchFocused' );
link.textContent = getName( file );
link.setAttribute( 'target', 'viewer' );
link.addEventListener( 'click', function ( event ) {
if ( event.button !== 0 || event.ctrlKey || event.altKey || event.metaKey ) return; };
selectFile( file ); filterInput.addEventListener( 'input', function () {
updateFilter();
} ); } );
return link;
} expandButton.addEventListener( 'click', function ( event ) {
for ( var key in files ) { event.preventDefault();
panel.classList.toggle( 'open' );
var section = files[ key ]; } );
var header = document.createElement( 'h2' ); panelScrim.onclick = function ( event ) {
header.textContent = key;
header.setAttribute( 'data-category', key );
container.appendChild( header );
for ( var i = 0; i < section.length; i ++ ) { event.preventDefault();
panel.classList.toggle( 'open' );
var file = section[ i ]; };
var link = createLink( file ); // iOS iframe auto-resize workaround
container.appendChild( link );
links[ file ] = link; if ( /(iPad|iPhone|iPod)/g.test( navigator.userAgent ) ) {
viewer.style.width = getComputedStyle( viewer ).width;
viewer.style.height = getComputedStyle( viewer ).height;
viewer.setAttribute( 'scrolling', 'no' );
} }
} }
function createLink( file ) {
var link = document.createElement( 'a' );
link.className = 'link';
link.href = file + '.html';
link.textContent = getName( file );
link.setAttribute( 'target', 'viewer' );
link.addEventListener( 'click', function ( event ) {
if ( event.button !== 0 || event.ctrlKey || event.altKey || event.metaKey ) return;
selectFile( file );
} );
return link;
}
function loadFile( file ) { function loadFile( file ) {
selectFile( file ); selectFile( file );
...@@ -173,43 +213,6 @@ ...@@ -173,43 +213,6 @@
} }
if ( window.location.hash !== '' && links[ window.location.hash.substring( 1 ) ] ) {
loadFile( window.location.hash.substring( 1 ) );
}
// filter
filterInput.onfocus = function ( event ) {
panel.classList.add( 'searchFocused' );
};
filterInput.onblur = function ( event ) {
if ( filterInput.value === '' ) {
panel.classList.remove( 'searchFocused' );
}
};
exitSearchButton.onclick = function ( event ) {
filterInput.value = '';
updateFilter();
panel.classList.remove( 'searchFocused' );
};
filterInput.addEventListener( 'input', function () {
updateFilter();
} );
function updateFilter() { function updateFilter() {
var v = filterInput.value; var v = filterInput.value;
...@@ -315,15 +318,19 @@ ...@@ -315,15 +318,19 @@
} }
filterInput.value = extractQuery(); function extractQuery() {
var p = window.location.search.indexOf( '?q=' );
if ( p !== - 1 ) {
if ( filterInput.value !== '' ) { return window.location.search.substr( 3 );
panel.classList.add( 'searchFocused' ); }
} return '';
updateFilter(); }
</script> </script>
......
...@@ -157,7 +157,7 @@ h1 a { ...@@ -157,7 +157,7 @@ h1 a {
display: none; display: none;
} }
#panel.searchFocused #filter { #panel.searchFocused #filterInput {
-webkit-mask-image: none; -webkit-mask-image: none;
mask-image: none; mask-image: none;
background-color: inherit; background-color: inherit;
...@@ -232,7 +232,7 @@ h1 a { ...@@ -232,7 +232,7 @@ h1 a {
content: ""; content: "";
} }
#panel #filter { #panel #filterInput {
flex: 1; flex: 1;
width: 100%; width: 100%;
padding: 0 36px; padding: 0 36px;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册