Skip to content

Instantly share code, notes, and snippets.

@ethertank
ethertank / String.trim.js
Created October 20, 2011 21:49
String.trim
(function() {
var _t = "[\x09-\x0D\x20\xA0\x85\u1680\u180E\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF]+",
_l = new RegExp("^" + _t),
_r = new RegExp(_t + "$"),
SP = String.prototype;
SP.trimLeft = function() { return this.replace(_l, ""); };
SP.trimRight = function() { return this.replace(_r, ""); };
SP.trim = function() { return this.trimLeft().trimRight(); };
})();
@ethertank
ethertank / daes.js
Created December 25, 2011 09:57
detect audio element supported
var audioElementSupported = (function(d) {
var a = d.createElement("audio"),
o = {},
s = "audio\/";
if (typeof a.canPlayType === "function") {
o.supported = Boolean(true);
o.mp3 = a.canPlayType(s + "mpeg");
o.wav = a.canPlayType(s + 'wav; codecs="1"');
o.ogg = a.canPlayType(s + 'ogg; codecs="vorbis"');
@ethertank
ethertank / getRandomColor.js
Last active September 29, 2015 10:57
getRandomColor
if (typeof getRandomColor === "undefined") {
var getRandomColor = function(type) {
var _c;
if (type) type = type.toUpperCase();
switch (type) {
case "RGB":
_c = "rgb(" + (Math.random() * 256 | 0) + ", " + (Math.random() * 256 | 0) + ", " + (Math.random() * 256 | 0) + ")";
break;
@ethertank
ethertank / getComputedStyle.js
Created January 17, 2012 09:29
getComputedStyle(function)
if(typeof getComputedStyle === "undefined") {
var getComputedStyle = function(targetElm){
return document.defaultView.getComputedStyle(targetElm, "") || targetElm.currentStyle;
};
}
@ethertank
ethertank / rAF.js
Last active September 30, 2015 17:38 — forked from paulirish/rAF.js
requestAnimationFrame / cancelAnimationFrame
// http://paulirish.com/2011/requestanimationframe-for-smart-animating/
// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
// requestAnimationFrame polyfill by Erik Möller
// fixes from Paul Irish and Tino Zijdel
(function() {
var lastTime = 0;
var vendors = ['ms', 'moz', 'webkit', 'o'];
for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
@ethertank
ethertank / memo.txt
Created February 24, 2012 01:52
HTMLElement.insertBefore のラッパー関数
挿入先要素の親要素の指定を自動化。
### usage ###
[html]
​<div><div id="target">target</div></div>​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​
[js]
var doc = document, elm = doc.createElement("div"), targetElm = doc.getElementById("target");
elm.appendChild(doc.createTextNode("insert !"));
@ethertank
ethertank / wrapElemtnt.js
Created February 25, 2012 22:12
要素を別の要素で包む関数
function wrapElement(targetElm, wrapperElm) {
wrapperElm.appendChild(targetElm.cloneNode(true));
targetElm.parentNode.replaceChild(wrapperElm, targetElm);
}
@ethertank
ethertank / outputDummyJSON.php
Created March 12, 2012 12:59
ダミーのjsonを出力するphp
<?php
$len = 5;
$jsonArray = array();
$bodyStr = "。";
for($i = 0; $i < 10; $i++){
$bodyStr = "仲村みう".$bodyStr;
}
for($i = 1, $l = $len + 1; $i < $l; $i++){
@ethertank
ethertank / clearfix.css
Created March 19, 2012 10:28
Clearfix
@charset "utf-8";
/*
※未検証。これだと古いIEが死ぬかな。でも育て甲斐がありそうな気がする。
※参考URL: http://norisfactory.com/stylesheetlab/000038.php
※データ: http://blog.ethertank.jp/2010/05/01-19:13:22
*/
.clearfix { zoom: 1; }
.clearfix:after {
@ethertank
ethertank / jQuery_blrblrTumblrImage.js
Last active October 1, 2015 23:17
jQuery blrblrTumblrImage
/*
* jQuery_blrblrTumblrImage.js
*
* Varsion: 0.1.7
* PublishDate: 2012-03-03 23:30
* LastUpdate : 2014-08-06 23:28
* Copyright (c) 2012- ethertank.jp
* Licensed under the MIT
*
* jQuery required (tested on 1.7.1)