videojs-mobile-ui 0.6.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/CHANGELOG.md +53 -0
  2. package/README.md +10 -2
  3. package/dist/videojs-mobile-ui.cjs.js +55 -28
  4. package/dist/videojs-mobile-ui.css +1 -1
  5. package/dist/videojs-mobile-ui.es.js +55 -28
  6. package/dist/videojs-mobile-ui.js +55 -28
  7. package/dist/videojs-mobile-ui.min.js +2 -2
  8. package/docs/api/TouchOverlay.html +964 -0
  9. package/docs/api/fonts/OpenSans-Bold-webfont.eot +0 -0
  10. package/docs/api/fonts/OpenSans-Bold-webfont.svg +1830 -0
  11. package/docs/api/fonts/OpenSans-Bold-webfont.woff +0 -0
  12. package/docs/api/fonts/OpenSans-BoldItalic-webfont.eot +0 -0
  13. package/docs/api/fonts/OpenSans-BoldItalic-webfont.svg +1830 -0
  14. package/docs/api/fonts/OpenSans-BoldItalic-webfont.woff +0 -0
  15. package/docs/api/fonts/OpenSans-Italic-webfont.eot +0 -0
  16. package/docs/api/fonts/OpenSans-Italic-webfont.svg +1830 -0
  17. package/docs/api/fonts/OpenSans-Italic-webfont.woff +0 -0
  18. package/docs/api/fonts/OpenSans-Light-webfont.eot +0 -0
  19. package/docs/api/fonts/OpenSans-Light-webfont.svg +1831 -0
  20. package/docs/api/fonts/OpenSans-Light-webfont.woff +0 -0
  21. package/docs/api/fonts/OpenSans-LightItalic-webfont.eot +0 -0
  22. package/docs/api/fonts/OpenSans-LightItalic-webfont.svg +1835 -0
  23. package/docs/api/fonts/OpenSans-LightItalic-webfont.woff +0 -0
  24. package/docs/api/fonts/OpenSans-Regular-webfont.eot +0 -0
  25. package/docs/api/fonts/OpenSans-Regular-webfont.svg +1831 -0
  26. package/docs/api/fonts/OpenSans-Regular-webfont.woff +0 -0
  27. package/docs/api/global.html +957 -0
  28. package/docs/api/index.html +159 -0
  29. package/docs/api/plugin.js.html +221 -0
  30. package/docs/api/scripts/linenumber.js +25 -0
  31. package/docs/api/scripts/prettify/Apache-License-2.0.txt +202 -0
  32. package/docs/api/scripts/prettify/lang-css.js +2 -0
  33. package/docs/api/scripts/prettify/prettify.js +28 -0
  34. package/docs/api/styles/jsdoc-default.css +358 -0
  35. package/docs/api/styles/prettify-jsdoc.css +111 -0
  36. package/docs/api/styles/prettify-tomorrow.css +132 -0
  37. package/docs/api/touchOverlay.js.html +211 -0
  38. package/index.html +185 -92
  39. package/package.json +10 -13
  40. package/src/plugin.js +59 -34
  41. package/test/plugin.test.js +46 -1
package/src/plugin.js CHANGED
@@ -9,12 +9,15 @@ const defaults = {
9
9
  enterOnRotate: true,
10
10
  exitOnRotate: true,
11
11
  lockOnRotate: true,
12
- iOS: false
12
+ lockToLandscapeOnEnter: false,
13
+ iOS: false,
14
+ disabled: false
13
15
  },
14
16
  touchControls: {
15
17
  seekSeconds: 10,
16
18
  tapTimeout: 300,
17
- disableOnEnd: false
19
+ disableOnEnd: false,
20
+ disabled: false
18
21
  }
19
22
  };
20
23
 
@@ -28,7 +31,7 @@ const screen = window.screen;
28
31
  const getOrientation = () => {
29
32
  if (screen) {
30
33
  // Prefer the string over angle, as 0° can be landscape on some tablets
31
- const orientationString = (screen.orientation || {}).type || screen.mozOrientation || screen.msOrientation || ''.split('-');
34
+ const orientationString = ((screen.orientation || {}).type || screen.mozOrientation || screen.msOrientation || '').split('-')[0];
32
35
 
33
36
  if (orientationString === 'landscape' || orientationString === 'portrait') {
34
37
  return orientationString;
@@ -62,36 +65,45 @@ const registerPlugin = videojs.registerPlugin || videojs.plugin;
62
65
  const onPlayerReady = (player, options) => {
63
66
  player.addClass('vjs-mobile-ui');
64
67
 
65
- if (options.touchControls.disableOnEnd || typeof player.endscreen === 'function') {
66
- player.addClass('vjs-mobile-ui-disable-end');
68
+ if (options.fullscreen.iOS) {
69
+ videojs.log.warn('videojs-mobile-ui: `fullscreen.iOS` is deprecated. Use Video.js option `preferFullWindow` instead.');
70
+ if (videojs.browser.IS_IOS && videojs.browser.IOS_VERSION > 9 &&
71
+ !player.el_.ownerDocument.querySelector('.bc-iframe')) {
72
+ player.tech_.el_.setAttribute('playsinline', 'playsinline');
73
+ player.tech_.supportsFullScreen = function() {
74
+ return false;
75
+ };
76
+ }
67
77
  }
68
78
 
69
- if (options.fullscreen.iOS &&
70
- videojs.browser.IS_IOS && videojs.browser.IOS_VERSION > 9 &&
71
- !player.el_.ownerDocument.querySelector('.bc-iframe')) {
72
- player.tech_.el_.setAttribute('playsinline', 'playsinline');
73
- player.tech_.supportsFullScreen = function() {
74
- return false;
75
- };
76
- }
79
+ if (!options.touchControls.disabled) {
80
+
81
+ if (options.touchControls.disableOnEnd || typeof player.endscreen === 'function') {
82
+ player.addClass('vjs-mobile-ui-disable-end');
83
+ }
77
84
 
78
- // Insert before the control bar
79
- let controlBarIdx;
80
- const versionParts = videojs.VERSION.split('.');
81
- const major = parseInt(versionParts[0], 10);
82
- const minor = parseInt(versionParts[1], 10);
83
-
84
- // Video.js < 7.7.0 doesn't account for precedding components that don't have elements
85
- if (major < 7 || (major === 7 && minor < 7)) {
86
- controlBarIdx = Array.prototype.indexOf.call(
87
- player.el_.children,
88
- player.getChild('ControlBar').el_
89
- );
90
- } else {
91
- controlBarIdx = player.children_.indexOf(player.getChild('ControlBar'));
85
+ // Insert before the control bar
86
+ let controlBarIdx;
87
+ const versionParts = videojs.VERSION.split('.');
88
+ const major = parseInt(versionParts[0], 10);
89
+ const minor = parseInt(versionParts[1], 10);
90
+
91
+ // Video.js < 7.7.0 doesn't account for precedding components that don't have elements
92
+ if (major < 7 || (major === 7 && minor < 7)) {
93
+ controlBarIdx = Array.prototype.indexOf.call(
94
+ player.el_.children,
95
+ player.getChild('ControlBar').el_
96
+ );
97
+ } else {
98
+ controlBarIdx = player.children_.indexOf(player.getChild('ControlBar'));
99
+ }
100
+
101
+ player.touchOverlay = player.addChild('TouchOverlay', options.touchControls, controlBarIdx);
92
102
  }
93
103
 
94
- player.addChild('TouchOverlay', options.touchControls, controlBarIdx);
104
+ if (options.fullscreen.disabled) {
105
+ return;
106
+ }
95
107
 
96
108
  let locked = false;
97
109
 
@@ -101,7 +113,7 @@ const onPlayerReady = (player, options) => {
101
113
  if (currentOrientation === 'landscape' && options.fullscreen.enterOnRotate) {
102
114
  if (player.paused() === false) {
103
115
  player.requestFullscreen();
104
- if (options.fullscreen.lockOnRotate &&
116
+ if ((options.fullscreen.lockOnRotate || options.fullscreen.lockToLandscapeOnEnter) &&
105
117
  screen.orientation && screen.orientation.lock) {
106
118
  screen.orientation.lock('landscape').then(() => {
107
119
  locked = true;
@@ -134,15 +146,21 @@ const onPlayerReady = (player, options) => {
134
146
  }
135
147
  }
136
148
 
137
- player.on('ended', _ => {
138
- if (locked === true) {
149
+ player.on('fullscreenchange', _ => {
150
+ if (player.isFullscreen() && options.fullscreen.lockToLandscapeOnEnter && getOrientation() === 'portrait') {
151
+ screen.orientation.lock('landscape').then(()=>{
152
+ locked = true;
153
+ }).catch((e) => {
154
+ videojs.log('Browser refused orientation lock:', e);
155
+ });
156
+ } else if (!player.isFullscreen() && locked) {
139
157
  screen.orientation.unlock();
140
158
  locked = false;
141
159
  }
142
160
  });
143
161
 
144
- player.on('fullscreenchange', _ => {
145
- if (!player.isFullscreen() && locked) {
162
+ player.on('ended', _ => {
163
+ if (locked === true) {
146
164
  screen.orientation.unlock();
147
165
  locked = false;
148
166
  }
@@ -161,17 +179,24 @@ const onPlayerReady = (player, options) => {
161
179
  * Enables the display regardless of user agent, for testing purposes
162
180
  * @param {Object} [options.fullscreen={}]
163
181
  * Fullscreen options.
182
+ * @param {boolean} [options.fullscreen.disabled=false]
183
+ * If true no fullscreen handling except the *deprecated* iOS fullwindow hack
164
184
  * @param {boolean} [options.fullscreen.enterOnRotate=true]
165
185
  * Whether to go fullscreen when rotating to landscape
166
186
  * @param {boolean} [options.fullscreen.exitOnRotate=true]
167
187
  * Whether to leave fullscreen when rotating to portrait (if not locked)
168
188
  * @param {boolean} [options.fullscreen.lockOnRotate=true]
169
189
  * Whether to lock orientation when rotating to landscape
190
+ * Unlocked when exiting fullscreen or on 'ended
191
+ * @param {boolean} [options.fullscreen.lockToLandscapeOnEnter=false]
192
+ * Whether to always lock orientation to landscape on fullscreen mode
170
193
  * Unlocked when exiting fullscreen or on 'ended'
171
194
  * @param {boolean} [options.fullscreen.iOS=false]
172
- * Whether to disable iOS's native fullscreen so controls can work
195
+ * Deprecated: Whether to disable iOS's native fullscreen so controls can work
173
196
  * @param {Object} [options.touchControls={}]
174
197
  * Touch UI options.
198
+ * @param {boolean} [options.touchControls.disabled=false]
199
+ * If true no touch controls are added.
175
200
  * @param {int} [options.touchControls.seekSeconds=10]
176
201
  * Number of seconds to seek on double-tap
177
202
  * @param {int} [options.touchControls.tapTimeout=300]
@@ -62,6 +62,24 @@ QUnit.test('inserts element before control bar', function(assert) {
62
62
  );
63
63
  });
64
64
 
65
+ QUnit.test('does not insert if disabled', function(assert) {
66
+
67
+ this.player.mobileUi({
68
+ forceForTesting: true,
69
+ touchControls: {
70
+ disabled: true
71
+ }
72
+ });
73
+
74
+ this.clock.tick(1);
75
+
76
+ assert.strictEqual(
77
+ this.player.touchOverlay,
78
+ undefined,
79
+ 'TouchOverlay should not be present'
80
+ );
81
+ });
82
+
65
83
  QUnit.test('iOS event listeners', function(assert) {
66
84
 
67
85
  const oldBrowser = videojs.browser;
@@ -118,7 +136,7 @@ QUnit[testOrSkip]('Android event listeners', function(assert) {
118
136
  assert.strictEqual(
119
137
  typeof window.screen.orientation.onchange,
120
138
  'function',
121
- 'screen.orientation.onchange is used for andorid'
139
+ 'screen.orientation.onchange is used for android'
122
140
  );
123
141
 
124
142
  this.player.dispose();
@@ -133,3 +151,30 @@ QUnit[testOrSkip]('Android event listeners', function(assert) {
133
151
 
134
152
  videojs.browser = oldBrowser;
135
153
  });
154
+
155
+ QUnit[testOrSkip]('Android event listeners skipped if disabled', function(assert) {
156
+
157
+ const oldBrowser = videojs.browser;
158
+
159
+ videojs.browser = videojs.mergeOptions(videojs.browser, {
160
+ IS_IOS: false,
161
+ IS_ANDROID: true
162
+ });
163
+
164
+ this.player.mobileUi({
165
+ forceForTesting: true,
166
+ fullscreen: {
167
+ disabled: true
168
+ }
169
+ });
170
+
171
+ this.clock.tick(1);
172
+
173
+ assert.notStrictEqual(
174
+ typeof window.screen.orientation.onchange,
175
+ 'function',
176
+ 'screen.orientation.onchange skipped for android'
177
+ );
178
+
179
+ videojs.browser = oldBrowser;
180
+ });