Skip to content

Instantly share code, notes, and snippets.

View chrisblakley's full-sized avatar
⚔️
Take that, entropy!

Chris Blakley chrisblakley

⚔️
Take that, entropy!
View GitHub Profile
@chrisblakley
chrisblakley / performance-timing.js
Created October 12, 2014 17:54
Show load times for pages in the browser console.
window.onload = function(){
setTimeout(function(){
if ( document.getElementsByTagName("html")[0].className.indexOf('lte-ie8') > -1 ) {
return;
}
var pageSpeed = [];
var values = [];
var colors = [];
@chrisblakley
chrisblakley / mmenu-back-close.js
Last active August 29, 2015 14:07
Close a mmenu using the back button with the History API and popstate
jQuery("#mmenu").mmenu({
/* Options Here */
}, {
/* Configuration Here */
}).on('opened.mm', function(){
history.replaceState(null, document.title, location);
history.pushState(null, document.title, location);
});
//Close mmenu on back button click
@chrisblakley
chrisblakley / wp-google-map-shortcode.php
Last active August 29, 2015 14:07
Allow for embedding Google Maps into your Wordpress posts
add_shortcode('map', 'map_shortcode');
function map_shortcode($atts){
extract( shortcode_atts(array("key" => '', "mode" => 'place', "q" => '', "center" => '', "origin" => '', "destination" => '', "waypoints" => '', "avoid" => '', "zoom" => '', "maptype" => 'roadmap', "language" => '', "region" => '', "width" => '100%', "height" => '250', "class" => '', "style" => ''), $atts) );
if ( $key == '' ) {
$key = ''; //@TODO: Replace with your own key to avoid designating a key every time.
}
if ( $q != '' ) {
$q = str_replace(' ', '+', $q);
$q = '&q=' . $q;
}
@chrisblakley
chrisblakley / wp-gumby-shortcodes.php
Last active August 29, 2015 14:07
Embed a Gumby grid into the Wordpress WYSIWYG editor
/*==========================
Gumby Framework Shortcodes
By Chris Blakley
gearside.com
Documentation: http://gearside.com/wordpress-shortcodes-gumby-framework/
===========================*/
@chrisblakley
chrisblakley / nebula_the_excerpt.php
Last active August 29, 2015 14:07
A smarter Wordpress excerpt.
//Use this instead of the_excerpt(); and get_the_excerpt(); so we can have better control over the excerpt.
//Several ways to implement this:
//Inside the loop (or outside the loop for current post/page): nebula_the_excerpt('Read more »', 20, 1);
//Outside the loop: nebula_the_excerpt(572, 'Read more »', 20, 1);
function nebula_the_excerpt( $postID=0, $more=0, $length=55, $hellip=0 ) {
if ( $postID && is_int($postID) ) {
$the_post = get_post($postID);
} else {
if ( $postID != 0 || is_string($postID) ) {
if ( $length == 0 || $length == 1 ) {
@chrisblakley
chrisblakley / ga-copy-tracking.js
Last active August 29, 2015 14:07
Detect copied text using Google Analytics
jQuery(document).on('cut copy', function(){
var currentPage = jQuery(document).attr('title');
var words = [];
var selection = window.getSelection() + '';
words = selection.split(' ');
wordsLength = words.length;
if (words.length > 8) {
words = words.slice(0, 8).join(' ');
ga('send', 'event', 'Copied Text', currentPage, words + '... [' + wordsLength + ' words]');
@chrisblakley
chrisblakley / detect-social-logged-in-users.html
Last active August 29, 2015 14:07
Tracking Social Media Events and Logged-In Users in Google Analytics
<!-- Google -->
<img style="display: none;" onLoad="google_user(true)" alt="" src="https://accounts.google.com/CheckCookie?continue=https%3A%2F%2Fwww.google.com%2Fintl%2Fen%2Fimages%2Flogos%2Faccounts_logo.png&amp;followup=https%3A%2F%2Fwww.google.com%2Fintl%2Fen%2Fimages%2Flogos%2Faccounts_logo.png&amp;chtml=LoginDoneHtml&amp;checkedDomains=youtube&amp;checkConnection=youtube%3A291%3A1" />
<!-- Google Plus (Note: May want to place this within a "is not mobile" check) -->
<img style="display: none;" onLoad="google_plus_user(true)" alt="" src="https://plus.google.com/up/?continue=https://www.google.com/intl/en/images/logos/accounts_logo.png&amp;type=st&amp;gpsrc=ogpy0" />
<!-- Twitter -->
<img style="display: none;" onLoad="twitter_user(true)" alt="" src="https://twitter.com/login?redirect_after_login=%2Fimages%2Fspinner.gif" />
<script>
@chrisblakley
chrisblakley / ie-compat-mode-detection.css
Last active August 29, 2015 14:07
Detect Internet Explorer compatibility modes with css_browser_selector.js and modernizr.js
.ie8.no-hashchange.no-rgba-no.applicationcache.no-pointerevents div.iemode {} /* IE8 w/ IE7 Standards */
.ie9.hashchange.no-rgba.no-applicationcache.no-pointerevents div.iemode {} /* IE9 w/ IE8 Standards */
.ie9.no-hashchange.no-rgba.no-applicationcache.no-pointerevents div.iemode {} /* IE9 w/ IE7 Standards */
.ie10.hashchange.rgba.no-applicationcache.no-pointerevents div.iemode {} /* IE10 w/ IE9 Standards */
.ie10.hashchange.no-rgba.no-applicationcache.no-pointerevents div.iemode {} /* IE10 w/ IE8 Standards */
.ie10.no-hashchange.no-rgba.no-applicationcache.no-pointerevents div.iemode {} /* IE10 w/ IE7 Standards */
.ie7.hashchange.rgba.applicationcache.no-pointerevents div.iemode {} /* IE10 Compatibility w/ IE10 Standards */
.ie7.hashchange.rgba.no-applicationcache.no-pointerevents div.iemode {} /* IE10 Compatibility w/ IE9 Standards */
@chrisblakley
chrisblakley / social-sharing.js
Created October 16, 2014 01:27
Share the current page to social sites and email without third-party plugins like Share This.
var loc = window.location;
var title = jQuery(document).attr('title');
var thumb = 'http://gearsidecreative.com/img/fb-thumb1.jpg';
var encloc = encodeURI(loc);
var enctitle = encodeURI(title);
$('.share-facebook').attr('href', 'http://www.facebook.com/sharer.php?u=' + encloc + '&amp;t=' + enctitle).attr('target', '_blank');
$('.share-twitter').attr('href', 'https://twitter.com/intent/tweet?text=' + enctitle + '&amp;url=' + encloc).attr('target', '_blank');
$('.share-linkedin').attr('href', 'http://www.linkedin.com/shareArticle?mini=true&amp;url=' + encloc + '&amp;title=' + enctitle).attr('target', '_blank');
$('.share-googleplus').attr('href', 'https://plus.google.com/share?url=' + encloc).attr('target', '_blank');
@chrisblakley
chrisblakley / step2.php
Created October 16, 2014 02:29
Querying current weather conditions to make it rain or snow on your site.
<div id="bgimgweather">
<?php
$url = 'http://w1.weather.gov/xml/current_obs/KSYR.xml';
$xml = simplexml_load_file($url);
$currentweather = $xml->weather;
//$currentweather = "Light Rain";
?>
</div>