Skip to content
This repository has been archived by the owner on Jan 15, 2021. It is now read-only.

Commit

Permalink
Updates for PR #129
Browse files Browse the repository at this point in the history
  • Loading branch information
deadlyfingers committed Mar 15, 2016
1 parent 299c38e commit c506133
Show file tree
Hide file tree
Showing 17 changed files with 42 additions and 106 deletions.
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Logs
logs
*.log
npm-debug.log

# Runtime data
pids
Expand All @@ -27,8 +28,9 @@ build/Release
node_modules
bower_components

# Intellij and Android
.idea/
# IDEs
.idea
.vscode

# VS Code
.settings/
Expand Down
1 change: 0 additions & 1 deletion app/jxcore/app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
'use strict'; // This JavaScript file runs on JXcore
/*jshint esnext: true */
/*global Mobile */

var fs = require('fs');
Expand Down
1 change: 1 addition & 0 deletions app/jxcore/hook.js
Original file line number Diff line number Diff line change
@@ -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');
Expand Down
34 changes: 17 additions & 17 deletions app/jxcore/public/elements/behaviors/tree-traversing.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
var PageBehaviors = PageBehaviors || {}; // namespace

/*
* This behaviour helps to traverse dom tree.
* This behaviour helps to traverse dom tree.
*/

PageBehaviors.TreeTraversing = {
Expand All @@ -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) {
Expand All @@ -57,4 +57,4 @@
},

};
</script>
</script>
12 changes: 1 addition & 11 deletions app/jxcore/public/elements/page-editor/page-editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,6 @@
},
isEdit: false
},
listeners: {
'camera-success': 'onCameraSuccess',
'camera-error': 'onCameraError',
'contact-changed': 'contactChangedHandler'
},
created: function() {
console.log(this.localName + ' was created');
},
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion app/jxcore/public/elements/routing.html
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion app/jxcore/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; img-src 'self' data: blob: filesystem:;">
<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval' data:; img-src 'self' data: blob: filesystem:;">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0">
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-capable" content="yes">
Expand Down
5 changes: 2 additions & 3 deletions app/jxcore/routes/_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions app/jxcore/routes/mockwebview.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
}
}
Expand Down
2 changes: 2 additions & 0 deletions test/helpers/appium-servers.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

exports.local = {
host: 'localhost',
port: 4723
Expand Down
2 changes: 2 additions & 0 deletions test/helpers/caps.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

var path = require("path");

exports.iosSimulator = {
Expand Down
2 changes: 1 addition & 1 deletion test/helpers/defaults.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"use strict";
'use strict';

module.exports = {
wait : {
Expand Down
2 changes: 2 additions & 0 deletions test/helpers/logging.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

exports.configure = function (driver) {
// See whats going on
driver.on('status', function (info) {
Expand Down
2 changes: 2 additions & 0 deletions test/helpers/setup.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

var wd = require("wd");

require('colors');
Expand Down
2 changes: 1 addition & 1 deletion test/helpers/webview.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"use strict";
'use strict';

var asserters = require("wd").asserters,
defaults = require("./defaults");
Expand Down
2 changes: 1 addition & 1 deletion test/postcardapp.js
Original file line number Diff line number Diff line change
@@ -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");
Expand Down
67 changes: 2 additions & 65 deletions www/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -43,7 +38,7 @@ function log(x) {
}

// -----------------------------------------------------------------------------
// Handle Cordova iframe events
// Cordova redirect to localhost
// -----------------------------------------------------------------------------

// Cordova ready
Expand All @@ -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
}

0 comments on commit c506133

Please sign in to comment.