-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdepage-player.js
1368 lines (1187 loc) · 45.6 KB
/
depage-player.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
/**
* @require framework/shared/jquery-1.8.3.js
* @require framework/shared/depage-jquery-plugins/depage-flash.js
* @require framework/shared/depage-jquery-plugins/depage-browser.js
*
* @file depage-player.js
*
* Adds a custom video player, using either HTML5 video if available, or falling back to flash if not.
*
* copyright (c) 2006-2013 Frank Hellenkamp [jonas@depage.net]
*
* @todo look into seekable to get better seeking directly to keyframes, also possible with the flash fallback
*
* @author Ben Wallis
*/
;(function($){
"use strict";
/*jslint browser: true*/
/*global $:false */
if(!$.depage){
$.depage = {};
}
// shiv {{{
/**
* Shiv Video
*
* Adds video element to the DOM to enable recognition in IE < 9.
*
* @return void
*/
if ($.depage.browser.msie && $.depage.browser.version < 9) {
$('head').append('<style>video{display:inline-block;*display:inline;*zoom:1}</style>');
document.createElement("video");
document.createElement("source");
}
// }}}
/**
* Depage Player
*
* @param el
* @param index - player index
* @param options
*
* @return context
*/
$.depage.player = function(el, index, options){
// {{{ variables
// To avoid scope issues, use 'base' instead of 'this' to reference this
// class from internal events and functions.
var base = this;
// Access to jQuery and DOM versions of element
base.$el = $(el);
base.el = el;
// Add a reverse reference to the DOM object
base.$el.data("depage.player", base);
// cache selectors
var $video = $('video', base.$el);
var video = $video[0];
var $indicator = null;
var $wrapper = null;
var duration = video.currentTime || base.$el.attr("data-video-duration");
var currentTime = 0;
base.playing = false;
var buffering = false;
// reference for defering fullscreen event
var resize_timeout = null;
// use the build-in controls for iPhone and iPad
var useCustomControls = !$.depage.browser.ios;
// set the player mode - 'html5' / 'flash' / false (fallback)
var mode = false;
var isInFullscreen = false;
// variable used to save element styles when using the fallback fullscreen
var styles_cache = null;
// cache window selector
var $window = $(window);
// cache the control selectors
base.controls = {};
// }}}
// {{{ init()
/**
* Init
*
* Setup the options.
*
* @return void
*/
base.init = function(){
base.options = $.extend({}, $.depage.player.defaultOptions, options);
base.options.width = base.options.width || base.$el.width();
base.options.height = base.options.height || base.$el.height();
base.options.playerId = base.options.playerId + index;
$.depage.player.instances[base.options.playerId] = base;
if (!$.depage.player.currentInstance) {
// make the first instance the current instance
$.depage.player.currentInstance = $.depage.player.instances[base.options.playerId];
}
base.$el.click( function() {
// clicking on the player makes it the current instance
$.depage.player.currentInstance = $.depage.player.instances[base.options.playerId];
});
// wrap video
base.wrap();
// listen to key events
// @todo choose current instance for events when more than one player on page
$(document).bind('keypress', function(e){
if ($(document.activeElement).is(':input')){
// continue only if an input is not the focus
return true;
}
switch (parseInt(e.which || e.keyCode, 10)) {
case 32 : // spacebar
case 112 : // 'p' key
if ($.depage.player.currentInstance.playing) {
$.depage.player.currentInstance.player.pause();
} else {
$.depage.player.currentInstance.player.play();
}
e.preventDefault();
break;
case 102 : // 'f' key
$.depage.player.currentInstance.player.fullscreen();
e.preventDefault();
break;
}
});
// listen to keydown events for cursors (n.b. keydown for chrome / ie support - http://code.google.com/p/chromium/issues/detail?id=2606)
$(document).bind('keydown', function(e){
if ($(document.activeElement).is(':input')){
// continue only if an input is not the focus
return true;
}
switch (parseInt(e.which || e.keyCode, 10)) {
case 39 : // cursor right
$.depage.player.currentInstance.player.seek(base.player.currentTime + 10);
e.preventDefault();
break;
case 37 : // cursor left
$.depage.player.currentInstance.player.seek(base.player.currentTime - 9);
e.preventDefault();
break;
}
});
};
// }}}
// {{{ videoSupport()
/**
* Video Support
*
* Checks browser video codec support.
*
* http://www.modernizr.com/
*
* NB IE9 Running on Windows Server SKU can cause an exception to be thrown, bug #224
*
* @returns object
*
*/
base.videoSupport = function (){
var support = {};
try {
support.ogg = video.canPlayType('video/ogg; codecs="theora"').replace(/^no$/,'');
support.h264 = video.canPlayType('video/mp4; codecs="avc1.42E01E"').replace(/^no$/,'');
support.webm = video.canPlayType('video/webm; codecs="vp8, vorbis"').replace(/^no$/,'');
} catch(e) { }
finally{
// earliest support for flash player with h264
support.flash = $.depage.flash({requiredVersion:"9,0,115"}).detect();
}
return support;
};
// }}}
// {{{ video()
/**
* Video
*
* Entry point to build the video.
* - Adds the wrapper div
* - Build the controls
* - Adds $indicator click handler
* - Autoloads
*
* @return void
*/
base.video = function() {
var support = base.videoSupport();
// SET TO DEBUG FLASH MODE
//support = { 'flash' : true };
// determine the supported player mode - flash or html5
if ( support.h264 && $('source[type="video/mp4"]', video).length > 0 ||
support.ogg && $('source[type="video/ogg"]', video).length > 0 ||
support.webm && $('source[type="video/webm"]', video).length > 0) {
mode = 'html5';
base.player = video;
base.html5.setup();
} else if (support.flash) {
mode = 'flash';
// setup flash player
base.player = { initialized: false };
base.flash.transport();
// preload
var preloadAttr = $video.attr('preload');
if (typeof(preloadAttr) !== 'undefined' && preloadAttr == 'true') {
base.flash.insertPlayer();
}
// TODO support for loop
} else {
// fallback
return false;
}
// autoplay
var autoplayAttr = $video.attr('autoplay');
if (typeof(autoplayAttr) !== 'undefined' && (autoplayAttr == 'true' || autoplayAttr == 'autoplay')) {
base.player.play();
}
$indicator = $("a.indicator", base.$el);
$indicator.bind("click touchstart", function() {
base.player.play();
return false;
});
var div = $("<div class=\"controls\"></div>");
var controlsAttr = $video.attr('controls');
if (typeof(controlsAttr) !== 'undefined' && (controlsAttr == 'true' || controlsAttr == 'controls')) {
if (useCustomControls) {
base.addControls(div);
} else {
$indicator.remove();
$video.attr("controls", true);
}
}
base.addLegend(div);
div.appendTo(base.$el);
setTimeout(base.resize, 20);
};
// }}}
/**
* Namespace HTML5 funcitons
*/
base.html5 = {
// {{{ setup
/**
* HTML5 Setup the handlers for the HTML5 video
*
* @return void
*/
setup : function() {
// attribute fixes issue with IE9 poster not displaying - add in html
// $video.attr('preload', 'none');
$video.bind("play", base.play);
$video.bind("canplay", base.resize);
$video.bind("playing", base.play);
$video.bind("pause", base.pause);
$video.bind("durationchange", function(){
base.duration(this.duration);
});
$video.bind("timeupdate", function(){
base.setCurrentTime(this.currentTime);
});
$video.bind("ended", base.end);
/**
* HTML5 Progress Event
*
* Fired when buffering
*
* TODO doesn't always seem to fire?
*
* @return false
*/
$video.bind("progress", function(){
var defer = null;
var progress = function(){
var loaded = 0;
if (video.buffered && video.buffered.length > 0 && video.buffered.end && video.duration) {
loaded = video.buffered.end(video.buffered.length-1) / video.duration;
}
// for browsers not supporting buffered.end (e.g., FF3.6 and Safari 5)
else if (typeof(video.bytesTotal) !== 'undefined' && video.bytesTotal > 0 &&
typeof(video.bufferedBytes) !== 'undefined') {
loaded = video.bufferedBytes / video.bytesTotal;
}
base.percentLoaded(loaded);
// last progress event not fired in all browsers
if ( !defer && loaded < 1 ) {
defer = setInterval(function(){ progress(); }, 1500);
}
else if (loaded >= 1) {
clearInterval(defer);
}
};
progress();
});
/**
* HTML5 Loaded Data Event
*
* Fired when the player is fully loaded
*
* TODO doesn't always seem to fire?
*
* @return false
*/
$video.bind("loadeddata", function(){
base.percentLoaded(1);
});
/**
* HTML5 Waiting Event
*
* Fired when the player stops becasue the next frame is not buffered.
*
* Display a buffering image if available.
*
* @return void
*/
$video.bind("waiting", function(){
var rotate = function() {
if (!base.playing) {
return;
}
base.html5.$buffering.css({
borderSpacing: 0
}).animate({
borderSpacing: 360
}, {
step: function(now, fx) {
$(this).css({
'-webkit-transform': 'rotate('+now+'deg)',
'-moz-transform': 'rotate('+now+'deg)',
'-ms-transform': 'rotate('+now+'deg)',
'-o-transform': 'rotate('+now+'deg)',
'transform': 'rotate('+now+'deg)'
});
},
complete: rotate,
easing: "linear",
duration: 1000
});
};
if (base.html5.$buffering) {
base.html5.$buffering.show();
rotate();
}
});
/**
* HTML5 Playing Event
*
* Fired when the playback starts after pausing or buffering.
*
* Clear the buffering image.
*
* @return void
*/
$video.bind("playing seeked", function(){
if (base.html5.$buffering) {
base.html5.$buffering.hide();
}
});
// resize
base.resize();
/**
* HTML5 Seek
*
* Create a seek method for the html5 player
*
* @param offset - current time;
*
* @return false
*/
base.player.seek = function(offset){
if (offset <= 0) {
offset = 0.1;
}
if (offset > duration) {
offset = duration;
}
base.player.currentTime = offset;
return false;
};
/**
* HTML5 Fullscreen
*
* Create a fullscreen method for the html5 player
*
* @return false
*/
base.player.fullscreen = function(){
// start playback on fullscreen
base.player.play();
var native_fullscreen_support = false;
if (true){ // SET FALSE TO DEBUG FULLSCREEN FALLBACK
if (typeof(base.player.webkitEnterFullScreen) !== 'undefined') {
// TODO http://stackoverflow.com/questions/7226114/dom-exception-11-when-calling-webkitenterfullscreen
base.player.webkitEnterFullScreen();
native_fullscreen_support = true;
} else if (typeof(base.player.webkitRequestFullScreen) !== 'undefined') {
// webkit (works in safari and chrome canary)
base.player.webkitRequestFullScreen();
native_fullscreen_support = true;
} else if (typeof(base.player.mozRequestFullScreen) !== 'undefined'){
// firefox (works in nightly)
base.player.mozRequestFullScreen();
native_fullscreen_support = true;
} else if (typeof(base.player.requestFullscreen) !== 'undefined') {
// w3c proposal
base.player.requestFullscreen();
native_fullscreen_support = true;
}
}
if (!native_fullscreen_support) {
// fallback
base.fullscreen();
}
// make sure the native player controls are displayed when going full screen (n.b. not automatic in firefox)
if (native_fullscreen_support) {
$video.attr('controls', true);
var is_fullscreen = true;
// bind to fullscreenchange event and clear up controls if exiting...
$(document).bind('fullscreenchange mozfullscreenchange webkitfullscreenchange', function(e) {
switch(e.type){
case 'fullscreenchange' :
is_fullscreen = document.fullscreen;
break;
case 'mozfullscreenchange' :
is_fullscreen = document.mozFullScreen;
break;
case 'webkitfullscreenchange' :
is_fullscreen = document.webkitIsFullScreen;
break;
}
if (!is_fullscreen) {
$video.removeAttr('controls');
}
});
}
// trigger onfullscreen event
if (base.options.onFullscreen) base.options.onFullscreen();
return false;
};
/**
* HTML5 Exit Fullscreen
*
* Exit fullscreen method for html5 - called manually
*
* @return false
*/
base.player.exitfullscreen = function(){
if (typeof(base.player.webkitExitFullScreen) !== 'undefined') {
base.player.webkitExitFullScreen();
} else if (typeof(document.webkitCancelFullScreen) !== 'undefined') {
// webkit (works in safari and chrome canary)
document.webkitCancelFullScreen();
} else if (typeof(document.mozCancelFullScreen) !== 'undefined'){
// firefox (works in nightly)
document.mozCancelFullScreen();
} else if (typeof(document.cancelFullScreen) !== 'undefined') {
// mozilla proposal
document.cancelFullScreen();
}
$video.removeAttr('controls');
if (base.options.onExitFullscreen) base.options.onExitFullscreen();
return false;
};
/**
* Bind to resize
*/
$(window).resize(base.resize);
}
// }}}
};
/**
* Namespace Flash Functions
*/
base.flash = {
// flash.transport() {{{
/**
* Flash Transport
*
* Adds transport actions to the flash player.
*
* Uses set interval to wait for flash initialization.
*
* @return void
*/
transport : function() {
var actions = [ "load", "play", "pause", "seek" ];
// {{{ serialize()
/**
* serialize
*
* Serializes the arguments passed to the flash player object
*
* @param string action - control action called
* @param array args - flash player arguments
*
* @return string code
*/
var serialize = function ( action, args ){
$.each(args, function(i, arg){
args[i] = '"' + String(arg).replace('"', '\"') + '"';
});
return action + "(" + args.join(',') + ");";
};
// }}}
$.each ( actions, function (i, action) {
base.player[action] = function() {
if (!base.player.initialized) {
base.flash.insertPlayer();
}
var code = serialize(action, Array.prototype.slice.call(arguments));
var defer = setInterval(function() {
caller();
}, 300);
var caller = function() {
try {
if (($.depage.browser.msie && eval("window['" + base.options.playerId + "'].f" + code)) ||
eval("document['" + base.options.playerId + "'].f" + code)) {
clearInterval(defer);
}
} catch (e) { }
};
};
});
/**
* Fullscreen
*
* Add a custom fullscreen action for the flash player
*
* TODO disabled in favour of native full screen flash
*
* @return void
*/
base.player.fullscreen = function() {
// DISABLE FULLSCREEN FLASH
//return false;
if (!base.player.initialized) {
base.flash.insertPlayer();
}
base.fullscreen();
};
},
// }}}
// {{{ flash.insertPlayer()
/**
* Insert Flash Player
*
* Insert the flash object for the player using the depage flash plugin.
*
* Removes the video.
*
* @return void
*/
insertPlayer : function() {
var flashParams = {
rand: Math.random(),
id : base.options.playerId
};
if (window.console && base.options.debug) {
flashParams.debug = "true";
}
var html = $.depage.flash().build({
src : base.options.assetPath + "depage_player.swf",
// TODO needs to fit screen for resize
width : "100%",
height : "100%",
id : base.options.playerId,
wmode : 'transparent',
params : flashParams
});
// remove video tag
$(video).remove();
// use innerHTML for IE < 9 otherwise player breaks!!
$wrapper[0].innerHTML += html.plainhtml;
base.player.initialized = true;
},
// }}}
// {{{ flash.initialize()
/**
* Initializes Flash Player
*
* tells flash player to load video
*
* @return void
*/
initialize : function() {
// get absolute url from source attribute with mp4-type
var $link = $("<a href=\"" + $('source[type="video/mp4"]', video).attr("src") + "\"></a>").appendTo("body");
var url = $link[0].toString();
$link.remove();
base.player.load(url);
},
// }}}
// {{{ flash.loaded()
/**
* Called when video has been loaded
*
* tells flash player to play video and seek to current position
*
* @return void
*/
loaded : function(firstSeekPoint) {
if (base.playing) {
base.player.play();
}
if (currentTime > firstSeekPoint) {
// don't seek before first seekpoint, or the flash player will reload the video
base.player.seek(currentTime);
}
}
// }}}
};
// {{{ resize()
/**
* Resize Player
*
* Attempt to resize the player to the given dimensions.
*
* Will constrain or crop according to the base.options.
*
* @return void
*/
base.resize = function() {
// get the player object
var $player = (mode==='flash') ? $('object', base.$el) : $video;
// crop to wrapper
if (mode==='html5' && base.options.crop && $wrapper){
// note that if the ready state is 0 (when not preloaded we do not have dimensions)
// fallback to element dom attributes
var $placeholder = $(".placeholder", base.$el);
var ratio = (mode==='flash' || $player[0].readyState === 0) ? $placeholder.width() / $placeholder.height() : $player[0].videoWidth / $player[0].videoHeight;
var toWidth = $wrapper.width();
var toHeight = $wrapper.height();
if (toWidth === 0 || toHeight === 0 || $placeholder.width() === 0 || $placeholder.height() === 0) {
$placeholder.bind("load.depage-player", base.resize);
return;
}
// scale to outer div maintain constraints
if (base.options.constrain && !isNaN(ratio)) {
if (toWidth / toHeight < ratio) {
toWidth = Math.ceil(ratio * toHeight);
} else {
toHeight = Math.ceil(toWidth / ratio);
}
}
var cropWidth = $wrapper.width();
var cropHeight = $wrapper.height();
if (cropWidth && cropHeight) {
// center video
$player
.css({
position: "absolute",
left: (cropWidth - toWidth) / 2,
top: (cropHeight - toHeight) / 2,
width: toWidth,
height: toHeight
});
}
} else if (!useCustomControls) {
}
};
// }}}
// {{{ wrap()
/**
* wrap
*
* Adds an overlay container if not present.
* Adds inline styling where provided.
* Used to crop the video or wrap the flash player.
*
* @param $wrap - selector to wrap
* @param width - width of overlay
* @param height - height of overlay
* @param overflow - overflow of overlay
*
* @return void
*/
base.wrap = function() {
if (!$wrapper) {
base.$el.find("video img").addClass("placeholder");
if (!useCustomControls && $video[0].outerHTML) {
// re-add html instead of using wrapAll when outerHTML is available
// because safari on iPhone and iPad don't show controls otherwise
var html = $video[0].outerHTML;
$video.remove();
$wrapper = $('<div class="wrapper" />').appendTo(base.el);
$wrapper.html(html);
$("video img, a.indicator", $wrapper).prependTo($wrapper);
$video = $("video", $wrapper);
} else {
$("video img, a.indicator", base.$el).add($video).wrapAll('<div class="wrapper" />');
$wrapper = $('.wrapper', base.el); // cache after dom append for IE < 9 ?!
}
$indicator = $wrapper.children("a.indicator").attr("href", "#play");
if (mode != "flash") {
base.html5.$buffering = $('<span class="buffer-indicator">buffering</span>').hide();
$wrapper.append(base.html5.$buffering);
}
}
};
// }}}
// {{{ fullscreen()
/**
* Fullscreen
*
* FALLBACK
*
* Custom full screen method implemented by the flash player,
* and as a fallback for HTML5 video where not browser supported.
*
* NB Deprecated Flash fullscreen mode
*
* @return void
*/
base.fullscreen = function () {
if (!isInFullscreen) {
enterFullscreenFallback();
base.player.play();
} else {
exitFullscreenFallback();
}
isInFullscreen = !isInFullscreen;
$.depage.player.currentInstance = $.depage.player.instances[base.options.playerId];
};
// }}}
// {{{ enterFullscreenFallback()
/**
* Enter Fullscreen
*
* FALLBACK for non native fullscreen support
*
* @return void
*/
var enterFullscreenFallback = function() {
var $body = $('body');
var $controls = $('.controls', base.$el);
var $button = $('.fullscreen', base.$el);
var $background = $('#depage-player-fullscreen-background');
if (!$background.length) {
$background = $("<div id=\"depage-player-fullscreen-background\" />");
$body.prepend($background);
} else {
$background.show();
}
// save original css attributes if none cached
// nb - this will be set if already fullscreen and resizing
styles_cache = styles_cache || {
'body' : $body.attr('style'),
'controls' : $controls.attr('style'),
'el' : base.$el.attr('style'),
'wrapper' : $wrapper.attr('style')
};
// set screen position to top corner
window.scrollTo(0, 0);
// set body css
$body.css( {
'margin':0,
'padding':0,
'overflow': "hidden"
});
base.$el.addClass("in-fullscreen");
resizeFullscreenFallback();
$wrapper.css({
width: "100%",
height: "100%"
});
// reposition controls
$controls
.css({
position : 'absolute',
zIndex : 1003,
bottom : - $controls.height(),
width : '100%'
})
// animate the controls on hover
// TODO
/*
.bind('mouseover.fullscreen', function() {
$this = $(this);
$this.stop();
$this.animate({
'opactity': '1',
'filter': 'alpha(opacity=1)' // IE < 8
});
})*/ ;
// listen to the escape key
$(document).bind('keyup.fullscreen', function(e){
var key = e.which || e.keyCode;
if (key == 27) {
exitFullscreenFallback();
$(document).unbind('keyup.fullscreen');
}
});
// bind to window resize event and re-init fullscreen
$window.bind('resize.fullscreen', function(){
clearTimeout(resize_timeout); // nb - some browsers file resize contiously wait 500ms
resize_timeout = setTimeout(function() {
resizeFullscreenFallback();
}, 500);
});
};
// }}}
// {{{ resizeFullscreenFallback()
/**
* Resize Fullscreen
*
* FALLBACK for non native fullscreen support
*
* @return void
*/
var resizeFullscreenFallback = function() {
var $body = $('body');
var $controls = $('.controls', base.$el);
var $button = $('.fullscreen', base.$el);
var $background = $('#depage-player-fullscreen-background');
// get screen dimensions
var screenWidth = $window.width();
var screenHeight = $window.height();
var controlsHeight = $controls.is(":visible") ? $controls.height() : 0;
// resize container and position absolutely
base.$el.css({
zIndex : '1002',
//position : 'fixed',
top : 0,
left : 0,
width : screenWidth,
height : screenHeight - controlsHeight,
padding: 0,
margin: 0
});
base.resize();
};
// }}}
// {{{ exitFullscreenFallback()
/**
* Exit Fullscreen
*
* FALLBACK for non native fullscreen support
*
* @param styles_chache - {controls: {...}, body {...}} - styles to apply (or restore) to elements on exit
*
* @return void
*/
var exitFullscreenFallback = function() {
var $body = $('body');
var $controls = $('.controls', base.$el);
var $button = $('.fullscreen', base.$el);
var $background = $('#depage-player-fullscreen-background');
// remove styles
$body.removeAttr('style');
$controls.removeAttr('style');
base.$el.removeAttr('style');
// remove background
$background.hide();
// restore cached css attributes
if (styles_cache) {
if (typeof(styles_cache.body) !== 'undefined'){
$body.css(styles_cache.body);
}
if (typeof(styles_cache.controls) !== 'undefined'){
$controls.css(styles_cache.controls);
}
if (typeof(styles_cache.el) !== 'undefined'){
base.$el.css(styles_cache.el);
}
if (typeof(styles_cache.wrapper) !== 'undefined'){
$wrapper.css(styles_cache.wrapper);
}
}
// clear styles cache (prevents issues with resizing)
styles_cache = null;
// make sure opacity is restored
// TODO animate fade in / out of controls
/*
$controls.css({
'opactity': '0',
'filter': 'alpha(opacity=0)' // IE < 8
});
*/