-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Editor: Support VideoPress post-editor preview #2267
Conversation
a39341a
to
1a91394
Compare
A few outstanding issues/remarks:
|
const namedAttrs = shortcode.attrs.named; | ||
const defaultWidth = 640; | ||
const defaultHeight = defaultWidth * 9 / 16; | ||
return { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using Object.assign
(or similarly, _.assign
or _.defaults
) can be a handy way to clearly identify the default values, while still allowing override if value is known:
return Object.assign( {
w: defaultWidth,
h: defaultHeight,
at: 0,
defaultLangCode: false
}, {
videopress_guid: shortcode.attrs.numeric[0],
w: parseInt( namedAttrs.w, 10 ),
h: parseInt( namedAttrs.h, 10 ),
autoplay: namedAttrs.autoplay === 'true',
hd: namedAttrs.hd === 'true',
loop: namedAttrs.loop === 'true',
at: parseInt( namedAttrs.at, 10 ),
defaultLangCode: namedAttrs.defaultlangcode
} );
Might be a negligible performance difference, though the clarity benefits should outweigh this. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very handy, indeed! It makes the intent of the code much clearer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very handy, indeed! It makes the intent of the code much clearer.
Actually, this will not work as expected, as the presence of the key in the second argument will override the default value, regardless of whether the value is truthy.
For example, try entering this in your browser console (assuming your browser supports Object.assign
):
Object.assign( { a: 1 }, { a: undefined } );
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the end I used lodash's _.defaults. I also had to substitute NaN
for undefined
to get the expected behavior (i.e. used the default if one exists for unspecified attributes).
Result of running
You might consider installing a linting plugin for your editor for these issues to be more evident: |
8b30730
to
8c65d3a
Compare
fe07fa8
to
c45610d
Compare
width: 100%; | ||
} | ||
|
||
.wpview-wrap iframe { | ||
display: block; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
I wonder if we could reuse some of the embed view logic to simplify this, as the oEmbed endpoint markup already returns the video's known dimensions and includes the resizing script automatically. |
defaultLangCode: namedAttrs.defaultlangcode | ||
}; | ||
|
||
return omit( attrs, ( v, k ) => defaultAttrValues[k] === v ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Many of the variable names in these files are obscure acronyms, which we try to avoid, as they're much more difficult to understand at a glance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made the variable names more descriptive.
Attribute names are cryptic because those are the names expected in the query string and I want to avoid mapping them back and forth.
f3fe8e9
to
f77b87b
Compare
Make boolean shortcode attributes active if the attribute value is missing but the attribute name is defined. That is how the front-end parses shortcode attributes. https://codex.wordpress.org/Shortcode_API#Attributes
f103161
to
3a30ac3
Compare
The branch is rebased and test are up to the new standard. Can you elaborate on how I could reproduce the multiple requests you saw? If I load a draft with video with debug messages enabled (
No other wpcom request is sent out for |
@mjuhasz : I should have paid attention to the "Initiator" column in the network tab: I'm guessing that these requests originate from the VideoPress script. Pretty unfortunate that the additional requests are made, but not sure we can do much about it under the current approach. |
@aduth VideoPress.js issues multiple requests for the same endpoint when loading a post which includes a video. Your former assessment still holds true:
|
Re-opening since it'd be great to get #1730 support for improving our video offering, especially as it's a part of a paid plan. |
Closed in favor of #8342 |
Closes: #1730
This pull request enables previewing of VideoPress videos in the post editor.
There is currently no VideoPress preview offered in the post editor on WordPress.com. When adding a VideoPress video to a post, only the shortcode text is shown in the editor post content. Only after saving and previewing the post can a user see how the post will look like.
Before:
After:
Testing instructions:
Scenario 1 - adding media from your library:
Strictly speaking Scenario 1 resolves issue #1730, nevertheless the following use cases should also work:
Scenario 2 - adding media by pasting a shortcode:
Same as Scenario 1, except Step 4: Insert the following shortcode text into the editor:
[wpvideo kUJmAcSf]
Scenario 3 - using shortcode attributes:
Same as Scenario 1, except:
Step 4: Insert the following shortcode text into the editor:
[wpvideo kUJmAcSf at=90 ]
Step 5: Note that a video player is displayed in the editor and its start time is 1m30s.
Remark: not all shortcode attributes are fully supported at this time for preview.