Skip to content

Instantly share code, notes, and snippets.

@shaunwallace
shaunwallace / gist:10d9364c3cd3fae5863e
Last active August 29, 2015 14:09
Activating Web Component Template
// prep
var d = document.createElement('template');
d.id = 'myOcotcat';
d.innerHTML = '<img src="" alt="my awesome octocat" width="200" height="200"/>';
document.body.appendChild(d);
// query the DOM for the specified template
var t = document.querySelector('#myOcotcat');
@shaunwallace
shaunwallace / merge sorted arrays
Created January 3, 2014 19:37
Take 2 sorted arrays and merge them into 1 sorted array
function sort( a1, a2 ) {
var i = 0
, j = 0
, l1 = a1.length
, l2 = a2.length
, a = [];
while( i < l1 && j < l2 ) {
@shaunwallace
shaunwallace / Adding up element's widths
Last active December 31, 2015 18:09
Computing the total width of all children elements inside of a given parent
//with jQuery
var parent = $(selector)
, totalWidthOfChildren = Array.prototype.reduce.call(parent.children(), function(a,b){ return a + $(b).outerWidth( true ); }, 0);
//without jquery
var parent = document.getElementById('selector')
, totalWidthOfChildren = Array.prototype.reduce.call(parent.children, function(a,b){ return a + outerWidth(b); }, 0);
function outerWidth( elem ) {
@shaunwallace
shaunwallace / document width tracker
Created May 17, 2013 07:31
Simple script to show the current document's width when developing responsive based sites
(function() {
var d = document.createElement('div')
, width = window.document.documentElement[ 'clientWidth' ];
d.id = 'documentWidth';
d.className = 'active';
d.innerHTML = '<p>' + width + '</p';
d.style.position = 'fixed';
d.style.top = '0';
function hideElement( elem, target ) {
//wrap as jquery object if it isnt one
elem = elem instanceof jQuery ? elem : $( elem );
//if there is a target and that target is a function then run that function
//and return the elem to hide otherwise simply hide the element
target ? typeof( target ) === 'function' ? ( target(elem) ).hide() : elem.find( target ).hide() : elem.hide();
}
@shaunwallace
shaunwallace / gist:5286704
Created April 1, 2013 18:28
place info search google places api
getPlaceInfo : function( options ) {
//console.log( options );
var request = {
location : new google.maps.LatLng( options.locations.lat, options.locations.lng )
}
, service = new google.maps.places.PlacesService( options.map )
, places = [];