Skip to content
This repository has been archived by the owner on Apr 21, 2022. It is now read-only.

Commit

Permalink
Merge pull request #36 from anaidenko/master
Browse files Browse the repository at this point in the history
Accept html tags and entities in fake-area.
  • Loading branch information
aurbano authored Jun 19, 2017
2 parents f6c2fa8 + 1921e9f commit ac498c0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
17 changes: 11 additions & 6 deletions dist/smart-area.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ angular.module('smartArea', [])
* + Scope Data +
* +----------------------------------------------------+ */

$scope.fakeArea = $scope.areaData;
$scope.fakeArea = htmlEncode($scope.areaData);
$scope.dropdownContent = 'Dropdown';
$scope.dropdown = {
content: [],
Expand Down Expand Up @@ -167,7 +167,7 @@ angular.module('smartArea', [])
var text = $scope.areaData,
position = getCharacterPosition();

$scope.fakeArea = $sce.trustAsHtml(text.substring(0, position) + '<span class="sa-tracking"></span>' + text.substring(position));
$scope.fakeArea = $sce.trustAsHtml(htmlEncode(text.substring(0, position)) + '<span class="sa-tracking"></span>' + htmlEncode(text.substring(position)));

// Tracking span
$timeout(function(){
Expand Down Expand Up @@ -299,7 +299,8 @@ angular.module('smartArea', [])
* a cssClass specified.
*/
function highlightText(){
var text = $scope.areaData;
var text = $scope.areaData,
html = htmlEncode(text);

if(typeof($scope.areaConfig.autocomplete) === 'undefined' || $scope.areaConfig.autocomplete.length === 0){
return;
Expand All @@ -308,16 +309,16 @@ angular.module('smartArea', [])
$scope.areaConfig.autocomplete.forEach(function(autoList){
for(var i=0; i<autoList.words.length; i++){
if(typeof(autoList.words[i]) === "string"){
text = text.replace(new RegExp("([^\\w]|\\b)("+autoList.words[i]+")([^\\w]|\\b)", 'g'), '$1<span class="'+autoList.cssClass+'">$2</span>$3');
html = html.replace(new RegExp("([^\\w]|\\b)("+autoList.words[i]+")([^\\w]|\\b)", 'g'), '$1<span class="'+autoList.cssClass+'">$2</span>$3');
}else{
text = text.replace(autoList.words[i], function(match){
html = html.replace(autoList.words[i], function(match){
return '<span class="'+autoList.cssClass+'">'+match+'</span>';
});
}
}
});
// Add to the fakeArea
$scope.fakeArea = $sce.trustAsHtml(text);
$scope.fakeArea = $sce.trustAsHtml(html);
}

/**
Expand Down Expand Up @@ -465,6 +466,10 @@ angular.module('smartArea', [])
}
}

function htmlEncode(html) {
return $('<div>').text(html).html();
}

/* +----------------------------------------------------+
* + Event Binding +
* +----------------------------------------------------+ */
Expand Down
4 changes: 2 additions & 2 deletions dist/smart-area.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ac498c0

Please sign in to comment.