Skip to content

Instantly share code, notes, and snippets.

@mapsam
mapsam / geojson.js
Last active January 12, 2019 01:10
javascript geojson creation loop
var geojson = {};
geojson['type'] = 'FeatureCollection';
geojson['features'] = [];
for (var k in data) {
var newFeature = {
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [parseFloat(data[k].lng), parseFloat(data[k].lon)]
@mapsam
mapsam / site.js
Created May 9, 2014 17:46
jquery open/close toggle stuff
$(document).ready(function($){
$('#open').click(function(){
$('#element').toggle(300).addClass('active');
});
$('#close').click(function(){
if($('#element').hasClass('active')) {
$('#element').toggle(300).removeClass('active');
}
});
});
@mapsam
mapsam / scroll.js
Last active August 29, 2015 14:01
scroll on anchor tag click within page
var height = $('header').height(); // element to offset scroll with (i.e. your navbar if it is fixed)
$('a[href*=#]').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
&& location.hostname == this.hostname) {
var $target = $(this.hash);
$target = $target.length && $target
|| $('[name=' + this.hash.slice(1) +']');
if ($target.length) {
var targetOffset = ($target.offset().top)-height; //offset from top based on element - this isn't required
$('html,body')
@mapsam
mapsam / jsonp.js
Created May 28, 2014 20:51
jQuery ajax with jsonp to census.gov
$.ajax({
type: "GET",
dataType: "jsonp",
contentType: "application/json",
url: 'http://geocoding.geo.census.gov/geocoder/locations/onelineaddress?address=131+Riverlawn+Ave%2C+Watertown%2C+53094&benchmark=9&format=jsonp',
success: function(data) {
console.log(data)
},
error: function(xhr, ajaxOptions, thrownError) {
console.log(xhr.status, thrownError);
@mapsam
mapsam / loop.php
Last active August 29, 2015 14:04
wordpress custom taxonomy list of terms and posts
<?php
// using a specified custom taxonomy slug
// find all taxonomy terms (categories) and
// the associated posts
$tax = 'TAXONOMY-SLUG';
echo '<ul>';
$terms = get_terms($tax);
foreach($terms as $term) {
echo '<li>'.$term->name;
@mapsam
mapsam / getID.php
Last active August 29, 2015 14:06
YouTube shortcode embed
<?php // get youtube ID function
function get_youtube_id($url) {
$query_string = array();
parse_str(parse_url($url, PHP_URL_QUERY), $query_string);
$id = $query_string["v"];
return $id;
}
@mapsam
mapsam / parallax.css
Created September 19, 2014 17:27
simple parallax
#parallax-wrap {
height: 400px; /* anything you want/need */
width: 100%;
position: relative;
display: block;
}
.parallax {
position:absolute;
width:100%;
height:100%;
@mapsam
mapsam / menu.js
Created September 24, 2014 20:33
menu toggling & resizing screen precautions
var nav = $('#nav'),
menu = $('#nav .menu'),
navButton = $('.nav-expand');
// mobile button dropdown
$('button.nav-expand').on('click', function(){
menu.slideToggle(200);
navButton.toggleClass('open');
});
var blocked = false,
threshold = 705;
@mapsam
mapsam / commas.js
Last active August 29, 2015 14:08
commas
function addCommas(n) {
var str = n.toString(),
len = str.length,
num = str.slice(0, len%3);
for(i=0;i<Math.floor(len/3);i++) {
num = num + ',' + str.substr(len%3+(3*i), 3);
}
if(num.slice(0,1)===',') {
@mapsam
mapsam / ajax.js
Created November 18, 2014 21:12
wordpress return post data on click
jQuery(document).ready(function($) {
$('.post').on('click', function(){
getPostInfo($(this).attr('data-postid'));
});
});
function getPostInfo(id) {
jQuery.ajax({
url: ajaxurl,
dataType: 'json',