Skip to content

Instantly share code, notes, and snippets.

View 5509's full-sized avatar

Kazunori Tokuda 5509

  • PixelGrid, Inc.
  • Tokyo, Japan
View GitHub Profile
@5509
5509 / classList
Created March 31, 2011 01:16
classList(DOMTokenList) polyfills
;(function() {
if ( !Element.__defineGetter__ || Element.prototype.hasOwnProperty("classList") ) return;
function classList(elm) {
this.elm = elm;
}
classList.prototype = {
add: function(klass) {
var _elm = this.elm,
@5509
5509 / bind()
Created April 4, 2011 09:42
汎用addEventListener(IE8以下を除く)
/*
* Bind events
* bind(obj, listener, func)
* or
* bind(obj, {
* listener : func,
* listener2 : func2,
* // and more
* })
*/
@5509
5509 / bind and unbind funcs
Created April 5, 2011 17:29
巡り巡ってElement.prototypeを断念。。namespace使ってbind、unbindできる(IE8以下を除く)
/*
* bind, unbind
*
* @author : nori(norimanai@gmail.com)
* @copyright : 5509(http://5509.me/)
* @license : The MIT License
* @modified : 2011-04-09 01:30
*
* HOW TO USE
* bind event : bind(elm, type, func) or bind(elm, {})
@5509
5509 / El.prototype.css
Created April 7, 2011 02:44
jQueryのCSSみたいなやつの簡易(しょぼい)版
/*
* CSS - set css style(s)
*
* HOW TO USE
* set css style : elm.css(type, val)
* set css styles : elm.css({type1: val1, type2: val2, ...})
*/
Element.prototype.css = function() { // arguments: (style, val) or {}
var _a = arguments, i, hash;
@5509
5509 / 汎用キューコンストラクタ
Created April 8, 2011 04:23
キューの仕組みを理解するために書いた。つまり車輪のなんたら。キューの管理配列と実行中フラグがprototypeに入ってしまってたので個別に
/*
* Queue
*
* @author : nori(norimanai@gmail.com)
* @copyright : 5509(http://5509.me/)
* @license : The MIT License
* @modified : 2011-04-08 13:22
*/
// 汎用キューコンストラクタ
function Queue() {
@5509
5509 / customevent
Created October 10, 2011 16:53
customEvent
function _trigger(elm, listener) {
var evtObj = undefined;
if ( 'createEvent' in document ) {
evtObj = document.createEvent('UIEvents');
evtObj.initEvent(listener, false, true);
elm.dispatchEvent(evtObj);
} else
if ( 'createEventObject' in document ) {
evtObj = document.createEventObject();
evtObj.name = listener;
@5509
5509 / animate
Created January 26, 2012 11:58
アニメーションするやつ
function animate(elem, styles, duration, easing) {
var dfd = new Deferred(),
fps = undefined,
current_time = 0,
style_key = undefined,
start_value = undefined,
end_value = undefined,
pt = '',
rev = false,
diff_start = 0,
@5509
5509 / gist:1770513
Created February 8, 2012 15:37
each
function each(arr, func) {
var i = 0,
l = arr.length;
for ( ; i < l; i = i + 1 ) {
func.apply(
arr[i],
([i]).concat(arguments)
);
}
@5509
5509 / repeat.coffee
Created February 23, 2012 13:27
Repeat func
# Repeat func
#
# @param {}
# {
# interval: 50,
# func: ->
# console.log 'func'
# }
#
# or
@5509
5509 / gist:2217089
Created March 27, 2012 15:36
Choosing use vendor prefix or not by like hash for Sass
$use:
-webkit-, true,
-moz-, true,
-o-, true,
-ms-, false;
@mixin addPrefix($property, $value, $def: false) {
$property: unquote($property);
$value: unquote($value);
@for $i from 1 through length($use)/2 {