Merge pull request #496 from glowing-bear/colourise-title

Parse colours in buffer title
This commit is contained in:
Tor Hveem 2015-01-13 13:54:52 +01:00
commit 63c7e10832
4 changed files with 61 additions and 48 deletions

View file

@ -215,7 +215,9 @@ $ openssl req -nodes -newkey rsa:4096 -keyout relay.pem -x509 -days 365 -out rel
</a>
<button ng-if="debugMode" ng-click="countWatchers()">Count<br />Watchers</button>
</div>
<div class="title" ng-bind-html="activeBuffer().title | linky:'_blank' | DOMfilter:'irclinky'" title="{{activeBuffer().title}}"></div>
<div class="title" title="{{activeBuffer().rtitle}}">
<span ng-repeat="part in activeBuffer().title" ng-class="::part.classes" ng-bind-html="::(part.text | linky:'_blank' | DOMfilter:'irclinky')"></span>
</div>
<div class="actions pull-right vertical-line-left">
<div class="pull-left">
<a class="settings-toggle" ng-click="showModal('settingsModal')" title="Options menu">

View file

@ -64,8 +64,13 @@ weechat.factory('handlers', ['$rootScope', '$log', 'models', 'plugins', 'notific
var buffer = obj.pointers[0];
var old = models.getBuffer(buffer);
old.fullName = obj.full_name;
old.title = obj.title;
old.title = models.parseRichText(obj.title);
old.number = obj.number;
old.rtitle = "";
for (var i = 0; i < old.title.length; ++i) {
old.rtitle += old.title[i].text;
}
};
var handleBufferRenamed = function(message) {

View file

@ -8,6 +8,48 @@
var models = angular.module('weechatModels', []);
models.service('models', ['$rootScope', '$filter', function($rootScope, $filter) {
var parseRichText = function(text) {
var textElements = weeChat.Protocol.rawText2Rich(text),
typeToClassPrefixFg = {
'option': 'cof-',
'weechat': 'cwf-',
'ext': 'cef-'
},
typeToClassPrefixBg = {
'option': 'cob-',
'weechat': 'cwb-',
'ext': 'ceb-'
};
textElements.forEach(function(textEl) {
textEl.classes = [];
// foreground color
var prefix = typeToClassPrefixFg[textEl.fgColor.type];
textEl.classes.push(prefix + textEl.fgColor.name);
// background color
prefix = typeToClassPrefixBg[textEl.bgColor.type];
textEl.classes.push(prefix + textEl.bgColor.name);
// attributes
if (textEl.attrs.name !== null) {
textEl.classes.push('coa-' + textEl.attrs.name);
}
var attr, val;
for (attr in textEl.attrs.override) {
val = textEl.attrs.override[attr];
if (val) {
textEl.classes.push('a-' + attr);
} else {
textEl.classes.push('a-no-' + attr);
}
}
});
return textElements;
};
this.parseRichText = parseRichText;
/*
* Buffer class
*/
@ -21,7 +63,7 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter)
var trimmedName = shortName.replace(/^[#&+]/, '') || (shortName ? ' ' : null);
// get channel identifier
var prefix = ['#', '&', '+'].indexOf(shortName.charAt(0)) >= 0 ? shortName.charAt(0) : '';
var title = message.title;
var title = parseRichText(message.title);
var number = message.number;
var pointer = message.pointers[0];
var notify = 3; // Default 3 == message
@ -44,6 +86,11 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter)
notify = message.notify;
}
var rtitle = "";
for (var i = 0; i < title.length; ++i) {
rtitle += title[i].text;
}
/*
* Adds a line to this buffer
*
@ -234,6 +281,7 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter)
prefix: prefix,
number: number,
title: title,
rtitle: rtitle,
lines: lines,
clear: clear,
requestedLines: requestedLines,
@ -268,53 +316,11 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter)
var date = message.date;
var shortTime = $filter('date')(date, 'HH:mm');
function addClasses(textElements) {
var typeToClassPrefixFg = {
'option': 'cof-',
'weechat': 'cwf-',
'ext': 'cef-'
};
var typeToClassPrefixBg = {
'option': 'cob-',
'weechat': 'cwb-',
'ext': 'ceb-'
};
textElements.forEach(function(textEl) {
textEl.classes = [];
// foreground color
var prefix = typeToClassPrefixFg[textEl.fgColor.type];
textEl.classes.push(prefix + textEl.fgColor.name);
// background color
prefix = typeToClassPrefixBg[textEl.bgColor.type];
textEl.classes.push(prefix + textEl.bgColor.name);
// attributes
if (textEl.attrs.name !== null) {
textEl.classes.push('coa-' + textEl.attrs.name);
}
var val;
for (var attr in textEl.attrs.override) {
val = textEl.attrs.override[attr];
if (val) {
textEl.classes.push('a-' + attr);
} else {
textEl.classes.push('a-no-' + attr);
}
}
});
}
var prefix = weeChat.Protocol.rawText2Rich(message.prefix);
addClasses(prefix);
var prefix = parseRichText(message.prefix);
var tags_array = message.tags_array;
var displayed = message.displayed;
var highlight = message.highlight;
var content = weeChat.Protocol.rawText2Rich(message.message);
addClasses(content);
var content = parseRichText(message.message);
if (highlight) {
prefix.forEach(function(textEl) {

View file

@ -54,7 +54,7 @@ weechat.factory('notifications', ['$rootScope', '$log', 'models', function($root
var activeBuffer = models.getActiveBuffer();
if (activeBuffer) {
$rootScope.pageTitle = activeBuffer.shortName + ' | ' + activeBuffer.title;
$rootScope.pageTitle = activeBuffer.shortName + ' | ' + activeBuffer.rtitle;
}
};