Skip to content

Commit

Permalink
adding a class attribute to <mark> tags to facilitate styling (only f…
Browse files Browse the repository at this point in the history
…or ranges)
  • Loading branch information
olance committed May 5, 2015
1 parent 92d4b30 commit 4fba45e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
17 changes: 15 additions & 2 deletions jquery.highlighttextarea.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
/*!
* jQuery highlightTextarea
* Copyright 2014 Damien "Mistic" Sorel (http://www.strangeplanet.fr)
* Original work Copyright 2014 Damien "Mistic" Sorel (http://www.strangeplanet.fr)
*
* Modified work Copyright 2015 Digital Cuisine (http://www.digitalcuisine.fr):
* - adding a class attribute to <mark> tags to facilitate styling (only for ranges)
*
* Licensed under MIT (http://opensource.org/licenses/MIT)
*/

Expand Down Expand Up @@ -73,7 +77,15 @@
$.each(this.settings.ranges, function(i, range) {
if (range.start < text.length) {
text = Utilities.strInsert(text, range.end, '</mark>');
text = Utilities.strInsert(text, range.start, '<mark style="background-color:'+ range.color +';">');

var mark = '<mark style="background-color:'+ range.color +';"';
if (range.class != null)
{
mark += 'class="' + range.class + '"';
}
mark += ">";

text = Utilities.strInsert(text, range.start, mark);
}
});

Expand Down Expand Up @@ -514,6 +526,7 @@
if ($.isArray(range.ranges[j])) {
out.push({
color: range.color,
class: range.class,
start: range.ranges[j][0],
end: range.ranges[j][1]
});
Expand Down
2 changes: 1 addition & 1 deletion jquery.highlighttextarea.min.css

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

4 changes: 2 additions & 2 deletions jquery.highlighttextarea.min.js

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

9 changes: 7 additions & 2 deletions tests/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,14 @@
});
$('#demo9').highlightTextarea({
ranges: [{
color: '#ADF0FF',
class: 'blue',
start: 0,
length: 5
}, {
color: '#FFFF00',
ranges: [[6, 11], [40, 55]]
}],
id: 'demo9-wrap',
debug: true
});

Expand Down Expand Up @@ -103,6 +104,10 @@
border-radius:0.5em;
background-color:#9999FF !important;
}

#demo9-wrap mark.blue {
background-color: #ADF0FF;
}
</style>
</head>

Expand Down Expand Up @@ -185,4 +190,4 @@ <h3>API</h3>
<footer>&copy; 2014 <a href="http://www.strangeplanet.fr">strangeplanet.fr</a> - Created by Damien "Mistic" Sorel</footer>

</body>
</html>
</html>

0 comments on commit 4fba45e

Please sign in to comment.