@ -1,7 +1,10 @@
( function ( ) {
'use strict' ;
var weechat = angular . module ( 'weechat' , [ 'ngRoute' , 'localStorage' , 'weechatModels' , 'plugins' , 'IrcUtils' , 'ngSanitize' , 'ngWebsockets' , 'ngTouch' ] ) ;
var weechat = angular . module ( 'weechat' , [ 'ngRoute' , 'localStorage' , 'weechatModels' , 'plugins' , 'IrcUtils' , 'ngSanitize' , 'ngWebsockets' , 'ngTouch' ] , function ( $compileProvider ) {
// hacky way to be able to find out if we're in debug mode
weechat . compileProvider = $compileProvider ;
} ) ;
weechat . config ( [ '$compileProvider' , function ( $compileProvider ) {
// hack to determine whether we're executing the tests
if ( typeof ( it ) === "undefined" && typeof ( describe ) === "undefined" ) {
@ -9,11 +12,33 @@ weechat.config(['$compileProvider', function ($compileProvider) {
}
} ] ) ;
weechat . controller ( 'WeechatCtrl' , [ '$rootScope' , '$scope' , '$store' , '$timeout' , '$log' , 'models' , 'connection' , 'notifications' , 'utils' , function ( $rootScope , $scope , $store , $timeout , $log , models , connection , notifications , utils ) {
weechat . controller ( 'WeechatCtrl' , [ '$rootScope' , '$scope' , '$store' , '$timeout' , '$log' , 'models' , 'connection' , 'notifications' , 'utils' , 'settings' ,
function ( $rootScope , $scope , $store , $timeout , $log , models , connection , notifications , utils , settings ) {
$scope . command = '' ;
$scope . themes = [ 'dark' , 'light' ] ;
settings . setDefaults ( {
'theme' : 'dark' ,
'host' : 'localhost' ,
'port' : 9001 ,
'ssl' : ( window . location . protocol === "https:" ) ,
'savepassword' : false ,
'autoconnect' : false ,
'nonicklist' : utils . isMobileUi ( ) ,
'noembed' : utils . isMobileUi ( ) ,
'onlyUnread' : false ,
'hotlistsync' : true ,
'orderbyserver' : true ,
'useFavico' : true ,
'showtimestamp' : true ,
'showtimestampSeconds' : false ,
'fontsize' : '14px' ,
'fontfamily' : ( utils . isMobileUi ( ) ? 'sans-serif' : 'Inconsolata, Consolas, Monaco, Ubuntu Mono, monospace' ) ,
'readlineBindings' : false
} ) ;
$scope . settings = settings ;
// From: http://stackoverflow.com/a/18539624 by StackOverflow user "plantian"
$rootScope . countWatchers = function ( ) {
var q = [ $rootScope ] , watchers = 0 , scope ;
@ -69,22 +94,16 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
// Enable debug mode if "?debug=1" or "?debug=true" is set
( function ( ) {
var hasReloaded = false ;
window . location . search . substring ( 1 ) . split ( '&' ) . forEach ( function ( f ) {
var segs = f . split ( '=' ) ;
if ( segs [ 0 ] === "debug" && [ "true" , "1" ] . indexOf ( segs [ 1 ] ) != - 1 ) {
$rootScope . debugMode = true ;
} else if ( segs [ 0 ] === "debugReload" && segs [ 1 ] === "1" ) {
hasReloaded = true ;
}
} ) ;
// If we haven't reloaded yet, do an angular reload with debug infos
// store whether this has happened yet in a GET parameter
if ( $rootScope . debugMode && ! hasReloaded ) {
document . location . search += "&debugReload=1" ;
setTimeout ( function ( ) {
angular . reloadWithDebugInfo ( ) ;
} , 0 ) ;
if ( $rootScope . debugMode && ! weechat . compileProvider . debugInfoEnabled ( ) ) {
angular . reloadWithDebugInfo ( ) ;
}
} ) ( ) ;
@ -196,7 +215,7 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
// we will send a /buffer bufferName command every time
// the user switches a buffer. This will ensure that notifications
// are cleared in the buffer the user switches to
if ( $ scop e. hotlistsync && ab . fullName ) {
if ( settings . hotlistsync && ab . fullName ) {
connection . sendCoreCommand ( '/buffer ' + ab . fullName ) ;
}
@ -218,7 +237,7 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
$rootScope . $on ( 'notificationChanged' , function ( ) {
notifications . updateTitle ( ) ;
if ( $ scop e. useFavico && $rootScope . favico ) {
if ( settings . useFavico && $rootScope . favico ) {
notifications . updateFavico ( ) ;
}
} ) ;
@ -249,72 +268,31 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
$rootScope . iterCandidate = null ;
$store . bind ( $scope , "host" , "localhost" ) ;
$store . bind ( $scope , "port" , "9001" ) ;
$store . bind ( $scope , "proto" , "weechat" ) ;
$store . bind ( $scope , "ssl" , ( window . location . protocol === "https:" ) ) ;
$store . bind ( $scope , "savepassword" , false ) ;
if ( $scope . savepassword ) {
$store . bind ( $scope , "password" , "" ) ;
if ( settings . savepassword ) {
$scope . $watch ( 'password' , function ( ) {
settings . password = $scope . password ;
} ) ;
settings . addCallback ( 'password' , function ( password ) {
$scope . password = password ;
} ) ;
$scope . password = settings . password ;
} else {
settings . password = '' ;
}
$store . bind ( $scope , "autoconnect" , false ) ;
// If we are on mobile change some defaults
// We use 968 px as the cutoff, which should match the value in glowingbear.css
var nonicklist = false ;
var noembed = false ;
var showtimestamp = true ;
$rootScope . wasMobileUi = false ;
if ( utils . isMobileUi ( ) ) {
nonicklist = true ;
noembed = true ;
$rootScope . wasMobileUi = true ;
}
// Save setting for displaying only buffers with unread messages
$store . bind ( $scope , "onlyUnread" , false ) ;
// Save setting for syncing hotlist
$store . bind ( $scope , "hotlistsync" , true ) ;
// Save setting for displaying nicklist
$store . bind ( $scope , "nonicklist" , nonicklist ) ;
// Save setting for displaying embeds
$store . bind ( $scope , "noembed" , noembed ) ;
// Save setting for channel ordering
$store . bind ( $scope , "orderbyserver" , true ) ;
// Save setting for updating favicon
$store . bind ( $scope , "useFavico" , true ) ;
// Save setting for showtimestamp
$store . bind ( $scope , "showtimestamp" , showtimestamp ) ;
// Save setting for showing seconds on timestamps
$store . bind ( $scope , "showtimestampSeconds" , false ) ;
// Save setting for playing sound on notification
$store . bind ( $scope , "soundnotification" , false ) ;
// Save setting for font family
$store . bind ( $scope , "fontfamily" ) ;
// Save setting for theme
$store . bind ( $scope , "theme" , 'dark' ) ;
// Save setting for font size
$store . bind ( $scope , "fontsize" , "14px" ) ;
// Save setting for readline keybindings
$store . bind ( $scope , "readlineBindings" , false ) ;
// Save settings for non-native Emoji support
$store . bind ( $scope , "enableJSEmoji" , false ) ;
if ( ! $scope . fontfamily ) {
if ( ! settings . fontfamily ) {
if ( utils . isMobileUi ( ) ) {
$ scop e. fontfamily = 'sans-serif' ;
settings . fontfamily = 'sans-serif' ;
} else {
$ scop e. fontfamily = "Inconsolata, Consolas, Monaco, Ubuntu Mono, monospace" ;
settings . fontfamily = "Inconsolata, Consolas, Monaco, Ubuntu Mono, monospace" ;
}
}
// Save setting for displaying embeds in rootScope so it can be used from service
$rootScope . auto _display _embedded _content = $scope . noembed === false ;
$scope . isSidebarVisible = function ( ) {
return document . getElementById ( 'content' ) . getAttribute ( 'sidebar-state' ) === 'visible' ;
} ;
@ -336,9 +314,8 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
document . getElementById ( 'content' ) . setAttribute ( 'sidebar-state' , 'hidden' ) ;
}
} ;
// This also fires on page load
$scope . $watch ( 'autoconnect' , function ( ) {
if ( $scope . autoconnect && ! $rootScope . connected && ! $rootScope . sslError && ! $rootScope . securityError && ! $rootScope . errorMessage ) {
settings . addCallback ( 'autoconnect' , function ( autoconnect ) {
if ( autoconnect && ! $rootScope . connected && ! $rootScope . sslError && ! $rootScope . securityError && ! $rootScope . errorMessage ) {
$scope . connect ( ) ;
}
} ) ;
@ -357,35 +334,31 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
// Open and close panels while on mobile devices through swiping
$scope . openNick = function ( ) {
if ( utils . isMobileUi ( ) ) {
if ( $ scop e. nonicklist ) {
$ scop e. nonicklist = false ;
if ( settings . nonicklist ) {
settings . nonicklist = false ;
}
}
} ;
$scope . closeNick = function ( ) {
if ( utils . isMobileUi ( ) ) {
if ( ! $ scop e. nonicklist ) {
$ scop e. nonicklist = true ;
if ( ! settings . nonicklist ) {
settings . nonicklist = true ;
}
}
} ;
// Watch model and update show setting when it changes
$scope . $watch ( 'noembed' , function ( ) {
$rootScope . auto _display _embedded _content = $scope . noembed === false ;
} ) ;
// Watch model and update channel sorting when it changes
$scope . $watch ( 'orderbyserver' , function ( ) {
$rootScope . predicate = $scope . orderbyserver ? 'serverSortKey' : 'number' ;
settings . addCallback ( 'orderbyserver' , function ( orderbyserver ) {
$rootScope . predicate = orderbyserver ? 'serverSortKey' : 'number' ;
} ) ;
$scope . $watch ( 'useFavico' , function ( ) {
settings . addCallback ( 'useFavico' , function ( useFavico ) {
// this check is necessary as this is called on page load, too
if ( ! $rootScope . connected ) {
return ;
}
if ( $scope . useFavico ) {
if ( useFavico ) {
notifications . updateFavico ( ) ;
} else {
$rootScope . favico . reset ( ) ;
@ -393,17 +366,12 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
} ) ;
// Update font family when changed
$scope . $watch ( 'fontfamily' , function ( ) {
utils . changeClassStyle ( 'favorite-font' , 'fontFamily' , $scope . fontfamily ) ;
settings . addCallback ( 'fontfamily' , function ( fontfamily ) {
utils . changeClassStyle ( 'favorite-font' , 'fontFamily' , fontfamily ) ;
} ) ;
// Update font size when changed
$scope . $watch ( 'fontsize' , function ( ) {
utils . changeClassStyle ( 'favorite-font' , 'fontSize' , $scope . fontsize ) ;
} ) ;
// Crude scoping hack. The keypress listener does not live in the same scope as
// the checkbox, so we need to transfer this between scopes here.
$scope . $watch ( 'readlineBindings' , function ( ) {
$rootScope . readlineBindings = $scope . readlineBindings ;
settings . addCallback ( 'fontsize' , function ( fontsize ) {
utils . changeClassStyle ( 'favorite-font' , 'fontSize' , fontsize ) ;
} ) ;
$scope . setActiveBuffer = function ( bufferId , key ) {
@ -529,7 +497,7 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
$rootScope . errorMessage = false ;
$rootScope . bufferBottom = true ;
$scope . connectbutton = 'Connecting ...' ;
connection . connect ( $ scop e. host , $ scop e. port , $scope . password , $ scop e. ssl ) ;
connection . connect ( settings . host , settings . port , $scope . password , settings . ssl ) ;
} ;
$scope . disconnect = function ( ) {
$scope . connectbutton = 'Connect' ;
@ -597,7 +565,7 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
if ( $scope . search && $scope . search !== "" ) {
return true ;
}
if ( $ scop e. onlyUnread ) {
if ( settings . onlyUnread ) {
// Always show current buffer in list
if ( models . getActiveBuffer ( ) === buffer ) {
return true ;
@ -612,7 +580,7 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
} ;
// Watch model and update show setting when it changes
$scope . $watch ( 'nonicklist' , function ( ) {
settings . addCallback ( 'nonicklist' , function ( ) {
$scope . showNicklist = $scope . updateShowNicklist ( ) ;
// restore bottom view
if ( $rootScope . connected && $rootScope . bufferBottom ) {
@ -631,7 +599,7 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
return false ;
}
// Check if option no nicklist is set
if ( $ scop e. nonicklist ) {
if ( settings . nonicklist ) {
return false ;
}
// Check if nicklist is empty
@ -665,7 +633,7 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
} ;
// Helper function since the keypress handler is in a different scope
$rootScope . toggleNicklist = function ( ) {
$ scop e. nonicklist = ! $ scop e. nonicklist ;
settings . nonicklist = ! settings . nonicklist ;
} ;