Skip to content

Instantly share code, notes, and snippets.

View nabrown's full-sized avatar

Nora Brown nabrown

View GitHub Profile
@nabrown
nabrown / App.vue
Created July 27, 2018 22:11
Main file for functional component and render function test app
<template>
<div id="app">
<FigureStandardSFC
src="cat-basking.jpg"
type="post-it"
:tags="['cat','feline','fuzzy','gray']"
@click="alertHello">Cat basking in the sun.</FigureStandardSFC>
<FigureStandardRF
src="red-tailed-hawk.jpg"
@nabrown
nabrown / FigureStandardSFC.vue
Created July 27, 2018 22:16
Standard, single-file component
<template>
<figure :class="type" v-on:click="$emit('click')">
<img :src="src" />
<figcaption v-if="$slots.default">
<span><slot></slot></span>
</figcaption>
<div class="tags" v-if="tags && type != 'framed'">
<span v-for="tag in tags"> {{ tag }}</span>
</div>
</figure>
@nabrown
nabrown / FigureStandardRF.js
Created July 27, 2018 22:31
Standard component using a render function
export default {
props: {
src: {
required: true,
type: String
},
type: {
required: true,
type: String
@nabrown
nabrown / FigureFunctionalRF.js
Created July 27, 2018 22:33
A functional component using a render function
export default {
functional: true,
props: {
src: {
required: true,
type: String
},
type: {
required: true,
type: String
@nabrown
nabrown / FigureFunctionalSFC.vue
Created July 28, 2018 00:34
A functional, single-file component
<template functional>
<figure :class="props.type" v-on:click="listeners.click">
<img :src="props.src" />
<figcaption v-if="slots().default">
<span><slot></slot></span>
</figcaption>
<div class="tags" v-if="props.tags && props.type != 'framed'">
<span v-for="tag in props.tags"> {{ tag }}</span>
</div>
</figure>
@nabrown
nabrown / MutationObserver-childList.js
Last active September 12, 2018 13:34
Using a mutation observer to watch for added child nodes
(function() {
// Select the node to observe
var targetNode = document.querySelector('#sqs-cart-root');
// If the targetNode exists on our page
if(targetNode){
// Watch when nodes are added to targetNode, or its descendants
var config = {
@nabrown
nabrown / MutationObserver-attributes.js
Created September 12, 2018 13:35
Using a mutation observer to watch for attribute changes
(function() {
// Select the node to observe
var targetNode = document.querySelector('.sqs-add-to-cart-button');
// The class we'll watch for
var className = 'cart-added';
// If the targetNode exists on our page
if(targetNode){
@nabrown
nabrown / unveil-func-jquery.js
Last active November 30, 2018 16:57
Unveil() function from jQuery.unveil.js
function unveil() {
// create an array of images that are in view
// by filtering the intial array
var inview = images.filter(function() {
var $img = $(this);
// if the image is hidden, don't bother
if ($img.is(":hidden")) return;
var wt = $w.scrollTop(), // window vertical scroll distance
wb = wt + $w.height(), // last point of document visible in browser window
@nabrown
nabrown / unveil-func-vanilla.js
Last active November 30, 2018 17:47
Unveil() function rewritten without jQuery
function unveil() {
// create an array of images that are in view
// by filtering the intial array
var inview = images.filter(function(img) {
// if the image is set to display: none
if (img.style.display === "none") return;
var rect = img.getBoundingClientRect(),
wt = window.scrollY, // window vertical scroll distance
wb = wt + w.innerHeight, // last point of document visible in browser window
@nabrown
nabrown / jquery.unveil.js
Last active November 30, 2018 18:09
Complete jQuery Unveil plugin
/**
* jQuery Unveil
* A very lightweight jQuery plugin to lazy load images
* http://luis-almeida.github.com/unveil
*
* Licensed under the MIT license.
* Copyright 2013 Luís Almeida
* https://github.com/luis-almeida
*
* Updated by Nora Brown to include `srcset`