-
Notifications
You must be signed in to change notification settings - Fork 136
/
mw.PlayerControlBuilder.js
2763 lines (2481 loc) · 81.1 KB
/
mw.PlayerControlBuilder.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
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* Msg text is inherited from embedPlayer
*/
( function( mw, $ ) { "use strict";
/**
* mw.PlayerControlBuilder object
* @param the embedPlayer element we are targeting
*/
mw.PlayerControlBuilder = function( embedPlayer, options ) {
return this.init( embedPlayer, options );
};
/**
* ControlsBuilder prototype:
*/
mw.PlayerControlBuilder.prototype = {
//Default Local values:
// Parent css Class name
playerClass : 'mv-player',
// Long string display of time value
longTimeDisp: true,
// Default volume layout is "vertical"
volumeLayout : 'vertical',
// Default control bar height
height: mw.getConfig( 'EmbedPlayer.ControlsHeight' ),
// Default supported components is merged with embedPlayer set of supported types
supportedComponents: {
// All playback types support options
'options': true
},
// Default supported menu items is merged with skin menu items
supportedMenuItems: {
// Player Select
'playerSelect' : true,
// Download the file menu
'download' : true,
// Share the video menu
'share' : true,
// Player library link
'aboutPlayerLibrary': true
},
// Flag to store the current fullscreen mode
inFullScreen: false,
// Flag to store if a warning binding has been added
addWarningFlag: false,
// Flag to store state of overlay on player
displayOptionsMenuFlag: false,
// Local storage of ControlBar Callback
hideControlBarCallback: false,
// Flag to store controls status (disabled/enabled)
controlsDisabled: false,
// Flag to enable / disable key space binding for play/pause
spaceKeyBindingEnabled: true,
// stores list of parents with absolute position:
parentsAbsoluteList: [],
// store list of parents with relative position:
parentsRelativeList: [],
// binding postfix
bindPostfix: '.controlBuilder',
/**
* Initialization Object for the control builder
*
* @param {Object} embedPlayer EmbedPlayer interface
*/
init: function( embedPlayer ) {
var _this = this;
this.embedPlayer = embedPlayer;
// Check for skin overrides for controlBuilder
var skinClass = embedPlayer.skinName.substr(0,1).toUpperCase() + embedPlayer.skinName.substr( 1 );
if ( mw['PlayerSkin' + skinClass ] ) {
// Clone as to not override prototype with the skin config
var _this = $.extend( true, { }, this, mw['PlayerSkin' + skinClass ] );
return _this;
}
// Return the controlBuilder Object:
return this;
},
/**
* Get the control bar height
* @return {Number} control bar height
*/
getHeight: function(){
return this.height;
},
/**
* Add the controls HTML to player interface
*/
addControls: function() {
// Set up local pointer to the embedPlayer
var embedPlayer = this.embedPlayer;
// Set up local controlBuilder
var _this = this;
// Remove any old controls & old overlays:
embedPlayer.getInterface().find( '.control-bar,.overlay-win' ).remove();
// Reset flags:
_this.displayOptionsMenuFlag = false;
// Setup the controlBar container ( starts hidden )
var $controlBar = $('<div />')
.addClass( 'ui-state-default ui-widget-header ui-helper-clearfix control-bar' )
.css( 'height', this.height );
// Controls are hidden by default if overlaying controls:
if( _this.isOverlayControls() ){
$controlBar.hide();
$controlBar.addClass('hover');
} else {
// Include the control bar height when calculating the layout
$controlBar.addClass('block');
}
// Make room for audio controls in the interface:
if( embedPlayer.isAudio() && embedPlayer.getInterface().height() == 0 ){
embedPlayer.getInterface().css( {
'height' : this.height
} );
}
// Add the controls to the interface
embedPlayer.getInterface().append( $controlBar );
if ( $.browser.mozilla && parseFloat( $.browser.version ) < 2 ) {
embedPlayer.triggerHelper( 'resizeIframeContainer', [ {'height' : embedPlayer.height + $controlBar.height() - 1} ] );
}
// Add the Controls Component
this.addControlComponents();
// Add top level Controls bindings
this.addControlBindings();
},
/**
* Add control components as defined per this.components
*/
addControlComponents: function( ) {
var _this = this;
// Set up local pointer to the embedPlayer
var embedPlayer = this.embedPlayer;
this.availableWidth = embedPlayer.getPlayerWidth();
mw.log( 'PlayerControlsBuilder:: addControlComponents into:' + this.availableWidth );
// Build the supportedComponents list
this.supportedComponents = $.extend( this.supportedComponents, embedPlayer.supports );
// Check for Attribution button
if( mw.getConfig( 'EmbedPlayer.AttributionButton' ) && embedPlayer.attributionbutton ){
this.supportedComponents[ 'attributionButton' ] = true;
}
// Check global fullscreen enabled flag
if( mw.getConfig( 'EmbedPlayer.EnableFullscreen' ) === false ){
this.supportedComponents[ 'fullscreen'] = false;
}
// Check if the options item is available
if( mw.getConfig( 'EmbedPlayer.EnableOptionsMenu' ) === false ){
this.supportedComponents[ 'options'] = false;
}
// Check for volume control
if( mw.getConfig( 'EmbedPlayer.EnableVolumeControl') === false ){
this.supportedComponents[ 'volumeControl'] = false;
}
// Check if we have multiple playable sources ( if only one source don't display source switch )
if( embedPlayer.mediaElement.getPlayableSources().length == 1 ){
this.supportedComponents[ 'sourceSwitch' ] = false;
}
// allow modules to add a component:
$( embedPlayer ).trigger( 'addControlBarComponent', this );
// Output components
for ( var componentId in this.components ) {
// Check for (component === false ) and skip
if( this.components[ componentId ] === false ){
continue;
}
// Special case items - Making sure they are to the left of everything else
var specialItems = [ 'playHead', 'timeDisplay', 'liveStreamStatus', 'liveStreamDVRStatus', 'liveStreamDVRScrubber', 'backToLive' ];
if ( $.inArray( componentId, specialItems ) != -1 ) {
continue;
}
// Skip "fullscreen" button for audio
if( componentId == 'fullscreen' && this.embedPlayer.isAudio() ){
continue;
}
this.addComponent( componentId );
}
// Add special case remaining components:
// In case of live stream we add a time display via liveStreamDVRPlugin
if( mw.getConfig( 'EmbedPlayer.EnableTimeDisplay' ) && !embedPlayer.isLive() ){
this.addComponent( 'timeDisplay' );
}
// In case of live stream we add the playhead via liveStreamDVRPlugin
if( this.availableWidth > 30 && !embedPlayer.isLive() ){
this.addComponent( 'playHead' );
}
if( embedPlayer.isLive() ) {
this.addComponent( 'liveStreamStatus' );
if ( embedPlayer.isDVR() ) {
this.addComponent( 'backToLive' );
this.addComponent( 'liveStreamDVRStatus' );
this.addComponent( 'liveStreamDVRScrubber' );
}
}
$(embedPlayer).trigger( 'controlBarBuildDone' );
},
/**
* add Component method
*/
addComponent : function( componentId ){
var _this = this;
//Set up local var refs
var embedPlayer = this.embedPlayer;
var $controlBar = embedPlayer.getInterface().find( '.control-bar' );
if ( _this.supportedComponents[ componentId ] ) {
if ( _this.availableWidth > _this.components[ componentId ].w ) {
// Append the component
$controlBar.append(
_this.getComponent( componentId )
);
_this.availableWidth -= _this.components[ componentId ].w;
mw.log( "PlayerControlBuilder: availableWidth:" + _this.availableWidth + ' ' + componentId + ' took: ' + _this.components[ componentId ].w )
} else {
mw.log( 'PlayerControlBuilder:: Not enough space for control component:' + componentId );
}
}
},
/**
* Get a window size for the player while preserving aspect ratio:
*
* @@TODO This has similar logic to mw.embedPlayerNative applyIntrinsicAspect we should look
* at merging their functionality.
*
* @param {object} windowSize
* object that set { 'width': {width}, 'height':{height} } of target window
* @return {object}
* css settings for fullscreen player
*/
getAspectPlayerWindowCss: function( windowSize ) {
var embedPlayer = this.embedPlayer;
var _this = this;
// Setup target height width based on max window size
if( !windowSize ){
var windowSize = {
'width' : $( window ).width(),
'height' : $( window ).height()
};
}
windowSize.width = parseInt( windowSize.width );
windowSize.height = parseInt( windowSize.height );
// See if we need to leave space for control bar
if( !_this.isOverlayControls() ){
//targetHeight = targetHeight - this.height;
windowSize.height = windowSize.height - this.height;
}
// Set target width
var targetWidth = windowSize.width;
var targetHeight = Math.floor( targetWidth * ( 1 / _this.getIntrinsicAspect() ) );
// Check if it exceeds the height constraint
// Add a buffer of 2 pixels to avoid resize when "pretty close"
if( targetHeight + 2 > windowSize.height ){
targetHeight = windowSize.height;
targetWidth = parseInt( targetHeight * _this.getIntrinsicAspect() );
}
var offsetTop = 0;
// Move the video down 1/2 of the difference of window height
offsetTop+= ( targetHeight < windowSize.height )? ( windowSize.height- targetHeight ) / 2 : 0;
// if the video is very tall in a short window adjust the size:
var offsetLeft = ( targetWidth < windowSize.width )? parseInt( windowSize.width- targetWidth ) / 2 : 0;
var position = (mw.isIOS4() && mw.isIphone()) ? 'static' : 'absolute';
mw.log( 'PlayerControlBuilder::getAspectPlayerWindowCss: ' + ' h:' + targetHeight + ' w:' + targetWidth + ' t:' + offsetTop + ' l:' + offsetLeft );
return {
'position' : position,
'height': parseInt( targetHeight ),
'width' : parseInt( targetWidth ),
'top' : parseInt( offsetTop ),
'left': parseInt( offsetLeft)
};
},
/**
* Get the intrinsic aspect ratio of media ( width / height )
* @return {float}
* size object with width and height
*/
getIntrinsicAspect: function(){
var vid = this.embedPlayer.getPlayerElement();
// Check for raw intrinsic media size:
if( vid && vid.videoWidth && vid.videoHeight ){
return vid.videoWidth / vid.videoHeight;
}
// See if we have source data attributes available:
if( this.embedPlayer.mediaElement &&
this.embedPlayer.mediaElement.selectedSource )
{
var ss = this.embedPlayer.mediaElement.selectedSource;
// See if we have a hardcoded aspect to the source ( Adaptive streams don't have width / height )
if( ss.aspect ){
return ss.aspect;
}
if( ss.width && ss.height ){
return ss.width / ss.height
}
}
// check for posterImage size: ( should have Intrinsic aspect size as well )
var img = this.embedPlayer.getInterface().find('.playerPoster')[0];
if( img && img.naturalWidth && img.naturalHeight){
return img.naturalWidth / img.naturalHeight
}
// if all else fails use embedPlayer.getWidth()
return this.embedPlayer.getWidth() / this.embedPlayer.getHeight()
},
/**
* Get the play button css
* @deprecated
*/
getPlayButtonPosition: function() {
mw.log( "Warrning: getPlayButtonPosition has been deprecated" );
var _this = this;
return {
'position' : 'absolute',
'left' : '50%',
'top' : '50%',
'margin-left' : - .5 * this.getComponentWidth( 'playButtonLarge' ),
'margin-top' : - .5 * this.getComponentHeight( 'playButtonLarge' )
};
},
/**
* Check if we're in Fullscreen
* @return {boolean)
*/
isInFullScreen: function() {
return this.inFullScreen;
},
/**
* Toggles full screen by calling
* doFullScreenPlayer to enable fullscreen mode
* restoreWindowPlayer to restore window mode
*/
toggleFullscreen: function( forceClose ) {
var _this = this;
// Do normal in-page fullscreen handling:
if( this.isInFullScreen() ){
this.restoreWindowPlayer();
}else {
this.doFullScreenPlayer();
}
},
/**
* Do full-screen mode
*/
doFullScreenPlayer: function( callback ) {
mw.log("PlayerControlBuilder:: doFullScreenPlayer" );
// Setup pointer to control builder :
var _this = this;
// Setup local reference to embed player:
var embedPlayer = this.embedPlayer;
// Setup a local reference to the player interface:
var $interface = embedPlayer.getInterface();
// Check fullscreen state ( if already true do nothing )
if( this.isInFullScreen() == true ){
return ;
}
this.inFullScreen = true;
// store the verticalScrollPosition
var isIframe = mw.getConfig('EmbedPlayer.IsIframeServer' ),
doc = isIframe ? window['parent'].document : window.document,
context = isIframe ? window['parent'] : window;
this.verticalScrollPosition = (doc.all ? doc.scrollTop : context.pageYOffset);
// Add fullscreen class to interface:
$interface.addClass( 'fullscreen' );
// if overlaying controls add hide show player binding.
if( _this.isOverlayControls() ){
_this.addFullscreenMouseMoveHideShowControls();
}
// Store the current scroll location on the iframe:
$( embedPlayer ).trigger( 'fullScreenStoreVerticalScroll' );
// Check for native support for fullscreen and we are in an iframe server
if( window.fullScreenApi.supportsFullScreen ) {
_this.preFullscreenPlayerSize = this.getPlayerSize();
var fullscreenHeight = null;
var fsTarget = this.getFsTarget();
var escapeFullscreen = function( event ) {
// grab the correct document target to check for fullscreen
var doc = ( mw.getConfig('EmbedPlayer.IsIframeServer' ) )?
window['parent'].document:
window.document;
if ( ! window.fullScreenApi.isFullScreen( doc ) ) {
_this.restoreWindowPlayer();
}
}
// remove any old binding:
fsTarget.removeEventListener( fullScreenApi.fullScreenEventName, escapeFullscreen );
// Add a binding to catch "escape" fullscreen
fsTarget.addEventListener( fullScreenApi.fullScreenEventName, escapeFullscreen );
// Make the iframe fullscreen:
window.fullScreenApi.requestFullScreen( fsTarget );
// There is a bug with mozfullscreenchange event in all versions of firefox with supportsFullScreen
// https://bugzilla.mozilla.org/show_bug.cgi?id=724816
// so we have to have an extra binding to check for size change and then restore.
if( $.browser.mozilla ){
_this.fullscreenRestoreCheck = setInterval( function(){
if( fullscreenHeight && $(window).height() < fullscreenHeight ){
// Mozilla triggered size change:
clearInterval ( _this.fullscreenRestoreCheck );
_this.restoreWindowPlayer();
}
// Set fullscreen height:
if( ! fullscreenHeight && _this.preFullscreenPlayerSize.height != $(window).height() ){
fullscreenHeight = $(window).height();
}
}, 250 );
}
} else {
// Check for hybrid html controls / native fullscreen support:
var vid = this.embedPlayer.getPlayerElement();
if( mw.getConfig('EmbedPlayer.EnableIpadNativeFullscreen')
&&
vid && vid.webkitSupportsFullscreen
){
this.doHybridNativeFullscreen();
return ;
} else {
// make the player target or iframe fullscreen
this.doContextTargetFullscreen();
}
}
// Bind escape to restore in page clip ( IE9 needs a secondary escape binding )
$( window ).keyup( function( event ) {
// Escape check
if( event.keyCode == 27 ){
_this.restoreWindowPlayer();
}
} );
// trigger the open fullscreen event:
$( embedPlayer ).trigger( 'onOpenFullScreen' );
},
/**
* Make the target player interface or iframe fullscreen
*/
doContextTargetFullscreen: function() {
var isIframe = mw.getConfig('EmbedPlayer.IsIframeServer' );
var
_this = this,
doc = isIframe ? window['parent'].document : window.document,
$doc = $( doc ),
$target = $( this.getFsTarget() ),
context = isIframe ? window['parent'] : window;
// update / reset local restore properties
this.parentsAbsoluteList = [];
this.parentsRelativeList = [];
// Set the original parent page scale if possible:
this.orginalParnetViewPortContent = $doc.find( 'meta[name="viewport"]' ).attr( 'content' );
this.orginalTargetElementLayout = {
'style' : $target[0].style.cssText,
'width' : $target.width(),
'height' : $target.height()
};
mw.log("PlayerControls:: doParentIframeFullscreen> verticalScrollPosition:" + this.verticalScrollPosition);
context.scroll(0, 0);
// Make sure the parent page page has a zoom of 1:
if( ! $doc.find('meta[name="viewport"]').length ){
$doc.find('head').append( $( '<meta />' ).attr('name', 'viewport') );
}
$doc.find('meta[name="viewport"]').attr('content', 'width=1024, user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1' );
// iPad 5 supports fixed position in a bad way, use absolute pos for iOS
var playerCssPosition = ( mw.isIOS() ) ? 'absolute': 'fixed';
// Remove absolute css of the $target's parents
$target.parents().each( function() {
var $parent = $( this );
if( $parent.css( 'position' ) == 'absolute' ) {
_this.parentsAbsoluteList.push( $parent );
$parent.css( 'position', 'static' );
}
if( $parent.css( 'position' ) == 'relative' ) {
_this.parentsRelativeList.push( $parent );
$parent.css( 'position', 'static' );
}
});
// Make the $target fullscreen
$target
.css({
'z-index': mw.getConfig( 'EmbedPlayer.FullScreenZIndex' ),
'position': playerCssPosition,
'top' : '0px',
'left' : '0px',
'margin': 0
})
.data(
'isFullscreen', true
)
.after(
// add a placeholder div to retain page layout in float / block based pages.
$('<div>').addClass('player-placeholder').css({
'width': this.orginalTargetElementLayout.width,
'height': this.orginalTargetElementLayout.height
})
)
var updateTargetSize = function() {
context.scroll(0, 0);
var innerHeight = context.innerHeight;
// mobile android chrome has an off by one bug for inner window size:
if( mw.isMobileChrome() ){
innerHeight+=1;
}
// Set innerHeight respective of Android pixle ratio
if( ( mw.isAndroid41() || mw.isAndroid42() || ( mw.isAndroid() && mw.isFirefox() ) ) && !mw.isMobileChrome()
&&
context.devicePixelRatio
) {
innerHeight = context.outerHeight / context.devicePixelRatio;
}
$target.css({
'width' : context.innerWidth,
'height' : innerHeight
}).trigger( 'resize' ); // make sure we have a resize event on target
// update player size if needed:
_this.embedPlayer.applyIntrinsicAspect();
};
updateTargetSize();
// Android fires orientationchange too soon, i.e width and height are wrong
var eventName = mw.isAndroid() ? 'resize' : 'orientationchange';
eventName += this.bindPostfix;
// Bind orientation change to resize player ( if fullscreen )
$( context ).bind( eventName, function(){
if( _this.isInFullScreen() ){
updateTargetSize();
}
});
// prevent scrolling when in fullscreen: ( both iframe and dom target use document )
document.ontouchmove = function( e ){
if( _this.isInFullScreen() ){
e.preventDefault();
}
};
},
/**
* Restore the player interface or iframe to a window player
*/
restoreContextPlayer: function(){
var isIframe = mw.getConfig('EmbedPlayer.IsIframeServer' );
var
_this = this,
doc = isIframe ? window['parent'].document : window.document,
$doc = $( doc ),
$target = $( this.getFsTarget() ),
context = isIframe ? window['parent'] : window;
mw.log("PlayerControlsBuilder:: restoreContextPlayer> verticalScrollPosition:" + this.verticalScrollPosition );
// Restore document zoom:
if( this.orginalParnetViewPortContent ){
$doc.find('meta[name="viewport"]').attr('content', this.orginalParnetViewPortContent );
} else {
// Restore user zoom: ( NOTE, there does not appear to be a way to know the
// initial scale, so we just restore to 1 in the absence of explicit viewport tag )
// In order to restore zoom, we must set maximum-scale to a valid value
$doc.find('meta[name="viewport"]').attr('content', 'initial-scale=1, maximum-scale=8, minimum-scale=1, user-scalable=yes' );
// Initial scale of 1 is too high. Restoring default scaling.
if ( mw.isMobileChrome() ) {
$doc.find('meta[name="viewport"]').attr('content', 'user-scalable=yes' );
}
}
if( this.orginalTargetElementLayout ) {
$target[0].style.cssText = this.orginalTargetElementLayout.style;
$target.attr({
'width': this.orginalTargetElementLayout.width,
'height': this.orginalTargetElementLayout.height
}).trigger( 'resize' )
// update player size if needed:
_this.embedPlayer.applyIntrinsicAspect();
// remove placeholder
$target.siblings( '.player-placeholder').remove();
}
// Restore any parent absolute pos:
$.each( _this.parentsAbsoluteList, function(inx, $elm) {
$elm.css( 'position', 'absolute' );
} );
$.each( _this.parentsRelativeList, function(inx, $elm) {
$elm.css( 'position', 'relative' );
} );
// Scroll back to the previews position ( in a timeout to allow dom to update )
setTimeout( function(){
context.scroll( 0, _this.verticalScrollPosition );
},100)
},
/**
* Supports hybrid native fullscreen, player html controls, and fullscreen is native
*/
doHybridNativeFullscreen: function(){
var vid = this.embedPlayer.getPlayerElement();
var _this = this;
vid.webkitEnterFullscreen();
// start to pull for exit fullscreen:
this.fsIntervalID = setInterval( function(){
var currentFS = vid.webkitDisplayingFullscreen;
// Check if we have entered fullscreen but the player
// has exited fullscreen with native controls click
if( _this.isInFullScreen() && !currentFS ){
// restore non-fullscreen player state
_this.inFullScreen = false;
// Trigger the onCloseFullscreen event:
$( _this.embedPlayer ).trigger( 'onCloseFullScreen' );
// Remove fullscreen class
_this.embedPlayer.getInterface().removeClass( 'fullscreen' );
// stop polling for state change.
clearInterval( _this.fsIntervalID );
}
}, 250 );
},
getWindowSize: function(){
return {
'width' : $(window).width(),
'height' : $(window).height()
};
},
doDomFullscreen: function(){
var _this = this;
var embedPlayer = this.embedPlayer;
var $interface = embedPlayer.getInterface();
// Remove any old mw-fullscreen-overlay
$( '.mw-fullscreen-overlay' ).remove();
_this.preFullscreenPlayerSize = this.getPlayerSize();
// Add the css fixed fullscreen black overlay as a sibling to the video element
// iOS4 does not respect z-index
$interface.after(
$( '<div />' )
.addClass( 'mw-fullscreen-overlay' )
// Set some arbitrary high z-index
.css('z-index', mw.getConfig( 'EmbedPlayer.FullScreenZIndex' ) )
.hide()
.fadeIn("slow")
);
// get the original interface to absolute positioned:
if( ! this.windowPositionStyle ){
this.windowPositionStyle = $interface.css( 'position' );
}
if( !this.windowZindex ){
this.windowZindex = $interface.css( 'z-index' );
}
// Get the base offset:
this.windowOffset = this.getWindowOffset();
// Change the z-index of the interface
$interface.css( {
'position' : 'fixed',
'z-index' : mw.getConfig( 'EmbedPlayer.FullScreenZIndex' ) + 1,
'top' : this.windowOffset.top,
'left' : this.windowOffset.left
} );
// If native persistent native player update z-index:
if( embedPlayer.isPersistentNativePlayer() ){
$( embedPlayer.getPlayerElement() ).css( {
'z-index': mw.getConfig( 'EmbedPlayer.FullScreenZIndex' ) + 1,
'position': 'absolute'
});
}
// Empty out the parent absolute index
_this.parentsAbsolute = [];
// Hide the body scroll bar
$('body').css( 'overflow', 'hidden' );
var topOffset = '0px';
var leftOffset = '0px';
// Check if we have an offsetParent
if( $interface.offsetParent()[0].tagName
&&
$interface.offsetParent()[0].tagName.toLowerCase() != 'body' )
{
topOffset = -this.windowOffset.top + 'px';
leftOffset = -this.windowOffset.left + 'px';
}
// Overflow hidden in fullscreen:
$interface.css( 'overlow', 'hidden' );
// Remove absolute css of the interface parents
$interface.parents().each( function() {
//mw.log(' parent : ' + $( this ).attr('id' ) + ' class: ' + $( this ).attr('class') + ' pos: ' + $( this ).css( 'position' ) );
if( $( this ).css( 'position' ) == 'absolute' ) {
_this.parentsAbsolute.push( $( this ) );
$( this ).css( 'position', null );
mw.log( 'PlayerControlBuilder:: should update position: ' + $( this ).css( 'position' ) );
}
});
// Bind escape to restore in page clip
$( window ).keyup( function( event ) {
// Escape check
if( event.keyCode == 27 ){
_this.restoreWindowPlayer();
}
} );
},
addFullscreenMouseMoveHideShowControls:function(){
var _this = this;
// Bind mouse move in interface to hide control bar
_this.mouseMovedFlag = false;
var oldX =0, oldY= 0;
_this.embedPlayer.getInterface().mousemove( function(e){
// debounce mouse movements
if( Math.abs( oldX - event.pageX ) > 4 || Math.abs( oldY - event.pageY ) > 4 ){
_this.mouseMovedFlag = true;
}
oldX = event.pageX;
oldY = event.pageY;
});
// Check every 2 seconds reset flag status if controls are overlay
var checkMovedMouse = function(){
if( _this.isInFullScreen() ){
if( _this.mouseMovedFlag ){
_this.mouseMovedFlag = false;
_this.showControlBar();
// Once we move the mouse keep displayed for 4 seconds
setTimeout( checkMovedMouse, 4000 );
} else {
// Check for mouse movement every 250ms
_this.hideControlBar();
setTimeout( checkMovedMouse, 250 );
}
return;
}
};
// always initially show the control bar:
_this.showControlBar();
// start monitoring for moving mouse
checkMovedMouse();
},
getWindowOffset: function(){
var windowOffset = this.embedPlayer.getInterface().offset();
windowOffset.top = windowOffset.top - $(document).scrollTop();
windowOffset.left = windowOffset.left - $(document).scrollLeft();
this.windowOffset = windowOffset;
return this.windowOffset;
},
// Display a fullscreen tip if configured to do and the browser supports it.
displayFullscreenTip: function(){
var _this = this;
// Mobile devices don't have f11 key
if( mw.isMobileDevice() ){
return ;
}
// Safari does not have a DOM fullscreen ( no subtitles, no controls )
if( $.browser.safari && ! /chrome/.test( navigator.userAgent.toLowerCase() ) ){
return ;
}
// OSX has a different short cut than windows and liux
var toolTipMsg = ( navigator.userAgent.indexOf('Mac OS X') != -1 )?
gM( 'mwe-embedplayer-fullscreen-tip-osx') :
gM( 'mwe-embedplayer-fullscreen-tip');
var $targetTip = this.addWarningBinding( 'EmbedPlayer.FullscreenTip',
$('<h3/>').html(
toolTipMsg
)
);
// Display the target warning:
$targetTip.show();
var hideTip = function(){
mw.setConfig('EmbedPlayer.FullscreenTip', false );
$targetTip.fadeOut('fast');
};
// Hide fullscreen tip if:
// We leave fullscreen,
$( this.embedPlayer ).bind( 'onCloseFullScreen', hideTip );
// After 5 seconds,
setTimeout( hideTip, 5000 );
// Or if we catch an f11 button press
$( document ).keyup( function( event ){
if( event.keyCode == 122 ){
hideTip();
}
return true;
});
},
// TOOD fullscreen iframe vs in page object abstraction
//( avoid repetitive conditionals in getters )
// TODO getPlayer size should just return the height of the "video holder"
getPlayerSize: function(){
var controlsHeight = ( this.isOverlayControls() )? 0 : this.getHeight();
var height = $(window).height() - controlsHeight;
if( mw.getConfig('EmbedPlayer.IsIframeServer' ) ){
return {
'height' : height,
'width' : $(window).width()
}
} else {
return {
'height' : this.embedPlayer.getInterface().height(),
'width' : this.embedPlayer.getInterface().width()
}
}
},
getFsTarget: function(){
if( mw.getConfig('EmbedPlayer.IsIframeServer' ) ){
// For desktops that supports native fullscreen api, give iframe as a target
var targetId;
if( window.fullScreenApi.supportsFullScreen ) {
targetId = this.embedPlayer.id + '_ifp';
} else {
// For dom based fullscreen, use iframe container div
targetId = this.embedPlayer.id;
}
return window['parent'].document.getElementById( targetId );
} else {
var $interface = this.embedPlayer.getInterface();
return $interface[0];
}
},
getDocTarget: function(){
if( mw.getConfig('EmbedPlayer.IsIframeServer' ) ){
return window['parent'].document;
} else {
return document;
}
},
/**
* Restore the window player
*/
restoreWindowPlayer: function() {
var _this = this;
mw.log("PlayerControlBuilder :: restoreWindowPlayer" );
var embedPlayer = this.embedPlayer;
// Check if fullscreen mode is already restored:
if( this.isInFullScreen() === false ){
return ;
}
// Set fullscreen mode to false
this.inFullScreen = false;
// remove the fullscreen interface
embedPlayer.getInterface().removeClass( 'fullscreen' );
// Check for native support for fullscreen and support native fullscreen restore
if ( window.fullScreenApi.supportsFullScreen ) {
var fsTarget = this.getFsTarget();
var docTarget = this.getDocTarget();
window.fullScreenApi.cancelFullScreen( fsTarget, docTarget );
}
// Restore the iFrame context player
this.restoreContextPlayer();
// Restore scrolling on iPad
$( document ).unbind( 'touchend.fullscreen' );
// Trigger the onCloseFullscreen event:
$( embedPlayer ).trigger( 'onCloseFullScreen' );
},
restoreDomPlayer: function(){
var _this = this;
// local ref to embedPlayer:
var embedPlayer = this.embedPlayer;
var $interface = embedPlayer.$interface;
var interfaceHeight = ( _this.isOverlayControls() )
? embedPlayer.getHeight()
: embedPlayer.getHeight() + _this.getHeight();
mw.log( 'restoreWindowPlayer:: h:' + interfaceHeight + ' w:' + embedPlayer.getWidth());
$('.mw-fullscreen-overlay').remove( 'slow' );
mw.log( 'restore embedPlayer:: ' + embedPlayer.getWidth() + ' h: ' + embedPlayer.getHeight() );
// Restore the player:
embedPlayer.getInterface().css( {
'width' : _this.preFullscreenPlayerSize.width,
'height' : _this.preFullscreenPlayerSize.height
});
var topPos = {
'position' : _this.windowPositionStyle,
'z-index' : _this.windowZindex,
'overlow' : 'visible',
'top' : '0px',
'left' : '0px'
};
// Restore non-absolute layout:
$( [ $interface, $interface.find('.playerPoster'), embedPlayer ] ).css( topPos );
if( embedPlayer.getPlayerElement() ){
$( embedPlayer.getPlayerElement() )
.css( topPos )
}
// Restore the body scroll bar
$('body').css( 'overflow', 'auto' );
// If native player restore z-index:
if( embedPlayer.isPersistentNativePlayer() ){
$( embedPlayer.getPlayerElement() ).css( {
'z-index': 'auto'
});
}
},
/**
* Get minimal width for interface overlay
*/
getOverlayWidth: function( ) {
return ( this.embedPlayer.getPlayerWidth() < 300 )? 300 : this.embedPlayer.getPlayerWidth();
},
/**
* Get minimal height for interface overlay
*/
getOverlayHeight: function( ) {
return ( this.embedPlayer.getPlayerHeight() < 200 )? 200 : this.embedPlayer.getPlayerHeight();
},
/**
* addControlBindings
* Adds control hooks once controls are in the DOM
*/
addControlBindings: function( ) {
// Set up local pointer to the embedPlayer
var embedPlayer = this.embedPlayer;
var _this = this;
var $interface = embedPlayer.getInterface();
_this.onControlBar = false;
// Remove any old interface bindings
$( embedPlayer ).unbind( this.bindPostfix );
var bindFirstPlay = false;