Repository: cordova-plugin-device Updated Branches: refs/heads/master d5a8ac46e -> 03ccd33ed
Added plugin support for the browser Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-device/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-device/commit/6ce0fdfe Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-device/tree/6ce0fdfe Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-device/diff/6ce0fdfe Branch: refs/heads/master Commit: 6ce0fdfe4d94871644a8e3d1862defac69d1062a Parents: ae3f2ed Author: Suraj Pindoria <suraj.pindo...@yahoo.com> Authored: Thu Aug 21 13:48:27 2014 -0700 Committer: Suraj Pindoria <suraj.pindo...@yahoo.com> Committed: Wed Aug 27 13:30:53 2014 -0700 ---------------------------------------------------------------------- doc/index.md | 10 ++++++ plugin.xml | 13 +++++++ src/browser/DeviceProxy.js | 78 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 101 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-plugin-device/blob/6ce0fdfe/doc/index.md ---------------------------------------------------------------------- diff --git a/doc/index.md b/doc/index.md index 9e5c677..3a6c6c2 100644 --- a/doc/index.md +++ b/doc/index.md @@ -49,6 +49,7 @@ Get the version of Cordova running on the device. - Amazon Fire OS - Android - BlackBerry 10 +- Browser - Firefox OS - iOS - Tizen @@ -65,6 +66,7 @@ different across versions of the same product. - Android - BlackBerry 10 +- Browser - iOS - Tizen - Windows Phone 7 and 8 @@ -75,6 +77,8 @@ different across versions of the same product. // Android: Nexus One returns "Passion" (Nexus One code name) // Motorola Droid returns "voles" // BlackBerry: Torch 9800 returns "9800" + // Browser: Google Chrome returns "Chrome" + // Safari returns "Safari" // iOS: for the iPad Mini, returns iPad2,5; iPhone 5 is iPhone 5,1. See http://theiphonewiki.com/wiki/index.php?title=Models // var model = device.model; @@ -105,6 +109,7 @@ Get the device's operating system name. - Android - BlackBerry 10 +- Browser4 - Firefox OS - iOS - Tizen @@ -116,6 +121,8 @@ Get the device's operating system name. // Depending on the device, a few examples are: // - "Android" // - "BlackBerry 10" + // - Browser: returns "MacIntel" on Mac + // returns "Win32" on Windows // - "iOS" // - "WinCE" // - "Tizen" @@ -192,6 +199,7 @@ Get the operating system version. - Android 2.1+ - BlackBerry 10 +- Browser - iOS - Tizen - Windows Phone 7 and 8 @@ -205,6 +213,8 @@ Get the operating system version. // // BlackBerry: Torch 9800 using OS 6.0 would return "6.0.0.600" // + // Browser: Returns version number for the browser + // // iPhone: iOS 3.2 returns "3.2" // // Windows Phone 7: returns current OS version number, ex. on Mango returns 7.10.7720 http://git-wip-us.apache.org/repos/asf/cordova-plugin-device/blob/6ce0fdfe/plugin.xml ---------------------------------------------------------------------- diff --git a/plugin.xml b/plugin.xml index fd8bdc5..1e36d6c 100644 --- a/plugin.xml +++ b/plugin.xml @@ -152,4 +152,17 @@ </js-module> </platform> + <!-- browser --> + <platform name="browser"> + <config-file target="config.xml" parent="/*"> + <feature name="Device"> + <param name="browser-package" value="Device" /> + </feature> + </config-file> + + <js-module src="src/browser/DeviceProxy.js" name="DeviceProxy"> + <runs /> + </js-module> + </platform> + </plugin> http://git-wip-us.apache.org/repos/asf/cordova-plugin-device/blob/6ce0fdfe/src/browser/DeviceProxy.js ---------------------------------------------------------------------- diff --git a/src/browser/DeviceProxy.js b/src/browser/DeviceProxy.js new file mode 100644 index 0000000..45e1d88 --- /dev/null +++ b/src/browser/DeviceProxy.js @@ -0,0 +1,78 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +var browser = require('cordova/platform'); +var cordova = require('cordova'); + +function getPlatform() { + return navigator.platform; +} + +function getModel() { + return getBrowserInfo(true); +} + +function getVersion() { + return getBrowserInfo(false); +} + +function getBrowserInfo(getModel) { + var userAgent = navigator.userAgent; + var returnVal; + + if ((offset = userAgent.indexOf('Chrome')) !== -1) { + returnVal = (getModel) ? 'Chrome' : userAgent.substring(offset + 7); + } else if ((offset = userAgent.indexOf('Safari')) !== -1) { + if (getModel) { + returnVal = 'Safari'; + } else { + returnVal = userAgent.substring(offset + 7); + + if ((offset = userAgent.indexOf('Version')) !== -1) { + returnVal = userAgent.substring(offset + 8); + } + } + } else if ((offset = userAgent.indexOf('Firefox')) !== -1) { + returnVal = (getModel) ? 'Firefox' : userAgent.substring(offset + 8); + } + + if ((offset = returnVal.indexOf(';')) !== -1 || (offset = returnVal.indexOf(' ')) !== -1) { + returnVal = returnVal.substring(0, offset); + } + + return returnVal; +} + + +module.exports = { + getDeviceInfo: function (success, error) { + setTimeout(function () { + success({ + cordova: browser.cordovaVersion, + platform: getPlatform(), + model: getModel(), + version: getVersion(), + uuid: null + }); + }, 0); + } +}; + +require("cordova/exec/proxy").add("Device", module.exports);