Skip to content

Instantly share code, notes, and snippets.

View aklump's full-sized avatar

Aaron Klump aklump

View GitHub Profile
@aklump
aklump / array_set_nested_element
Last active August 29, 2015 14:16
Set a multidimensional array element based on an array of nested keys.
/**
* Set a multidimensional array element based on an array of nested keys.
*
* @code
* $vars = array();
* $string = 'some.string.of.keys';
* $keys = explode('.', $string);
* $value = 'final value';
* array_set_nested_element($vars, $keys, $value);
* @endcode
@aklump
aklump / font-size
Last active October 6, 2015 03:07
Output font-size in rem with px fallback
/**
* Output font-size (and line-height) in rem with px fallback
*
* After declaring a font-size of 100% on the html tag, you should use the
@font_size for all other font-size declarations.
*
* @code
* html {
* font: 100%/1.4 "Times New Roman", Times, Serif normal;
* }
@aklump
aklump / jquery.viewport_class.js
Last active October 6, 2015 07:57
jQuery plugin to apply current viewport to a DOM element and fire a callback function when viewport changes.
This gist has moved: http://www.intheloftstudios.com/packages/jquery/jquery.viewport_class
@aklump
aklump / jquery.loft_labels.js
Last active October 7, 2015 09:58
jQuery plugin to move form labels into the textfield
This has moved to http://www.intheloftstudios.com/packages/jquery/jquery.loft_labels
@aklump
aklump / jquery.fapi_widths.js
Last active October 8, 2015 04:18
jQuery plugin to equalize form element widths
/**
* Form Element Width Equalizer Plugin (Optimized for Drupal FAPI)
*
* Adjusts the widths of child elements to a set pixel dimension.
*
* Makes all text fields and text areas (or other as specified in
* options.elements) equal widths by subracting the css properties of: margin,
* border and padding from each element.
*
* If width is omitted then all elements will have their width matched to $(this)
@aklump
aklump / jquery.running_clock.js
Last active October 10, 2015 22:17
jQuery plugin to append a running clock to an element
This has been moved to http://www.intheloftstudios.com/packages/jquery/jquery.running_clock
@aklump
aklump / jquery.list_search_filter.js
Last active October 14, 2015 00:18
Create a searchable list by textfield jQuery Plugin
/**
* Create a searchable list by textfield jQuery Plugin
*
* @param object $input
* A jQuery object of a textfield to use as the search box
* @param options
* code: the ascii code of the key to use for lookup; when this is pressed
the list will be searched, defaults to 13 for the Return key.
* auto: min length needed before it will autosearch, for large lists
setting this too low results in poor performance. Set this to 0 to turn off
@aklump
aklump / my_theme_has_content.php
Last active October 19, 2015 22:16
A handy function to add to Drupal 7 theme to determine if a renderable arrays contain output.
/**
* Checks one or more render arrays for any visible content.
*
* @param ... array One or more renderable arrays.
*
* @return bool
*/
function my_theme_has_content() {
$build = func_get_args();
@aklump
aklump / jquery.scrolling_anchors.js
Last active October 20, 2015 17:59
jQuery plugin to convert your anchors to scrolling anchors
/**
* Smooth scroll to anchors
*
* Looks first for a dom with id of the href fragment of the link; then it looks
for an dom element by name=fragment
*
* @param function callback
* onClick callback function receives two params jQuery objects: link, target
* @param object options
* - distance: int
@aklump
aklump / higher_jquery_in_theme.php
Created November 14, 2015 16:45
Include a higher version of jQuery in your Drupal 7 theme using hook_js_alter in template.php
/**
* Implements hook_js_alter().
*
* Replace the system-provided jquery with our own higher version for the theme.
*/
function my_theme_js_alter(&$javascript) {
// Go through and replace the jquery that is being provided by the system
// with out own higher version for the theme. We use an array
// here in case the jquery update module is/is not being used.