You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ti...@apache.org on 2012/09/04 20:50:33 UTC
[2/3] webworks commit: Updating sample app
Updating sample app
Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-blackberry-webworks/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-blackberry-webworks/commit/3d7b4ce7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-blackberry-webworks/tree/3d7b4ce7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-blackberry-webworks/diff/3d7b4ce7
Branch: refs/heads/master
Commit: 3d7b4ce7c950296b77dcda52e7da7f9f556f0d5c
Parents: d97cac0
Author: Tim Kim <ti...@nitobi.com>
Authored: Tue Sep 4 10:17:51 2012 -0700
Committer: Tim Kim <ti...@nitobi.com>
Committed: Tue Sep 4 10:17:51 2012 -0700
----------------------------------------------------------------------
bin/templates/project/www/css/index.css | 11 ++++---
bin/templates/project/www/index.html | 9 ++---
bin/templates/project/www/js/index.js | 39 ++++++++++++++----------
bin/templates/project/www/spec/helper.js | 4 ++
bin/templates/project/www/spec/index.js | 38 ++++++++++++------------
5 files changed, 56 insertions(+), 45 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cordova-blackberry-webworks/blob/3d7b4ce7/bin/templates/project/www/css/index.css
----------------------------------------------------------------------
diff --git a/bin/templates/project/www/css/index.css b/bin/templates/project/www/css/index.css
index bacd6e3..f1f9d76 100644
--- a/bin/templates/project/www/css/index.css
+++ b/bin/templates/project/www/css/index.css
@@ -78,8 +78,7 @@ h1 {
text-align:center;
}
-.status {
- background-color:#333333;
+.event {
border-radius:4px;
-webkit-border-radius:4px;
color:#FFFFFF;
@@ -88,11 +87,13 @@ h1 {
padding:2px 0px;
}
-.status.complete {
- background-color:#4B946A;
+.event.listening {
+ background-color:#333333;
+ display:block;
}
-.hide {
+.event.received {
+ background-color:#4B946A;
display:none;
}
http://git-wip-us.apache.org/repos/asf/incubator-cordova-blackberry-webworks/blob/3d7b4ce7/bin/templates/project/www/index.html
----------------------------------------------------------------------
diff --git a/bin/templates/project/www/index.html b/bin/templates/project/www/index.html
index ead0413..92484ad 100644
--- a/bin/templates/project/www/index.html
+++ b/bin/templates/project/www/index.html
@@ -28,13 +28,12 @@
<body>
<div class="app">
<h1>Apache Cordova</h1>
- <div id="deviceready">
- <p class="status pending blink">Connecting to Device</p>
- <p class="status complete blink hide">Device is Ready</p>
+ <div id="deviceready" class="blink">
+ <p class="event listening">Connecting to Device</p>
+ <p class="event received">Device is Ready</p>
</div>
</div>
- <script type="text/javascript" src="js/webworks.js"></script>
- <script type="text/javascript" src="cordova-2.1.0rc1.js"></script>
+ <script type="text/javascript" src="cordova-2.1.0.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript">
app.initialize();
http://git-wip-us.apache.org/repos/asf/incubator-cordova-blackberry-webworks/blob/3d7b4ce7/bin/templates/project/www/js/index.js
----------------------------------------------------------------------
diff --git a/bin/templates/project/www/js/index.js b/bin/templates/project/www/js/index.js
index 7223130..31d9064 100644
--- a/bin/templates/project/www/js/index.js
+++ b/bin/templates/project/www/js/index.js
@@ -17,26 +17,33 @@
* under the License.
*/
var app = {
+ // Application Constructor
initialize: function() {
- this.bind();
+ this.bindEvents();
},
- bind: function() {
- document.addEventListener('deviceready', this.deviceready, false);
+ // Bind Event Listeners
+ //
+ // Bind any events that are required on startup. Common events are:
+ // 'load', 'deviceready', 'offline', and 'online'.
+ bindEvents: function() {
+ document.addEventListener('deviceready', this.onDeviceReady, false);
},
- deviceready: function() {
- // This is an event handler function, which means the scope is the event.
- // So, we must explicitly called `app.report()` instead of `this.report()`.
- app.report('deviceready');
+ // deviceready Event Handler
+ //
+ // The scope of 'this' is the event. In order to call the 'receivedEvent'
+ // function, we must explicity call 'app.receivedEvent(...);'
+ onDeviceReady: function() {
+ app.receivedEvent('deviceready');
},
- report: function(id) {
- // Report the event in the console
- console.log("Report: " + id);
+ // Update DOM on a Received Event
+ receivedEvent: function(id) {
+ var parentElement = document.getElementById(id);
+ var listeningElement = parentElement.querySelector('.listening');
+ var receivedElement = parentElement.querySelector('.received');
- // Toggle the state from "pending" to "complete" for the reported ID.
- // Accomplished by adding .hide to the pending element and removing
- // .hide from the complete element.
- document.querySelector('#' + id + ' .pending').className += ' hide';
- var completeElem = document.querySelector('#' + id + ' .complete');
- completeElem.className = completeElem.className.split('hide').join('');
+ listeningElement.setAttribute('style', 'display:none;');
+ receivedElement.setAttribute('style', 'display:block;');
+
+ console.log('Received Event: ' + id);
}
};
http://git-wip-us.apache.org/repos/asf/incubator-cordova-blackberry-webworks/blob/3d7b4ce7/bin/templates/project/www/spec/helper.js
----------------------------------------------------------------------
diff --git a/bin/templates/project/www/spec/helper.js b/bin/templates/project/www/spec/helper.js
index 821604b..929f776 100644
--- a/bin/templates/project/www/spec/helper.js
+++ b/bin/templates/project/www/spec/helper.js
@@ -25,5 +25,9 @@ var helper = {
var e = document.createEvent('Event');
e.initEvent(name, true, true);
obj.dispatchEvent(e);
+ },
+ getComputedStyle: function(querySelector, property) {
+ var element = document.querySelector(querySelector);
+ return window.getComputedStyle(element).getPropertyValue(property);
}
};
http://git-wip-us.apache.org/repos/asf/incubator-cordova-blackberry-webworks/blob/3d7b4ce7/bin/templates/project/www/spec/index.js
----------------------------------------------------------------------
diff --git a/bin/templates/project/www/spec/index.js b/bin/templates/project/www/spec/index.js
index b43fefa..20f8be5 100644
--- a/bin/templates/project/www/spec/index.js
+++ b/bin/templates/project/www/spec/index.js
@@ -20,48 +20,48 @@ describe('app', function() {
describe('initialize', function() {
it('should bind deviceready', function() {
runs(function() {
- spyOn(app, 'deviceready');
+ spyOn(app, 'onDeviceReady');
app.initialize();
helper.trigger(window.document, 'deviceready');
});
waitsFor(function() {
- return (app.deviceready.calls.length > 0);
- }, 'deviceready should be called once', 500);
+ return (app.onDeviceReady.calls.length > 0);
+ }, 'onDeviceReady should be called once', 500);
runs(function() {
- expect(app.deviceready).toHaveBeenCalled();
+ expect(app.onDeviceReady).toHaveBeenCalled();
});
});
});
- describe('deviceready', function() {
+ describe('onDeviceReady', function() {
it('should report that it fired', function() {
- spyOn(app, 'report');
- app.deviceready();
- expect(app.report).toHaveBeenCalledWith('deviceready');
+ spyOn(app, 'receivedEvent');
+ app.onDeviceReady();
+ expect(app.receivedEvent).toHaveBeenCalledWith('deviceready');
});
});
- describe('report', function() {
+ describe('receivedEvent', function() {
beforeEach(function() {
var el = document.getElementById('stage');
el.innerHTML = ['<div id="deviceready">',
- ' <p class="status pending">Pending</p>',
- ' <p class="status complete hide">Complete</p>',
+ ' <p class="event listening">Listening</p>',
+ ' <p class="event received">Received</p>',
'</div>'].join('\n');
});
- it('should show the completion state', function() {
- app.report('deviceready');
- var el = document.querySelector('#deviceready .complete:not(.hide)');
- expect(el).toBeTruthy();
+ it('should hide the listening element', function() {
+ app.receivedEvent('deviceready');
+ var displayStyle = helper.getComputedStyle('#deviceready .listening', 'display');
+ expect(displayStyle).toEqual('none');
});
- it('should hide the pending state', function() {
- app.report('deviceready');
- var el = document.querySelector('#deviceready .pending.hide');
- expect(el).toBeTruthy();
+ it('should show the received element', function() {
+ app.receivedEvent('deviceready');
+ var displayStyle = helper.getComputedStyle('#deviceready .received', 'display');
+ expect(displayStyle).toEqual('block');
});
});
});