Put class definitions on top
This commit is contained in:
parent
b1d7655776
commit
c4697feede
1 changed files with 71 additions and 72 deletions
143
js/models.js
143
js/models.js
|
@ -5,6 +5,77 @@
|
|||
var models = angular.module('weechatModels', []);
|
||||
|
||||
models.service('models', ['colors', function(colors) {
|
||||
/*
|
||||
* Buffer class
|
||||
*/
|
||||
this.Buffer = function(message) {
|
||||
// weechat properties
|
||||
var fullName = message['full_name']
|
||||
var pointer = message['pointers'][0]
|
||||
var lines = []
|
||||
var active = false;
|
||||
var notification = false;
|
||||
|
||||
/*
|
||||
* Adds a line to this buffer
|
||||
*
|
||||
* @param line the BufferLine object
|
||||
* @return undefined
|
||||
*/
|
||||
var addLine = function(line) {
|
||||
lines.push(line);
|
||||
}
|
||||
|
||||
return {
|
||||
id: pointer,
|
||||
fullName: fullName,
|
||||
lines: lines,
|
||||
addLine: addLine
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* BufferLine class
|
||||
*/
|
||||
this.BufferLine = function(weechatBufferLine) {
|
||||
|
||||
/*
|
||||
* Parse the text elements from the buffer line added
|
||||
*
|
||||
* @param message weechat message
|
||||
*/
|
||||
function parseLineAddedTextElements(message) {
|
||||
var prefix = colors.parse(message['objects'][0]['content'][0]['prefix']);
|
||||
|
||||
var buffer = message['objects'][0]['content'][0]['buffer'];
|
||||
text_elements = _.union(prefix, text);
|
||||
text_elements =_.map(text_elements, function(text_element) {
|
||||
if ('fg' in text_element) {
|
||||
text_element['fg'] = colors.prepareCss(text_element['fg']);
|
||||
}
|
||||
// TODO: parse background as well
|
||||
|
||||
return text_element;
|
||||
});
|
||||
return text_elements;
|
||||
}
|
||||
|
||||
|
||||
var buffer = message['objects'][0]['content'][0]['buffer'];
|
||||
var date = message['objects'][0]['content'][0]['date'];
|
||||
var text = colors.parse(message['objects'][0]['content'][0]['message']);
|
||||
var content = parseLineAddedTextElements(message);
|
||||
|
||||
return {
|
||||
content: content,
|
||||
date: date,
|
||||
buffer: buffer,
|
||||
text: text[0]['text'],
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
var BufferList = []
|
||||
activeBuffer = null;
|
||||
|
@ -91,76 +162,4 @@ models.service('models', ['colors', function(colors) {
|
|||
var firstBuffer = _.keys(this.model['buffers'])[0];
|
||||
this.setActiveBuffer(firstBuffer);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Buffer class
|
||||
*/
|
||||
this.Buffer = function(message) {
|
||||
// weechat properties
|
||||
var fullName = message['full_name']
|
||||
var pointer = message['pointers'][0]
|
||||
var lines = []
|
||||
var active = false;
|
||||
var notification = false;
|
||||
|
||||
/*
|
||||
* Adds a line to this buffer
|
||||
*
|
||||
* @param line the BufferLine object
|
||||
* @return undefined
|
||||
*/
|
||||
var addLine = function(line) {
|
||||
lines.push(line);
|
||||
}
|
||||
|
||||
return {
|
||||
id: pointer,
|
||||
fullName: fullName,
|
||||
lines: lines,
|
||||
addLine: addLine
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* BufferLine class
|
||||
*/
|
||||
this.BufferLine = function(weechatBufferLine) {
|
||||
|
||||
/*
|
||||
* Parse the text elements from the buffer line added
|
||||
*
|
||||
* @param message weechat message
|
||||
*/
|
||||
function parseLineAddedTextElements(message) {
|
||||
var prefix = colors.parse(message['objects'][0]['content'][0]['prefix']);
|
||||
|
||||
var buffer = message['objects'][0]['content'][0]['buffer'];
|
||||
text_elements = _.union(prefix, text);
|
||||
text_elements =_.map(text_elements, function(text_element) {
|
||||
if ('fg' in text_element) {
|
||||
text_element['fg'] = colors.prepareCss(text_element['fg']);
|
||||
}
|
||||
// TODO: parse background as well
|
||||
|
||||
return text_element;
|
||||
});
|
||||
return text_elements;
|
||||
}
|
||||
|
||||
|
||||
var buffer = message['objects'][0]['content'][0]['buffer'];
|
||||
var date = message['objects'][0]['content'][0]['date'];
|
||||
var text = colors.parse(message['objects'][0]['content'][0]['message']);
|
||||
var content = parseLineAddedTextElements(message);
|
||||
|
||||
return {
|
||||
content: content,
|
||||
date: date,
|
||||
buffer: buffer,
|
||||
text: text[0]['text'],
|
||||
}
|
||||
|
||||
}
|
||||
}]);
|
||||
|
|
Loading…
Reference in a new issue