Skip to content

Latest commit

 

History

History
193 lines (160 loc) · 3.82 KB

README.markdown

File metadata and controls

193 lines (160 loc) · 3.82 KB

Device.js makes it easy for you to write Conditional CSS and JavaScript based on device operating system (iOS, Android, Blackberry), orientation (Portrait vs. Landscape), and type (Tablet vs. Mobile).

View the Demo

EXAMPLES

Device.js inserts CSS classes into the <html> element.

iPhone

Android Tablet

Blackberry Tablet

USAGE

Just include the script. The script then updates the <html> section with the appropriate classes based on the device's characteristics.

<script src="device.js"></script>

CONDITIONAL CSS

The following tables map which CSS classes are added based on device and orientation.

Device CSS Class Names

Device CSS Classes
iPad ios ipad tablet
iPhone ios iphone mobile
iPod ios ipod mobile
Android Phone android mobile
Android Tablet android tablet
BlackBerry Phone blackberry mobile
BlackBerry Tablet blackberry tablet
Windows Phone windows mobile
Windows Tablet (no support)
Desktop desktop

Orientation CSS Class Names

Orientation CSS Classes
Landscape landscape
Portrait portrait

CONDITIONAL JAVASCRIPT

Device.js also includes support for conditional JavaScript, allowing you to write checks on the following device characteristics:

Device JavaScript Methods

Device JavaScript Method
iPad device.ipad()
iPhone device.iphone()
iPod device.ipod()
Android device.android()
Android Phone device.androidPhone()
Android Tablet device.androidTablet()
BlackBerry device.blackberry()
BlackBerry Phone device.blackberryPhone()
BlackBerry Tablet device.blackberryTablet()
Windows Phone device.windowsPhone()
Windows Tablet (no support)

Orientation JavaScript Methods

Orientation JavaScript Method
Landscape device.landscape()
Portrait device.portrait()

TODO

  • Add UserAgent sniffing for edge cases.
  • Add fallback in case "orientation" event doesn't exist.

DEVICE SUPPORT

  • iOS: iPhone, iPod, iPad
  • Android: Phones & Tablets
  • Blackberry: Phones & Tablets
  • Windows Phone (no Windows Tablet support yet)

SUGGESTIONS

All comments in how to improve this library are very welcome. Feel free post suggestions to the Issue tracker, or even better, fork the repository to implement your own ideas and submit a pull request.

LICENSE

Unless attributed otherwise, everything is under the MIT License (see LICENSE for more info).