From c506133c64a61b5565ac36a649837250e9be97c1 Mon Sep 17 00:00:00 2001 From: David Douglas Date: Tue, 15 Mar 2016 16:49:32 +0000 Subject: [PATCH] Updates for PR #129 --- .gitignore | 6 +- app/jxcore/app.js | 1 - app/jxcore/hook.js | 1 + .../elements/behaviors/tree-traversing.html | 34 +++++----- .../elements/page-editor/page-editor.html | 12 +--- app/jxcore/public/elements/routing.html | 2 +- app/jxcore/public/index.html | 2 +- app/jxcore/routes/_api.js | 5 +- app/jxcore/routes/mockwebview.js | 4 +- test/helpers/appium-servers.js | 2 + test/helpers/caps.js | 2 + test/helpers/defaults.js | 2 +- test/helpers/logging.js | 2 + test/helpers/setup.js | 2 + test/helpers/webview.js | 2 +- test/postcardapp.js | 2 +- www/js/index.js | 67 +------------------ 17 files changed, 42 insertions(+), 106 deletions(-) diff --git a/.gitignore b/.gitignore index 35d648f..d92031e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ # Logs logs *.log +npm-debug.log # Runtime data pids @@ -27,8 +28,9 @@ build/Release node_modules bower_components -# Intellij and Android -.idea/ +# IDEs +.idea +.vscode # VS Code .settings/ diff --git a/app/jxcore/app.js b/app/jxcore/app.js index 7f28bbb..604bd1d 100644 --- a/app/jxcore/app.js +++ b/app/jxcore/app.js @@ -1,5 +1,4 @@ 'use strict'; // This JavaScript file runs on JXcore -/*jshint esnext: true */ /*global Mobile */ var fs = require('fs'); diff --git a/app/jxcore/hook.js b/app/jxcore/hook.js index 2453988..d2aa38e 100755 --- a/app/jxcore/hook.js +++ b/app/jxcore/hook.js @@ -1,4 +1,5 @@ #!/usr/bin/env node +'use strict'; // Cordova hook script used to trigger gulp scripts module.exports = function(context) { var Q = context.requireCordovaModule('q'); diff --git a/app/jxcore/public/elements/behaviors/tree-traversing.html b/app/jxcore/public/elements/behaviors/tree-traversing.html index 9644a4a..1a28968 100644 --- a/app/jxcore/public/elements/behaviors/tree-traversing.html +++ b/app/jxcore/public/elements/behaviors/tree-traversing.html @@ -3,7 +3,7 @@ var PageBehaviors = PageBehaviors || {}; // namespace /* - * This behaviour helps to traverse dom tree. + * This behaviour helps to traverse dom tree. */ PageBehaviors.TreeTraversing = { @@ -25,22 +25,22 @@ break; case '.': parentSelector = parentSelector.substr(1); - matchTest = this._hasClass; - break; - case '[': - parentSelector = parentSelector.slice(1,-1); - matchTest = this._hasAttribute; - break; - default: - parentSelector = parentSelector.toLowerCase(); - matchTest = this._hasTag; - } + matchTest = this._hasClass; + break; + case '[': + parentSelector = parentSelector.slice(1,-1); + matchTest = this._hasAttribute; + break; + default: + parentSelector = parentSelector.toLowerCase(); + matchTest = this._hasTag; + } for (; element && element !== document ; element = element.parentElement) { - if( matchTest(element, parentSelector) ) { - return element; - } - } - return false; + if( matchTest(element, parentSelector) ) { + return element; + } + } + return false; }, _hasId : function (element, selector) { @@ -57,4 +57,4 @@ }, }; - \ No newline at end of file + diff --git a/app/jxcore/public/elements/page-editor/page-editor.html b/app/jxcore/public/elements/page-editor/page-editor.html index f25fa18..1ad904f 100644 --- a/app/jxcore/public/elements/page-editor/page-editor.html +++ b/app/jxcore/public/elements/page-editor/page-editor.html @@ -69,11 +69,6 @@ }, isEdit: false }, - listeners: { - 'camera-success': 'onCameraSuccess', - 'camera-error': 'onCameraError', - 'contact-changed': 'contactChangedHandler' - }, created: function() { console.log(this.localName + ' was created'); }, @@ -160,11 +155,7 @@ } }, - // Note: - // Cordova functions cannot be called directly from inside an iframe. - // On mobile the Cordova webview origin is file:// - // but the origin of iframe running JXcore Express app is http://localhost - // Cordova functions are therefore triggered using Cross Origin Messaging. + // Cordova Camera function _cameraButtonHandler: function(e) { var options = { quality: 80, @@ -211,7 +202,6 @@ if (typeof imageData !== 'undefined') { // NB: insert the base64 image tag for displaying PouchDB image attachments return "data:image/jpeg;base64," + imageData; - //return this.imageDataToImageSource(imageData); } return "data:image/gif;base64," + "R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"; diff --git a/app/jxcore/public/elements/routing.html b/app/jxcore/public/elements/routing.html index 3e9d42f..b258c35 100644 --- a/app/jxcore/public/elements/routing.html +++ b/app/jxcore/public/elements/routing.html @@ -13,7 +13,7 @@ function hasSession() { console.log("session username:" + myApp.username); - if (myApp.username && myApp.username.length > 0) { + if (myApp.username) { return true; } else { return false; diff --git a/app/jxcore/public/index.html b/app/jxcore/public/index.html index 0263c99..ce71872 100644 --- a/app/jxcore/public/index.html +++ b/app/jxcore/public/index.html @@ -3,7 +3,7 @@ - + diff --git a/app/jxcore/routes/_api.js b/app/jxcore/routes/_api.js index 68f572a..43c1664 100644 --- a/app/jxcore/routes/_api.js +++ b/app/jxcore/routes/_api.js @@ -8,15 +8,14 @@ function addressBookRoutes (db) { router.route('/login').post(function(req, res) { res.setHeader('Content-Type', 'application/json'); // form validation - if (typeof req.body.username === 'undefined' || - typeof req.body.deviceIdentity === 'undefined') { + if (req.body.username == null || req.body.deviceIdentity == null) { res.status(400).json({ error: 'User identity is undefined' }); return; } // user input validation var username = req.body.username.trim(); var deviceIdentity = req.body.deviceIdentity.trim(); - if (username.length <= 0 || deviceIdentity.length <= 0) { + if (username.length == 0 || deviceIdentity.length == 0) { res.status(400).json({ error: 'User identity is required' }); return; } diff --git a/app/jxcore/routes/mockwebview.js b/app/jxcore/routes/mockwebview.js index d510a42..6a14886 100644 --- a/app/jxcore/routes/mockwebview.js +++ b/app/jxcore/routes/mockwebview.js @@ -2,7 +2,7 @@ var express = require('express'); var faker = require('faker'); -// this is a mock API to start testing ajax calls from UI +// this is a mock API for localhost development to test Identity Exchange UI function mockWebviewRoutes () { var api = express.Router(); @@ -23,7 +23,7 @@ function mockWebviewRoutes () { if (x>0) { console.log("lost "+x+" peers"); while (x--) { - pollingData.peers.splice( Math.floor( + pollingData.peers.splice( Math.floor( Math.random()*pollingData.peers.length), 1); } } diff --git a/test/helpers/appium-servers.js b/test/helpers/appium-servers.js index 403cdd1..21cc0c1 100644 --- a/test/helpers/appium-servers.js +++ b/test/helpers/appium-servers.js @@ -1,3 +1,5 @@ +'use strict'; + exports.local = { host: 'localhost', port: 4723 diff --git a/test/helpers/caps.js b/test/helpers/caps.js index 3c9ab8f..238e7ad 100644 --- a/test/helpers/caps.js +++ b/test/helpers/caps.js @@ -1,3 +1,5 @@ +'use strict'; + var path = require("path"); exports.iosSimulator = { diff --git a/test/helpers/defaults.js b/test/helpers/defaults.js index 2fb7ad7..dd8aaeb 100644 --- a/test/helpers/defaults.js +++ b/test/helpers/defaults.js @@ -1,4 +1,4 @@ -"use strict"; +'use strict'; module.exports = { wait : { diff --git a/test/helpers/logging.js b/test/helpers/logging.js index 1906014..ce1e5cb 100644 --- a/test/helpers/logging.js +++ b/test/helpers/logging.js @@ -1,3 +1,5 @@ +'use strict'; + exports.configure = function (driver) { // See whats going on driver.on('status', function (info) { diff --git a/test/helpers/setup.js b/test/helpers/setup.js index 7275a68..972c1cc 100644 --- a/test/helpers/setup.js +++ b/test/helpers/setup.js @@ -1,3 +1,5 @@ +'use strict'; + var wd = require("wd"); require('colors'); diff --git a/test/helpers/webview.js b/test/helpers/webview.js index 8d331c5..3947f99 100644 --- a/test/helpers/webview.js +++ b/test/helpers/webview.js @@ -1,4 +1,4 @@ -"use strict"; +'use strict'; var asserters = require("wd").asserters, defaults = require("./defaults"); diff --git a/test/postcardapp.js b/test/postcardapp.js index 3066d7a..2172877 100644 --- a/test/postcardapp.js +++ b/test/postcardapp.js @@ -1,4 +1,4 @@ -"use strict"; +'use strict'; if (!require('fs').existsSync(__dirname+"/node_modules")) { console.log("'node_modules' folder not found. Please refer to readme.md"); diff --git a/www/js/index.js b/www/js/index.js index 0f9ab3d..b447328 100644 --- a/www/js/index.js +++ b/www/js/index.js @@ -23,17 +23,12 @@ var inter = setInterval(function() { alert(JSON.stringify(err)); } else { log('jxcore_ready'); - jxcore_ready(); + isJXcoreReady = true; } }); }); }, 5); -function jxcore_ready() { - isJXcoreReady = true; - //document.getElementById('appFrame').src = HOST; -} - function registerCordovaFunctions() { jxcore('log').register(log); } @@ -43,7 +38,7 @@ function log(x) { } // ----------------------------------------------------------------------------- -// Handle Cordova iframe events +// Cordova redirect to localhost // ----------------------------------------------------------------------------- // Cordova ready @@ -64,61 +59,3 @@ var inter2 = setInterval(function(){ console.log("Cordova and JXCore are both ready. Redirect to:", HOST); window.location.href = HOST; }, 5); - -// Listen for messages posted from iframe -window.addEventListener('message', receiveMessage, false); - -// Handle cross orgin message -var contentWindow; -function receiveMessage(event) { - console.log('webview received message'); - - if (event.origin !== HOST) { - console.log("Access denied :("); - return; - } - - // retain reference to the (iframe) window object that sent the message - contentWindow = event.source; - - if (!isCordovaReady) { - console.log("Error, Cordova not ready!"); - return; - } - - var msg = event.data; - if (msg.action === 'navigator.camera.getPicture') { - getPicture(msg.options); - } -} - -function getPicture(options) { - var quality = (options.quality || 80), - targetWidth = (options.targetWidth || 1080), - targetHeight = (options.targetHeight || 720); - var cameraOptions = { - quality: quality, - targetWidth: targetWidth, - targetHeight: targetHeight, - encodingType: Camera.EncodingType.JPEG, - correctOrientation: true, - saveToPhotoAlbum: false, - allowEdit: false, - destinationType: Camera.DestinationType.DATA_URL - }; - console.log("getPicture", options, cameraOptions); - // DATA_URL returns image as base64 encoded string - navigator.camera.getPicture( cameraSuccess, cameraFail, cameraOptions); -} - -function cameraSuccess(imageData) { - console.log("cameraSuccess"); - // post message back to iframe - contentWindow.postMessage( {image:imageData}, "*"); // HOST -} - -function cameraFail(message) { - console.log("cameraFail"); - // post message back to iframe - contentWindow.postMessage( {error:message}, "*"); // HOST -}