You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by sh...@apache.org on 2012/08/31 23:30:23 UTC

[4/5] [CB-1338] Update www/ Application

http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/6deee4ff/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 ffb7ba8..f1f9d76 100644
--- a/bin/templates/project/www/css/index.css
+++ b/bin/templates/project/www/css/index.css
@@ -16,11 +16,11 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-html,
-body {
-    height:100%;
-    font-size:12px;
-    width:100%;
+* {
+    -webkit-touch-callout: none;                /* prevent callout to copy image, etc when tap to hold */
+    -webkit-text-size-adjust: none;             /* prevent webkit from resizing text to fit */
+    -webkit-tap-highlight-color: rgba(0,0,0,0); /* make transparent link selection, adjust last value opacity 0 to 1.0 */
+    -webkit-user-select: none;                  /* prevent copy paste, to allow, change 'none' to 'text' */
 }
 
 body {
@@ -37,30 +37,35 @@ body {
     );
     background-attachment:fixed;
     font-family:'HelveticaNeue-Light', 'HelveticaNeue', Helvetica, Arial, sans-serif;
+    font-size:12px;
+    height:100%;
+    margin:0px;
+    padding:0px;
     text-transform:uppercase;
+    width:100%;
 }
 
-/* portrait layout for the app (default) */
+/* Portrait layout (default) */
 .app {
-    background:url(../img/logo.png) no-repeat;
-    position:absolute;
+    background:url(../img/logo.png) no-repeat center top; /* 170px x 200px */
+    position:absolute;             /* position in the center of the screen */
     left:50%;
     top:50%;
-    margin:-120px 0 0 -110px;       /* shift container to top-left by half its width and height */
-    background-position:center top;
-    height:100px;                   /* add enough room for text */
-    padding:180px 0px 0px 0px;      /* background-image height - image's shadow */
+    height:50px;                   /* text area height */
+    width:225px;                   /* text area width */
     text-align:center;
+    padding:180px 0px 0px 0px;     /* image height is 200px (bottom 20px are overlapped with text) */
+    margin:-115px 0px 0px -112px;  /* offset vertical: half of image height and text area height */
+                                   /* offset horizontal: half of text area width */
 }
 
-/* lanscape layout for the app (when wide enough) */
-@media screen and (min-aspect-ratio: 1/1) and (min-width:445px) {
+/* Landscape layout (with min-width) */
+@media screen and (min-aspect-ratio: 1/1) and (min-width:400px) {
     .app {
         background-position:left center;
-        height:140px;             /* height + padding = background image size */
-        padding-left:170px;       /* background width */
-        padding-top:60px;         /* vertically center the text to background image */
-        margin:-90px 0 0 -200px;  /* shift container to top left by half its width and height */
+        padding:75px 0px 75px 170px;  /* padding-top + padding-bottom + text area = image height */
+        margin:-90px 0px 0px -198px;  /* offset vertical: half of image height */
+                                      /* offset horizontal: half of image width and text area width */
     }
 }
 
@@ -73,21 +78,22 @@ h1 {
     text-align:center;
 }
 
-.status {
-    background-color:#333333;
+.event {
     border-radius:4px;
     -webkit-border-radius:4px;
     color:#FFFFFF;
     font-size:12px;
-    margin:0px 20px;
-    padding:2px 20px;
+    margin:0px 30px;
+    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-ios/blob/6deee4ff/bin/templates/project/www/img/logo.png
----------------------------------------------------------------------
diff --git a/bin/templates/project/www/img/logo.png b/bin/templates/project/www/img/logo.png
index e8169cf..9519e7d 100644
Binary files a/bin/templates/project/www/img/logo.png and b/bin/templates/project/www/img/logo.png differ

http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/6deee4ff/bin/templates/project/www/index.html
----------------------------------------------------------------------
diff --git a/bin/templates/project/www/index.html b/bin/templates/project/www/index.html
index 92b21e3..a0d5550 100644
--- a/bin/templates/project/www/index.html
+++ b/bin/templates/project/www/index.html
@@ -21,19 +21,19 @@
     <head>
         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
         <meta name="format-detection" content="telephone=no" />
-        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width;" />
+        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
         <link rel="stylesheet" type="text/css" href="css/index.css" />
         <title>Hello World</title>
     </head>
     <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="cordova-2.1.0rc1.js"></script>
+        <script type="text/javascript" src="cordova-2.1.0rc2.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-ios/blob/6deee4ff/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..3b75d3f 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-ios/blob/6deee4ff/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-ios/blob/6deee4ff/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');
         });
     });
 });