Skip to content

Instantly share code, notes, and snippets.

View paulhhowells's full-sized avatar

Paul H Howells paulhhowells

  • Shepperton, U.K.
View GitHub Profile
@paulhhowells
paulhhowells / HTML5_stub.html
Last active October 13, 2015 23:57
html5 stub
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="description" content="" />
<meta name="keywords" content="" />
<meta name="author" content="" />
<meta name="HandheldFriendly" content="True" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
@paulhhowells
paulhhowells / tinymce-drupal.css
Last active December 10, 2015 12:38
Tinymce css for drupal tinymce wysiwyg profile. (Uses base64 encoded images, so replace with urls that point to image files if your intended user's browsers are old enough to not support base64). Utilises edeverett’s idea of illustrating to rich text editor users the markup they are creating or editing.
/*
* wysiwyg tinymce css for use in Drupal 7
* with the addition of styles based on a great idea by edeverett http://edeverett.co.uk/
* and diagnostic css from Eric Meyer http://meyerweb.com/eric/tools/css/diagnostics/
*
* requires a modern browser (more recent than IE7 anyway ;-) for the base64 encoded images
*
*/
p,
@paulhhowells
paulhhowells / Per node background colour. Drupal 7.
Last active December 12, 2015 03:48
Set a (whole) page’s background colour on a per node basis. A Drupal 7 theme function that adds a class to the body tag.
/*
* Implements template_preprocess_html
*
* requires:
* the content type to have a List[text] field called 'field_bg_colour'
* using Display Suite the field may be Hidden but not Disabled
*/
function THEMENAME_preprocess_html(&$variables) {
// if a background colour has been set within the node,
@paulhhowells
paulhhowells / Theme Bean Block & Display Suite Combo.php
Last active April 6, 2017 20:36
Enable bean blocks to be themed (using a .tpl file) according to bean-type: i.e. block__bean__BEAN-TYPE.tpl
Enable bean blocks to be themed (using a .tpl file) according to bean-type:
i.e. block__bean__BEAN-TYPE.tpl
Why? Combine a Bean Block with Display Suite and the innards of the block will match the DS layout
used, however the outer wrapping of the block must be themed separately. However if you write a
.tpl that matches the block it will take precedence and the DS layout will be lost. This prevents
using a DS layout for each type of Bean while simultaneously having full control over the Bean
Block’s mark-up.
This solution adds a theme hook suggestion so that .tpl files may be written for each type of Bean.
@paulhhowells
paulhhowells / Render Tabs D7.php
Last active December 12, 2015 05:38
Render Tabs — don’t print them if you don’t need ’em. Drupal 7.
add to template.php:
/*
* Implements template_preprocess_page
*/
function THEMENAME_preprocess_page(&$variables, $hook) {
// create $render_tabs & $show_render_tabs for page.tpl
$render_tabs = render($variables['tabs']);
$variables['render_tabs'] = $render_tabs;
@paulhhowells
paulhhowells / recursively to find the first instance of a key and return its value.php
Last active December 16, 2015 06:09
PHP: search an array recursively to find the first instance of a key and return its value. array_find_first_recursive($needle, $haystack)
/*
* search an array recursively to find
* the first instance of a key and return its value
*
* useful when you do not know the location of a key nested (only once) in a multidimensional array
*
*/
function array_find_first_recursive($needle_key, array $haystack) {
if (array_key_exists($needle_key, $haystack)) {
@paulhhowells
paulhhowells / array_numbered_key_elements.drupal.php
Created April 16, 2013 14:49
array_numbered_key_elements() Many Drupal 7 arrays mix numeric and associate keys, and you often need to separate the numerically keyed children from the associatively keyed arrays. This function returns an array containing only the numbered keys ready to be iterated through.
/*
* returns: an array containing only the numbered keys
*
* notes: array_intersect_key() is faster than array_intersect()
*/
function array_numbered_key_elements($array) {
return array_intersect_key($array, element_children($array));
}
@paulhhowells
paulhhowells / array_key_split.php
Created April 16, 2013 14:55
array_key_split()
/*
* supply an array with integer and string indexes
* and get an associative array divided into #string & #integer
* or if a key_type argument is supplied then get an array with only the keys that match it
*
* arguments:
* $key_type is optional, and may be 'integer' or 'string'
*
* for use by process_tested_class()
*/
@paulhhowells
paulhhowells / register resize callbacks .js
Last active December 16, 2015 11:29
register callback functions that fire on jQuery resize() — use for passing callbacks with arguments, or methods that use 'this' to reference parent object
/*jslint bitwise: true, eqeq: false, sloppy: true, white: true, browser: true, devel: true, indent: 2 */
/*globals phh, jQuery, window, console */
/*
unnecessary if you only need:
$(window).resize(function() {
// do something A
});
$(window).resize(function() {
// do something A
});
@paulhhowells
paulhhowells / namespace with jQuery ready .js
Last active December 16, 2015 11:49
namespace with jQuery on ready
var phh = phh || {};
// jQuery closure
(function ($) {
// ready
$(function () {
if (phh.options) {
$.extend(true, phh.prefs, phh.options);
}