-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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
Restore video tag attributes on tech change #1369
Closed
dcharbonnier
wants to merge
13
commits into
videojs:master
from
dcharbonnier:feature/video-attr-restore
Closed
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
4af8af0
add test for video tag attr conservation
dcharbonnier c4aa9fa
set attributes of video tag and not only values
dcharbonnier 2537c98
add unsupported attribute to the video tag - test failing
dcharbonnier 0e78c9e
helper to set attributes on an element from a map of values
dcharbonnier aeefefe
dummy compare of html content with a sort of the attributes
dcharbonnier dae47c6
ignore html attributes order for comparition
dcharbonnier 998183f
save original tag attributes
dcharbonnier a443d21
restore original tag attributes n creation and overwrite if required …
dcharbonnier 72bbabd
replace object.keys with vjs.obj.each for ie<9
dcharbonnier ca8313b
fix spacing
dcharbonnier b54f5e2
API consistency, getAttributeValues renamed to getElementAttributes
dcharbonnier 1c5f928
clear variable naming
dcharbonnier 0604746
move setElementAttributes close to getElementAttributes
dcharbonnier File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
helper to set attributes on an element from a map of values
- Loading branch information
commit 0e78c9e53c7710c693d1758d8f3692d85053cda0
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,25 @@ vjs.createEl = function(tagName, properties){ | |
return el; | ||
}; | ||
|
||
/** | ||
* Apply attributes to an html element. | ||
* @param {Element} el Target element. | ||
* @param {Object=} attributes Element attributes to be applied. | ||
* @private | ||
*/ | ||
vjs.setElementAttributes = function(el, attributes){ | ||
var keys = Object.keys(attributes); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe Object.keys will error in ie8. You can use vjs.obj.each instead. |
||
for(var i = 0,l = keys.length;i<l;i++) { | ||
var attrName = keys[i]; | ||
var attrValue = attributes[attrName]; | ||
if (attrValue === null || typeof attrValue === 'undefined' || attrValue === false) { | ||
el.removeAttribute(attrName); | ||
} else { | ||
el.setAttribute(attrName,attrValue === true ? '' : attrValue); | ||
} | ||
} | ||
}; | ||
|
||
/** | ||
* Uppercase the first letter of a string | ||
* @param {String} string String to be uppercased | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -152,6 +152,22 @@ test('should read tag attributes from elements, including HTML5 in all browsers' | |
equal(trackVals['title'], 'test'); | ||
}); | ||
|
||
|
||
test('should set tag attributes from object', function(){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for writing tests! |
||
|
||
var tags = '<video id="vid1" controls data-test="ok"></video>'; | ||
|
||
document.getElementById('qunit-fixture').innerHTML += tags; | ||
var el = document.getElementById('vid1'); | ||
vjs.setElementAttributes(el, {controls: false,'data-test': 'asdf'}); | ||
|
||
var vid1Vals = vjs.getAttributeValues(document.getElementById('vid1')); | ||
|
||
equal(vid1Vals['controls'], undefined); | ||
equal(vid1Vals['id'], 'vid1'); | ||
equal(vid1Vals['data-test'], 'asdf'); | ||
}); | ||
|
||
test('should get the right style values for an element', function(){ | ||
var el = document.createElement('div'); | ||
var container = document.createElement('div'); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The name should match the existing
getAttributeValues
in the same file for API consistency. I'd be fine with changing that togetElementAttributes
since it's not an exported function yet.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.
changed to getElementAttributes
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.
Ok that's understandable. What are the unsymmetrical pieces?
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.
business logic on getAttributeValues : knownBooleans = ','+'autoplay,controls,loop,muted,default'+',';
setElementAttributes is 'html oriented', you have a dom element you want to update the attributes according to a dict. Nothing related to videojs.
BTW I already changed it but can revert the change and if we keep this change I should put the set and get methods on the same place, now the setElementAttributes is near the createEl
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.
Yeah, that's true. There's some overlap because of the translation from empty string to boolean, so I prefer they stay consistent here. Also I'm wondering if we couldn't remove the knownBooleans and switch every empty string value to a boolean. That might take a little research so not something we need to deal with in this pull request.