Skip to content

Instantly share code, notes, and snippets.

View timbielawski's full-sized avatar

Tim Bielawski timbielawski

  • Cherry Blossom
  • Woodstock
View GitHub Profile
@timbielawski
timbielawski / Nextjs-InitProps-HOC.js
Created December 31, 2018 13:13
HOC for nextJs App for separating getInitialProps from page component
import React from "react";
import ErrorPage from 'next/error';
import errorCodeMapper from '../server/error-code-mapper';
const withInitProps = getInitPropsFunc => WrappedComponent => {
return class InitProps extends React.Component {
static async getInitialProps(args) {
try {
return await getInitPropsFunc(args);
} catch (error) {
@timbielawski
timbielawski / youtube-responsive-function.js
Last active December 31, 2018 07:55
Javascript function to find youtube embeds / iframes in an element and make them responsive
adjustYoutubeEmbed = element => {
if (element) {
const iframes = element.getElementsByTagName("iframe");
for (let i in iframes) {
if (iframes[i].src && iframes[i].src.match(/^https:\/\/www\.youtube\.com/)) {
let iframe = iframes[i];
iframe.setAttribute("style", "position: absolute; top: 0; left: 0; width: 100%; height: 100%; border: 0;");
const width = iframe.width;
const height = iframe.height;
let paddingTop = 0;