Skip to content

Instantly share code, notes, and snippets.

@jacobovidal
jacobovidal / ArenguForm-HOC.jsx
Last active February 26, 2020 11:42
Arengu React Component
import React from 'react';
import PropTypes from 'prop-types';
const ARENGU_SDK_LOADED = 'af-init';
/**
* Component to render a form from Arengu
*/
export class ArenguForm extends React.Component {
@jacobovidal
jacobovidal / feed.csv
Last active September 6, 2019 09:28
Landing Page Template + CSV feed
title description hero_image form_id slug
Page title 1 This is a page description 1 https://www.example.com/image1.jpg 123456789 landing-slug-1
Page title 2 This is a page description 2 https://www.example.com/image2.jpg 123456789 landing-slug-2
Page title 3 This is a page description 3 https://www.example.com/image3.jpg 123456789 landing-slug-3
Page title 4 This is a page description 4 https://www.example.com/image4.jpg 123456789 landing-slug-4
Page title 5 This is a page description 5 https://www.example.com/image5.jpg 123456789 landing-slug-5
Page title 6 This is a page description 6 https://www.example.com/image6.jpg 123456789 landing-slug-6
Page title 7 This is a page description 7 https://www.example.com/image7.jpg 123456789 landing-slug-7
Page title 8 This is a page description 8 https://www.example.com/image8.jpg 123456789 landing-slug-8
Page title 9 This is a page description 9 https://www.example.com/image9.jpg 123456789 landing-slug-9
@jacobovidal
jacobovidal / example.html
Last active March 2, 2020 10:30
AMP form example with Arengu
<!doctype html>
<html ⚡>
<head>
<meta charset="utf-8">
<script async src="https://cdn.ampproject.org/v0.js"></script>
<script async custom-element="amp-form" src="https://cdn.ampproject.org/v0/amp-form-0.1.js"></script>
<script async custom-template="amp-mustache" src="https://cdn.ampproject.org/v0/amp-mustache-0.2.js"></script>
@jacobovidal
jacobovidal / isScrollable.js
Created February 7, 2018 09:55
Scroll tracking trigger to check if page height is bigger than the double of your viewport (Useful for Google Tag Manager)
// If using with GTM, anonymize the function name
function isScrollable() {
function getDocumentHeight() {
return Math.max(document.body.scrollHeight, document.body.offsetHeight,
document.documentElement.clientHeight, document.documentElement.scrollHeight, document.documentElement.offsetHeight);
}
function getViewPortHeight() {
return Math.max(document.documentElement.clientHeight, window.innerHeight || 0) * 2;
}
@jacobovidal
jacobovidal / in_viewport.js
Created December 18, 2017 01:36
Check if element is in viewport
// Determine if an element is in the visible viewport
function isInViewport(element) {
var rect = element.getBoundingClientRect();
var html = document.documentElement;
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= (window.innerHeight || html.clientHeight) &&
rect.right <= (window.innerWidth || html.clientWidth)
);
@jacobovidal
jacobovidal / observer-example.js
Created November 9, 2017 15:39
Mutation observer example in JavaScript
if (window.MutationObserver || window.WebKitMutationObserver) {
var observer = new MutationObserver(function (mutations, observer) {
// Do something after node has changed
console.log('#div has changed')
});
// Configuration of the observer
var config = {
subtree: true,
attributes: true
@jacobovidal
jacobovidal / slugify.js
Last active August 30, 2017 09:34
JavaScript slugify
function slugify(text)
{
var accents = 'ÀÁÂÃÄÅàáâãäåÒÓÔÕÕÖØòóôõöøÈÉÊËèéêëðÇçÐÌÍÎÏìíîïÙÚÛÜùúûüÑñŠšŸÿýŽž';
var accentsOut = "AAAAAAaaaaaaOOOOOOOooooooEEEEeeeeeCcDIIIIiiiiUUUUuuuuNnSsYyyZz";
text = text.split('');
var txtLen = text.length;
var i, x;
for (i = 0; i < txtLen; i++) {
if ((x = accents.indexOf(text[i])) != -1) {
text[i] = accentsOut[x];
@jacobovidal
jacobovidal / .htaccess
Created July 27, 2017 15:46
Security headers to .htaccess
<ifModule mod_headers.c>
Header always set X-Content-Type-Options "nosniff"
Header always set X-XSS-Protection "1; mode=block"
Header always set X-Frame-Options "deny"
</IfModule>
@jacobovidal
jacobovidal / scroll-tracking.js
Last active December 30, 2018 07:42
Google Analytics scroll tracking snippet using dataLayer
// https://github.com/felix/gtm-scrolldepth
var startTime = +new Date;
var scrollCache = [];
documentElement = document.documentElement;
function throttle(func, wait) {
var context, args, result;
var timeout = null;
var previous = 0;
var later = function () {
@jacobovidal
jacobovidal / functions.php
Created July 12, 2017 12:19
Disable default tags, emojis and resources in WordPress via functions.php
<?php
/**
* Disable Emojis
*/
remove_action('admin_print_styles', 'print_emoji_styles');
remove_action('wp_head', 'print_emoji_detection_script', 7);
remove_action('admin_print_scripts', 'print_emoji_detection_script');
remove_action('wp_print_styles', 'print_emoji_styles');
remove_filter('wp_mail', 'wp_staticize_emoji_for_email');
remove_filter('the_content_feed', 'wp_staticize_emoji');