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