Skip to content

Instantly share code, notes, and snippets.

View mandelbro's full-sized avatar
🌀

Chris Montes mandelbro

🌀
View GitHub Profile
@mandelbro
mandelbro / gist:2723479
Last active October 5, 2015 00:28
simple jQuery plugin to enable the hover state on non-standard elements, I mostly use it for adding a hover state to li elements in menus
/**
* hoverEnabler
* @mandelbro 05/16/2012
*
* A simple solution to adding css hover effects to elements
* in a cross browser capatable way
*
* Just add the .hoverEnabler class to any element which lacks
@mandelbro
mandelbro / Email Login with D6
Created June 18, 2012 01:20
Enable login with user id or email in Drupal 6
/**
* Implements hook_form_alter
*/
function trnAccount_form_alter(&$form, &$form_state, $form_id) {
global $user;
switch($form_id) :
case 'user_login':
// build the validators array
@mandelbro
mandelbro / jQuery-transitionend
Created November 13, 2012 19:40
Quick jQuery plugin to get the duration of a CSS transition for an element
(function( $ ) {
/**
* jQuery.transtionend
* Retrievs the total amount of time, in miliseconds that
* an element will be transitioned
*/
$.fn.transtionend = function() {
@mandelbro
mandelbro / not-the-konami-code.js
Last active December 15, 2015 05:38
This definitely isn't a jQuery snippet to enable the Konami code on your site...
(function($) { // make this friendly to other libraries
$(function() {
var theCode = { // what code, I don't know what code you're talking about...
sequence: new Array(38,38,40,40,37,39,37,39,66,65,13), //
index: 0
};
$('body').on('keyup', function(event) {
//changed from 'keydown' so the function triggers on release of the key instead of as soon as its pressed
@mandelbro
mandelbro / jQuery flexiFrame plugin
Last active December 15, 2015 06:39
When you set an iFrame to max-width 100%, it can't adjust it's own height. That is because iFrames are stupid, this plugin is like a 4 year education to an iFrame, which the iFrame will squander anyway.
(function($) {
var methods = {
adjustHeight : function(ratio, width) {
if(width == currentWidth) return;
currentWidth = width;
this.height(width/ratio);
}
},
currentWidth;
@mandelbro
mandelbro / jQuery Media Query List Events
Created April 14, 2013 22:34
Triggers jQuery events when some key mediaQuery breakpoints are hit
(function($){
$(function() {
var mqls = [window.matchMedia("(min-width: 1900px)"), window.matchMedia("(max-width: 780px)"), window.matchMedia("(max-width: 480px)")],
handleOrientationChange = function(mql) {
switch(mql.media) {
case '(min-width: 1900px)' :
@mandelbro
mandelbro / Development Questionnaire
Last active December 20, 2015 15:28
This is the questionnaire I use for starting new web development projects, chiefly when I am taking a project over from design.
#########################################################################################
# _ _ _ ______ _____ _ _ #
# | | | | | | | _ \ | _ | | | (_) #
# | | | | ___| |__ | | | |_____ __ | | | |_ _ ___ ___| |_ _ ___ _ __ ___ #
# | |/\| |/ _ \ '_ \ | | | / _ \ \ / / | | | | | | |/ _ \/ __| __| |/ _ \| '_ \/ __| #
# \ /\ / __/ |_) | | |/ / __/\ V / \ \/' / |_| | __/\__ \ |_| | (_) | | | \__ \ #
# \/ \/ \___|_.__/ |___/ \___| \_/ \_/\_\\__,_|\___||___/\__|_|\___/|_| |_|___/ #
# #
#########################################################################################
@mandelbro
mandelbro / getGrabberEvents.js
Last active December 22, 2015 00:59
Touch event detection is tricky now that desktop browsers are reporting touch events in windows. This script first checks for MS Pointer events, which combine touch and click events for devices like the Surface or HP touchsmart laptops. Otherwise it checks for HTML5 standard touch events AND the window.orientation object, this ensures the user i…
// this will pull events for a grabber action: down, up, and move
var getGrabberEvents = function() {
// run through possible events
if(window.navigator.msPointerEnabled) { // windows specific
// see http://msdn.microsoft.com/en-us/library/ie/hh673557(v=vs.85).aspx
return 'MSPointerDown MSPointerUp MSPointerMove';
} else if(window.orientation && Modernizr.touch) { // html5 standard touch events
// if you don't want to use modernizr, see this thread:
// http://stackoverflow.com/questions/14267598/is-there-a-more-elegant-way-to-detect-touch-events-support-and-assign-either-a
return 'touchstart touchend touchmove';
@mandelbro
mandelbro / zepto-jquery-plugin-boilerplate.js
Last active December 22, 2015 21:19
jQuery/Zepto Plugin Boilerplate
/*jslint devel: true, nomen: true, unparam: true, white: true, indent: 4 */
//
// $.fn.pluginName
//
;(function ($, window, undefined) {
// Give the plugin a descriptive name
var pluginName = 'pluginName',
/**
* Blueprint JS starter view controller
*/
var exampleViewController = (function( $, window, undefined ) {
// this is a private function
var buildListeners = function() {
var self = this,
// add a map of callbacks to use for the listeners below
callbacks = {};