From 2fc8968002cf2f40128c39699c3ffbaac73fc9ed Mon Sep 17 00:00:00 2001 From: heff Date: Wed, 13 May 2015 22:45:01 -0700 Subject: [PATCH] @heff added support for fluid widths, aspect ratios, and metadata defaults. closes #1952 --- CHANGELOG.md | 1 + package.json | 1 + src/css/components/_layout.scss | 37 +++++++- src/css/components/_poster.scss | 4 + src/js/options.js | 3 - src/js/player.js | 149 ++++++++++++++++++++++++++++++-- src/js/tech/html5.js | 3 + test/unit/player.js | 71 +++++++++++---- 8 files changed, 238 insertions(+), 31 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d65928bf..c0b345613 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ CHANGELOG * @bc-bbay fixed instance where progress bars would go passed 100% ([view](https://github.com/videojs/video.js/pull/2040)) * @eXon began Tech 2.0 work, improved how tech events are handled by the player ([view](https://github.com/videojs/video.js/pull/2057)) * @gkatsev added get and set global options methods ([view](https://github.com/videojs/video.js/pull/2115)) +* @heff added support for fluid widths, aspect ratios, and metadata defaults ([view](https://github.com/videojs/video.js/pull/1952)) -------------------- diff --git a/package.json b/package.json index e8ad67f04..5a6105ace 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,7 @@ "browserify-istanbul": "^0.2.1", "browserify-versionify": "^1.0.4", "chg": "~0.2.0", + "css": "^2.2.0", "grunt": "^0.4.4", "grunt-aws-s3": "^0.12.1", "grunt-banner": "^0.3.1", diff --git a/src/css/components/_layout.scss b/src/css/components/_layout.scss index 371bead21..418f241f9 100644 --- a/src/css/components/_layout.scss +++ b/src/css/components/_layout.scss @@ -1,7 +1,15 @@ .video-js { - display: block; + /* inline-block is as close as we get to the video el's display:inline */ + display: inline-block; + /* Make video.js videos align top when next to video elements */ + vertical-align: top; box-sizing: border-box; + /* Default to the video element width/height. This will be overridden by + * the source width height unless changed elsewhere. */ + width: 300px; + height: 150px; + color: $primary-text; background-color: $primary-bg; position: relative; @@ -9,8 +17,6 @@ /* Start with 10px for base font size so other dimensions can be em based and easily calculable. */ font-size: $base-font-size; - /* Allow poster to be vertially aligned. */ - vertical-align: middle; /* Provide some basic defaults for fonts */ font-weight: normal; @@ -37,6 +43,29 @@ box-sizing: inherit; } +/* Fill the width of the containing element and use padding to create the + desired aspect ratio. Default to 16x9 unless another ratio is given. */ +@mixin apply-aspect-ratio($width, $height) { + width: 100%; + max-width: 100%; + height: 0; + padding-top: 100% * ($height/$width); +} + +.video-js.vjs-fluid, +.video-js.vjs-16-9 { + @include apply-aspect-ratio(16, 9); +} + +.video-js.vjs-4-3 { + @include apply-aspect-ratio(4, 3); +} + +.video-js.vjs-fill { + width: 100%; + height: 100%; +} + /* Playback technology elements expand to the width/height of the containing div