Skip to content

Instantly share code, notes, and snippets.

View sampotts's full-sized avatar

Sam Potts sampotts

View GitHub Profile
@sampotts
sampotts / async.js
Created January 18, 2015 00:54
Async SVG sprite/symbol loading
(function(d,p){
var a = new XMLHttpRequest(), b = d.body;
a.open("GET", p, !0);
a.send();
a.onload = function(){
var c = d.createElement("div");
c.style.display = "none";
c.innerHTML = a.responseText;
b.insertBefore(c,b.childNodes[0]);
}
gulp.task("sprite", function () {
return gulp
.src(input)
.pipe(svgmin())
.pipe(svgstore())
.pipe(gulp.dest(output));
});
// ==========================================================================
// SVG sprite loading
// This file should be at the top of the body to avoid a flash
// ==========================================================================
// Loading SVG in with AJAX
// ---------------------------------
(function(url) {
var id = "svg-sprite",
cb = (window.location.host.indexOf("local.") === 0);
<svg role="img" class="icon"><use xlink:href="/path/to/sprite.svg#icon-poop"></svg>
<svg role="img" class="icon"><use xlink:href="#icon-poop"></svg>
@sampotts
sampotts / icons.css
Last active September 19, 2015 13:06
// Base size icon styles
// --------------------------------------------
.icon {
fill: currentColor;
width: 24px;
height: 24px;
vertical-align: -3px;
}
// Icons inside elements
// --------------------------------------------
a svg,
button svg,
label svg {
pointer-events: none;
}
<!doctype html>
<html>
<head>
<title>Redirecting...</title>
<meta http-equiv="refresh" content="0;URL=https://selz.com">
</head>
<body></body>
</html>
(function($) {
'use strict';
var values = {},
settings = [];
// Grab all inputs
$(".generated-form :input").each(function() {
var $input = $(this),
name = $input.attr("name"),
;(function() {
if (!('MutationObserver' in window)) {
return;
}
var observer = new MutationObserver(function(mutations) {  
    console.log('mutation: ' + mutations.length);
    for(var m = 0; m < mutations.length; ++m) {
        for(var n = 0; n < mutations[m].addedNodes.length; ++n) {
            findEmbed(mutations[m].addedNodes[n]);