Skip to content

Instantly share code, notes, and snippets.

View aklump's full-sized avatar

Aaron Klump aklump

View GitHub Profile
@aklump
aklump / jquery.swiper.js
Last active December 14, 2015 17:59
jQuery plugin for a fancy left/right slider for prev/next type browsing
/**
* Swiper jQuery Plugin
*
* You need to also include:
http://www.netcu.de/jquery-touchwipe-iphone-ipad-library
*
* @code
* <script>
* $('.track').swiper({
* 'trainClass': 'train',
@aklump
aklump / jquery.iframe_to_div.js
Last active May 30, 2019 16:55
A jQuery plugin to replace iframes with divs containing their source by loading via ajax. Benefits use parent page's css and have an auto height to your iframe.
/**
* Convert iframes to divs via ajax iframe_to_div jQuery Plugin
*
* Uses javascript to replace iframes with divs containing their source content
* by loading via ajax. If you use this to load vanilla html snippets, this has the
* effect of applying the page's css to your vanilla html snippet.
*
* This will not work if the iframe src is not a relative link due to ajax restrictions across domains.
*
* As an example:
@aklump
aklump / jquery.resume_playback.js
Last active December 21, 2015 04:49
Remembers the playback position of media and resumes on page load. The playhead position is set on the media events: play, pause, and seeked; as well the position is recorded at an interval defined in the options, anytime the media is playing.
/**
* HTML5 Media Resume Playback (Playhead Position Memory) jQuery Plugin
*
* Remembers the playback position of media and resumes on page load. The
* playhead position is set on the media events: play, pause, and seeked; as
* well the position is recorded at an interval defined in the options, anytime
* the media is playing.
*
* Requires the jStorage plugin <http://www.jstorage.info/>
*
@aklump
aklump / jquery.multi_fadein.js
Last active December 25, 2015 23:29
A jQuery Plugin to fade in multiple DOM elements in step-wise succession.
/**
* A jQuery Plugin to fade in multiple DOM elements in step-wise succession.
*
* @param bool|object options
* A boolean value will be interpreted as {start: [value]}.
* An object with these properties:
* - speed int How fast to reveal the step in seconds. Each element may also
control it's individual speed with the attribute data-speed.
* - delay int Defaults to 0. How many seconds between the end of one step and
the start of the next. You may also use data-delay for element specific
@aklump
aklump / element_properties_to_children
Last active December 28, 2015 03:09
PHP: Convert a renderable Drupal array's properties to children.
/**
* Convert all element properties to children
*
* @param array $array An array with one or more keys that begine with '#' .
*
* @return array Any key that began with '#' will have the # stripped.
*/
function element_properties_to_children($array) {
$keys = array_map(create_function('$item', 'return substr($item, 1);'), array_keys($array));
@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 / drupal7-field-node-access.php
Last active January 19, 2018 23:36
Drupal 7 node access per entity using a field dropdown, callback functions and the node access API.
<?php
/**
* Shows how to create a field that controls node access in Drupal 7 based
* on callback functions using the node access API and a field select list;
* so that content managers can easily control per-entity access control
* using a simply dropdown.
*
* 1. Create a custom module and insert the following 3 functions.
* 2. Create a List(text) field called field_access with widget select and
* attach it to the entity where you want to control access.
@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 / 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.
@aklump
aklump / HOOK_is_dark_image.php
Last active January 19, 2018 23:30
Drupal 7 snippet to determine if an image is mostly dark.
<?php
/**
* Determine if an image is mostly dark.
*
* @param string $uri The uri of the image file.
* @param array $options
* - resolution int The larger the number the more measurements will be taken
* and the longer it will take. Defaults to 10.
* - threshold int The luminance threshold. 170 is equal to #acacac.
* @param array $info Pass an array to be filled with data used to calculate