Skip to content

Instantly share code, notes, and snippets.

View s-hiroshi's full-sized avatar

Hiroshi Sawai s-hiroshi

View GitHub Profile
@s-hiroshi
s-hiroshi / slideshow
Created February 13, 2012 07:32
jQuery > simple slide show
// シンプルなスライドショー
// photo-main メイン画像コンテナ
// photo-thumb サムネイルコンテナ
$('#photo-thumb a').click(function() {
$('#photo-main img').hide();
var path = $(this).attr('href');
var img = new Image();
img.src = path;
// 画像をスムーズに切り替えるために一度removeしてからappendする。
$('#photo-main img').remove();
@s-hiroshi
s-hiroshi / closure.js
Created February 22, 2012 08:03
JavScript > closure
// クロージャーは呼び出し元が関数の変数名解決の環境を保持する。
// そのためクロージャーは呼び出し元から参照できる必要がある。
// 参照の可能性がないものはガーベージコレクションされる。
// クロージャーではない単なる関数
// 呼び出し元に何も帰らないので
// hogeを抜けた時点で変数var, incはガーベージコレクションされる
function hoge() {
var count = 0;
function inc() {
@s-hiroshi
s-hiroshi / wordpress_rss.php
Created February 24, 2012 08:42
WordPress > get rss feed
<h3>外部ブログ表示</h3>
<?php // Get RSS Feed(s)
include_once(ABSPATH . WPINC . '/rss.php');
$rss = fetch_rss('フィードのパス');
$maxitems = 5;
$items = array_slice($rss->items, 0, $maxitems);
?>
<ul>
<?php if (empty($items)) : ?>
<li>投稿はありません。</li>
@s-hiroshi
s-hiroshi / offset.js
Created February 25, 2012 07:49
jQuery > calculate offset
function getOffset(inner, outer) {
// オフセット
var offsetX = Math.ceil(($(outer).width() - $(inner).width()) / 2);
var offsetY = Math.ceil(($(outer).height - $(inner).height()) / 2);
var offset = {
x: offsetX,
y: offsetY
};
return offset;
}
@s-hiroshi
s-hiroshi / ajax_server.php
Created February 28, 2012 12:53
jQuery > simple Ajax sample
<?php
$value = htmlspecialchars($_GET["test"]);
header("Content-Type: text/html; charset=UTF-8");
echo $value;
?>
@s-hiroshi
s-hiroshi / observe.js
Created February 29, 2012 04:07
JavaScript > tddjs > for my study of tddjs
/*
Copyright (c) Copyright (c) 2010-2011, Christian Johansen
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
Neither the name of the <ORGANIZATION> nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
@s-hiroshi
s-hiroshi / infotown.center.js
Created March 29, 2012 07:33
jQuery > plugin > layout element to center
/**
*
* layout element to center for targettarget
*
* @param {jQuery} target optional
* @param {String} type optional vertical, horizonal, all
* @return jQuery Object
*/
jQuery.fn.setCenter = function(target, type) {
target = target || $(window);
@s-hiroshi
s-hiroshi / typo.js
Created April 18, 2012 05:40
JavaScript > lib > It displays one character at a time.
<html>
<body>
<p id="foo"></p>
</body>
</html>
@s-hiroshi
s-hiroshi / index.html
Created April 18, 2012 13:59
JavaScript > pattern > cross browser event listener (JavaScriptパターン p194)
<html>
<body>
<p><button id="foo">Click</button></p>
</body>
</html>
@s-hiroshi
s-hiroshi / customtimeout.js
Created April 21, 2012 11:57
JavaScript > pattern > setTimeout
/**
* Custom function can pass arguments(string, number, object, array, function) to a function.
*/
/**
* 参考サイト
* WIZARD-CODE ウィザード・コードのブログ | WIZ-CODE.blog
* http://wiz-code.digick.jp/blog/?p=711
*/
function customTimeout() {