Add Favio.js support. Fixes #28

This commit is contained in:
Tor Hveem 2013-10-15 15:21:13 +02:00
parent 2617dadb65
commit a9d469867a
4 changed files with 32 additions and 4 deletions

View file

@ -16,6 +16,7 @@
<script type="text/javascript" src="js/websockets.js"></script>
<script type="text/javascript" src="js/models.js"></script>
<script type="text/javascript" src="js/plugins.js"></script>
<script type="text/javascript" src="js/favico-0.3.0.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
</head>

7
js/favico-0.3.0.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View file

@ -166,10 +166,11 @@ models.service('models', ['$rootScope', 'colors', function($rootScope, colors) {
});
activeBuffer.active = true;
activeBuffer.unread = '';
activeBuffer.notification = '';
activeBuffer.unread = 0;
activeBuffer.notification = 0;
$rootScope.$emit('activeBufferChanged');
$rootScope.$emit('notificationChanged');
}
/*

View file

@ -201,11 +201,13 @@ weechat.factory('handlers', ['$rootScope', 'colors', 'models', 'plugins', functi
if (!initial) {
if (!buffer.active && _.contains(message.tags, 'notify_message') && !_.contains(message.tags, 'notify_none')) {
buffer.unread++;
$rootScope.$emit('notificationChanged');
}
if(message.highlight || _.contains(message.tags, 'notify_private') ) {
buffer.notification++;
$rootScope.createHighlight(buffer, message);
$rootScope.$emit('notificationChanged');
}
}
}
@ -424,13 +426,29 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
}
}
$rootScope.$on('activeBufferChanged', function() {
$rootScope.scrollToBottom();
document.getElementById('sendMessage').focus();
var ab = models.getActiveBuffer();
$rootScope.pageTitle = ab.shortName + ' | ' + ab.title;
});
$rootScope.$on('notificationChanged', function() {
var notifications = _.reduce(models.model.buffers, function(memo, num) { return parseInt(memo||0) + num.notification;});
if (notifications > 0 ) {
$scope.favico = new Favico({
animation:'none'
});
$scope.favico.badge(notifications);
}else {
var unread = _.reduce(models.model.buffers, function(memo, num) { return parseInt(memo||0) + num.unread;});
$scope.favico = new Favico({
animation:'none',
bgColor : '#5CB85C',
textColor : '#ff0',
});
$scope.favico.badge(unread);
}
});
$scope.buffers = models.model.buffers;
$scope.activeBuffer = models.getActiveBuffer
@ -506,7 +524,7 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
if (models.getActiveBuffer() == buffer) {
return true;
}
return (parseInt(buffer.unread) || 0) > 0;
return buffer.unread > 0;
}
return true;
};
@ -556,5 +574,6 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
return true;
}
};
}]
);