@@ -558,13 +558,20 @@ function StyleBox() {
558558
559559// Apply styles to a div. If there is no div passed then it defaults to the
560560// div on 'this'.
561- StyleBox . prototype . applyStyles = function ( styles , div ) {
561+ StyleBox . prototype . applyStyles = function ( styles , div , inlineStyles , onapplystyles ) {
562562 div = div || this . div ;
563- for ( var prop in styles ) {
564- if ( styles . hasOwnProperty ( prop ) ) {
565- div . style [ prop ] = styles [ prop ] ;
563+
564+ if ( this . inlineStyles ) {
565+ for ( var prop in styles ) {
566+ if ( styles . hasOwnProperty ( prop ) ) {
567+ div . style [ prop ] = styles [ prop ] ;
568+ }
566569 }
567570 }
571+
572+ if ( typeof this . onapplystyles === 'function' ) {
573+ this . onapplystyles ( styles , div ) ;
574+ }
568575} ;
569576
570577StyleBox . prototype . formatStyle = function ( val , unit ) {
@@ -573,9 +580,11 @@ StyleBox.prototype.formatStyle = function(val, unit) {
573580
574581// Constructs the computed display state of the cue (a div). Places the div
575582// into the overlay which should be a block level element (usually a div).
576- function CueStyleBox ( window , cue , styleOptions ) {
583+ function CueStyleBox ( window , cue , styleOptions , inlineStyles , onapplystyles ) {
577584 StyleBox . call ( this ) ;
578585 this . cue = cue ;
586+ this . inlineStyles = inlineStyles ;
587+ this . onapplystyles = onapplystyles ;
579588
580589 // Parse our cue's text into a DOM tree rooted at 'cueDiv'. This div will
581590 // have inline positioning and will function as the cue background box.
@@ -595,7 +604,7 @@ function CueStyleBox(window, cue, styleOptions) {
595604 unicodeBidi : "plaintext"
596605 } ;
597606
598- this . applyStyles ( styles , this . cueDiv ) ;
607+ this . applyStyles ( styles , this . cueDiv , inlineStyles , onapplystyles ) ;
599608
600609 // Create an absolutely positioned div that will be used to position the cue
601610 // div. Note, all WebVTT cue-setting alignments are equivalent to the CSS
@@ -973,7 +982,7 @@ var CUE_BACKGROUND_PADDING = "1.5%";
973982// Runs the processing model over the cues and regions passed to it.
974983// @param overlay A block level element (usually a div) that the computed cues
975984// and regions will be placed into.
976- WebVTT . processCues = function ( window , cues , overlay ) {
985+ WebVTT . processCues = function ( { window, cues, overlay, onapplystyles , inlineStyles = true } = { } ) {
977986 if ( ! window || ! cues || ! overlay ) {
978987 return null ;
979988 }
@@ -1026,7 +1035,7 @@ WebVTT.processCues = function(window, cues, overlay) {
10261035 cue = cues [ i ] ;
10271036
10281037 // Compute the intial position and styles of the cue div.
1029- styleBox = new CueStyleBox ( window , cue , styleOptions ) ;
1038+ styleBox = new CueStyleBox ( window , cue , styleOptions , inlineStyles , onapplystyles ) ;
10301039 paddedOverlay . appendChild ( styleBox . div ) ;
10311040
10321041 // Move the cue div to it's correct line position.
0 commit comments