Book Image

CoffeeScript Application Development Cookbook

By : Mike Hatfield
Book Image

CoffeeScript Application Development Cookbook

By: Mike Hatfield

Overview of this book

Table of Contents (18 chapters)
CoffeeScript Application Development Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Getting device information


It is sometimes helpful to have specific information about the user's device. Cordova provides a device object that provides such information.

Getting ready

To retrieve device information, we must install the device plugin with the following command:

cordova plugin add org.apache.cordova.device

How to do it...

To get device information, follow these steps:

  1. Add the following HTML to index.html:

    <div data-role="view" id="app-device" 
      data-title="Contacts"
      data-layout="layout">
      <h3>Device Information</h3>
      <p>
        <a data-role="button"
          data-click="app.demos.device.onFetchInfo">
          Fetch Device Info</a>
      </p>
      <ul id="device-info" data-role="listview"
        data-style="inset" style="display: none;">
      </ul>
    </div>
  2. Create a file named coffee/device.coffee with the following code:

    $deviceInfo =   $('#device-info')
    
    onFetchInfo = ->
      $deviceInfo.empty()
      $deviceInfo.append "<li>Name: #{device...