mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-09-16 10:58:01 +00:00
feat(mail): Improve mail search (advanced search)
This commit is contained in:
@@ -473,6 +473,8 @@
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
if (this.$parts)
|
||||
// Use the cache
|
||||
return this.$parts;
|
||||
@@ -480,12 +482,80 @@
|
||||
else if (this.parts)
|
||||
_visit(this.parts);
|
||||
|
||||
|
||||
// Highlight words
|
||||
if (parts && this.$mailbox && this.$mailbox.getHighlightWords().length > 0) {
|
||||
var i = 0, j = 0;
|
||||
for (i = 0; i < parts.length; i++) {
|
||||
if (parts[i]
|
||||
&& parts[i].type
|
||||
&& ("UIxMailPartHTMLViewer" == parts[i].type
|
||||
|| "UIxMailPartTextViewer" == parts[i].type)) {
|
||||
// Content
|
||||
parts[i].content = this.highlightSearchTerms(parts[i].content);
|
||||
// Title
|
||||
this.subject = this.getHighlightSubject();
|
||||
// From
|
||||
this.from = this.getHighlightFrom();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Cache result
|
||||
this.$parts = parts;
|
||||
|
||||
return parts;
|
||||
};
|
||||
|
||||
/**
|
||||
* @function highlightSearchTerms
|
||||
* @memberof Message.prototype
|
||||
* @desc Returns the data with highlight search
|
||||
* @returns the data with highlighted search terms
|
||||
*/
|
||||
Message.prototype.highlightSearchTerms = function (data) {
|
||||
var i = 0;
|
||||
if (this.$mailbox.getHighlightWords()
|
||||
&& this.$mailbox.getHighlightWords().length > 0
|
||||
&& data
|
||||
&& -1 === data.indexOf("data-markjs")) {
|
||||
var dom = document.createElement("DIV");
|
||||
dom.innerHTML = data;
|
||||
var markInstance = new Mark(dom);
|
||||
markInstance.mark(this.$mailbox.getHighlightWords());
|
||||
data = dom.innerHTML;
|
||||
dom.remove();
|
||||
}
|
||||
|
||||
return data;
|
||||
};
|
||||
|
||||
/**
|
||||
* @function getHighlightSubject
|
||||
* @memberof Message.prototype
|
||||
* @desc Returns the subject with highlight search
|
||||
* @returns the subject with highlighted search terms
|
||||
*/
|
||||
Message.prototype.getHighlightSubject = function () {
|
||||
return this.highlightSearchTerms(this.subject);
|
||||
};
|
||||
|
||||
/**
|
||||
* @function getHighlightFrom
|
||||
* @memberof Message.prototype
|
||||
* @desc Returns the from with highlight search
|
||||
* @returns the from with highlighted search terms
|
||||
*/
|
||||
Message.prototype.getHighlightFrom = function () {
|
||||
var i = 0;
|
||||
for (i = 0; i < this.from.length; i++) {
|
||||
this.from[i].full = this.highlightSearchTerms(this.from[i].full);
|
||||
this.from[i].name = this.highlightSearchTerms(this.from[i].name);
|
||||
}
|
||||
|
||||
return this.from;
|
||||
};
|
||||
|
||||
/**
|
||||
* @function $editableContent
|
||||
* @memberof Message.prototype
|
||||
|
||||
Reference in New Issue
Block a user