Skip to content

Add bindings for HTMLVideoElement.videoWidth and videoHeight #3927

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 15, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Test whether dimension bindings still work for video elements
  • Loading branch information
MattiasBuelens committed Nov 15, 2019
commit 51c1adeca5171d5c1ce2e1ddc78514606214fefa
17 changes: 16 additions & 1 deletion test/js/samples/video-bindings/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import {
SvelteComponent,
add_render_callback,
add_resize_listener,
detach,
element,
init,
Expand All @@ -16,6 +17,7 @@ import {
function create_fragment(ctx) {
let video;
let video_updating = false;
let video_resize_listener;
let video_animationframe;
let dispose;

Expand All @@ -33,6 +35,7 @@ function create_fragment(ctx) {
return {
c() {
video = element("video");
add_render_callback(() => ctx.video_elementresize_handler.call(video));
if (ctx.videoHeight === void 0 || ctx.videoWidth === void 0) add_render_callback(() => ctx.video_resize_handler.call(video));

dispose = [
Expand All @@ -42,6 +45,7 @@ function create_fragment(ctx) {
},
m(target, anchor) {
insert(target, video, anchor);
video_resize_listener = add_resize_listener(video, ctx.video_elementresize_handler.bind(video));
},
p(changed, ctx) {
if (!video_updating && changed.currentTime && !isNaN(ctx.currentTime)) {
Expand All @@ -54,6 +58,7 @@ function create_fragment(ctx) {
o: noop,
d(detaching) {
if (detaching) detach(video);
video_resize_listener.cancel();
run_all(dispose);
}
};
Expand All @@ -63,6 +68,12 @@ function instance($$self, $$props, $$invalidate) {
let { currentTime } = $$props;
let { videoHeight } = $$props;
let { videoWidth } = $$props;
let { offsetWidth } = $$props;

function video_elementresize_handler() {
offsetWidth = this.offsetWidth;
$$invalidate("offsetWidth", offsetWidth);
}

function video_timeupdate_handler() {
currentTime = this.currentTime;
Expand All @@ -80,12 +91,15 @@ function instance($$self, $$props, $$invalidate) {
if ("currentTime" in $$props) $$invalidate("currentTime", currentTime = $$props.currentTime);
if ("videoHeight" in $$props) $$invalidate("videoHeight", videoHeight = $$props.videoHeight);
if ("videoWidth" in $$props) $$invalidate("videoWidth", videoWidth = $$props.videoWidth);
if ("offsetWidth" in $$props) $$invalidate("offsetWidth", offsetWidth = $$props.offsetWidth);
};

return {
currentTime,
videoHeight,
videoWidth,
offsetWidth,
video_elementresize_handler,
video_timeupdate_handler,
video_resize_handler
};
Expand All @@ -98,7 +112,8 @@ class Component extends SvelteComponent {
init(this, options, instance, create_fragment, safe_not_equal, {
currentTime: 0,
videoHeight: 0,
videoWidth: 0
videoWidth: 0,
offsetWidth: 0
});
}
}
Expand Down
3 changes: 2 additions & 1 deletion test/js/samples/video-bindings/input.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
export let currentTime;
export let videoHeight;
export let videoWidth;
export let offsetWidth;
</script>

<video bind:currentTime bind:videoHeight bind:videoWidth/>
<video bind:currentTime bind:videoHeight bind:videoWidth bind:offsetWidth/>