-
Notifications
You must be signed in to change notification settings - Fork 137
/
mw.Playlist.js
executable file
·841 lines (758 loc) · 24.3 KB
/
mw.Playlist.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
/**
* Playlist Embed. Enables the embedding of a playlist using the mwEmbed player
*/
( function( mw, $ ) { "use strict";
mw.Playlist = function( options ){
return this.init( options );
};
mw.Playlist.prototype = {
// Stores the current clip index to be played
clipIndex: 0,
// Stores the cached player size:
targetPlayerSize: null,
// The source handler
sourceHandler: null,
// the theme handler:
theme : null,
// player Id
playerId: null,
// Store if the current mouse gesture was a mouse up ( only affects iPad emulation with desktop browers )
onTouchScroll: false,
// Flag for disabling jumping between clips
enableClipSwitch: true,
bindPostfix: '.playlist',
// constructor
init: function( options ) {
var _this = this;
// Check for required options:
if( options.src )
this.src = options.src;
if( options.srcPayLoad ){
this.srcPayLoad = unescape(options.srcPayLoad).replace(/\+/g,' ');
}
this.target = options.target;
if( options.embedPlayer ) {
this.embedPlayer = options.embedPlayer;
this.embedPlayer.playlist = this;
}
// We assign the base player the id of the playlist ( since we want the player api to be
// exposed for the playlist id )
this.playerId = ( this.embedPlayer )?
this.embedPlayer.id :
( options['id'] )? options['id'] :
$( this.target ).attr( 'id' );
// Setup the id for the playlist container:
this.id = 'plholder_' + this.playerId;
// Update the target id
$( this.target ).attr( 'id', this.id );
this.target = '#' + this.id;
// Set binding to disable "waitForMeta" for playlist items ( We know the size and length )
$( mw ).bind( 'checkPlayerWaitForMetaData', function(even, playerElement ){
if( $( playerElement ).hasClass( 'mwPlaylist') ){
playerElement.waitForMeta = false;
}
});
this.type = ( options.type ) ?
options.type:
mw.getConfig('Playlist.DefaultType' );
var namedOptions = [ 'layout', 'playerAspect', 'itemThumbWidth', 'titleHeight', 'titleLength', 'descriptionLength' ];
$.each( namedOptions, function(inx, optionName ){
var confName = 'Playlist.' + optionName.charAt(0).toUpperCase() + optionName.substr(1);
_this[ optionName ] = ( typeof options[ optionName ] != 'undefined' )?
options[ optionName ] :
mw.getConfig( confName );
});
},
// try to get the title height from the source handler, else from the local configuration
getTitleHeight: function(){
if( this.sourceHandler && typeof this.sourceHandler.titleHeight != 'undefined' )
return this.sourceHandler.titleHeight;
return this.titleHeight;
},
formatTitle: function( text ){
if( text.length > this.titleLength )
//return text.substr(0, this.titleLength-3) + ' ...';
return text;
},
formatDescription: function( text ){
if( text.length > this.descriptionLength )
return text.substr(0, this.descriptionLength-3) + ' ...';
return text;
},
drawPlaylist: function( drawDoneCallback ){
var _this = this;
// Set the target to loadingSpinner ( if we don't already have an embedPlayer )
if( !this.embedPlayer ){
$( this.target ).loadingSpinner();
}
var callback = function(){
if( _this.sourceHandler.autoPlay || _this.autoPlay ){
// only auto play if ipad3x ( iPad 4 and iOS does not let you autoplay )
if( !mw.isIOS() || mw.isIpad3() ){
_this.playClip( _this.clipIndex );
}
}
drawDoneCallback();
};
this.loadPlaylistHandler( function( sourceHandler ){
// Done loading playlist hide loader ( this is kind of messy )
if( !_this.embedPlayer ){
$( _this.target ).empty();
}
mw.log("Playlist::drawPlaylist: sourceHandler:" + sourceHandler);
// Check if load failed or empty playlist
if( _this.sourceHandler.getClipList().length == 0 ){
$( _this.target ).text( gM('mwe-playlist-empty') );
callback();
return ;
}
// Check if we should include the ui
if( _this.sourceHandler.hasPlaylistUi() ){
_this.drawUI( callback );
} else {
if( !_this.isPlayerPreset() ){
$( _this.target )
.empty()
.append(
_this.getPlayerContainer()
);
}
_this.drawEmbedPlayer( _this.clipIndex, callback );
}
});
},
getClipList:function(){
return this.sourceHandler.getClipList();
},
isPlayerPreset:function(){
// check if the player container already exists ( playlist iframe pre-layout )
var $pl = $( this.target ).find( '.media-rss-video-player-container' );
return !!( $pl.length );
},
getPlayerContainer:function(){
return $( '<span />' )
.addClass( 'media-rss-video-player-container')
.css({
'float' : 'left'
})
.append(
$('<div />').addClass( 'media-rss-video-player' ).css( 'position', 'relative' )
);
},
/**
* Draw the media rss playlist ui
*/
drawUI: function( callback ){
var _this = this;
// Empty the target and setup player and playerList divs
$( _this.target )
.addClass( 'ui-widget-content' )
.css('position', 'relative' );
if( !_this.isPlayerPreset() ){
$( _this.target ).append(
_this.getPlayerContainer()
);
}
// @@TODO Add media-playlist-ui container
// Add the video list:
$( _this.target ).append(
$('<div />')
.attr( 'id', 'video-list-wrapper-' + _this.id )
.addClass('video-list-wrapper')
.css({
'position' : 'absolute',
'z-index' : '1',
'overflow-x' : 'hidden',
'overflow-y' : 'auto',
'bottom': '0px'
})
.append(
$( '<div />')
.addClass( 'media-rss-video-list' )
.attr( 'id', 'media-rss-video-list-' + _this.id )
)
.hide()
);
// Check if we have multiple playlist and setup the list and bindings
if( _this.sourceHandler.hasMultiplePlaylists() ){
var playlistSet = _this.sourceHandler.getPlaylistSet();
if( _this.layout == 'vertical' ){
var leftPx = '0px';
} else {
// just the default left side assignment ( updates once we have player size )
var leftPx = '444px';
var playerSize = _this.getTargetPlayerSize();
if( playerSize.width )
leftPx = playerSize.width;
}
var $plListContainer =$('<div />')
.addClass( 'playlist-set-container' )
.css({
'position' : 'absolute',
'overflow' : 'hidden',
'top' : '3px',
'height' : '20px',
'padding' : '4px',
'left' : leftPx
})
.append(
$('<span />')
.addClass( 'playlist-set-list' )
.css( {
'white-space':'pre'
})
);
$( _this.target ).append( $plListContainer );
var $plListSet = $( _this.target ).find( '.playlist-set-list' );
$.each( playlistSet, function( inx, playlist){
// check for playlist name:
if( !playlist.name ){
return true;
}
// Add a divider
if( inx != 0 ){
$plListSet.append( $('<span />').text( ' | ') );
}
var $plLink = $('<a />')
.attr('href', '#')
.text( playlist.name )
.click( function(){
_this.switchTab( inx );
return false;
})
.buttonHover();
// highlight the default
if( inx == 0 ){
$plLink.addClass( 'ui-state-active' );
}
$plListSet.append( $plLink );
});
// Check playlistSet width and add scroll left / scroll right buttons
if( $plListSet.width() > $plListContainer.width() ){
var baseButtonWidth = 24;
$plListSet.css( {
'position': 'absolute',
'left' : baseButtonWidth + 'px'
});
var $scrollButton = $('<div />')
.addClass( 'ui-corner-all ui-state-default' )
.css({
'position' : 'absolute',
'top' : '-1px',
'cursor' : 'pointer',
'margin' :'0px',
'padding' : '2px',
'width' : '16px',
'height' : '16px'
});
var $buttonSpan = $('<span />')
.addClass( 'ui-icon' )
.css('margin', '2px' );
var plScrollPos = 0;
var scrollToListPos = function( pos ){
listSetLeft = $plListSet.find('a').eq( pos ).offset().left -
$plListSet.offset().left ;
mw.log("scroll to: " + pos + ' left: ' + listSetLeft);
$plListSet.animate({'left': -( listSetLeft - baseButtonWidth) + 'px'} );
};
$plListContainer
.append(
$scrollButton.clone()
.css('left', '0px')
.append( $buttonSpan.clone().addClass('ui-icon-circle-arrow-w') )
.click( function(){
//slide right
if( plScrollPos >= 0){
mw.log("scroll right");
plScrollPos--;
scrollToListPos( plScrollPos );
}
})
.buttonHover(),
$scrollButton.clone()
.css('right', '0px')
.append( $buttonSpan.clone().addClass('ui-icon-circle-arrow-e') )
.click( function(){
//slide left
if( plScrollPos < $plListSet.find('a').length-1 ){
plScrollPos++;
scrollToListPos( plScrollPos );
}
})
.buttonHover()
);
}
};
// Add the selectable media list
_this.addMediaList();
var $videoListWraper = $( '#video-list-wrapper-' + _this.id );
// Update the player
_this.drawEmbedPlayer( _this.clipIndex, function(){
var playerSize = _this.getTargetPlayerSize();
// Update the list height ( vertical layout )
if( _this.layout == 'vertical' ){
var verticalSpace = $( _this.target + ' .media-rss-video-player-container' ).height();
$videoListWraper.css( {
'top' : parseInt( verticalSpace ) + 4,
'left' : '0px',
'right' : '4px'
} );
// Add space for the multi-playlist selector:
if( _this.sourceHandler.hasMultiplePlaylists() ){
$videoListWraper.css({
'top' : parseInt( verticalSpace ) + 26
});
}
} else {
// Update horizontal layout
$videoListWraper.css( {
'top' : '0px',
'left' : parseInt( playerSize.width ) + 4,
'right' : '2px',
'margin-top' : '5px'
} );
// Add space for the multi-playlist selector:
if( _this.sourceHandler.hasMultiplePlaylists() ){
$( _this.target + ' .playlist-set-container').css( {
'left' : parseInt( playerSize.width ) + 4
});
$videoListWraper.css( {
'top' : '26px'
});
}
}
// Show the videoList
$videoListWraper.show();
_this.sourceHandler.adjustTextWidthAfterDisplay( $videoListWraper );
// Should test for touch support
if( mw.isMobileDevice() && !$('#video-list-wrapper-' + _this.id )[0].iScroll ){
// give real height for iScroll:
$videoListWraper.css("height", $videoListWraper.height() );
// add iScroll:
$('#video-list-wrapper-' + _this.id )[0].iScroll =
new iScroll( 'video-list-wrapper-' + _this.id, {
'onTouchEnd': function(e, moved){
if( moved !== false){
_this.onTouchScroll = true;
} else {
_this.onTouchScroll = false
}
return false
},
'hScroll' : false,
'hideScrollbar' : false
});
}
if( callback ) {
callback();
}
});
},
switchTab: function( inx ){
var _this = this;
var $tabSet = $( _this.target ).find( '.playlist-set-list' );
$tabSet
.find('a')
.eq( inx )
.addClass( 'ui-state-active' )
.siblings().removeClass('ui-state-active');
_this.sourceHandler.setPlaylistIndex( inx );
mw.log( 'mw.Playlist:: selectPlaylist:' + inx );
$( _this.target + ' .media-rss-video-list')
.empty()
.append(
$('<div />')
.css({
'position' : 'absolute',
'top' : '45%',
'left' : '45%'
})
.loadingSpinner()
)
_this.sourceHandler.loadCurrentPlaylist( function(){
$( _this.target + ' .media-rss-video-list').empty();
_this.addMediaList();
});
},
/**
* Update the target size of the player
*/
getTargetPlayerSize: function( ){
var _this = this;
if( this.targetPlayerSize ){
return this.targetPlayerSize;
}
// Get the target width and height:
this.targetWidth = $( this.target ).width();
this.targetHeight = $( this.target ).height();
// if there is no player interface take all the allowed space:
if( !_this.sourceHandler.hasPlaylistUi() ){
return {
'width' : this.targetWidth + 'px',
'height' : this.targetHeight + 'px'
};
}
if( _this.layout == 'vertical' ){
/* Vertical layout */
var pa = this.playerAspect.split(':');
this.targetPlayerSize = {
'width' : this.targetWidth + 'px',
'height' : parseInt( ( pa[1] / pa[0] ) * this.targetWidth )
};
} else {
/* horizontal layout */
// Check if we have explicit video size
var playerWidth = parseInt( $( this.target + ' .media-rss-video-player-container' ).css('width') );
if( isNaN( playerWidth) || !playerWidth ){
if( _this.sourceHandler.getVideoListWidth() != 'auto' ){
playerWidth = this.targetWidth - _this.sourceHandler.getVideoListWidth();
} else {
var pa = this.playerAspect.split(':');
playerWidth = parseInt( ( pa[0] / pa[1] ) * this.targetHeight );
}
}
this.targetPlayerSize = {
'height' : ( this.targetHeight - this.getTitleHeight() ) + 'px',
'width' : playerWidth + 'px'
};
}
if( this.targetPlayerSize.width > this.targetWidth ){
var pa = this.playerAspect.split(':');
this.targetPlayerSize.width = this.targetWidth;
this.targetPlayerSize.height = parseInt( ( pa[1] / pa[0] ) * this.targetWidth );
}
return this.targetPlayerSize;
},
getEmbedPlayer: function(){
return $('#' + this.getVideoPlayerId() )[0];
},
getVideoPlayerTarget: function(){
return $( this.target + ' .media-rss-video-player' );
},
// Play a clipIndex, if the player is already in the page swap the player src to the new target
playClip: function( clipIndex, autoContinue ){
var _this = this;
mw.log( "mw.Playlist::playClip > " + clipIndex );
// Check for a video/audio tag already in the page:
var embedPlayer = this.getEmbedPlayer();
this.clipIndex = clipIndex;
if( !embedPlayer ){
mw.log("Error: Playlist:: playClip called with null embedPlayer ");
return ;
}
// trigger a playlist_playClip event:
embedPlayer.triggerHelper( 'Playlist_PlayClip', [ clipIndex, !!autoContinue ]);
// Hand off play clip request to sourceHandler:
_this.sourceHandler.playClip( embedPlayer, clipIndex, function(){
mw.log( "mw.Playlist::playClip > sourceHandler playClip callback ");
// Do any local player interface updates:
_this.updatePlayerUi( clipIndex );
// Add playlist specific bindings:
_this.addClipBindings();
// Restore onDoneInterfaceFlag
embedPlayer.onDoneInterfaceFlag = true;
} );
},
/**
* Update the player
*/
drawEmbedPlayer: function( clipIndex , callback ){
var _this = this;
mw.log( "mw.Playlist:: updatePlayer " + clipIndex );
this.clipIndex = clipIndex;
// Check if we really have to update:
var embedPlayer = _this.getEmbedPlayer();
if( $( embedPlayer ).data('clipIndex') == clipIndex ){
callback();
return ;
}
// Pass off player updates to sourceHandler
_this.sourceHandler.drawEmbedPlayer( clipIndex, function(){
// update Ui:
_this.updatePlayerUi( _this.clipIndex );
// Add playlist specific bindings:
_this.addClipBindings();
// Issue the playlist ready callback
callback();
});
},
addClipBindings: function( ){
var _this = this;
mw.log( "mw.Playlist::addClipBindings" );
var embedPlayer = _this.getEmbedPlayer();
// remove any old playlist bindings:
$( embedPlayer ).unbind( this.bindPostfix );
// Once the player is ready add any custom bindings
_this.sourceHandler.addEmbedPlayerBindings( embedPlayer );
// Add the seek forward / back buttons
_this.addPlaylistSeekButtons();
// Add ad bindings
_this.addPlaylistAdBindings();
// Setup ondone playing binding to play next clip (if autoContinue is true )
if( _this.sourceHandler.autoContinue == true ){
$( embedPlayer ).bind( 'postEnded' + _this.bindPostfix, function(event ){
mw.log("mw.Playlist:: postEnded > on inx: " + _this.clipIndex );
// Play next clip
if( parseInt( _this.clipIndex ) + 1 < _this.sourceHandler.getClipCount() ){
// Update the onDone action object to not run the base control done:
mw.log("mw.Playlist:: postEnded > continue playlist set: onDoneInterfaceFlag false ");
embedPlayer.onDoneInterfaceFlag = false;
_this.clipIndex = parseInt( _this.clipIndex ) + 1;
// update the player and play the next clip
_this.playClip( _this.clipIndex, true );
} else {
mw.log("mw.Playlist:: End of playlist, run normal end action" );
// Update the onDone action object to not run the base control done:
embedPlayer.onDoneInterfaceFlag = true;
}
});
}
var uiSelector = '.playlist-set-container,.playlist-block-list,.video-list-wrapper,.playlist-scroll-buttons';
// fullscreen support
$( embedPlayer ).bind( 'onOpenFullScreen' + this.bindPostfix, function(){
// hide inteface components ( these should readlly all be in their own div! )
$(uiSelector).hide();
// hide the playlist blocker:
$( _this.target + ' .playlist-block-list').hide();
});
$( embedPlayer ).bind( 'onCloseFullScreen' + this.bindPostfix, function(){
// restore the playlist blocker ( if present
$( _this.target + ' .playlist-block-list').show();
// only resize if the playlist has a ui:
if( !_this.sourceHandler.includeInLayout ){
return ;
}
// Do another resize on a timeout ( takes time for iframe to resize )
setTimeout(function(){
_this.syncPlayerSize();
}, 250);
$(uiSelector).show();
});
},
syncPlayerSize: function(){
var _this = this;
var playerSize = {
'width' : $( _this.target + ' .media-rss-video-player-container' ).width() + 'px',
'height' : ( $( _this.target + ' .media-rss-video-player-container' ).height() - _this.getTitleHeight() ) + 'px'
};
_this.embedPlayer.resizePlayer( playerSize, false );
},
updatePlayerUi:function( clipIndex ){
var _this = this;
// Give a chance for sourceHandler to update player ui
_this.sourceHandler.updatePlayerUi( clipIndex );
// Update the player list if present:
$( _this.target + ' .clipItemBlock')
.removeClass( 'ui-state-active' )
.addClass( 'ui-state-default' )
.eq( clipIndex )
.addClass( 'ui-state-active' );
},
getVideoPlayerId: function( ){
return this.playerId;
},
// Checks if the player has next prev playlist buttons if not adds them.
addPlaylistSeekButtons: function(){
var _this = this;
var embedPlayer = this.getEmbedPlayer();
// Don't add seek buttons if we don't have an embedPlayer:
if( ! embedPlayer ){
return ;
}
// add previous / next buttons if not present:
// TODO (HACK) we should do real controlBar support for custom buttons
if( embedPlayer.controlBuilder ){
var $controlBar = embedPlayer.$interface.find('.control-bar');
if( $controlBar.find( '.ui-icon-seek-next' ).length != 0 ){
// already have seek buttons
return false;
}
var $plButton = $('<div />')
.addClass("ui-state-default ui-corner-all ui-icon_link lButton")
.buttonHover()
.append(
$('<span />')
.addClass( "ui-icon")
);
var $playButton = $controlBar.find( '.play-btn');
if( _this.sourceHandler.isNextButtonDisplayed() ){
// make space ( reduce playhead length )
var pleft = parseInt( $controlBar.find( '.play_head' ).css( 'left' ) ) + 28;
$controlBar.find('.play_head').css('left', pleft);
var $nextButton = $plButton.clone().attr({
'title' : 'Next clip'
})
.click(function(){
if(_this.enableClipSwitch && _this.clipIndex + 1 < _this.sourceHandler.getClipCount() ){
_this.clipIndex++;
_this.playClip( _this.clipIndex );
return ;
}
mw.log( "Error: mw.playlist can't next: current: " + _this.clipIndex );
})
.find('span').addClass('ui-icon-seek-next')
.parent()
.buttonHover();
$playButton.after($nextButton);
}
if( _this.sourceHandler.isPreviousButtonDisplayed() ){
// make space ( reduce playhead length )
var pleft = parseInt( $controlBar.find( '.play_head' ).css( 'left' ) ) + 28;
$controlBar.find('.play_head').css('left', pleft);
var $prevButton = $plButton.clone().attr({
'title' : 'Previous clip'
})
.click(function(){
if( _this.enableClipSwitch && _this.clipIndex - 1 >= 0 ){
_this.clipIndex--;
_this.playClip( _this.clipIndex );
return ;
}
mw.log("Cant prev: cur:" + _this.clipIndex );
})
.find('span').addClass('ui-icon-seek-prev')
.parent()
.buttonHover();
$playButton.after($prevButton);
}
}
},
// add bindings for playlist playback ( disable playlist item selection during ad Playback )
addPlaylistAdBindings: function(){
var _this = this;
var embedPlayer = this.getEmbedPlayer();
$( embedPlayer ).bind('AdSupport_StartAdPlayback' + this.bindPostfix, function(){
_this.blockPlaylist();
});
$( embedPlayer ).bind('AdSupport_EndAdPlayback' + this.bindPostfix, function(){
_this.restorePlaylist();
});
},
blockPlaylist: function(){
var _this = this;
var embedPlayer = this.getEmbedPlayer();
// Add the Disable clip switch flag:
_this.enableClipSwitch = false;
// Add a gray overlay
var $listwrap = $( '#video-list-wrapper-plholder_' + this.embedPlayer.id );
var cssPops = ['width','height', 'position', 'bottom', 'right', 'left', 'top'];
var cssObj = {};
// Copy in all the settings:
$.each( cssPops, function(inx, prop){
cssObj[ prop ] = $listwrap.css(prop);
});
// remove height
if( cssObj[ 'height' ] ){
cssObj[ 'height' ] = null;
}
// make sure we are not in fullscreen ( and there is nothing to cover up )
if( !$( _this.target + ' .playlist-block-list').length ){
$listwrap.before(
$('<div />').css( cssObj )
.addClass('playlist-block-list')
.css({
'z-index': 2,
'background-color' : '#FFF',
'opacity' : '0.7',
'filter' : 'alpha(opacity=70)'
})
.click(function(){
// don't let event propagate
return false;
})
);
}
// if in fullscreen hide the listwrap
if( embedPlayer.controlBuilder.inFullScreen ){
$( _this.target + ' .playlist-block-list').hide();
}
},
restorePlaylist: function(){
// Restore clip switch:
this.enableClipSwitch = true;
$( this.target + ' .playlist-block-list').remove();
},
/**
* Add the media list with the selected clip highlighted
*/
addMediaList: function() {
var _this = this;
var $targetItemList = $( this.target + ' .media-rss-video-list');
// update the playlistItme total available width
this.playlistItemWidth = $targetItemList.width();
$.each( this.sourceHandler.getClipList(), function( inx, clip ){
mw.log( 'mw.Playlist::addMediaList: On clip: ' + inx);
if( inx > mw.getConfig( 'Playlist.MaxClips' ) ){
return false;
}
// Output each item with the current selected index:
var $itemBlock = $('<div />')
.addClass( 'ui-widget-content ui-corner-all playlistItem ui-helper-clearfix' );
if( _this.clipIndex == inx ){
$itemBlock.addClass( 'ui-state-active');
} else {
$itemBlock.addClass( 'ui-state-default' );
}
// Add a single row table with image, title then duration
$itemBlock.append(
_this.sourceHandler.getPlaylistItem( inx )
)
.data( 'clipIndex', inx )
.buttonHover()
.addClass( 'clipItemBlock' )
.css( {
'cursor': 'pointer'
} )
.click( function(event){
// check that we can switch clips:
if( !_this.enableClipSwitch ){
return ;
}
// from chrome pretending to be iOS ( store the last touch event )
if( _this.onTouchScroll ){
return ;
}
// Update _this.clipIndex
_this.clipIndex = $( this ).data( 'clipIndex' );
_this.playClip( _this.clipIndex );
}); //close $itemBlock
// Add the itemBlock to the targetItem list
$targetItemList.append(
$itemBlock
);
mw.log("Added item block : " + $targetItemList.children().length );
});
},
play: function(){
mw.log( 'mw.Playlist::play ');
var embedPlayer = $('#' + this.getVideoPlayerId() )[0];
embedPlayer.play();
},
/**
* Load the playlist driver from a source
* @param {function} callback Function to be called once load is complete.
*/
loadPlaylistHandler: function( callback ){
var _this = this;
// Allow plugins to setup the source handler:
$( mw ).trigger('Playlist_GetSourceHandler', [ this ] );
if( !_this.sourceHandler ){
switch( this.type ){
case 'application/rss+xml':
_this.sourceHandler = new mw.PlaylistHandlerMediaRss( this );
break;
}
};
// Load the playlist
_this.sourceHandler.loadPlaylist( function(){
callback( _this.sourceHandler );
});
},
/**
* Set the playlist source handler
*/
setSourceHandler: function ( sourceHandler ){
this.sourceHandler = sourceHandler;
}
};
})( window.mw, jQuery );