Skip to content

Instantly share code, notes, and snippets.

View mathiasbynens's full-sized avatar

Mathias Bynens mathiasbynens

View GitHub Profile
// Original code from http://www.blog.highub.com/mobile-2/a-fix-for-iphone-viewport-scale-bug/
var metas = document.getElementsByTagName('meta');
var i;
if (navigator.userAgent.match(/iPhone/i)) {
for (i=0; i<metas.length; i++) {
if (metas[i].name == "viewport") {
metas[i].content = "width=device-width, minimum-scale=1.0, maximum-scale=1.0";
}
}
@mathiasbynens
mathiasbynens / README.md
Created April 22, 2011 08:06
Improved swipe gestures plugin for jQuery

Improved swipe gestures plugin for jQuery

What was changed (compared to the original v0.1.2):

  • Don’t modify the default settings internally.
  • Merge the options recursively (deep copy) so that the custom threshold values actually get used.
  • Allow overriding the options globally through $.fn.swipe.options.
  • Use namespaced jQuery events (using the swipe namespace) instead of DOM2 addEventListener to prevent errors in old IEs.
  • Simplified and optimized code.
  • Changed swipeLeft and swipeRight functions to be called within the context of the bound element. Thanks, @kswedberg!
var elemDisplays = {},
// Store the iframe outside the function to reuse it
iframe,
iframeDoc;
function defaultDisplay( nodeName ) {
if ( !elemDisplays[ nodeName ] ) {
// Try the classical method first, which is far faster
var elem = document.createElement( nodeName ),
display;
@mathiasbynens
mathiasbynens / LICENSE.txt
Created May 23, 2011 07:47 — forked from 140bytes/LICENSE.txt
Google Analytics snippet in 140 bytes
Author: Mathias Bynens <http://mathiasbynens.be/>
This code is licensed under the WTFPL. Feel free to relicense as needed.
@mathiasbynens
mathiasbynens / some-more-info-on-css-hacks.md
Created May 25, 2011 17:33
Some more info on CSS hacks

There seems to be a difference between longhand properties (e.g. background-color) and shorthand properties (e.g. background). Some CSS hacks only work for one or the other. I’ve updated my test case to test these separately, and there are some interesting results.

The following hacks target IE8 but not IE9:

  • longhandproperty: \0value\0;
  • longhandproperty: \0value;

In practice, you might use these like so:

  • background-color: \0red\0;
@mathiasbynens
mathiasbynens / LICENSE.txt
Last active October 5, 2022 10:38 — forked from 140bytes/LICENSE.txt
UTF-8 byte counter in 49 bytes
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Mathias Bynens <http://mathiasbynens.be/>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@mathiasbynens
mathiasbynens / jquery.fluid-youtube-videos-original.js
Created June 8, 2011 13:07
Fluid width YouTube videos of different aspect ratios, by Chris Coyier
// Original code from http://css-tricks.com/examples/FluidWidthYouTube/iframe.php
$(function() {
// find all videos
var allVideos = $("iframe[src^='http://www.youtube.com']"),
// The thing that is fluid width
body = $("body"),
@mathiasbynens
mathiasbynens / LICENSE.txt
Created June 11, 2011 08:56 — forked from 140bytes/LICENSE.txt
Quick and dirty way to check if a given string can be used as an unquoted attribute value in HTML. (50 bytes)
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Mathias Bynens <http://mathiasbynens.be/>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@mathiasbynens
mathiasbynens / fronteers11-belgians.js
Created June 17, 2011 16:47
Belgian #fronteers11 attendees
// Run this in your console on http://fronteers.nl/
// @fronteers Can haz JSON-P, pretty please?
jQuery.get('/congres/2011/attendees.json', function(data) {
var belgians = data.fronteers2011.andAllTheirOtherData.filter(function(attendee) {
return attendee.country == 'BE';
}).map(function(attendee) {
return attendee.name + (attendee.twitter ? ' (@' + attendee.twitter + ')' : '');
}),
title = belgians.length + ' Belgian attendees:';
@mathiasbynens
mathiasbynens / jsconsole.user.js
Created June 24, 2011 13:51
User script to enable the large side-by-side view on jsconsole.com.
// ==UserScript==
// @name Enable the large side-by-side view on jsconsole.com. This is only useful until https://github.com/remy/jsconsole/issues/22 is fixed.
// @author Mathias Bynens <http://mathiasbynens.be/>
// @match http://jsconsole.com/*
// ==/UserScript==
document.body.className = 'large';