Skip to content

Instantly share code, notes, and snippets.

View MarcusJT's full-sized avatar

Marcus MarcusJT

View GitHub Profile
@adactio
adactio / _polyfills.js
Created November 9, 2020 17:19
JavaScript polyfills for matches,closest, and forEach.
// https://github.com/jonathantneal/closest/blob/master/src/index.js
var ElementPrototype = window.Element.prototype;
if (typeof ElementPrototype.matches !== 'function') {
ElementPrototype.matches = ElementPrototype.msMatchesSelector || ElementPrototype.mozMatchesSelector || ElementPrototype.webkitMatchesSelector || function matches(selector) {
var element = this;
var elements = (element.document || element.ownerDocument).querySelectorAll(selector);
var index = 0;
while (elements[index] && elements[index] !== element) {
++index;
}
@davatron5000
davatron5000 / the-state-of-element-container-queries.md
Last active August 23, 2023 15:43
The State of Element/Container Queries

The State of Container Queries

tl;dr Developers would like the idea to style components based on a parent's width rather than depend solely on the viewport media query. This would allow modular components to style themselves while being agnostic to the viewport.

There is currently a lot of developer interest in getting a feature like Container Queries (née "Element Queryies") shipped in a browser.

2-min Catchup

Here are official'ish documents to outline the developer community's desires.

@ebidel
ebidel / imports_timing.js
Last active March 24, 2016 19:21
HTML Imports Resource Timing performance
// Know how fast your HTML Imports are.
// crbug.com/505279 - doesn't show sub-import resources.
var imports = document.querySelectorAll('link[rel="import"]');
[].forEach.call(imports, function(link) {
var entries = performance.getEntriesByName(link.href);
console.info('=== HTML Imports perf ===');
entries.forEach(function(e) {
console.log(e.name, 'took', e.duration, 'ms');
});
});
@ebidel
ebidel / app.html
Last active May 1, 2021 15:42
Fast Polymer app loading - optimized for first render, progressively enhanced lazy loading
<!DOCTYPE html>
<html>
<head>
<style>
body.loading #splash {
opacity: 1;
}
#splash {
position: absolute;
top: 0;
@paulirish
paulirish / readme.md
Last active April 2, 2024 20:18
resolving the proper location and line number through a console.log wrapper

console.log wrap resolving for your wrapped console logs

I've heard this before:

What I really get frustrated by is that I cannot wrap console.* and preserve line numbers

We enabled this in Chrome DevTools via blackboxing a bit ago.

If you blackbox the script file the contains the console log wrapper, the script location shown in the console will be corrected to the original source file and line number. Click, and the full source is looking longingly into your eyes.

var webviewProvider = (function() {
if (/\/FBIOS/i.test(navigator.userAgent) === true) {
return 'facebook';
}
if (/Twitter for/i.test(navigator.userAgent) === true) {
return 'twitter';
}
if (/Pinterest\//.test(navigator.userAgent) === true) {
return 'pinterest';
}
@ningsuhen
ningsuhen / Regex.swift
Last active April 27, 2019 18:39
Swift extension for Native String class to support Regex match and Regex replace. Credit - http://www.swift-studies.com/blog/2014/6/12/regex-matching-and-template-replacement-operators-in-swift
import Foundation
struct Regex {
var pattern: String {
didSet {
updateRegex()
}
}
var expressionOptions: NSRegularExpressionOptions {
didSet {
@tedw
tedw / fancy-underline.scss
Last active January 2, 2020 20:59
Fancy Link Underlines ala Medium.com – https://medium.com/designing-medium/7c03a9274f9
// Requires Bourbon
@import "bourbon/bourbon";
// Use CSS gradient and text shadow to create line that breaks for descenders
// Inspired by https://medium.com/designing-medium/7c03a9274f9
@mixin fancyUnderline( $color: currentColor, $bgcolor: #fff ) {
@include background-image( linear-gradient( to bottom, $bgcolor 50%, $color 50% ) );
background-position: 0 89%;
background-repeat: repeat-x;
background-size: 1px 1px;
@JeffJacobson
JeffJacobson / google-analytics-honor-doNotTrack.js
Last active October 26, 2018 21:11
Google Analytics setup respecting navigator.doNotTrack.
// Setup Google Analytics, but not if user has specified that they don't want to be tracked.
(function (dnt, cookieDomain) {
var scriptTag, hostRe = new RegExp(cookieDomain.replace(".", "\\.") + "$");
if (dnt !== "yes" && dnt !== "1") {
window.ga = window.ga || function () { (ga.q = ga.q || []).push(arguments) }; ga.l = +new Date;
ga('create', 'YOUR-ID-HERE', hostRe.test(location.host) ? cookieDomain : "auto");
ga(function (tracker) {
tracker.set("appName", "Your app name here");
tracker.send('pageview');
});
@HoundstoothSTL
HoundstoothSTL / anchor-scroll-with-offset.js
Created May 3, 2013 15:43
Anchor scroll with fixed header offset
(function($) {
$('a[href*=#]:not([href=#])').click(function()
{
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
|| location.hostname == this.hostname)
{
var target = $(this.hash),
headerHeight = $(".primary-header").height() + 5; // Get fixed header height