Skip to content

Instantly share code, notes, and snippets.

View terkel's full-sized avatar

Takeru Suzuki terkel

View GitHub Profile
@terkel
terkel / jquery.autofocus.js
Created September 23, 2011 00:55
HTML5 Autofocus Polyfill using jQuery
(function ($) {
$(function () {
if (!supportsInputAttribute('autofocus')) {
$('[autofocus=]').focus(); // http://bugs.jquery.com/ticket/5637
}
});
// detect support for input attirbute
function supportsInputAttribute (attr) {
@terkel
terkel / jquery.placeholder.js
Created September 23, 2011 00:56
HTML5 Placeholder Polyfill using jQuery
(function ($) {
$(function () {
if (!supportsInputAttribute('placeholder')) {
$('[placeholder]').each(function () {
var $this = $(this),
$form = $this.closest('form'),
placeholderText = $this.attr('placeholder'),
placeholderColor = 'GrayText',
defaultColor = $this.css('color');
@terkel
terkel / jquery.print-link-urls.js
Created September 24, 2011 14:34
jQuery Print Link URLs Plugin
@terkel
terkel / gist:1241497
Created September 26, 2011 02:27
table と th/td でボーダー色を変える
div {
border: 1px solid red;
*border-style: none;
}
div table {
border-style: hidden;
*border: 1px solid red;
}
div table th,
div table td {
@terkel
terkel / jquery.matches.js
Created September 30, 2011 15:12
CSS4 :matches selector for jQuery
// http://twitter.com/padolsey/status/119790781417537536
$.expr[':'].matches = (function (_) {
return function (el, i ,m) {
return !!_(m[3]||'*',[el])[0];
};
}($.find.matches));
@terkel
terkel / gist:1271790
Created October 8, 2011 03:01
addEvent
// http://gihyo.jp/dev/serial/01/crossbrowser-javascript/0007
var addEvent = (function () {
if (document.addEventListener) {
return function(node, type, handler) {
node.addEventListener(type, handler, false);
};
} else if (document.attachEvent) {
return function(node, type, handler) {
node.attachEvent('on' + type, function (event) {
handler.call(node, event);
@terkel
terkel / gist:1292496
Created October 17, 2011 12:24
Tweet Entities parser
// API docs: https://dev.twitter.com/docs/tweet-entities
// Inspired by: https://gist.github.com/442463
function parseTweetEntities (tweet) {
var result = [],
entities = [],
lastIndex = 0,
key,
i,
len,
elem;
@terkel
terkel / gist:1329581
Created November 1, 2011 01:17
Centering floated items
/* http://hail2u.net/blog/webdesign/centering-floated-list.html */
.centered {
position: relative;
overflow: hidden;
}
.centered ul {
position: relative;
left: 50%;
float: left;
}
@terkel
terkel / reset.css
Created November 12, 2011 10:56
CSS Reset
/*!
* CSS Reset 2011-12-25
* https://gist.github.com/gists/1360380
*
* Author: Takeru Suzuki, http://terkel.jp/
* License: Public domain
*
* Inspired by Normalize.css: http://necolas.github.com/normalize.css/
*/
@terkel
terkel / gist:1452154
Created December 9, 2011 16:11
Detect IE and add class to the html element
// Including IE detection by James Padolsey: https://gist.github.com/527683
(function (html) {
var ie = (function () {
var undef,
v = 3,
div = document.createElement('div'),
all = div.getElementsByTagName('i');
while (div.innerHTML = '<!--[if gt IE ' + (++v) + ']><i></i><![endif]-->', all[0]);
return (v > 4)? v: undef;
}());