Skip to content

Instantly share code, notes, and snippets.

/* mobile UA detection http://jsfiddle.net/Takazudo/rxPYk/ */
var ua = (function(){
var ua = {};
var navigator = window.navigator;
var platforms = [
{ property: 'platform', regex: /iPhone/i, identity: 'iPhone' },
{ property: 'platform', regex: /iPod/i, identity: 'iPod' },
{ property: 'userAgent', regex: /iPad/i, identity: 'iPad' },
{ property: 'userAgent', regex: /Blackberry/i, identity: 'Blackberry' },
/*!
* viewport handler
*
* for tablet: 1024px fix
* others: width=device-width
* iPhone: +scaleFix
*/
(function(){
/* desktop page width */
/* css only preload */
.foobar:after{
content: '';
width:0;
height:0;
position:absolute;
left:-9999px;
background:url(../images_v2/arrows/up.png);
}
/* make pure css triangle */
.cssTriangle{
display:block;
height:20px;
position:relative;
overflow:hidden;
}
.cssTriangle span{
position: absolute;
width: 0;
/* jQuery deferred chain example
demo on jsfiddle: http://jsfiddle.net/Takazudo/ekbc4/ */
var $ul = $('#dump');
function dump(msg){
$ul.append('<li>' + msg + '</li>');
}
/* deferred functions */
@Takazudo
Takazudo / commentexample.js
Created June 10, 2011 08:34
js commentation example
/* js comment format collection */
/*!
* script name
*
* @author : Takeshi Takatsudo (takazudo[at]gmail.com)
* @copyright : Takeshi Takatsudo
* @license : The MIT License
* @link : http://.....
* @modified : 2011/04/26 HH:MM:SS
/* cache manifest debug from http://jonathanstark.com/blog/2009/09/27/debugging-html-5-offline-application-cache/ */
(function(){
var $log = $('#log'); // #log is ul
function log(msg){
$log.append('<li>' + msg + '</li>');
}
var cacheStatusValues = [];
cacheStatusValues[0] = 'uncached';
@Takazudo
Takazudo / debugJsonServiceResponse.php
Created July 6, 2011 06:56
simulate delayed json response with php
<?php
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Content-type: application/json; charset=utf-8');
sleep(1);
readfile('amazonresult.json')
?>
@Takazudo
Takazudo / shake.js
Created July 7, 2011 10:09
shake the input element
/* validation input shake */
jQueryObject.stop()
.animate({ left: "-6px" }, 40).animate({ left: "6px" }, 40)
.animate({ left: "-6px" }, 40).animate({ left: "6px" }, 40)
.animate({ left: "0px" }, 40);
function randomNum(from, to) {
return from + Math.floor( Math.random() * (to - from + 1) );
}
function randomChar(length){
var library = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'];
var res = '';
for(var i=0; i<length; i++){
res = [res, library[randomNum(0,9)]].join('');
}
return res;