Skip to content

Instantly share code, notes, and snippets.

View gist:376127
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 () {
View 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 Jun 7, 2010
衝突しないjQueryの書き方
View 衝突しないjQueryの書き方
(function ($) {
// ここで普通に書く
})(jQuery.noConflict(true));
@kyo-ago
kyo-ago / String.prototype.template
Created Jun 30, 2010
String.prototype.template
View 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 Jun 30, 2010
google mapでアイコン出すサンプル
View 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 Jul 6, 2010
redhatにswfmill入れるコマンド
View gist:464927
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 Jul 20, 2010
日付を固定長に変換
View 日付を固定長に変換
function YYYYMMDD (d) { return [d.getFullYear(), '0' + (d.getMonth() + 1), '0' + d.getDate()].join('-').replace(/-\d(\d\d)/g, '-$1'); };
View gist:518516
$('#hoge1').delay(700).fadeIn(500, function () {
$('#hoge2').delay(700).fadeIn(500, function () {
$('#hoge3').delay(700).fadeIn(500);
});
});
View gist:569543
$().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 Sep 22, 2010
getScrollTop, getScrollLeftの設定
View gist:591381
/**
* 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;