Skip to content

Instantly share code, notes, and snippets.

/**
* browser sinffing
* http://james.padolsey.com/javascript/detect-ie-in-js-using-conditional-comments/
*/
(function(){
var ie = (function(){
var undef,
v = 3,
div = document.createElement('div'),
@Takazudo
Takazudo / randomPick.js
Created October 29, 2011 10:27
randomPick/randomNum
/* need underscore.js */
/**
* randomNum
* randomNum(3,6); => 4
*/
var randomNum = function(from, to) {
return from + Math.floor( Math.random() * (to - from + 1) );
};
@Takazudo
Takazudo / sessionStorage.js
Created June 8, 2012 08:46 — forked from tagawa/sessionStorage.js
sessionStorage polyfill
/*
* Based on: http://www.quirksmode.org/js/cookies.html
* and https://github.com/wojodesign/local-storage-js/blob/master/storage.js
* and https://gist.github.com/350433
* License: http://www.opensource.org/licenses/MIT
*/
(function(window) {
'use strict';
window.sessionStorage = window.sessionStorage || {
@Takazudo
Takazudo / events.js
Created July 31, 2012 17:45
lazy event implementation
/* eventmodule */
/* Events */
var Events = {
on: function(events, callback) {
if(!this._observer) {
this._observer = $({});
}
this._observer.bind(events, callback);
@Takazudo
Takazudo / safariversiondetection.js
Created October 23, 2012 09:57
safari version detection
var oldSafari = (function() {
var ua = window.navigator.userAgent;
if(!/safari/i.test(ua)) {
return false;
}
if(/chrome/i.test(ua)) {
// chrome has 'Safari' in its ua.
return false;
}
if(/mobile/i.test(ua)) {
@Takazudo
Takazudo / htmlDprTweak.js
Created February 20, 2014 08:31
devicePixelRatio className tweak
/**
* `html` class tweaking
* if `devicePixelRatio` was 2, switch html's class
* from `dpr-1` to `dpr-2`
*/
(function() {
var html = document.getElementsByTagName("html")[0];
/* helpers */
@Takazudo
Takazudo / detectPositionFixed.js
Last active February 17, 2018 13:58
position fixed detection
// a little modified version of
// position: fixed support detection from jQuery mobile.
//
// This script also defines Android2.x as out of support.
//
// https://github.com/jquery/jquery-mobile/blob/master/js/support.js
// http://demos.jquerymobile.com/1.4.4/toolbar-fixed/
// http://jimbergman.net/webkit-version-in-android-version/
Modernizr.addTest('positionfixed', function() {
@Takazudo
Takazudo / ieversiondetection.coffee
Created September 14, 2012 13:43
IE version detection
# IE version detection
# original: http://james.padolsey.com/javascript/detect-ie-in-js-using-conditional-comments/
ie = do ->
version = 3
div = document.createElement 'div'
all = div.getElementsByTagName 'i'
refresh = ->
version += 1
/* 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' },