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 2017/03/10 01:57:21 UTC
[6/6] cordova-plugin-screen-orientation git commit: getter for
onchange, add/remove event listeners, this closes #12
getter for onchange, add/remove event listeners, this closes #12
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-screen-orientation/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-screen-orientation/commit/9d6f2d27
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-screen-orientation/tree/9d6f2d27
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-screen-orientation/diff/9d6f2d27
Branch: refs/heads/master
Commit: 9d6f2d271da52ccbd4ab90a4c64cb07bd1f95ef5
Parents: 90128f4
Author: Jesse MacFadyen <pu...@gmail.com>
Authored: Thu Mar 9 17:57:00 2017 -0800
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Thu Mar 9 17:57:00 2017 -0800
----------------------------------------------------------------------
tests/tests.js | 23 ++++++++++++++++++++++-
www/screenorientation.js | 25 +++++++++++++++++--------
2 files changed, 39 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-screen-orientation/blob/9d6f2d27/tests/tests.js
----------------------------------------------------------------------
diff --git a/tests/tests.js b/tests/tests.js
index c19500e..b91f81a 100644
--- a/tests/tests.js
+++ b/tests/tests.js
@@ -54,8 +54,29 @@ exports.defineAutoTests = function() {
expect(typeof window.screen.orientation.angle).toBe('number');
});
- xit('should have an `onchange` property (function)', function() {
+ it('should have an `onchange` settable function', function() {
+ // it should be null to start
+ expect(window.screen.orientation.onchange).toBe(null);
+ // then we set it
+ var funk = function(){};
+ window.screen.orientation.onchange = funk;
+ // now it should exist
expect(window.screen.orientation.onchange).toBeDefined();
+ expect(window.screen.orientation.onchange).toBe(funk);
+ // clear it
+ window.screen.orientation.onchange = null;
+ // it should be null again
+ expect(window.screen.orientation.onchange).toBe(null);
+ });
+
+ it('should have an eventListener interface',function() {
+ expect(window.screen.orientation.addEventListener).toBeDefined();
+ expect(typeof window.screen.orientation.addEventListener).toBe('function');
+
+ expect(window.screen.orientation.removeEventListener).toBeDefined();
+ expect(typeof window.screen.orientation.removeEventListener).toBe('function');
+
+
});
});
http://git-wip-us.apache.org/repos/asf/cordova-plugin-screen-orientation/blob/9d6f2d27/www/screenorientation.js
----------------------------------------------------------------------
diff --git a/www/screenorientation.js b/www/screenorientation.js
index bafc046..022e0ba 100644
--- a/www/screenorientation.js
+++ b/www/screenorientation.js
@@ -95,32 +95,41 @@ function resolveOrientation(orientation, resolve, reject) {
addScreenOrientationApi(screen.orientation);
var onChangeListener = null;
-Object.defineProperty(screen.orientation, 'onchange', {
+Object.defineProperty(screen.orientation, 'onchange', {
set: function(listener) {
+ console.log("setting onchange to : " + listener);
+
if (onChangeListener != null) {
- screen.orienation.removeEventListener('change', onChangeListener);
+ screen.orientation.removeEventListener('change', onChangeListener);
}
-
onChangeListener = listener;
-
if (onChangeListener != null) {
screen.orientation.addEventListener('change', onChangeListener);
}
},
+ get: function() {
+ return (onChangeListener ? onChangeListener : null);
+ },
enumerable: true,
});
-
+var evtTarget = new XMLHttpRequest(); //document.createElement('div');
var orientationchange = function() {
setOrientationProperties();
var event = document.createEvent('Events');
event.initEvent("change", false, false);
- document.dispatchEvent(event);
-
+ evtTarget.dispatchEvent(event);
};
+screen.orientation.addEventListener = function(a,b,c) {
+ return evtTarget.addEventListener(a,b,c);
+}
+screen.orientation.removeEventListener = function(a,b,c) {
+ return evtTarget.removeEventListener(a,b,c);
+}
+
function setOrientationProperties() {
switch (window.orientation) {
case 0:
@@ -140,5 +149,5 @@ function setOrientationProperties() {
}
window.addEventListener("orientationchange", orientationchange, true);
-screen.orientation.addEventListener = document.addEventListener;
+
module.exports = screenOrientation;
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org