Skip to content

Instantly share code, notes, and snippets.

View githiro's full-sized avatar

Hiro githiro

  • Tokyo
View GitHub Profile
@githiro
githiro / gist:5706653
Created June 4, 2013 15:10
JS: smaller lazy-load inspired by lazyload
(function($, window, document, undefined) {
$.fn.lazyload = function(options) {
var $window = $(window),
elements = this,
settings = {
threshold : 0,
fadein_speed : "200",
container : window,
data_attribute : "src",
appear : null,
@githiro
githiro / gist:5725996
Last active December 18, 2015 04:29
PHP judge janguage
if (array_key_exists("lang", $_COOKIE))
{
$view->lang = $_COOKIE['lang'];
}
else
{
$lang = (substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2) === "ja")? 'ja' : 'en';
setcookie("lang", $lang, 0, "/");
$view->lang = "ja";
}
@githiro
githiro / IndexController.php
Created June 6, 2013 23:52
PHP: determine template
////////////////////// public_html/controllers/IndexController //////////////////////
<?php
class IndexController extends Zend_Controller_Action
{
public function loadTemplate($name)
{
if (!array_key_exists("isAjax", $_POST))
{
$this->view->action = $name;
$this->_forward('container');
@githiro
githiro / gist:5746763
Created June 10, 2013 05:43
JS: Get domain name(include protocol, port)
var domain = (location.origin)? location.origin : (location.protocol + "//" + location.host);
@githiro
githiro / gist:5761835
Last active December 18, 2015 09:29
CSS: All transition propaties
-moz-transition-property: all;
-webkit-transition-property: all;
-o-transition-property: all;
transition-property: all;
-moz-transition-timing-function: cubic-bezier(0,1,.9,1);
-webkit-transition-timing-function: cubic-bezier(0,1,.9,1);
-o-transition-timing-function: cubic-bezier(0,1,.9,1);
transition-timing-function: cubic-bezier(0,1,.9,1);
-moz-transition-duration: .3s;
-webkit-transition-duration: .3s;
@githiro
githiro / gist:5764878
Created June 12, 2013 12:37
JS: requestAnimationFrame(cross browser)
if (!window.requestAnimationFrame) {
window.requestAnimationFrame = (function() {
return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function(callback) {
window.setTimeout(callback, 1000 / 60);
};
})();
}
@githiro
githiro / gist:5770228
Created June 13, 2013 00:12
JS, HTML: Basic Tab UI
//html
<div class="uiTabList clearfix">
<p class="nav">
<a href="javascript: void 0;" onclick="_self.changeTab(this);" class="active">Menu Title 1</a>
<a href="javascript: void 0;" onclick="_self.changeTab(this);">Menu Title 2</a>
</p>
<div class="tabs">
<div class="tab active">
</div>
<div class="tab">
@githiro
githiro / gist:5787413
Last active December 18, 2015 13:09
PHP: isVaildInetAddress - PEAR Class Mail_RFC822(not strict mode only)
function isValidInetAddress($data)
{
$regex = '/^([*+!.&#$|\'\\%\/0-9a-z^_`{}=?~:-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,})$/i';
if (preg_match($regex, trim($data), $matches))
{
return array($matches[1], $matches[2]);
}
else
{
return false;
@githiro
githiro / gist:5787419
Created June 15, 2013 08:39
PHP: escape all in array function
function escapeAllInArray($array)
{
foreach ($array as $key => $value)
{
$array[$key] = htmlspecialchars($value, ENT_QUOTES, $charset);
}
return $array;
}
@githiro
githiro / gist:5805759
Created June 18, 2013 14:24
JS: add onload event on window
$.event.add(window, "load", function()
{
});