forked from Archives/Athou_commafeed
highlight search results
This commit is contained in:
@@ -424,4 +424,26 @@ module.directive('droppable', [ 'CategoryService', 'FeedService',
|
||||
});
|
||||
}
|
||||
};
|
||||
} ]);
|
||||
} ]);
|
||||
|
||||
|
||||
module.filter('highlight', function() {
|
||||
return function(html, keywords) {
|
||||
if (keywords) {
|
||||
var tokens = keywords.split(' ');
|
||||
for (var i = 0; i < tokens.length; i++) {
|
||||
var expr = new RegExp(tokens[i], 'gi');
|
||||
var container = $('<span>').html(html);
|
||||
var elements = container.find('*').addBack();
|
||||
var textNodes = elements.not('iframe').contents().not(elements);
|
||||
textNodes.each(function() {
|
||||
var replaced = this.nodeValue.replace(expr, '<span class="highlight-search">$&</span>');
|
||||
$('<span>').html(replaced).insertBefore(this);
|
||||
$(this).remove();
|
||||
});
|
||||
return container.html();
|
||||
}
|
||||
}
|
||||
return html;
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user