Skip to content

Commit 4fba45e

Browse files
committed
adding a class attribute to <mark> tags to facilitate styling (only for ranges)
1 parent 92d4b30 commit 4fba45e

File tree

4 files changed

+25
-7
lines changed

4 files changed

+25
-7
lines changed

jquery.highlighttextarea.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
/*!
22
* jQuery highlightTextarea
3-
* Copyright 2014 Damien "Mistic" Sorel (http://www.strangeplanet.fr)
3+
* Original work Copyright 2014 Damien "Mistic" Sorel (http://www.strangeplanet.fr)
4+
*
5+
* Modified work Copyright 2015 Digital Cuisine (http://www.digitalcuisine.fr):
6+
* - adding a class attribute to <mark> tags to facilitate styling (only for ranges)
7+
*
48
* Licensed under MIT (http://opensource.org/licenses/MIT)
59
*/
610

@@ -73,7 +77,15 @@
7377
$.each(this.settings.ranges, function(i, range) {
7478
if (range.start < text.length) {
7579
text = Utilities.strInsert(text, range.end, '</mark>');
76-
text = Utilities.strInsert(text, range.start, '<mark style="background-color:'+ range.color +';">');
80+
81+
var mark = '<mark style="background-color:'+ range.color +';"';
82+
if (range.class != null)
83+
{
84+
mark += 'class="' + range.class + '"';
85+
}
86+
mark += ">";
87+
88+
text = Utilities.strInsert(text, range.start, mark);
7789
}
7890
});
7991

@@ -514,6 +526,7 @@
514526
if ($.isArray(range.ranges[j])) {
515527
out.push({
516528
color: range.color,
529+
class: range.class,
517530
start: range.ranges[j][0],
518531
end: range.ranges[j][1]
519532
});

jquery.highlighttextarea.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jquery.highlighttextarea.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/index.html

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,14 @@
5858
});
5959
$('#demo9').highlightTextarea({
6060
ranges: [{
61-
color: '#ADF0FF',
61+
class: 'blue',
6262
start: 0,
6363
length: 5
6464
}, {
6565
color: '#FFFF00',
6666
ranges: [[6, 11], [40, 55]]
6767
}],
68+
id: 'demo9-wrap',
6869
debug: true
6970
});
7071

@@ -103,6 +104,10 @@
103104
border-radius:0.5em;
104105
background-color:#9999FF !important;
105106
}
107+
108+
#demo9-wrap mark.blue {
109+
background-color: #ADF0FF;
110+
}
106111
</style>
107112
</head>
108113

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

187192
</body>
188-
</html>
193+
</html>

0 commit comments

Comments
 (0)