Pārlūkot izejas kodu

New namespace Lungo.Device

soyjavi 13 gadi atpakaļ
vecāks
revīzija
89ffcb14eb

+ 55 - 0
src/device/Lungo.Device.Audio.js

@@ -0,0 +1,55 @@
+ /**
+ * Audio API (HTML5 Feature)
+ * Pending to final SPEC, now it's a Phonegap Wrapper
+ *
+ *
+ * @namespace LUNGO.Device
+ * @class Audio
+ *
+ * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
+ */
+
+LUNGO.Device.Audio = (function(lng, undefined) {
+    var _background = document.createElement('audio');
+    var _sound = document.createElement('audio');
+
+    /**
+    * Plays music in background with automatic rewind.
+    *
+    * @method background
+    *
+    * @param  {string} Source of sound file
+     */
+    var background = function(source) {
+        if (source) {
+            _setSourceAndPlay(_sound, source);
+            _background.addEventListener('ended', function(){
+                this.currentTime = 0;
+            }, false);
+        }
+        else {
+            _background.pause();
+        }
+    };
+
+    /**
+    * Play a given sound
+    *
+    * @method play
+    *
+    * @param  {string} Source of sound file
+     */
+    var play = function(source) {
+        _setSourceAndPlay(_sound, source);
+    };
+
+    _setSourceAndPlay = function(container, source) {
+        container.setAttribute('src', source);
+        container.play();
+    };
+
+    return {
+        background: background,
+        play: play
+    }
+})(LUNGO);

+ 17 - 0
src/device/Lungo.Device.Camera.js

@@ -0,0 +1,17 @@
+/**
+ * Camera API (HTML5 Feature)
+ * Pending to final SPEC, now it's a Phonegap Wrapper
+ *
+ * @namespace LUNGO.Device
+ * @class Camera
+ *
+ * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
+ */
+
+LUNGO.Device.Camera = (function(lng, undefined) {
+
+    return {
+
+    };
+
+})(LUNGO);

+ 16 - 0
src/device/Lungo.Device.Connection.js

@@ -0,0 +1,16 @@
+/**
+ * Connection API (HTML5 Feature)
+ *
+ * @namespace LUNGO.Device
+ * @class Connection
+ *
+ * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
+ */
+
+LUNGO.Device.Connection = (function(lng, undefined) {
+
+    return {
+
+    };
+
+})(LUNGO);

+ 18 - 0
src/device/Lungo.Device.Contacts.js

@@ -0,0 +1,18 @@
+/**
+ * Contacts API (HTML5 Feature)
+ * Pending to final SPEC, now it's a Phonegap Wrapper
+ * http://www.w3.org/TR/contacts-api/
+ *
+ * @namespace LUNGO.Device
+ * @class Contacts
+ *
+ * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
+ */
+
+LUNGO.Device.Contacts = (function(lng, undefined) {
+
+    return {
+
+    };
+
+})(LUNGO);

+ 130 - 0
src/device/Lungo.Device.Gps.js

@@ -0,0 +1,130 @@
+/**
+ * Geolocation API (HTML5 Feature)
+ * Pending to final SPEC, now it's a Phonegap Wrapper
+ * http://www.w3.org/TR/geolocation-API/
+ *
+ * @namespace LUNGO.Device
+ * @class Gps
+ *
+ * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
+ */
+
+LUNGO.Device.Gps = (function(lng, undefined) {
+
+    var _position = null;
+    var _watcher = null;
+
+    var CALLBACK = {
+        success: null,
+        error: null
+    };
+
+    var GPS_OPTIONS = {
+        enableHighAccuracy: false,
+        timeout: 10000,
+        maximumAge: 60000
+    };
+
+    /**
+     * @ToDo
+     *
+     * @method get
+     *
+     * @param {Function} Callback
+     */
+    var get = function(callbacks, options) {
+        if (_isReady()) {
+            _bindCallbacks(callbacks);
+            navigator.geolocation.getCurrentPosition(_success, _error, options);
+        }
+    };
+
+    /**
+     * @ToDo
+     *
+     * @method get
+     *
+     * @param {Function} @ToDo
+     * @param {object} @ToDo
+     */
+    var watch = function(callbacks, options) {
+        if (_isReady()) {
+            _bindCallbacks(callbacks);
+            _watcher = navigator.geolocation.watchPosition(_success, _error, options);
+        }
+    };
+
+    /**
+     * @ToDo
+     *
+     * @method position
+     *
+     */
+    var position = function() {
+        return _position;
+    };
+
+    /**
+     * @ToDo
+     *
+     * @method clear
+     */
+    var stop = function() {
+        _clearPosition();
+    };
+
+    /**
+     * Console system to display messages when you are in debug mode.
+     *
+     * @method log
+     *
+     * @param {number} Severity based in (1)Log, (2)Warn, (>2)Error
+     * @param {string} Message to show in console
+     */
+    var address = function(latitude, longitude, callback) {
+        // @ToDo: Check Social Analytics RESTful
+    };
+
+    var _isReady = function() {
+        if (navigator.geolocation) {
+            _clearPosition();
+            return true;
+        } else {
+            lng.core.log(3, 'Lungo.Device.Gps [ERROR]: navigator.geolocation is innacesible.')
+            return false;
+        }
+    };
+
+    var _clearPosition = function() {
+        _position = null;
+
+        if (_watcher) {
+            navigator.geolocation.clearWatch(_watcher);
+            _watcher = null;
+        }
+    };
+
+    var _bindCallbacks = function(callbacks) {
+        CALLBACK.success = (callbacks.success || null);
+        CALLBACK.error = (callbacks.error || null);
+    };
+
+    var _success = function(position) {
+        _position = position.coords;
+        CALLBACK.success.call(CALLBACK.success, position);
+    };
+
+    var _error = function(error) {
+        _clearPosition();
+        CALLBACK.error.call(CALLBACK.error, error);
+    };
+
+    return {
+        get: get,
+        watch: watch,
+        position: position,
+        address: address,
+        stop: stop
+    }
+
+})(LUNGO);

+ 70 - 0
src/device/Lungo.Device.Notification.js

@@ -0,0 +1,70 @@
+/**
+ * Notifacion API (HTML5 Feature)
+ * Pending to final SPEC, now it's a Phonegap Wrapper
+ *
+ * @namespace LUNGO.Device
+ * @class Notification
+ *
+ * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
+ */
+
+LUNGO.Device.Notification = (function(lng, undefined) {
+
+    /**
+     * Shows a custom alert or dialog box.
+     *
+     * @method alert
+     *
+     * @param {string} Dialog message
+     * @param {Function} Callback to invoke when alert dialog is dismissed.
+     * @param {string} Dialog title (Optional, Default: "Alert")
+     * @param {string} Button name (Optional, Default: "OK")
+     */
+    var alert = function(message, callback, title, buttonName) {
+        navigator.notification.alert(message, callback, title, buttonName)
+    };
+
+    /**
+     * Shows a customizable confirmation dialog box.
+     *
+     * @method confirm
+     *
+     * @param {string} Dialog message @ToDo
+     * @param {function} Callback to invoke with index of button pressed (1, 2 or 3).
+     * @param {string} Dialog title (Optional, Default: "Confirm")
+     * @param {string} Comma separated string with button labels (Optional, Default: "OK,Cancel")
+     */
+    var confirm = function(message, callback, title, buttonLabels) {
+        navigator.notification.confirm(message, callback, title, buttonLabels)
+    };
+
+    /**
+     * The device will play a beep sound.
+     *
+     * @method beep
+     *
+     * @param {number} The number of times to repeat the beep
+     */
+    var beep = function(times) {
+        navigator.notification.beep(times)
+    };
+
+    /**
+     * Vibrates the device for the specified amount of time.
+     *
+     * @method vibrate
+     *
+     * @param {number} Milliseconds to vibrate the device. 1000 milliseconds equals 1 second
+     */
+    var vibrate = function(milliseconds) {
+        navigator.notification.vibrate(milliseconds)
+    };
+
+    return {
+        alert: alert,
+        confirm: confirm,
+        beep: beep,
+        vibrate: vibrate
+    };
+
+})(LUNGO);

+ 46 - 0
src/device/Lungo.Device.Orientation.js

@@ -0,0 +1,46 @@
+/**
+ * Orientation Events API (HTML5 Feature)
+ * DOM events that provide information about the physical orientation and
+ * motion of a hosting device.
+ * http://www.w3.org/TR/orientation-event/
+ *
+ * @namespace LUNGO.Device
+ * @class Camera
+ *
+ * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
+ */
+
+LUNGO.Device.Orientation = (function(lng, undefined) {
+
+    var EVENTS = {
+        ORIENTATION: 'deviceorientation',
+        MOTION: 'devicemotion',
+        COMPASS_CALIBRATION: 'compassneedscalibration'
+    };
+
+    var onChange = function(callback) {
+        _addEvent(EVENTS.ORIENTATION, callback);
+    };
+
+    var onMotion = function(callback) {
+        _addEvent(EVENTS.MOTION, callback);
+    };
+
+    var onNeedsCalibration = function(callback) {
+        _addEvent(EVENTS.COMPASS_CALIBRATION, callback);
+    };
+
+    var _addEvent = function(event, callback) {
+        //@todo: Cross-browser: IE fix
+        window.addEventListener(event, function(event) {
+            callback.apply(callback, event);
+        }, true);
+    };
+
+    return {
+        onChange: onChange,
+        onMotion: onMotion,
+        onNeedsCalibration: onNeedsCalibration
+    };
+
+})(LUNGO);