Skip to content

Instantly share code, notes, and snippets.

View ethanhinson's full-sized avatar

Ethan Hinson ethanhinson

View GitHub Profile
@ethanhinson
ethanhinson / resize-gmaps.js
Created August 29, 2013 23:47
Resizing GoogleMaps inside of a div which is hidden
/**
* This example will work with foundation 4 sections. However, the idea is the same for any collapsed map.
* Load a map object
* Find it's parent (which is hidden)
* Bind a click event to the element which 'unhides' your container
* */
(function($) {
Drupal.behaviors.foundationCollapseHack = {
attach: function(context, settings) {
// check whether we have a map
@ethanhinson
ethanhinson / x-domain.js
Created August 30, 2013 23:03
Easy cross domain tracking with jQuery
Drupal.behaviors.crossDomainTracking = {
attach: function(context, settings) {
//Catch all outgoing links for a specific domain
$('a[href*="mydomain.com"]').click(function() {
_gaq.push(['_link', this.href]);
return false;
});
// Add onSubmit _linkByPost to all <form> elements for a specific domain
$('form[action*="mydomain.com"]').attr('onSubmit','_gaq.push(["_linkByPost", this])');
}
@ethanhinson
ethanhinson / autosize-f4.js
Created September 5, 2013 06:01
Autosize the Foundation 4 section tab titles
// Make sure that other JS has finished it's stuff
$(window).load(function() {
// Existence check for elements as well as whether we are in mobile or not
if($('.MY-CSS-SELECTOR .section-container .section p.title').length > 0 && $(window).width() > 480) {
// Simple math to determine the percentage width of each title
var c = $('.MY-CSS-SELECTOR .section-container .section p.title').length;
var w = Math.floor(100 / c);
// Iterate over DOM elements and get the index so we can set an offset
$('.MY-CSS-SELECTOR .section-container .section p.title').each(function() {
// The left position will be the index of the element in relation to the tab container TIMES the width
@ethanhinson
ethanhinson / responsive-button.scss
Last active December 27, 2015 15:09
mixin for a sweet mobile button
//--------------------------------------------Button mixins------------------------------------------------//
// We need to define a new button-base because there are some font settings like line height we don't always want
// This is because of variable type faces and font-sizes
@mixin responsive-button-base() {
border-style:$button-border-style;
border-width:$button-border-width;
}
<?php
if ( ! class_exists( 'Autoload_WP' ) ) {
/**
* Generic autoloader for classes named in WordPress coding style.
*/
class Autoload_WP {
public $dir = __DIR__;
@ethanhinson
ethanhinson / sortable-columns.php
Created November 11, 2013 20:00
Add a custom sortable column to a WordPress custom post type admin list.
<?php
/**
*
* Custom sortable columns on property admin list
*
*/
function property_id_column_register( $columns ) {
// Insert property ID in between date/title
@ethanhinson
ethanhinson / oop-settings.php
Created November 11, 2013 23:05
OOP approach to building settings screens
<?php
/**
*
* Class for our options
*
*
* @TODO: Make this into separate pages instead of sections
* @TODO: ->theme single field templates maybe? But Def a better way for blocks of HTML
<?php
/**
* Revert specified features.
*
* @TODO Check that it really is Forced features revert. Currently an exact
* copy of the function initially placed in feature_projects.install.
*
* Code mostly taken from drush.
*/
@ethanhinson
ethanhinson / config.rb
Created November 18, 2013 02:11
IE 9 and below doesn't support more than 4095 individual selectors. SCSS can blow through this pretty easily. To get around it. We can implement a simple class in our config.rb file and implement a save hook to write the additional styles. These should be included with an IE conditional.
# Requre a specific version in this file:
# gem 'zurb-foundation', '=4.3.1'
require 'zurb-foundation'
# Require any additional compass plugins here.
# IE 9 and below only support up to 4095 CSS selectors
# This class will split all selectors after that point
class CssSplitter
def self.split(infile, outdir = File.dirname(infile), max_selectors = 4095)
@ethanhinson
ethanhinson / attach-js.php
Created December 6, 2013 22:50
Attaching JS to every page's footer in with WordPress best practices.
<?php
/**
* All code should live in functions.php of the active theme
*/
function attach_js() { ?>
<script type="text/javascript">
document.write('ALL MY JS CAN GO IN BETWEEN THESE SCRIPT TAGS'); //Test script only, not required
</script>
<?php }