mirror of
https://github.com/wahyd4/cdnjs.git
synced 2026-08-09 04:46:00 +10:00
add device.js v0.1.61
This commit is contained in:
@@ -0,0 +1,205 @@
|
||||
(function() {
|
||||
var previousDevice, _addClass, _doc_element, _find, _handleOrientation, _hasClass, _orientation_event, _removeClass, _supports_orientation, _user_agent;
|
||||
|
||||
previousDevice = window.device;
|
||||
|
||||
window.device = {};
|
||||
|
||||
_doc_element = window.document.documentElement;
|
||||
|
||||
_user_agent = window.navigator.userAgent.toLowerCase();
|
||||
|
||||
device.ios = function() {
|
||||
return device.iphone() || device.ipod() || device.ipad();
|
||||
};
|
||||
|
||||
device.iphone = function() {
|
||||
return _find('iphone');
|
||||
};
|
||||
|
||||
device.ipod = function() {
|
||||
return _find('ipod');
|
||||
};
|
||||
|
||||
device.ipad = function() {
|
||||
return _find('ipad');
|
||||
};
|
||||
|
||||
device.android = function() {
|
||||
return _find('android');
|
||||
};
|
||||
|
||||
device.androidPhone = function() {
|
||||
return device.android() && _find('mobile');
|
||||
};
|
||||
|
||||
device.androidTablet = function() {
|
||||
return device.android() && !_find('mobile');
|
||||
};
|
||||
|
||||
device.blackberry = function() {
|
||||
return _find('blackberry') || _find('bb10') || _find('rim');
|
||||
};
|
||||
|
||||
device.blackberryPhone = function() {
|
||||
return device.blackberry() && !_find('tablet');
|
||||
};
|
||||
|
||||
device.blackberryTablet = function() {
|
||||
return device.blackberry() && _find('tablet');
|
||||
};
|
||||
|
||||
device.windows = function() {
|
||||
return _find('windows');
|
||||
};
|
||||
|
||||
device.windowsPhone = function() {
|
||||
return device.windows() && _find('phone');
|
||||
};
|
||||
|
||||
device.windowsTablet = function() {
|
||||
return device.windows() && (_find('touch') && !device.windowsPhone());
|
||||
};
|
||||
|
||||
device.fxos = function() {
|
||||
return (_find('(mobile;') || _find('(tablet;')) && _find('; rv:');
|
||||
};
|
||||
|
||||
device.fxosPhone = function() {
|
||||
return device.fxos() && _find('mobile');
|
||||
};
|
||||
|
||||
device.fxosTablet = function() {
|
||||
return device.fxos() && _find('tablet');
|
||||
};
|
||||
|
||||
device.meego = function() {
|
||||
return _find('meego');
|
||||
};
|
||||
|
||||
device.cordova = function() {
|
||||
return window.cordova && location.protocol === 'file:';
|
||||
};
|
||||
|
||||
device.nodeWebkit = function() {
|
||||
return typeof window.process === 'object';
|
||||
};
|
||||
|
||||
device.mobile = function() {
|
||||
return device.androidPhone() || device.iphone() || device.ipod() || device.windowsPhone() || device.blackberryPhone() || device.fxosPhone() || device.meego();
|
||||
};
|
||||
|
||||
device.tablet = function() {
|
||||
return device.ipad() || device.androidTablet() || device.blackberryTablet() || device.windowsTablet() || device.fxosTablet();
|
||||
};
|
||||
|
||||
device.desktop = function() {
|
||||
return !device.tablet() && !device.mobile();
|
||||
};
|
||||
|
||||
device.portrait = function() {
|
||||
return (window.innerHeight / window.innerWidth) > 1;
|
||||
};
|
||||
|
||||
device.landscape = function() {
|
||||
return (window.innerHeight / window.innerWidth) < 1;
|
||||
};
|
||||
|
||||
device.noConflict = function() {
|
||||
window.device = previousDevice;
|
||||
return this;
|
||||
};
|
||||
|
||||
_find = function(needle) {
|
||||
return _user_agent.indexOf(needle) !== -1;
|
||||
};
|
||||
|
||||
_hasClass = function(class_name) {
|
||||
var regex;
|
||||
regex = new RegExp(class_name, 'i');
|
||||
return _doc_element.className.match(regex);
|
||||
};
|
||||
|
||||
_addClass = function(class_name) {
|
||||
if (!_hasClass(class_name)) {
|
||||
return _doc_element.className += " " + class_name;
|
||||
}
|
||||
};
|
||||
|
||||
_removeClass = function(class_name) {
|
||||
if (_hasClass(class_name)) {
|
||||
return _doc_element.className = _doc_element.className.replace(class_name, "");
|
||||
}
|
||||
};
|
||||
|
||||
if (device.ios()) {
|
||||
if (device.ipad()) {
|
||||
_addClass("ios ipad tablet");
|
||||
} else if (device.iphone()) {
|
||||
_addClass("ios iphone mobile");
|
||||
} else if (device.ipod()) {
|
||||
_addClass("ios ipod mobile");
|
||||
}
|
||||
} else if (device.android()) {
|
||||
if (device.androidTablet()) {
|
||||
_addClass("android tablet");
|
||||
} else {
|
||||
_addClass("android mobile");
|
||||
}
|
||||
} else if (device.blackberry()) {
|
||||
if (device.blackberryTablet()) {
|
||||
_addClass("blackberry tablet");
|
||||
} else {
|
||||
_addClass("blackberry mobile");
|
||||
}
|
||||
} else if (device.windows()) {
|
||||
if (device.windowsTablet()) {
|
||||
_addClass("windows tablet");
|
||||
} else if (device.windowsPhone()) {
|
||||
_addClass("windows mobile");
|
||||
} else {
|
||||
_addClass("desktop");
|
||||
}
|
||||
} else if (device.fxos()) {
|
||||
if (device.fxosTablet()) {
|
||||
_addClass("fxos tablet");
|
||||
} else {
|
||||
_addClass("fxos mobile");
|
||||
}
|
||||
} else if (device.meego()) {
|
||||
_addClass("meego mobile");
|
||||
} else if (device.nodeWebkit()) {
|
||||
_addClass("node-webkit");
|
||||
} else {
|
||||
_addClass("desktop");
|
||||
}
|
||||
|
||||
if (device.cordova()) {
|
||||
_addClass("cordova");
|
||||
}
|
||||
|
||||
_handleOrientation = function() {
|
||||
if (device.landscape()) {
|
||||
_removeClass("portrait");
|
||||
return _addClass("landscape");
|
||||
} else {
|
||||
_removeClass("landscape");
|
||||
return _addClass("portrait");
|
||||
}
|
||||
};
|
||||
|
||||
_supports_orientation = "onorientationchange" in window;
|
||||
|
||||
_orientation_event = _supports_orientation ? "orientationchange" : "resize";
|
||||
|
||||
if (window.addEventListener) {
|
||||
window.addEventListener(_orientation_event, _handleOrientation, false);
|
||||
} else if (window.attachEvent) {
|
||||
window.attachEvent(_orientation_event, _handleOrientation);
|
||||
} else {
|
||||
window[_orientation_event] = _handleOrientation;
|
||||
}
|
||||
|
||||
_handleOrientation();
|
||||
|
||||
}).call(this);
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
/*! device.js 0.1.61 */
|
||||
(function(){var a,b,c,d,e,f,g,h,i,j;a=window.device,window.device={},c=window.document.documentElement,j=window.navigator.userAgent.toLowerCase(),device.ios=function(){return device.iphone()||device.ipod()||device.ipad()},device.iphone=function(){return d("iphone")},device.ipod=function(){return d("ipod")},device.ipad=function(){return d("ipad")},device.android=function(){return d("android")},device.androidPhone=function(){return device.android()&&d("mobile")},device.androidTablet=function(){return device.android()&&!d("mobile")},device.blackberry=function(){return d("blackberry")||d("bb10")||d("rim")},device.blackberryPhone=function(){return device.blackberry()&&!d("tablet")},device.blackberryTablet=function(){return device.blackberry()&&d("tablet")},device.windows=function(){return d("windows")},device.windowsPhone=function(){return device.windows()&&d("phone")},device.windowsTablet=function(){return device.windows()&&d("touch")&&!device.windowsPhone()},device.fxos=function(){return(d("(mobile;")||d("(tablet;"))&&d("; rv:")},device.fxosPhone=function(){return device.fxos()&&d("mobile")},device.fxosTablet=function(){return device.fxos()&&d("tablet")},device.meego=function(){return d("meego")},device.cordova=function(){return window.cordova&&"file:"===location.protocol},device.nodeWebkit=function(){return"object"==typeof window.process},device.mobile=function(){return device.androidPhone()||device.iphone()||device.ipod()||device.windowsPhone()||device.blackberryPhone()||device.fxosPhone()||device.meego()},device.tablet=function(){return device.ipad()||device.androidTablet()||device.blackberryTablet()||device.windowsTablet()||device.fxosTablet()},device.desktop=function(){return!device.tablet()&&!device.mobile()},device.portrait=function(){return window.innerHeight/window.innerWidth>1},device.landscape=function(){return window.innerHeight/window.innerWidth<1},device.noConflict=function(){return window.device=a,this},d=function(a){return-1!==j.indexOf(a)},f=function(a){var b;return b=new RegExp(a,"i"),c.className.match(b)},b=function(a){return f(a)?void 0:c.className+=" "+a},h=function(a){return f(a)?c.className=c.className.replace(a,""):void 0},device.ios()?device.ipad()?b("ios ipad tablet"):device.iphone()?b("ios iphone mobile"):device.ipod()&&b("ios ipod mobile"):b(device.android()?device.androidTablet()?"android tablet":"android mobile":device.blackberry()?device.blackberryTablet()?"blackberry tablet":"blackberry mobile":device.windows()?device.windowsTablet()?"windows tablet":device.windowsPhone()?"windows mobile":"desktop":device.fxos()?device.fxosTablet()?"fxos tablet":"fxos mobile":device.meego()?"meego mobile":device.nodeWebkit()?"node-webkit":"desktop"),device.cordova()&&b("cordova"),e=function(){return device.landscape()?(h("portrait"),b("landscape")):(h("landscape"),b("portrait"))},i="onorientationchange"in window,g=i?"orientationchange":"resize",window.addEventListener?window.addEventListener(g,e,!1):window.attachEvent?window.attachEvent(g,e):window[g]=e,e()}).call(this);
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "device.js",
|
||||
"filename": "device.min.js",
|
||||
"version": "0.1.59",
|
||||
"version": "0.1.61",
|
||||
"homepage": "https://github.com/matthewhudson/device.js",
|
||||
"description": "Device.js makes it easy to write conditional CSS _and/or_ JavaScript based on device operating system (iOS, Android, Blackberry, Windows, Firefox OS, MeeGo), orientation (Portrait vs. Landscape), and type (Tablet vs. Mobile).",
|
||||
"author": {
|
||||
|
||||
Reference in New Issue
Block a user