You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by pu...@apache.org on 2015/02/15 07:40:07 UTC

cordova-windows git commit: CB-8321 Add supported orientations config.xml preference handling for `windows` platform

Repository: cordova-windows
Updated Branches:
  refs/heads/master 279bbea55 -> fd18e17de


CB-8321 Add supported orientations config.xml preference handling for `windows` platform


Project: http://git-wip-us.apache.org/repos/asf/cordova-windows/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-windows/commit/fd18e17d
Tree: http://git-wip-us.apache.org/repos/asf/cordova-windows/tree/fd18e17d
Diff: http://git-wip-us.apache.org/repos/asf/cordova-windows/diff/fd18e17d

Branch: refs/heads/master
Commit: fd18e17de4969222186998a7d1e7a0beabbd4fde
Parents: 279bbea
Author: daserge <da...@yandex.ru>
Authored: Sat Jan 17 15:02:44 2015 +0300
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Sat Feb 14 22:39:10 2015 -0800

----------------------------------------------------------------------
 template/cordova/lib/prepare.js | 59 ++++++++++++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-windows/blob/fd18e17d/template/cordova/lib/prepare.js
----------------------------------------------------------------------
diff --git a/template/cordova/lib/prepare.js b/template/cordova/lib/prepare.js
index b7c71ae..7ebf0e4 100644
--- a/template/cordova/lib/prepare.js
+++ b/template/cordova/lib/prepare.js
@@ -130,6 +130,65 @@ function applyCoreProperties(config, manifest, manifestPath) {
             publisherNameElement.text = author;
         }
     }
+
+    // Supported orientations
+    var isWin80 = manifest.find('.//VisualElements') != null;
+    var isWin81 = manifest.find('.//m2:VisualElements') != null;
+    var isWP81 = manifest.find('.//m3:VisualElements') != null;
+
+    var rotationPreferenceName, rotationPreferenceRootName;
+
+    if(isWin80) {
+        rotationPreferenceName = 'Rotation';
+        rotationPreferenceRootName = 'InitialRotationPreference';
+    } else if(isWin81) {
+        rotationPreferenceName = 'm2:Rotation';
+        rotationPreferenceRootName = 'm2:InitialRotationPreference';
+    } else if(isWP81) {
+        rotationPreferenceName = 'm3:Rotation';
+        rotationPreferenceRootName = 'm3:InitialRotationPreference';
+    }
+
+    var orientation = config.getPreference('Orientation');
+    if (orientation) {
+        var rotationPreferenceRoot = manifest.find('.//' + rotationPreferenceRootName);
+        if(rotationPreferenceRoot == null) {
+            visualElems.append(et.Element(rotationPreferenceRootName));
+            rotationPreferenceRoot = manifest.find('.//' + rotationPreferenceRootName);
+        }
+
+        rotationPreferenceRoot.clear();
+
+        function applyOrientations(orientationsArr) {
+            orientationsArr.forEach(function(orientationValue) {
+                var el = et.Element(rotationPreferenceName)
+                el.attrib.Preference = orientationValue;
+                rotationPreferenceRoot.append(el);
+            });
+        }
+
+        // Updates supported orientations
+        //<InitialRotationPreference>
+        //    <Rotation Preference = "portrait" | "landscape" | "portraitFlipped" | "landscapeFlipped" /> {1,4}
+        //</InitialRotationPreference>
+        var orientations;
+        if(orientation === 'default') {
+            // This means landscape and portrait
+            applyOrientations(['portrait', 'landscape', 'landscapeFlipped']);
+        } else if(orientation === 'portrait') {
+            applyOrientations(['portrait']);
+        } else if(orientation === 'landscape') {
+            applyOrientations(['landscape', 'landscapeFlipped']);
+        } else { // Platform-specific setting like "portrait,landscape,portraitFlipped"
+            applyOrientations(orientation.split(','));
+        }
+    } else {
+        // Remove InitialRotationPreference root element to revert to defaults
+        var rotationPreferenceRoot = visualElems.find('.//' + rotationPreferenceRootName);
+        if(rotationPreferenceRoot != null) {
+            visualElems.remove(null, rotationPreferenceRoot);
+        }
+    }
 }
 
 // Adjust version number as per CB-5337 Windows8 build fails due to invalid app version


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org