Skip to content

Instantly share code, notes, and snippets.

View mattfarina's full-sized avatar
┻━┻ ︵ヽ(`Д´)ノ︵ ┻━┻

Matt Farina mattfarina

┻━┻ ︵ヽ(`Д´)ノ︵ ┻━┻
View GitHub Profile
(function($) {
//
// Automatically calls all functions in APP.init
//
jQuery(document).ready(function() {
APP.go();
});
//
// Module pattern:
/**
* Helper function; removes all required element flags on a section of a form.
*
* @param array $element
* A form or section of a form.
*
* @return array
* A section of a form tree with #required = 0 everyehere.
*/
function example_remove_required($element) {
function checkPlain(str) {
var length,
r = new RegExp('(&)|(\")|(<)|(>)|([^&\"<>]*)', 'g')
replacements = ["&amp;", "&quot;", "&lt;", "&gt;"],
retval = '',
match = r.exec(str);
while (match[0] != "") {
length = match.length;
for (var i = 1; i < length; ++i) {
if (match[i] != undefined) {
@mattfarina
mattfarina / gist:751854
Created December 22, 2010 18:08
Make Drupal 7 search button an image button.
/**
* Implements hook_form_alter().
*
* Courtesy of JohnAlbin
*/
function THEMENAME_form_search_block_form_alter(&$form, &$form_state) {
$form['actions']['submit']['#type'] = 'image_button';
$form['actions']['submit']['#src'] = drupal_get_path('theme', 'THEMENAME') . '/images/button-search.png';
}
@mattfarina
mattfarina / gist:756870
Created December 28, 2010 03:28
Drupal / jQuery html5 placeholder support for browsers without native support
// Here we use a similar set of variables passed in as jQuery. The lone difference is
// the inclusion of the Drupal variable. We pass in the global variables we use which
// provides proper dependency injection and for compressors to have names that can be
// more easily shrunk.
(function($, Drupal, window, document, undefined) {
Drupal.sitetheme = Drupal.sitetheme || {};
/*
* Initialize placeholder functionality on a text based input element.
$.support.positionFixed = (function () {
var el, support,
body = document.body || document.getElementsByTagName("body")[0] || document.documentElement;
// Boolean indicating whether or not "position: fixed" is supported.
// Using the DOM to create an element is much faster than using jQuery.
el = document.createElement("div");
el.style.position = "fixed";
el.style.top = "10px";
el.style.visibility = "hidden";
@mattfarina
mattfarina / gist:974898
Created May 16, 2011 17:20
Strip tags from pathauto node title
function custom_tokens_alter(array &$replacements, array $context) {
$options = $context['options'];
$sanitize = !empty($options['sanitize']);
if ($context['type'] == 'node' && !empty($context['data']['node'])) {
$node = $context['data']['node'];
foreach ($context['tokens'] as $name => $original) {
switch ($name) {
case 'title':
$title = !empty($options['pathauto']) ? strip_tags($node->title) : $node->title;
@mattfarina
mattfarina / custom.module
Created December 27, 2011 14:00
Protocol relative image paths in Drupal 7
<?php
/**
* Implementation of hook_preprocess_image().
*
* Make images that use a full url be protocol relative.
*/
function custom_preprocess_image(&$variables) {
// If the image URL starts with a protocol remove it and use a
@mattfarina
mattfarina / custom.module
Created December 27, 2011 16:05
Protocol Relative URLs in Drupal 7
<?php
/**
* Implements hook_file_url_alter().
*
* Make all URLs be protocol relative.
* Note: protocol relatice URLs will cause IE7/8 to download stylesheets twice.
* @see http://www.stevesouders.com/blog/2010/02/10/5a-missing-schema-double-download/
*/
function custom_file_url_alter(&$url) {
require 'rubygems'
require 'sequel'
require 'fileutils'
require 'yaml'
# NOTE: This converter requires Sequel and the MySQL gems.
# The MySQL gem can be difficult to install on OS X. Once you have MySQL
# installed, running the following commands should work:
# $ sudo gem install sequel
# $ sudo gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config