Skip to content

Instantly share code, notes, and snippets.

View dfadler's full-sized avatar

Dustin Fadler dfadler

View GitHub Profile
@dfadler
dfadler / input-reset.js
Created December 7, 2011 16:51
Saves default text input value, removes on click, and resets if the user does not enter a string
$('input[type=text]').each(function(i){
var defaultValue = new Array();
defaultValue[i] = $(this).val();
$(this).click(function(){
if($(this).val() == defaultValue[i]){
$(this).val('');
}
});
@dfadler
dfadler / ie7-before-after.js
Created February 15, 2012 17:07
Before and after for IE7
// Appends a div to the passed object(s)
function appendToObject(obj) {
if(typeof(obj) === 'object') {
for(var i = 0; i <= obj.length; i ++) {
$(obj[i])
.append('<div class="after">.</div>');
}
@dfadler
dfadler / panel-tracking.js
Created March 8, 2012 21:36
Panel Tracking
jQuery(document).ready(function($){
//vars
var pagePanels = [],
panelsId = [],
panelsOffset = [];
// Stores the links to the panels
$('#navigation div > div.navMenuLeft a, #navigation div > div.navMenuRight a')
.each( function(i) {
@dfadler
dfadler / html-email.haml
Created April 11, 2012 14:42
Haml HTML Email Boilerplate
!!!
%html{ :xmlns => "http://www.w3.org/1999/xhtml" }
%head
:plain
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
%meta{ :name => "viewport", :content => "width=device-width, initial-scale=1.0" }
%title
=stylesheet_link_tag 'site'
%body{ }
@dfadler
dfadler / external-link.js
Created April 12, 2012 18:53
Opens external links in new window
@dfadler
dfadler / column-height.js
Created April 19, 2012 16:05
Set Column Height
function setColumnHeight(obj1, obj2) {
if($(obj1).height() < $(obj2).height()) {
$(obj1)
.css({
'height': $(obj2).height()
});
} else {
$(obj2)
.css({
'height': $(obj1).height()
@dfadler
dfadler / external-link-confirmation.js
Created April 23, 2012 15:41
Confirm external link and open in a new window
@dfadler
dfadler / url-string-validation.php
Last active October 3, 2015 14:58
Http and Https string Validation
<?php
// Checks a url string for http || https if its not there then http is applied
function validate_url_string( $url_string ) {
$pattern = '/^(http:\/\/|https:\/\/)/';
preg_match( $pattern, $url_string, $matches );
$url_string = count( $matches ) > 0 ? $url_string : 'http://'.$url_string;
return $url_string;
@dfadler
dfadler / string-truncation.php
Last active October 4, 2015 03:18
PHP String Truncation
<?php
/**
* Truncates a string to be no more than $numwords. **Will work with html if $strip_html is true**
* @param string $input The string to be truncated
* @param int $numwords The number of words to be returned
* @param string $padding Ellipsis...
* @param boolean $strip_html Should be set to true if html is contained within $input
* @return string The truncated string
*/
@dfadler
dfadler / shuffle.js
Created May 2, 2012 20:13
Javascript Array Shuffle
// Thanks dude http://css-tricks.com/snippets/javascript/shuffle-array/
function shuffle(o) {
for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
return o;
};