Skip to content

Instantly share code, notes, and snippets.

View FrankFonts's full-sized avatar
🏠
Working from home

Frank Fonts FrankFonts

🏠
Working from home
View GitHub Profile
<ng-container *ngTemplateOutlet="navigation; context: {classes: 'desktop', label: 'desktop'}"></ng-container>
<ng-container *ngTemplateOutlet="navigation; context: {classes: 'mobile', label: 'mobile'}"></ng-container>
<ng-template #navigation let-classes="classes" let-label="label">
<div [ngClass]="classes">
{{ label }}
</div>
</ng-template>
@FrankFonts
FrankFonts / tab-selector.js
Created June 29, 2022 11:13
Tab Selector
"use strict";
window.addEventListener("load", function () {
var tabLinks = document.querySelectorAll(".search-results__tab-link");
var tabs = document.querySelectorAll(".search-results__tab");
tabLinks.forEach(function (element) {
element.addEventListener("click", function (event) {
activateTab(event.target.dataset.tabId);
});
@FrankFonts
FrankFonts / get-property-value.js
Created June 14, 2022 12:06
getPropertyValue in JS
let tabs = document.querySelector('.tab__links');
let tabsPaddingLeft = parseInt(window.getComputedStyle(tabs, null).getPropertyValue('padding-left'));
@FrankFonts
FrankFonts / url-first-parameter-detection.js
Created June 14, 2022 10:42
URL First Parameter Detection
// get the FIRST url parameter
// between the start of query string (? excluded)
// and the first separator (& excluded)
"use strict";
window.onload = () => {
// Optional Chaining and Nullish Coalescing
@FrankFonts
FrankFonts / js-upon-pageload.js
Last active June 9, 2022 07:48
Ways to run .js after page has loaded
// vanilla JS solution
window.onload = function(){
CODE HERE;
};
// vanilla JS solution, equivalent to the code above
window.addEventListener("load", function() {
CODE HERE;
@FrankFonts
FrankFonts / camelise.js
Last active May 28, 2022 11:48
camelise(str) JS function
// The function camelise(str) changes dash-separated words
// like “my-short-string” into camel-cased “myShortString”.
// Removes all dashes, each word after dash becomes uppercased.
function camelize(str) {
return str.split('-').reduce((a, b) => {
return a + b[0].toUpperCase()+b.slice(1);
});
}
@FrankFonts
FrankFonts / css-selectors.scss
Last active June 14, 2022 10:43
CSS Selectors
**.class** .intro
/* Selects all elements with class="intro" */
**.class1.class2** .name1.name2
/* Selects all elements with both name1 and name2 set within its class attribute */
**.class1 .class2** .name1 .name2
/* Selects all elements with name2 that is a descendant of an element with name1 */
**#id** #firstname
@FrankFonts
FrankFonts / window-width-and-height.js
Created May 25, 2022 11:41
Best way to query the REAL window width and height (scrollbars included if there is any)
let width = window.innerWidth
|| document.documentElement.clientWidth
|| document.body.clientWidth;
let height = window.innerHeight
|| document.documentElement.clientHeight
|| document.body.clientHeight;
@FrankFonts
FrankFonts / simple-html-table-blueprint.html
Created May 20, 2022 11:17
Simple HTML Table blueprint
<table>
<!-- We may add a caption to our table -->
<caption>Caption may come here</caption>
<!-- Styling with <col> -->
<colgroup>
<col>
<col>
<col style="background-color: yellow">
</colgroup>
aList = [0, 1, 2, 3]
temp = []
j = len(aList)-1
for i in range(j, -1, -1):
temp.append(aList[i])
aList = temp