Skip to content

Instantly share code, notes, and snippets.

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>sldk</title>
</head>
<body>
<p>etjebleuh</p>
@MiguelDebruyne
MiguelDebruyne / gist:10563744
Created April 13, 2014 00:40
Javascript: Sexy PubSub
// Works in modern browsers + IE9, but Modernizr has a polyfill baked in for function.bind.
// Hat tip Paul Irish
var o = $( {});
$.subscribe = o.on.bind(o);
$.unsubscribe = o.off.bind(o);
$.publish = o.trigger.bind(o);
@MiguelDebruyne
MiguelDebruyne / gist:10563790
Created April 13, 2014 00:43
CSS: Image Replacement
.ir {
border: 0;
font: 0/0 a;
text-shadow: none;
color: transparent;
background-color: transparent;;
}
@MiguelDebruyne
MiguelDebruyne / gist:10563864
Created April 13, 2014 00:46
JavaScript: jQuery PubSub
(function($) {
var o = $( {});
$.each({
on: 'subscribe',
trigger: 'publish',
off: 'unsubscribe'
}, function( key, api) {
$[api] = function() {
$[key].apply( o, arguments );
@MiguelDebruyne
MiguelDebruyne / gist:10564025
Created April 13, 2014 00:53
Javascript: Detect IE Version
// ----------------------------------------------------------
// A short snippet for detecting versions of IE in JavaScript
// without resorting to user-agent sniffing
// ----------------------------------------------------------
// If you're not in IE (or IE version is less than 5) then:
// ie === undefined
// If you're in IE (>=5) then you can determine which version:
// ie === 7; // IE7
// Thus, to detect IE:
// if (ie) {}
@MiguelDebruyne
MiguelDebruyne / Eric Meyer's reset reloaded
Created April 15, 2014 07:54
CSS: Eric Meyer's reset reloaded
/* Eric Meyer's reset reloaded
http://meyerweb.com/eric/thoughts/2007/05/01/reset-reloaded/
*/
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, font, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
dl, dt, dd, ol, ul, li,
@MiguelDebruyne
MiguelDebruyne / Basic validator form validation
Created April 15, 2014 17:25
JavaScript: Basic validator form validation
function formValidation() {
jQuery.validator.addMethod("twowords", function(value, element) {
var tagCheckRE = new RegExp("(\\w+)(\\s+)(\\w+)");
return tagCheckRE.test(value);
}, "At least two words.");
var numInputFieldsToCheck =
$('#contactForm').find('input').length -1 +
$('#contactForm').find('textarea').length;
@MiguelDebruyne
MiguelDebruyne / JS Fastclick
Created April 16, 2014 06:34
Javascript: Fastclick
function FastButton(element, handler) {
this.element = element;
this.handler = handler;
element.addEventListener('touchstart', this, false);
};
FastButton.prototype.handleEvent = function(event) {
switch (event.type) {
case 'touchstart': this.onTouchStart(event); break;
case 'touchmove': this.onTouchMove(event); break;
case 'touchend': this.onClick(event); break;
if(jQuery.browser)
{
/* SmileyWar.com Mobile Orientation Detection */
// set rules on initial load and when the screen changes size or orientation.
$(window).on("load resize",function(){
var h = $(window).height();
var w = $(window).width();
if ( w < 768) {
@MiguelDebruyne
MiguelDebruyne / IE7 background-size fallback
Created April 17, 2014 07:24
CSS: IE7 background-size fallback
filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(
src='images.gif',
sizingMethod='scale');
-ms-filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(
src='images.gif',
sizingMethod='scale')";