-
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
Fix to avoid duplicate chapters by building a new list each time #3354
Changes from 3 commits
8a9944a
be8d2e8
8740f0c
d575e93
32f7bbd
426c0a8
a70e2c4
399d85e
842df6a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,9 +75,11 @@ class ChaptersButton extends TextTrackButton { | |
createMenu() { | ||
let tracks = this.player_.textTracks() || []; | ||
let chaptersTrack; | ||
let items = this.items = []; | ||
let items = this.items || []; | ||
|
||
for (let i = 0, length = tracks.length; i < length; i++) { | ||
for (let i = tracks.length - 1; i >= 0; i--) { | ||
|
||
// We will always choose the last track as our chaptersTrack | ||
let track = tracks[i]; | ||
|
||
if (track['kind'] === this.kind_) { | ||
|
@@ -97,6 +99,13 @@ class ChaptersButton extends TextTrackButton { | |
}); | ||
menu.children_.unshift(title); | ||
Dom.insertElFirst(title, menu.contentEl()); | ||
this.addChild(menu); | ||
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. should this line just not be here? |
||
} else { | ||
// We will empty out the menu children each time because we want a | ||
// fresh new menu child list each time | ||
items.forEach(item => menu.removeChild(item)); | ||
// Empty out the ChaptersButton menu items because we no longer need them | ||
items = []; | ||
} | ||
|
||
if (chaptersTrack && chaptersTrack.cues == null) { | ||
|
@@ -124,17 +133,26 @@ class ChaptersButton extends TextTrackButton { | |
|
||
menu.addChild(mi); | ||
} | ||
|
||
this.addChild(menu); | ||
} | ||
|
||
if (this.items.length > 0) { | ||
if (items.length > 0) { | ||
this.show(); | ||
} | ||
|
||
// Assigning the value of items back to this.items for next iteration | ||
this.items = items; | ||
return menu; | ||
} | ||
|
||
// Overriding the update button because duplicate chapters get created each time when | ||
// we try to put the chapter title into the DOM | ||
|
||
update() { | ||
if(this.children_.length <= 1) { | ||
this.firstCall = true; | ||
super.update(); | ||
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. This can still be called if a non-chapters track is added. We should make sure that it only does anything when chapters are added. |
||
} else if(this.children_.length > 1) { | ||
this.children_.pop(); | ||
} | ||
} | ||
} | ||
|
||
ChaptersButton.prototype.kind_ = 'chapters'; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,11 @@ class MenuButton extends ClickableComponent { | |
if (this.menu) { | ||
this.removeChild(this.menu); | ||
} | ||
// We need to remove the menu because we are already adding one before. | ||
// This can create duplicate menu items causing tests to fail | ||
if(this.menu === undefined && this.firstCall) { | ||
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. this duplicated the code from lines 41-34. |
||
this.removeChild(menu); | ||
} | ||
|
||
this.menu = menu; | ||
this.addChild(menu); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -171,17 +171,20 @@ const elIdAttr = 'vdata' + (new Date()).getTime(); | |
* @function getElData | ||
*/ | ||
export function getElData(el) { | ||
let id = el[elIdAttr]; | ||
|
||
if (!id) { | ||
id = el[elIdAttr] = Guid.newGUID(); | ||
} | ||
|
||
if (!elData[id]) { | ||
elData[id] = {}; | ||
} | ||
|
||
return elData[id]; | ||
//if(el) { | ||
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. work-in-progress checked in. |
||
|
||
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. extra whitespace. |
||
let id = el[elIdAttr]; | ||
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. The indent is off. It shouldn't be showing up as changed in the diff. |
||
|
||
if (!id) { | ||
id = el[elIdAttr] = Guid.newGUID(); | ||
} | ||
|
||
if (!elData[id]) { | ||
elData[id] = {}; | ||
} | ||
|
||
return elData[id]; | ||
//} | ||
} | ||
|
||
/** | ||
|
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.
why remove this?
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.
Added the comment back
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.
This shouldn't be showing up as changed in the diff.