Skip to content

Instantly share code, notes, and snippets.

View davidbrooks's full-sized avatar

David Brooks davidbrooks

View GitHub Profile
@davidbrooks
davidbrooks / image_orienter.js
Created August 6, 2011 23:05
Tests to see whether the targeted image is a vertical or horizontal image and adds the appropriate class.
function check_image_orientation(image_to_check){
$(image_to_check).load(function(){
function orient_image() {
var image_width = parseInt(image_to_check.width());
var image_height = parseInt(image_to_check.height());
if (image_height <= image_width) {
$(image_to_check).addClass('horizontal_image');
} else {
@davidbrooks
davidbrooks / mobile_desktop.js
Created February 19, 2014 15:27
Quick mobile/desktop detection
var test_check = parseInt($('footer').css('border-bottom-width'));
if (test_check == '1') {
$('body').addClass('mobile');
} else {
$('body').addClass('not_mobile');
}
@davidbrooks
davidbrooks / module_pattern_boilerplate.js
Created February 20, 2014 14:59
My starting point for a standard JS file. Module pattern + jQuery.
var interaction = (function($, window, undefined) {
// These are some global variables.
var example_a = '';
// This is a standard document ready from jQuery. It allows the script to self-start.
$(document).ready(function(){
interaction.init();
});
return {
init: function(){
// These things happen when the page is loaded
@davidbrooks
davidbrooks / resizer.php
Created July 23, 2014 19:59
A bulk image resizer, in PHP
<?php
$new_width = '640';
$uploadFolder = "images/";
$original_directory = $uploadFolder.'originals/';
// This first loop just moves anything missing over to the originals directory
foreach (glob($uploadFolder."*") as $filename) {
$file = explode($uploadFolder, $filename);
$file = $file[1];
@davidbrooks
davidbrooks / self_replace.js
Created July 31, 2014 17:59
Finds everything with class="replace" and throws it through handlebars against a loaded config file.
function replace() {
var source, template, html;
$.getJSON( "/config.json", function( data ) {
$('.replace').each(function () {
source = $(this).parent().html();
template = Handlebars.compile(source);
html = template(data);
$(this).parent().html(html);
});
});