文書の先頭では、必ず以下の文を記述する。
use strict; # 厳しい文法チェック
use warnings; # 警告を表示
/** | |
* Merge defaults with user options | |
* @private | |
* @param {Object} defaults Default settings | |
* @param {Object} options User options | |
* @returns {Object} Merged values of defaults and options | |
*/ | |
var extend = function (defaults, options) { | |
var extended = {}; | |
var prop; |
var getObjectLength = function (obj) { | |
var a, l = 0; | |
for (a in obj) { | |
l++; | |
} | |
return l; | |
}; |
var addCamma = function (number, fig) { | |
var str, ptn; | |
fig = fig || 3; | |
str = String(number).replace(/,/g, ''); | |
ptn = RegExp('^(-?\\d+)(\\d{' + fig + '})'); | |
while(str != (str = str.replace(ptn, "$1,$2"))); | |
return str; | |
}; |
var toAN = function (data) { | |
var dataType = typeof data, | |
str = String(data); | |
str = str.replace(/[A-Za-z0-9]/g, function(s) { | |
return String.fromCharCode(s.charCodeAt(0) - 65248); | |
}); | |
return dataType == 'number' ? Number(str) : str; | |
}; |
var getQuery = function (url) { | |
if (typeof url !== 'string') { | |
url = window.location.href; | |
} | |
var queries = url.slice(url.indexOf('?') + 1).split('&'), | |
obj = {}; | |
for (var i = queries.length; i--;) { | |
var query = queries[i].split('='); | |
obj[query[0]] = query[1]; | |
} |
var cancelBubble, | |
cancelEvent; | |
cancelBubble = (function () { | |
var func = function () {}; | |
if (typeof Event !== 'undefined' && typeof Event.prototype.stopPropagation === 'function') { | |
func = function (e) { e.stopPropagation(); }; | |
} else if (window.event) { | |
func = function () { window.event.cancelBubble = true; }; | |
} |
var addEvent, | |
removeEvent; | |
if (typeof window.addEventListener === 'function') { | |
addEvent = function (el, type, fn) { el.addEventListener(type, fn, false); }; | |
removeEvent = function (el, type, fn) { el.removeEventListener(type, fn, false); }; | |
} else if (typeof document.attachEvent === 'function') { | |
addEvent = function (el, type, fn) { el.attachEvent('on' + type, fn); }; | |
removeEvent = function (el, type, fn) { el.detachEvent('on' + type, fn); }; | |
} else { |
<?php | |
class UserAgent{ | |
private $ua; | |
private $device; | |
public function set(){ | |
$this->ua = mb_strtolower($_SERVER['HTTP_USER_AGENT']); | |
if(strpos($this->ua,'iphone') !== false){ | |
$this->device = 'mobile'; | |
}elseif(strpos($this->ua,'ipod') !== false){ | |
$this->device = 'mobile'; |
var _ua = (function(u){ | |
return { | |
Tablet:(u.indexOf("windows") != -1 && u.indexOf("touch") != -1) || u.indexOf("ipad") != -1 || (u.indexOf("android") != -1 && u.indexOf("mobile") == -1) || (u.indexOf("firefox") != -1 && u.indexOf("tablet") != -1) || u.indexOf("kindle") != -1 || u.indexOf("silk") != -1 || u.indexOf("playbook") != -1, | |
Mobile:(u.indexOf("windows") != -1 && u.indexOf("phone") != -1) || u.indexOf("iphone") != -1 || u.indexOf("ipod") != -1 || (u.indexOf("android") != -1 && u.indexOf("mobile") != -1) || (u.indexOf("firefox") != -1 && u.indexOf("mobile") != -1) || u.indexOf("blackberry") != -1 | |
} | |
})(window.navigator.userAgent.toLowerCase()); |