Skip to content

Instantly share code, notes, and snippets.

@kyo-ago
kyo-ago / gist:376127
Created April 23, 2010 03:12
url dispatcher
var dispatcher = function (path, func) {
if (func) return dispatcher.path_func.push([path, func]);
$.each(dispatcher.path_func, function () {
if (path.match(this[0])) return this[1]();
});
};
dispatcher.path_func = [];
setTimeout(function () { dispatcher(location.pathname); }, 0);
dispatcher('.', function () {
@kyo-ago
kyo-ago / jQuery.tap.js
Created May 20, 2010 12:00
jQuery.tap.js
$.fn.tap = function (func) {
$.ifFunction(func) ? func.call(this, this) : console.debug(this)
return this;
};
$(‘div’).find(‘a’).tap(function () {
console.debug(this[0]);
});
@kyo-ago
kyo-ago / 衝突しないjQueryの書き方
Created June 7, 2010 07:35
衝突しないjQueryの書き方
(function ($) {
// ここで普通に書く
})(jQuery.noConflict(true));
@kyo-ago
kyo-ago / String.prototype.template
Created June 30, 2010 09:20
String.prototype.template
(function () {
String.prototype.template = function (param) {
function esc (c) { return '&#'+c.charCodeAt(0)+';'; };
var reg = new RegExp('[&"<>\']', 'g');
return this.replace(/\[%(.+?)%\]/g, function (arg1, key) {
return ((param[key] || '')+'').replace(reg, esc);
});
};
})();
@kyo-ago
kyo-ago / google mapでアイコン出すサンプル
Created June 30, 2010 13:50
google mapでアイコン出すサンプル
$(function () {
var gmap = $('#gmap');
if (!gmap.length) return;
$.getJSON(gmap.find(':hidden').val(), function (data) {
if (!GBrowserIsCompatible()) return;
var map = new GMap2(gmap.get(0));
map.addControl(new GMapTypeControl());
map.addControl(new GLargeMapControl());
var bounds = new GLatLngBounds();
var markers = [];
@kyo-ago
kyo-ago / gist:464927
Created July 6, 2010 02:28
redhatにswfmill入れるコマンド
yum -y install gcc-c++ libpng-devel libjpeg-devel freetype* libxslt-devel
wget http://swfmill.org/releases/swfmill-0.3.0.tar.gz
tar xzf swfmill-0.3.0.tar.gz
cd swfmill-0.3.0
wget http://lab.klab.org/files/flash/encoding.patch
patch -fp1 < encoding.patch
./configure
make && make install
@kyo-ago
kyo-ago / 日付を固定長に変換
Created July 20, 2010 02:30
日付を固定長に変換
function YYYYMMDD (d) { return [d.getFullYear(), '0' + (d.getMonth() + 1), '0' + d.getDate()].join('-').replace(/-\d(\d\d)/g, '-$1'); };
@kyo-ago
kyo-ago / gist:518516
Created August 11, 2010 05:16
逐次実行
$('#hoge1').delay(700).fadeIn(500, function () {
$('#hoge2').delay(700).fadeIn(500, function () {
$('#hoge3').delay(700).fadeIn(500);
});
});
@kyo-ago
kyo-ago / gist:569543
Created September 8, 2010 02:58
click_wrapper
$().ajaxSend(function () {
if ($('#click_wrapper').length) return;
$('<div id="click_wrapper">').appendTo('body').css('opacity', 0);
}).bind('ajaxComplete', function () {
setTimeout(function () {
$('#click_wrapper').remove();
}, 500);
});
$('body').live('pageAnimationStart', function () {
if ($('#click_wrapper').length) return;
@kyo-ago
kyo-ago / gist:591381
Created September 22, 2010 08:55
getScrollTop, getScrollLeftの設定
/**
* getScrollTop, getScrollLeftの設定
* @returns scroll position
*/
$.each([['Top', 'Y'], ['Left', 'X']], function () {
var name = this;
$[('getScroll' + name[0])] = function () {
var b = document.body['scroll' + name[0]] || 0;
var e = document.documentElement['scroll' + name[0]] || 0;
var s = window['scroll' + name[1]] || 0;