Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #28 from fagga/master

Dynamic video size
  • Loading branch information...
commit 8f78b2f63a1048875b6551b87d77ed81d3ce1f9e 2 parents f30ef3c + f27f399
@octatone authored
Showing with 67 additions and 1 deletion.
  1. +67 −1 js/tv.js
View
68 js/tv.js
@@ -62,7 +62,12 @@ var Globals = {
sfw: true,
shuffle: false,
shuffled: [],
- theme: 'light'
+ theme: 'light',
+
+ content_minwidth: 130, // minimum width of #content w/o width of player
+ content_minheight: 320, // minimum height of #content w/o height of player
+ vd_minwidth: 30, // minimum width of #video-display w/o width of player
+ vd_minheight: 213, // minimum height of #video-display w/o height of player
};
/* MAIN (Document Ready) */
@@ -155,6 +160,10 @@ $().ready(function(){
}
});
+ $(window).resize(function() {
+ resizePlayer();
+ });
+
/* clear add sr on click */
$('#channel-name').click(function(){
$(this).val('');
@@ -509,6 +518,7 @@ function loadVideo(video) {
$video_source.html(video_source_text).fadeIn('slow');
});
+ resizePlayer();
fillScreen();
}
}
@@ -817,6 +827,62 @@ function fillScreen() {
}
}
+function resizePlayer() {
+ if(typeof(Globals.cur_chan) == 'undefined' ||
+ typeof(Globals.videos[Globals.cur_chan]) == 'undefined') {
+ setTimeout(resizePlayer, 100);
+ return;
+ }
+
+ consoleLog('window size changed: ' + $(window).width() + 'x' + $(window).height());
+ sitename = Globals.videos[Globals.cur_chan].video[Globals.cur_video].domain;
+
+ if(sitename == 'youtube.com' || sitename == 'youtu.be') {
+ player = $('#ytplayer');
+ }
+ else if(sitename == 'vimeo.com') {
+ player = $('#vimeoplayer');
+ }
+ else {
+ consoleLog('unsupported player: '+sitename);
+ return;
+ }
+
+ curr_player_width = player.width();
+ curr_player_height = player.height();
+ win_width = $(window).width()
+ win_height = $(window).height()
+
+ // consoleLog('content_min size: ' + (Globals.content_minwidth+curr_player_width) + 'x' + (Globals.content_minheight+curr_player_height));
+ // consoleLog('vd_min size: ' + (Globals.vd_minwidth+curr_player_width) + 'x' + (Globals.vd_minheight+curr_player_height));
+
+ if(win_width < 853+Globals.content_minwidth || win_height < 505+Globals.content_minheight) {
+ player_width = 640;
+ player_height = 385;
+ }
+ else if(win_width < 1280+Globals.content_minwidth || win_height < 745+Globals.content_minheight) {
+ player_width = 853;
+ player_height = 505;
+ }
+ else {
+ player_width = 1280;
+ player_height = 745;
+ }
+
+ if(player_width == curr_player_width) { return; } // nothing to do
+ consoleLog('resizing player to '+player_width+'x'+player_height);
+ player.width(player_width);
+ player.height(player_height);
+ player_width = player.width(); // player may not accept our request
+ player_height = player.height();
+
+ consoleLog('new player size: '+player_width+'x'+player_height);
+
+ $('#content').width(player_width + Globals.content_minwidth);
+ $('#video-display').width(player_width + Globals.vd_minwidth);
+ $('#video-display').height(player_height + Globals.vd_minheight);
+}
+
function togglePlay(){
switch(Globals.videos[Globals.cur_chan].video[Globals.cur_video].domain){
case 'youtube.com': case 'youtu.be':
Please sign in to comment.
Something went wrong with that request. Please try again.