Skip to content

Instantly share code, notes, and snippets.

@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 */
var legacyIE = (function() {
var ua = navigator.userAgent;
var matchRes = ua.match(/msie\s?(\d+)/i);
// '.... MSIE 7.0; Windows....'
// => ["MSIE 7", "7"]
if(!matchRes) { return false; }
var version = matchRes[1];
var win8orhigher = (function() {
// windows browsers has str like "Windows NT 6.2" in its UA
// Win8 UAs' version is "6.2"
// browsers above this version may has touch events.
var ua = navigator.userAgent;
var matched = ua.match(/Windows NT ([\d\.]+)/);
if(!matched) { return false; }
var version = matched[1] * 1;
if(version < 6.2) { return false; }
return true;
# transitionEnd event name detection from Modernizr
# http://modernizr.com/docs/
transEndEventName = do ->
names =
WebkitTransition: "webkitTransitionEnd"
MozTransition: "transitionend"
OTransition: "oTransitionEnd"
msTransition: "MSTransitionEnd"
transition: "transitionend"
@Takazudo
Takazudo / eventmodule.coffee
Created December 10, 2012 10:42
lazy event implementation with jQuery
/* lazy eventy implementation with jQuery */
class Module
on: (evName, callback) ->
@_observer = $({}) unless @_observer?
@_observer.on evName, (args...) =>
args.shift() # we don't want event object
callback.apply @_observer, args
@
one: (evName, callback) ->
@Takazudo
Takazudo / audiopreloader.coffee
Created December 5, 2012 07:44
audio on the fly doesn't fire events correctly
class Module
_.extend Module::, Backbone.Events
class AudioPreloader extends Module
constructor: (options) ->
@options = options
@playableSrc = @_detectPlayableSrc()
@Takazudo
Takazudo / requestAnimationFramePolyfill.coffee
Created November 27, 2012 10:09
requestAnimationFrame polyfill
window.requestAnimFrame = do ->
window.requestAnimationFrame or
window.webkitRequestAnimationFrame or
window.mozRequestAnimationFrame or
window.oRequestAnimationFrame or
window.msRequestAnimationFrame or
(callback, element) ->
window.setTimeout callback, 1000 / 60
@Takazudo
Takazudo / lazyEventModuleWithBackbone.coffee
Created November 27, 2012 09:44
lazyEventModuleWithBackbone
class Module
_.extend Module::, Backbone.Events
class App extends Module
app = new App
app.on 'hoge', ->
console.log 'hoge done!'
@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 / jquerymobiletransition.html
Created September 14, 2012 14:52
jquery mobile page transition example
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>test</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.1/jquery.mobile-1.1.1.min.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
<script src="http://code.jquery.com/mobile/1.1.1/jquery.mobile-1.1.1.min.js"></script>
</head>