Skip to content

Instantly share code, notes, and snippets.

View andberry's full-sized avatar

Andrea Berardi andberry

View GitHub Profile
@andberry
andberry / responsive-tables
Created September 30, 2021 01:58
Responsive Tables: quick solution to make a table horizontally scrollable
/*
responsiveTables.js
add a wrapper around every table in DOM
and style make it horizontally scrollable (css below)
*/
function responsiveTables() {
const tablesEls = document.querySelectorAll('table');
for (const item of Array.from(tablesEls)) {
const tableWrapperEl = document.createElement('div');
tableWrapperEl.classList.add('c-responsive-table-wrapper');
@andberry
andberry / jquery-document-ready-vanilla-javascript.js
Last active October 26, 2021 09:37
jQuery $(document).ready() in vanilla JavaScript
/*
https://developer.mozilla.org/en-US/docs/Web/API/Window/DOMContentLoaded_event
- The DOMContentLoaded event fires when the initial HTML document has been completely loaded and parsed,
without waiting for stylesheets, images, and subframes to finish loading.
- A different event, load, should be used only to detect a fully-loaded page.
https://developer.mozilla.org/en-US/docs/Web/API/Document/readyState
- loading: The document is still loading.
- interactive: The document has finished loading and the document has been parsed but sub-resources such as scripts, images, stylesheets and frames are still loading.
- completeThe document and all sub-resources have finished loading. The state indicates that the load event is about to fire.
@andberry
andberry / berry-in-page-search-with-vue
Last active July 15, 2022 18:00
In page search with Vue.js
# HTML
[...]
<div id="searchapp">
<div class="search" ref="searchEl">
<input id="search__input" type="text" name="search" placeholder="Type for search (min 3 chars)" v-model="searchString">
<transition name="fade">
<div v-if="searchResults.length > 0 && searchResultsVisible === true" class="search__results">
<ul>
<li v-for="(doc, k) in searchResults" :key="k">