Skip to content

Instantly share code, notes, and snippets.

View johnny5th's full-sized avatar

Johnny Martin johnny5th

View GitHub Profile
@johnny5th
johnny5th / template.php
Created April 23, 2012 20:02
Drupal Strip Image Width/Height
function mayfield_preprocess_image(&$variables) {
unset ($variables['width'], $variables['height'], $variables['attributes']['width'],$variables['attributes']['height']);
}
<nav>
<ul>
<?php foreach ($items as $delta => $item): ?>
<li><?php print render($item); ?></li>
<?php endforeach; ?>
</ul>
</nav>
@johnny5th
johnny5th / IEMQConv.rb
Created May 16, 2012 16:18
IE Media Query Converter
#!/usr/bin/ruby
# IE Media Query Converter
# Usage: IEMQConv.rb filein fileout
#
# Grabs all media query content in a CSS file and outputs a file
# containing all of the CSS without the media query tags.
# Useful for giving <=IE8 all of the site styles without
# media query support.
@johnny5th
johnny5th / mongoaddybook.php
Created June 4, 2012 22:50
Mongo Test - Address Book
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
// connect
$m = new Mongo();
// select a database
$db = $m->mongotest;
@johnny5th
johnny5th / FormProc.class.php
Created July 2, 2012 16:41
Simple Form Processor Class - uses php mail() function
<?php
/* PHP FORM PROCESSOR
* A simple form processor with basic validation
* Sends with local mail() protocol
*/
class FormProc{
/* ATTRIBUTES */
@johnny5th
johnny5th / superfishSubNavShowHide
Created January 9, 2013 20:36
Functions to remove the sub nav out of a superfish menu on mobile screen widths to disable the onhover tap on iOS.
function hideSubNav(menu) {
if($(menu).attr('data-sub-removed') == 1)
return false;
var hiddennav = $(menu).parent().children('.removednav').eq(0);
if(hiddennav.length == 0)
var hiddennav = $('<div class="removednav" style="display: none">').appendTo($(menu).parent());
$(menu).find('.menuparent').each(function(){
@johnny5th
johnny5th / moveElement.js
Created January 10, 2013 23:33
A function to append an element to a container, but first check if it is already there.
function moveElement(elem, container) {
var elemobj = $(elem);
var containerobj = $(container);
if(!elemobj.parent().is(container)) // Check if already there
elemobj.appendTo(container);
}
@johnny5th
johnny5th / drupalSubNav.php
Last active December 11, 2015 03:59
Add a subnav to a Drupal theme from the secondary menu and include a "back" button if the active trail is in the sub nav.
<?php
function TEMPLATE_preprocess_page(&$variables, $hook) {
$variables['secondary_menu'] = menu_secondary_menu();
$activesub = false;
foreach($variables['secondary_menu'] as $item) {
if(isset($item['attributes']['class']))
foreach($item['attributes']['class'] as $class)
if($class == "active-trail")
$activesub = true;
@johnny5th
johnny5th / accordion.js
Last active December 12, 2015 00:48
Jquery for a simple accordion function for content
$('.accordion .item').addClass('closed').click(function(){
if($(this).hasClass('closed')) {
$(this).removeClass('closed').addClass('open').children('.content').show('fast');
$(this).parent().children().not($(this)).removeClass('open').addClass('closed').children('.content').hide('fast');
} else {
$(this).removeClass('open').addClass('closed').children('.content').hide('fast');
}
});
@johnny5th
johnny5th / drupal_click-to-open-nav_fast-click.js
Created April 16, 2013 15:43
Click to open nav menu for mobile screens based on drupal. Includes jquery.animate-enhanced and FastClick
/**
* @file
* A JavaScript file for the theme.
*
* In order for this JavaScript to be loaded on pages, see the instructions in
* the README.txt next to this file.
*/
// JavaScript should be made compatible with libraries other than jQuery by
// wrapping it with an "anonymous closure". See: