1(function() { 2 var _addClass, _doc_element, _find, _handleOrientation, _hasClass, _orientation_event, _removeClass, _supports_orientation, _user_agent; 3 4 window.device = {}; 5 6 _doc_element = window.document.documentElement; 7 8 _user_agent = window.navigator.userAgent.toLowerCase(); 9 10 device.ios = function() { 11 return device.iphone() || device.ipod() || device.ipad(); 12 }; 13 14 device.iphone = function() { 15 return _find('iphone'); 16 }; 17 18 device.ipod = function() { 19 return _find('ipod'); 20 }; 21 22 device.ipad = function() { 23 return _find('ipad'); 24 }; 25 26 device.android = function() { 27 return _find('android'); 28 }; 29 30 device.androidPhone = function() { 31 return device.android() && _find('mobile'); 32 }; 33 34 device.androidTablet = function() { 35 return device.android() && !_find('mobile'); 36 }; 37 38 device.blackberry = function() { 39 return _find('blackberry') || _find('bb10') || _find('rim'); 40 }; 41 42 device.blackberryPhone = function() { 43 return device.blackberry() && !_find('tablet'); 44 }; 45 46 device.blackberryTablet = function() { 47 return device.blackberry() && _find('tablet'); 48 }; 49 50 device.windows = function() { 51 return _find('windows'); 52 }; 53 54 device.windowsPhone = function() { 55 return device.windows() && _find('phone'); 56 }; 57 58 device.windowsTablet = function() { 59 return device.windows() && _find('touch'); 60 }; 61 62 device.fxos = function() { 63 return _find('(mobile; rv:') || _find('(tablet; rv:'); 64 }; 65 66 device.fxosPhone = function() { 67 return device.fxos() && _find('mobile'); 68 }; 69 70 device.fxosTablet = function() { 71 return device.fxos() && _find('tablet'); 72 }; 73 74 device.mobile = function() { 75 return device.androidPhone() || device.iphone() || device.ipod() || device.windowsPhone() || device.blackberryPhone() || device.fxosPhone(); 76 }; 77 78 device.tablet = function() { 79 return device.ipad() || device.androidTablet() || device.blackberryTablet() || device.windowsTablet() || device.fxosTablet(); 80 }; 81 82 device.portrait = function() { 83 return Math.abs(window.orientation) !== 90; 84 }; 85 86 device.landscape = function() { 87 return Math.abs(window.orientation) === 90; 88 }; 89 90 _find = function(needle) { 91 return _user_agent.indexOf(needle) !== -1; 92 }; 93 94 _hasClass = function(class_name) { 95 var regex; 96 regex = new RegExp(class_name, 'i'); 97 return _doc_element.className.match(regex); 98 }; 99 100 _addClass = function(class_name) { 101 if (!_hasClass(class_name)) { 102 return _doc_element.className += " " + class_name; 103 } 104 }; 105 106 _removeClass = function(class_name) { 107 if (_hasClass(class_name)) { 108 return _doc_element.className = _doc_element.className.replace(class_name, ""); 109 } 110 }; 111 112 if (device.ios()) { 113 if (device.ipad()) { 114 _addClass("ios ipad tablet"); 115 } else if (device.iphone()) { 116 _addClass("ios iphone mobile"); 117 } else if (device.ipod()) { 118 _addClass("ios ipod mobile"); 119 } 120 } else if (device.android()) { 121 if (device.androidTablet()) { 122 _addClass("android tablet"); 123 } else { 124 _addClass("android mobile"); 125 } 126 } else if (device.blackberry()) { 127 if (device.blackberryTablet()) { 128 _addClass("blackberry tablet"); 129 } else { 130 _addClass("blackberry mobile"); 131 } 132 } else if (device.windows()) { 133 if (device.windowsTablet()) { 134 _addClass("windows tablet"); 135 } else if (device.windowsPhone()) { 136 _addClass("windows mobile"); 137 } else { 138 _addClass("desktop"); 139 } 140 } else if (device.fxos()) { 141 if (device.fxosTablet()) { 142 _addClass("fxos tablet"); 143 } else { 144 _addClass("fxos mobile"); 145 } 146 } else { 147 _addClass("desktop"); 148 } 149 150 _handleOrientation = function() { 151 if (device.landscape()) { 152 _removeClass("portrait"); 153 return _addClass("landscape"); 154 } else { 155 _removeClass("landscape"); 156 return _addClass("portrait"); 157 } 158 }; 159 160 _supports_orientation = "onorientationchange" in window; 161 162 _orientation_event = _supports_orientation ? "orientationchange" : "resize"; 163 164 if (window.addEventListener) { 165 window.addEventListener(_orientation_event, _handleOrientation, false); 166 } else if (window.attachEvent) { 167 window.attachEvent(_orientation_event, _handleOrientation); 168 } else { 169 window[_orientation_event] = _handleOrientation; 170 } 171 172 _handleOrientation(); 173 174}).call(this);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.