mirror of
https://github.com/videojs/video.js.git
synced 2024-11-28 08:58:46 +02:00
@misteroneill restore some 4.x utilities and remove deprecated functionality. closes #2406
This commit is contained in:
parent
aa8601f22f
commit
8aa61d3b1a
@ -79,6 +79,7 @@ CHANGELOG
|
||||
* @eXon added the language to the options the tech receives ([view](https://github.com/videojs/video.js/pull/2338))
|
||||
* @mmcc Added "inline" option to MenuButton and updated VolumeMenuButton to be able to utilize it ([view](https://github.com/videojs/video.js/pull/2378))
|
||||
* @misteroneill restore some properties on window.videojs. ([view](https://github.com/videojs/video.js/pull/2395))
|
||||
* @misteroneill restore some 4.x utilities and remove deprecated functionality ([view](https://github.com/videojs/video.js/pull/2406))
|
||||
|
||||
--------------------
|
||||
|
||||
|
@ -30,7 +30,7 @@ import mergeOptions from './utils/merge-options.js';
|
||||
* <div class="vjs-button">Button</div>
|
||||
* </div>
|
||||
* ```
|
||||
* Components are also event emitters.
|
||||
* Components are also event targets.
|
||||
* ```js
|
||||
* button.on('click', function(){
|
||||
* console.log('Button Clicked!');
|
||||
|
@ -7,7 +7,6 @@ import LoadProgressBar from './load-progress-bar.js';
|
||||
import PlayProgressBar from './play-progress-bar.js';
|
||||
import * as Fn from '../../utils/fn.js';
|
||||
import formatTime from '../../utils/format-time.js';
|
||||
import roundFloat from '../../utils/round-float.js';
|
||||
|
||||
/**
|
||||
* Seek Bar and holder for the progress bars
|
||||
@ -46,7 +45,7 @@ class SeekBar extends Slider {
|
||||
updateARIAAttributes() {
|
||||
// Allows for smooth scrubbing, when player can't keep up.
|
||||
let time = (this.player_.scrubbing()) ? this.player_.getCache().currentTime : this.player_.currentTime();
|
||||
this.el_.setAttribute('aria-valuenow', roundFloat(this.getPercent()*100, 2)); // machine readable value of progress bar (percentage complete)
|
||||
this.el_.setAttribute('aria-valuenow', (this.getPercent() * 100).toFixed(2)); // machine readable value of progress bar (percentage complete)
|
||||
this.el_.setAttribute('aria-valuetext', formatTime(time, this.player_.duration())); // human readable value of progress bar (time complete)
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,6 @@
|
||||
import Slider from '../../slider/slider.js';
|
||||
import Component from '../../component.js';
|
||||
import * as Fn from '../../utils/fn.js';
|
||||
import roundFloat from '../../utils/round-float.js';
|
||||
|
||||
// Required children
|
||||
import VolumeLevel from './volume-level.js';
|
||||
@ -90,8 +89,9 @@ class VolumeBar extends Slider {
|
||||
*/
|
||||
updateARIAAttributes() {
|
||||
// Current value of volume bar as a percentage
|
||||
this.el_.setAttribute('aria-valuenow', roundFloat(this.player_.volume()*100, 2));
|
||||
this.el_.setAttribute('aria-valuetext', roundFloat(this.player_.volume()*100, 2)+'%');
|
||||
let volume = (this.player_.volume() * 100).toFixed(2);
|
||||
this.el_.setAttribute('aria-valuenow', volume);
|
||||
this.el_.setAttribute('aria-valuetext', volume + '%');
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,13 +1,13 @@
|
||||
/**
|
||||
* @file event-emitter.js
|
||||
* @file event-target.js
|
||||
*/
|
||||
import * as Events from './utils/events.js';
|
||||
|
||||
var EventEmitter = function() {};
|
||||
var EventTarget = function() {};
|
||||
|
||||
EventEmitter.prototype.allowedEvents_ = {};
|
||||
EventTarget.prototype.allowedEvents_ = {};
|
||||
|
||||
EventEmitter.prototype.on = function(type, fn) {
|
||||
EventTarget.prototype.on = function(type, fn) {
|
||||
// Remove the addEventListener alias before calling Events.on
|
||||
// so we don't get into an infinite type loop
|
||||
let ael = this.addEventListener;
|
||||
@ -15,18 +15,18 @@ EventEmitter.prototype.on = function(type, fn) {
|
||||
Events.on(this, type, fn);
|
||||
this.addEventListener = ael;
|
||||
};
|
||||
EventEmitter.prototype.addEventListener = EventEmitter.prototype.on;
|
||||
EventTarget.prototype.addEventListener = EventTarget.prototype.on;
|
||||
|
||||
EventEmitter.prototype.off = function(type, fn) {
|
||||
EventTarget.prototype.off = function(type, fn) {
|
||||
Events.off(this, type, fn);
|
||||
};
|
||||
EventEmitter.prototype.removeEventListener = EventEmitter.prototype.off;
|
||||
EventTarget.prototype.removeEventListener = EventTarget.prototype.off;
|
||||
|
||||
EventEmitter.prototype.one = function(type, fn) {
|
||||
EventTarget.prototype.one = function(type, fn) {
|
||||
Events.one(this, type, fn);
|
||||
};
|
||||
|
||||
EventEmitter.prototype.trigger = function(event) {
|
||||
EventTarget.prototype.trigger = function(event) {
|
||||
let type = event.type || event;
|
||||
|
||||
if (typeof event === 'string') {
|
||||
@ -43,6 +43,6 @@ EventEmitter.prototype.trigger = function(event) {
|
||||
Events.trigger(this, event);
|
||||
};
|
||||
// The standard DOM EventTarget.dispatchEvent() is aliased to trigger()
|
||||
EventEmitter.prototype.dispatchEvent = EventEmitter.prototype.trigger;
|
||||
EventTarget.prototype.dispatchEvent = EventTarget.prototype.trigger;
|
||||
|
||||
export default EventEmitter;
|
||||
export default EventTarget;
|
@ -1,3 +1,5 @@
|
||||
import log from './utils/log';
|
||||
|
||||
/*
|
||||
* @file extends.js
|
||||
*
|
||||
@ -49,6 +51,10 @@ const extendsFn = function(superClass, subClassMethods={}) {
|
||||
let methods = {};
|
||||
|
||||
if (typeof subClassMethods === 'object') {
|
||||
if (typeof subClassMethods.init === 'function') {
|
||||
log.warn('Constructor logic via init() is deprecated; please use constructor() instead.');
|
||||
subClassMethods.constructor = subClassMethods.init;
|
||||
}
|
||||
if (subClassMethods.constructor !== Object.prototype.constructor) {
|
||||
subClass = subClassMethods.constructor;
|
||||
}
|
||||
|
@ -638,7 +638,7 @@ class Player extends Component {
|
||||
*/
|
||||
handleTechReady() {
|
||||
this.triggerReady();
|
||||
|
||||
|
||||
// Keep the same volume as before
|
||||
if (this.cache_.volume) {
|
||||
this.techCall('setVolume', this.cache_.volume);
|
||||
@ -1457,20 +1457,6 @@ class Player extends Component {
|
||||
return !!this.isFullscreen_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Old naming for isFullscreen()
|
||||
*
|
||||
* @param {Boolean=} isFS Update the player's fullscreen state
|
||||
* @return {Boolean} true if fullscreen false if not when getting
|
||||
* @return {Player} self when setting
|
||||
* @deprecated
|
||||
* @method isFullScreen
|
||||
*/
|
||||
isFullScreen(isFS) {
|
||||
log.warn('player.isFullScreen() has been deprecated, use player.isFullscreen() with a lowercase "s")');
|
||||
return this.isFullscreen(isFS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Increase the size of the video to full screen
|
||||
* ```js
|
||||
@ -1527,18 +1513,6 @@ class Player extends Component {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Old naming for requestFullscreen
|
||||
*
|
||||
* @return {Boolean} true if fullscreen false if not when getting
|
||||
* @deprecated
|
||||
* @method requestFullScreen
|
||||
*/
|
||||
requestFullScreen() {
|
||||
log.warn('player.requestFullScreen() has been deprecated, use player.requestFullscreen() with a lowercase "s")');
|
||||
return this.requestFullscreen();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the video to its normal size after having been in full screen mode
|
||||
* ```js
|
||||
@ -1565,18 +1539,6 @@ class Player extends Component {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Old naming for exitFullscreen
|
||||
*
|
||||
* @return {Player} self
|
||||
* @deprecated
|
||||
* @method cancelFullScreen
|
||||
*/
|
||||
cancelFullScreen() {
|
||||
log.warn('player.cancelFullScreen() has been deprecated, use player.exitFullscreen()');
|
||||
return this.exitFullscreen();
|
||||
}
|
||||
|
||||
/**
|
||||
* When fullscreen isn't supported we can stretch the video container to as wide as the browser will let us.
|
||||
*
|
||||
|
@ -3,7 +3,6 @@
|
||||
*/
|
||||
import Component from '../component.js';
|
||||
import * as Dom from '../utils/dom.js';
|
||||
import roundFloat from '../utils/round-float.js';
|
||||
import document from 'global/document';
|
||||
import assign from 'object.assign';
|
||||
|
||||
@ -130,7 +129,7 @@ class Slider extends Component {
|
||||
}
|
||||
|
||||
// Convert to a percentage for setting
|
||||
let percentage = roundFloat(progress * 100, 2) + '%';
|
||||
let percentage = (progress * 100).toFixed(2) + '%';
|
||||
|
||||
// Set the new bar width or height
|
||||
if (this.vertical()) {
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* @file text-track-list.js
|
||||
*/
|
||||
import EventEmitter from '../event-emitter';
|
||||
import EventTarget from '../event-target';
|
||||
import * as Fn from '../utils/fn.js';
|
||||
import * as browser from '../utils/browser.js';
|
||||
import document from 'global/document';
|
||||
@ -48,7 +48,7 @@ let TextTrackList = function(tracks) {
|
||||
}
|
||||
};
|
||||
|
||||
TextTrackList.prototype = Object.create(EventEmitter.prototype);
|
||||
TextTrackList.prototype = Object.create(EventTarget.prototype);
|
||||
TextTrackList.prototype.constructor = TextTrackList;
|
||||
|
||||
/*
|
||||
|
@ -7,7 +7,7 @@ import * as Guid from '../utils/guid.js';
|
||||
import * as browser from '../utils/browser.js';
|
||||
import * as TextTrackEnum from './text-track-enums';
|
||||
import log from '../utils/log.js';
|
||||
import EventEmitter from '../event-emitter';
|
||||
import EventTarget from '../event-target';
|
||||
import document from 'global/document';
|
||||
import window from 'global/window';
|
||||
import XHR from '../xhr.js';
|
||||
@ -186,7 +186,7 @@ let TextTrack = function(options={}) {
|
||||
}
|
||||
};
|
||||
|
||||
TextTrack.prototype = Object.create(EventEmitter.prototype);
|
||||
TextTrack.prototype = Object.create(EventTarget.prototype);
|
||||
TextTrack.prototype.constructor = TextTrack;
|
||||
|
||||
/*
|
||||
|
@ -4,7 +4,6 @@
|
||||
import document from 'global/document';
|
||||
import window from 'global/window';
|
||||
import * as Guid from './guid.js';
|
||||
import roundFloat from './round-float.js';
|
||||
|
||||
/**
|
||||
* Shorthand for document.getElementById()
|
||||
@ -56,7 +55,7 @@ export function createEl(tagName='div', properties={}){
|
||||
|
||||
/**
|
||||
* Insert an element as the first child node of another
|
||||
*
|
||||
*
|
||||
* @param {Element} child Element to insert
|
||||
* @param {Element} parent Element to insert child into
|
||||
* @private
|
||||
@ -271,7 +270,7 @@ export function getElAttributes(tag) {
|
||||
/**
|
||||
* Attempt to block the ability to select text while dragging controls
|
||||
*
|
||||
* @return {Boolean}
|
||||
* @return {Boolean}
|
||||
* @method blockTextSelection
|
||||
*/
|
||||
export function blockTextSelection() {
|
||||
@ -284,7 +283,7 @@ export function blockTextSelection() {
|
||||
/**
|
||||
* Turn off text selection blocking
|
||||
*
|
||||
* @return {Boolean}
|
||||
* @return {Boolean}
|
||||
* @method unblockTextSelection
|
||||
*/
|
||||
export function unblockTextSelection() {
|
||||
@ -295,11 +294,11 @@ export function unblockTextSelection() {
|
||||
|
||||
/**
|
||||
* Offset Left
|
||||
* getBoundingClientRect technique from
|
||||
* getBoundingClientRect technique from
|
||||
* John Resig http://ejohn.org/blog/getboundingclientrect-is-awesome/
|
||||
*
|
||||
* @param {Element} el Element from which to get offset
|
||||
* @return {Object=}
|
||||
* @return {Object=}
|
||||
* @method findElPosition
|
||||
*/
|
||||
export function findElPosition(el) {
|
||||
@ -329,7 +328,7 @@ export function findElPosition(el) {
|
||||
|
||||
// Android sometimes returns slightly off decimal values, so need to round
|
||||
return {
|
||||
left: roundFloat(left),
|
||||
top: roundFloat(top)
|
||||
left: Math.round(left),
|
||||
top: Math.round(top)
|
||||
};
|
||||
}
|
||||
|
@ -1,16 +0,0 @@
|
||||
/**
|
||||
* @file round-float.js
|
||||
*
|
||||
* Should round off a number to a decimal place
|
||||
*
|
||||
* @param {Number} num Number to round
|
||||
* @param {Number} dec Number of decimal places to round to
|
||||
* @return {Number} Rounded number
|
||||
* @private
|
||||
* @method roundFloat
|
||||
*/
|
||||
const roundFloat = function(num, dec=0) {
|
||||
return Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
|
||||
};
|
||||
|
||||
export default roundFloat;
|
@ -4,6 +4,7 @@
|
||||
import document from 'global/document';
|
||||
import * as setup from './setup';
|
||||
import Component from './component';
|
||||
import EventTarget from './event-target';
|
||||
import globalOptions from './global-options.js';
|
||||
import Player from './player';
|
||||
import plugin from './plugins.js';
|
||||
@ -16,6 +17,7 @@ import log from './utils/log.js';
|
||||
import xhr from './xhr.js';
|
||||
import * as Dom from './utils/dom.js';
|
||||
import * as browser from './utils/browser.js';
|
||||
import * as Url from './utils/url.js';
|
||||
import extendsFn from './extends.js';
|
||||
import merge from 'lodash-compat/object/merge';
|
||||
import createDeprecationProxy from './utils/create-deprecation-proxy.js';
|
||||
@ -208,13 +210,24 @@ videojs.getComponent = Component.getComponent;
|
||||
*/
|
||||
videojs.registerComponent = Component.registerComponent;
|
||||
|
||||
/*
|
||||
/**
|
||||
* A suite of browser and device tests
|
||||
*
|
||||
* @type {Object}
|
||||
* @private
|
||||
*/
|
||||
videojs.browser = browser;
|
||||
|
||||
/**
|
||||
* Whether or not the browser supports touch events. Included for backward
|
||||
* compatibility with 4.x, but deprecated. Use `videojs.browser.TOUCH_ENABLED`
|
||||
* instead going forward.
|
||||
*
|
||||
* @deprecated
|
||||
* @type {Boolean}
|
||||
*/
|
||||
videojs.TOUCH_ENABLED = browser.TOUCH_ENABLED;
|
||||
|
||||
/**
|
||||
* Subclass an existing class
|
||||
* Mimics ES6 subclassing with the `extends` keyword
|
||||
@ -414,6 +427,22 @@ videojs.createTimeRange = createTimeRange;
|
||||
*/
|
||||
videojs.xhr = xhr;
|
||||
|
||||
/**
|
||||
* Resolve and parse the elements of a URL
|
||||
*
|
||||
* @param {String} url The url to parse
|
||||
* @return {Object} An object of url details
|
||||
* @method parseUrl
|
||||
*/
|
||||
videojs.parseUrl = Url.parseUrl;
|
||||
|
||||
/**
|
||||
* Event target class.
|
||||
*
|
||||
* @type {Function}
|
||||
*/
|
||||
videojs.EventTarget = EventTarget;
|
||||
|
||||
// REMOVING: We probably should add this to the migration plugin
|
||||
// // Expose but deprecate the window[componentName] method for accessing components
|
||||
// Object.getOwnPropertyNames(Component.components).forEach(function(name){
|
||||
|
@ -1,6 +1,6 @@
|
||||
import TextTrackList from '../../../src/js/tracks/text-track-list.js';
|
||||
import TextTrack from '../../../src/js/tracks/text-track.js';
|
||||
import EventEmitter from '../../../src/js/event-emitter.js';
|
||||
import EventTarget from '../../../src/js/event-target.js';
|
||||
|
||||
var noop = Function.prototype;
|
||||
var genericTracks = [
|
||||
@ -146,7 +146,7 @@ test('a "removetrack" event is triggered when tracks are removed', function() {
|
||||
});
|
||||
|
||||
test('trigger "change" event when "modechange" is fired on a track', function() {
|
||||
var tt = new EventEmitter(),
|
||||
var tt = new EventTarget(),
|
||||
ttl = new TextTrackList([tt]),
|
||||
changes = 0,
|
||||
changeHandler = function() {
|
||||
|
@ -1,8 +0,0 @@
|
||||
import roundFloat from '../../../src/js/utils/round-float.js';
|
||||
|
||||
test('should round a number', function(){
|
||||
ok(roundFloat(1.01) === 1);
|
||||
ok(roundFloat(1.5) === 2);
|
||||
ok(roundFloat(1.55, 2) === 1.55);
|
||||
ok(roundFloat(10.551, 2) === 10.55);
|
||||
});
|
Loading…
Reference in New Issue
Block a user