Skip to content

Commit ea13d5e

Browse files
committedAug 30, 2015
Initial commit
0 parents  commit ea13d5e

File tree

363 files changed

+30336
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

363 files changed

+30336
-0
lines changed
 

‎README.md

+121
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
**Creating basic JXCore application with angular**
2+
3+
Supposing you already have installed node package manager (npm), first step is to install cordova:
4+
5+
npm install -g cordova
6+
7+
Then create basic cordova application and name it "jxcore-tutorial-angular":
8+
9+
cordova create jxcore-tutorial-angular
10+
11+
Next step is to add jxcore plugin to project. Download an install JXcore: http://jxcore.com/downloads/. Then install `download-cli`:
12+
13+
npm install -g download-cli
14+
15+
Download jxcore-cordova binary into your Cordova/Phonegap project:
16+
17+
cd jxcore-tutorial-angular
18+
download https://github.com/jxcore/jxcore-cordova-release/raw/master/0.0.4/io.jxcore.node.jx
19+
20+
Extract it:
21+
22+
jx io.jxcore.node.jx
23+
24+
Add plugin:
25+
26+
cordova plugins add io.jxcore.node/
27+
28+
All html/js/css files are stored in `www` folder. When app is started, `www/index.html` file is displayed (you can change this from `config.xml`). Let's empty `www` folder and create new `index.html` file with following content:
29+
30+
<html>
31+
<head>
32+
<title>Hello Angular</title>
33+
</head>
34+
<body>
35+
<script type="text/javascript" src="cordova.js"></script>
36+
<script type="text/javascript" src="jxcore.js"></script>
37+
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.4/angular .min.js"></script>
38+
<script type="text/javascript" src="js/index.js"></script>
39+
</body>
40+
</html>
41+
42+
We have included all necessary libraries. Let's create `js/index.js` main file where we will run angular application:
43+
44+
// create main angular module
45+
var app = angular.module('app', []);
46+
47+
//...
48+
49+
// log notifications on interface
50+
function log(txt) {
51+
var el = document.createElement('div');
52+
el.textContent = txt;
53+
document.body.appendChild(el);
54+
}
55+
56+
// start angular after jxcore is ready
57+
(function check() {
58+
if (typeof jxcore === 'undefined') {
59+
setTimeout(check, 5);
60+
} else {
61+
jxcore('app.js').loadMainFile(function(ret, err) {
62+
if (err) {
63+
log(err);
64+
} else {
65+
angular.bootstrap(document, [app.name]);
66+
}
67+
});
68+
}
69+
})();
70+
71+
On the first line, we create angular module named "app" with empty dependency list. Then we wait for loading jxcore and after that initializing angular app. Now let's add logic to application, creating factory and controller:
72+
73+
Factory:
74+
75+
app.factory('jxcoreSrvc', ['$q', '$rootScope', function (q, rootScope) {
76+
return {
77+
callAsyncFunction: function (name, data) {
78+
var defered = q.defer();
79+
jxcore(name).call(data, function(result, err){
80+
if (err) {
81+
defered.reject(err);
82+
} else {
83+
defered.resolve(result);
84+
}
85+
});
86+
return defered.promise;
87+
}
88+
};
89+
}]);
90+
91+
Controller:
92+
93+
app.controller('indexCtrl', ['$scope', 'jxcoreSrvc', function (scope, jxcoreSrvc) {
94+
scope.callServerFunction = function () {
95+
jxcoreSrvc.callAsyncFunction('serverFunction', 'foo').then(function (result) {
96+
scope.result = result;
97+
});
98+
};
99+
}]);
100+
101+
Add angular template html to `index.html` body:
102+
103+
<div ng-controller="indexCtrl">
104+
<button type="button" ng-click="callServerFunction()"> Call server function </button>
105+
<div ng-if="result">
106+
Response: {{result}}
107+
</div>
108+
</div>
109+
110+
Now let's add jxcore file `jxcore/app.js`:
111+
112+
Mobile('serverFunction').registerAsync(function(message, callback){
113+
setTimeout(function() {
114+
callback(message + ' bar');
115+
}, 500);
116+
});
117+
118+
Add platforms:
119+
120+
cordova platforms add android
121+
cordova platforms add ios

‎config.xml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version='1.0' encoding='utf-8'?>
2+
<widget id="io.cordova.hellocordova" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
3+
<name>HelloCordova</name>
4+
<description>
5+
A sample Apache Cordova application that responds to the deviceready event.
6+
</description>
7+
<author email="dev@cordova.apache.org" href="http://cordova.io">
8+
Apache Cordova Team
9+
</author>
10+
<content src="index.html" />
11+
<plugin name="cordova-plugin-whitelist" version="1" />
12+
<access origin="*" />
13+
<allow-intent href="http://*/*" />
14+
<allow-intent href="https://*/*" />
15+
<allow-intent href="tel:*" />
16+
<allow-intent href="sms:*" />
17+
<allow-intent href="mailto:*" />
18+
<allow-intent href="geo:*" />
19+
<platform name="android">
20+
<allow-intent href="market:*" />
21+
</platform>
22+
<platform name="ios">
23+
<allow-intent href="itms:*" />
24+
<allow-intent href="itms-apps:*" />
25+
</platform>
26+
</widget>

0 commit comments

Comments
 (0)