2016-03-23 19:28:22 -04:00
var FFZ = window . FrankerFaceZ ,
utils = require ( '../utils' ) ;
2015-07-31 17:44:49 -04:00
// --------------------
// Settings
// --------------------
2015-10-24 22:44:00 -04:00
FFZ . settings _info . portrait _mode = {
type : "select" ,
options : {
0 : "Disabled" ,
1 : "Automatic (Use Window Aspect Ratio)" ,
2 : "Always On" ,
3 : "Automatic (Video Below)" ,
4 : "Always On (Video Below)"
} ,
value : 0 ,
process _value : function ( val ) {
if ( val === false )
return 0 ;
if ( val === true )
return 1 ;
if ( typeof val === "string" )
return parseInt ( val ) || 0 ;
return val ;
} ,
category : "Appearance" ,
no _mobile : true ,
no _bttv : true ,
name : "Portrait Mode (Chat Below Video)" ,
help : "Display the right sidebar beneath (or above) the video player for viewing in portrait orientations." ,
on _update : function ( val ) {
if ( this . has _bttv )
return ;
2016-03-23 20:23:04 -04:00
var Layout = utils . ember _lookup ( 'controller:layout' ) ;
2015-10-24 22:44:00 -04:00
if ( ! Layout )
return ;
Layout . set ( 'rawPortraitMode' , val ) ;
this . _fix _menu _position ( ) ;
}
}
2015-11-07 22:56:15 -05:00
FFZ . settings _info . portrait _warning = {
value : false ,
visible : false
}
2015-07-31 17:44:49 -04:00
FFZ . settings _info . swap _sidebars = {
type : "boolean" ,
value : false ,
2016-05-12 00:11:50 -04:00
category : "Sidebar" ,
2015-07-31 17:44:49 -04:00
no _mobile : true ,
no _bttv : true ,
2015-10-17 18:05:44 -04:00
2015-07-31 17:44:49 -04:00
name : "Swap Sidebar Positions" ,
help : "Swap the positions of the left and right sidebars, placing chat on the left." ,
on _update : function ( val ) {
if ( this . has _bttv )
return ;
document . body . classList . toggle ( "ffz-sidebar-swap" , val ) ;
this . _fix _menu _position ( ) ;
}
} ;
2015-10-17 18:05:44 -04:00
FFZ . settings _info . flip _dashboard = {
type : "boolean" ,
value : false ,
2016-03-23 19:28:22 -04:00
category : "Dashboard" ,
2015-10-17 18:05:44 -04:00
no _mobile : true ,
no _bttv : true ,
2016-03-23 19:28:22 -04:00
name : "Swap Column Positions" ,
2015-10-17 18:05:44 -04:00
help : "Swap the positions of the left and right columns of the dashboard." ,
on _update : function ( val ) {
if ( this . has _bttv )
return ;
document . body . classList . toggle ( "ffz-flip-dashboard" , val ) ;
}
} ;
2015-07-31 17:44:49 -04:00
FFZ . settings _info . right _column _width = {
type : "button" ,
value : 340 ,
category : "Appearance" ,
no _mobile : true ,
no _bttv : true ,
2015-10-17 18:05:44 -04:00
2015-07-31 17:44:49 -04:00
name : "Right Sidebar Width" ,
help : "Set the width of the right sidebar for chat." ,
2015-10-17 18:05:44 -04:00
2015-07-31 17:44:49 -04:00
method : function ( ) {
2016-03-23 19:28:22 -04:00
var f = this ,
old _val = this . settings . right _column _width || 340 ;
2015-10-17 18:05:44 -04:00
2016-03-23 19:28:22 -04:00
utils . prompt ( "Right Sidebar Width" , "Please enter a new width for the right sidebar, in pixels.</p><p><b>Minimum:</b> 250<br><b>Default:</b> 340" , old _val , function ( new _val ) {
if ( new _val === null || new _val === undefined )
return ;
2015-10-17 18:05:44 -04:00
2016-03-23 19:28:22 -04:00
var width = parseInt ( new _val ) ;
if ( ! width || Number . isNaN ( width ) || ! Number . isFinite ( width ) )
width = 340 ;
2015-07-31 17:44:49 -04:00
2016-03-23 19:28:22 -04:00
f . settings . set ( 'right_column_width' , Math . max ( 250 , width ) ) ;
} ) ;
2015-07-31 17:44:49 -04:00
} ,
on _update : function ( val ) {
if ( this . has _bttv )
return ;
2015-10-17 18:05:44 -04:00
2016-03-23 20:23:04 -04:00
var Layout = utils . ember _lookup ( 'controller:layout' ) ;
2015-07-31 17:44:49 -04:00
if ( ! Layout )
return ;
2015-10-17 18:05:44 -04:00
2015-07-31 17:44:49 -04:00
Layout . set ( 'rightColumnWidth' , val ) ;
Ember . propertyDidChange ( Layout , 'contentWidth' ) ;
}
} ;
// --------------------
// Initialization
// --------------------
FFZ . prototype . setup _layout = function ( ) {
if ( this . has _bttv )
return ;
document . body . classList . toggle ( "ffz-sidebar-swap" , this . settings . swap _sidebars ) ;
this . log ( "Creating layout style element." ) ;
var s = this . _layout _style = document . createElement ( 'style' ) ;
s . id = 'ffz-layout-css' ;
document . head . appendChild ( s ) ;
this . log ( "Hooking the Ember Layout controller." ) ;
2016-03-23 20:23:04 -04:00
var Layout = utils . ember _lookup ( 'controller:layout' ) ,
2015-07-31 17:44:49 -04:00
f = this ;
if ( ! Layout )
return ;
Layout . reopen ( {
rightColumnWidth : 340 ,
2015-10-24 22:44:00 -04:00
rawPortraitMode : 0 ,
portraitVideoBelow : false ,
portraitMode : function ( ) {
var raw = this . get ( "rawPortraitMode" ) ;
this . set ( 'portraitVideoBelow' , raw === 3 || raw === 4 ) ;
if ( raw === 0 )
return false ;
if ( raw === 2 || raw === 4 )
return true ;
// Not sure if I should be adding some other value to offset the ratio. What feels best?
var ratio = this . get ( "windowWidth" ) / ( this . get ( "windowHeight" ) + 120 + 60 ) ;
return ratio < 1 ;
} . property ( "rawPortraitMode" , "windowHeight" , "windowWidth" ) ,
2015-10-17 18:05:44 -04:00
2015-07-31 17:44:49 -04:00
isTooSmallForRightColumn : function ( ) {
2015-10-24 22:44:00 -04:00
if ( ! f . has _bttv && this . get ( 'portraitMode' ) ) {
var size = this . get ( 'playerSize' ) ,
height = size [ 1 ] ;
// Make sure we have at least a bit of room for the chat.
2015-11-07 22:56:15 -05:00
return this . get ( "windowHeight" ) < ( height + 120 + 60 + 200 ) ;
2015-10-24 22:44:00 -04:00
} else
return this . get ( "windowWidth" ) < ( 1090 - this . get ( 'rightColumnWidth' ) )
} . property ( "windowWidth" , "rightColumnWidth" , "playerSize" , "windowHeight" ) ,
2015-10-17 18:05:44 -04:00
2015-07-31 17:44:49 -04:00
contentWidth : function ( ) {
var left _width = this . get ( "isLeftColumnClosed" ) ? 50 : 240 ,
2015-10-24 22:44:00 -04:00
right _width = ! f . has _bttv && this . get ( 'portraitMode' ) ? 0 : this . get ( "isRightColumnClosed" ) ? 0 : this . get ( "rightColumnWidth" ) ;
2015-07-31 17:44:49 -04:00
return this . get ( "windowWidth" ) - left _width - right _width - 60 ;
2015-10-17 18:05:44 -04:00
2015-10-24 22:44:00 -04:00
} . property ( "windowWidth" , "portraitMode" , "isRightColumnClosed" , "isLeftColumnClosed" , "rightColumnWidth" ) ,
2015-10-17 18:05:44 -04:00
2015-10-24 22:44:00 -04:00
playerSize : function ( ) {
2015-10-17 18:05:44 -04:00
var h = this . get ( 'windowHeight' ) ,
c = this . get ( 'PLAYER_CONTROLS_HEIGHT' ) ,
r = this . get ( 'contentWidth' ) ,
i = ( 9 * r / 16 ) + c ,
d = h - 120 - 60 ,
c = h - 94 - 185 ,
l = Math . floor ( r ) ,
o = Math . floor ( Math . min ( i , d ) ) ,
s = Math . floor ( Math . min ( i , c ) ) ;
2015-10-24 22:44:00 -04:00
return [ l , o , s ] ;
} . property ( "contentWidth" , "windowHeight" , "portraitMode" , "PLAYER_CONTROLS_HEIGHT" ) ,
playerStyle : function ( ) {
var size = this . get ( 'playerSize' ) ,
width = size [ 0 ] ,
height = size [ 1 ] ,
host _height = size [ 2 ] ;
2016-03-23 19:28:22 -04:00
return "<style>.dynamic-player, .dynamic-player object, .dynamic-player video{width:" + width + "px !important;height:" + height + "px !important} .dynamic-target-player,.dynamic-target-player object, .dynamic-target-player video{width:" + width + "px !important;height:" + host _height + "px !important}</style><style>.dynamic-player .player object, .dynamic-player .player video{width:100% !important; height:100% !important}</style>" ;
2015-10-24 22:44:00 -04:00
} . property ( "playerSize" ) ,
2015-10-17 18:05:44 -04:00
2015-11-07 22:56:15 -05:00
ffzPortraitWarning : function ( ) {
2016-03-25 18:32:35 -04:00
var t = this ;
// Delay this, in case we're just resizing the window.
setTimeout ( function ( ) {
if ( ! f . settings . portrait _mode || f . _portrait _warning || f . settings . portrait _warning || document . body . getAttribute ( 'data-current-path' ) . indexOf ( 'user.' ) !== 0 || ! t . get ( 'isTooSmallForRightColumn' ) )
return ;
2015-10-17 18:05:44 -04:00
2016-03-25 18:32:35 -04:00
f . _portrait _warning = true ;
f . show _message ( 'Twitch\'s Chat Sidebar has been hidden as a result of FrankerFaceZ\'s Portrait Mode because the window is too wide.<br><br>Please <a href="#" onclick="ffz.settings.set(\'portrait_mode\',0);jQuery(this).parents(\'.ffz-noty\').remove();ffz._portrait_warning = false;return false">disable Portrait Mode</a> or make your window narrower.<br><br><a href="#" onclick="ffz.settings.set(\'portrait_warning\',true);jQuery(this).parents(\'.ffz-noty\').remove();return false">Do not show this message again</a>' ) ;
} , 50 ) ;
2015-10-17 18:05:44 -04:00
2015-11-07 22:56:15 -05:00
} . observes ( "isTooSmallForRightColumn" ) ,
2015-10-17 18:05:44 -04:00
2015-07-31 17:44:49 -04:00
ffzUpdateCss : function ( ) {
2015-10-24 22:44:00 -04:00
var out = '' ;
if ( ! f . has _bttv ) {
2016-03-25 18:32:35 -04:00
if ( this . get ( 'isRightColumnClosed' ) )
out = '' ;
else {
if ( this . get ( 'portraitMode' ) ) {
var size = this . get ( 'playerSize' ) ,
video _below = this . get ( 'portraitVideoBelow' ) ,
window _height = this . get ( 'windowHeight' ) ,
window _width = this . get ( 'windowWidth' ) ,
video _height = size [ 1 ] + 120 + 60 ,
chat _height = window _height - video _height ,
video _top = video _below ? chat _height : 0 ,
chat _top = video _below ? 0 : video _height ,
theatre _video _height = Math . floor ( Math . max ( window _height * 0.1 , Math . min ( window _height - 300 , 9 * window _width / 16 ) ) ) ,
theatre _chat _height = window _height - theatre _video _height ,
theatre _video _top = video _below ? theatre _chat _height : 0 ,
theatre _chat _top = video _below ? 0 : theatre _video _height ;
2016-05-27 00:59:03 -04:00
out = 'body[data-current-path^="user."] #left_col .warp { min-height: inherit }' +
'body[data-current-path^="user."] #left_col { overflow: hidden }' +
'body[data-current-path^="user."] #left_col .warp,' +
'body[data-current-path^="user."] #left_col,' +
2016-03-25 18:32:35 -04:00
'body[data-current-path^="user."]:not(.ffz-sidebar-swap) #main_col{' +
'margin-right:0 !important;' +
'top:' + video _top + 'px;' +
'height:' + video _height + 'px}' +
'body[data-current-path^="user."].ffz-sidebar-swap #main_col{' +
'margin-left:0 !important;' +
'top:' + video _top + 'px;' +
'height:' + video _height + 'px}' +
'body[data-current-path^="user."] #right_col{' +
'width:100%;' +
'top:' + chat _top + 'px;' +
'height:' + chat _height + 'px}' +
2016-05-27 00:59:03 -04:00
'body[data-current-path^="user."] .app-main.theatre #left_col .warp,' +
2016-03-25 18:32:35 -04:00
'body[data-current-path^="user."] .app-main.theatre #left_col,' +
'body[data-current-path^="user."] .app-main.theatre #main_col{' +
'top:' + theatre _video _top + 'px;' +
'height:' + theatre _video _height + 'px}' +
'body[data-current-path^="user."] .app-main.theatre #right_col{' +
'top:' + theatre _chat _top + 'px;' +
'height:' + theatre _chat _height + 'px}' ;
} else {
var width = this . get ( 'rightColumnWidth' ) ;
out = '#main_col.expandRight #right_close{left: none !important}' +
'#right_col{width:' + width + 'px}' +
'body:not(.ffz-sidebar-swap) #main_col:not(.expandRight){' +
'margin-right:' + width + 'px}' +
'body.ffz-sidebar-swap #main_col:not(.expandRight){' +
'margin-left:' + width + 'px}' ;
}
}
2015-10-24 22:44:00 -04:00
f . _layout _style . innerHTML = out ;
}
} . observes ( "isRightColumnClosed" , "playerSize" , "rightColumnWidth" , "portraitMode" , "windowHeight" , "windowWidth" ) ,
2015-10-17 18:05:44 -04:00
2016-03-24 12:01:25 -04:00
ffzUpdatePlayerStyle : function ( ) {
Ember . propertyDidChange ( Layout , 'playerStyle' ) ;
} . observes ( 'windowHeight' , 'windowWidth' ) ,
2015-10-24 22:44:00 -04:00
ffzUpdatePortraitCSS : function ( ) {
var portrait = this . get ( "portraitMode" ) ;
document . body . classList . toggle ( "ffz-portrait" , ! f . has _bttv && portrait ) ;
2015-07-31 17:44:49 -04:00
2015-10-24 22:44:00 -04:00
} . observes ( "portraitMode" ) ,
2015-10-17 18:05:44 -04:00
2015-07-31 17:44:49 -04:00
ffzFixTabs : function ( ) {
if ( f . settings . group _tabs && f . _chatv && f . _chatv . _ffz _tabs ) {
setTimeout ( function ( ) {
f . _chatv && f . _chatv . $ ( '.chat-room' ) . css ( 'top' , f . _chatv . _ffz _tabs . offsetHeight + "px" ) ;
} , 0 ) ;
}
2015-10-24 22:44:00 -04:00
} . observes ( "isRightColumnClosed" , "rightColumnWidth" , "portraitMode" , "playerSize" )
2015-07-31 17:44:49 -04:00
} ) ;
// Force the layout to update.
Layout . set ( 'rightColumnWidth' , this . settings . right _column _width ) ;
2015-10-24 22:44:00 -04:00
Layout . set ( 'rawPortraitMode' , this . settings . portrait _mode ) ;
// Force re-calculation of everything.
2015-11-07 22:56:15 -05:00
Ember . propertyDidChange ( Layout , 'windowWidth' ) ;
2015-10-24 22:44:00 -04:00
Ember . propertyDidChange ( Layout , 'windowHeight' ) ;
2016-05-06 02:23:12 -04:00
Layout . ffzUpdatePortraitCSS ( ) ;
2015-07-31 17:44:49 -04:00
}