I am trying to make a text highlight using a search keyword. I did my best. But I couldn't get a result of what I required.
Now I don't have any idea to proceed further to complete my requirement. any one give the correct suggestion or help me to complete the highlight
by search key word functionality?
Actually my search
input sits in the header of the page. ( global ) from I would like to highlight the text in the page by keyword entries.
here is my code :
var app = angular.module('plunker', []);
app.controller('headerController', function ($scope) {
var replacer = function(match, item) {
return '<span class="highlight">'+match+'</span>';
}
var tokenize = function(keywords) {
keywords = keywords.replace(new RegExp(',$','g'), '').split(',');
var i;
var l = keywords.length;
for (i=0;i<l;i++) {
keywords[i] = '\\W'+keywords[i].replace(new RegExp('^ | $','g'), '')+'\\W';
}
return keywords;
}
$scope.search = {value:''}
$scope.$watch('search.value', function(newval, oldval) {
if(!newval) {
return false;
}
var tokenized = tokenize(newval);
var regex = new RegExp(tokenized.join('|'), 'gmi');
console.log( tokenized );
})
})
app.controller('controller1', function($scope) {
$scope.para1 = 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.';
});
app.controller('controller2', function($scope) {
$scope.para2 = 'It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.';
});
app.controller('controller3', function($scope) {
$scope.para3 = 'The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.';
});