forked from jbr/jQuery.highlightRegex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
80 lines (73 loc) · 2.17 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<html>
<head>
<title>jQuery.highlightRegex() demonstration</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
<script src="highlightRegex.js"></script>
<script type='text/javascript'>
//<![CDATA[
$(function() {
$('#toggle-link').toggle(function(){
regex = /[aeiou]/ig
$('#regex').text(regex);
$('#content').highlightRegex(regex);
$(this).text("click to clear");
}, function(){
$('#content').highlightRegex();
$(this).text('click to re-highlight');
})
$('#fancy-input').keyup(function(){
var regex;
$('#fancy-text').highlightRegex();
try { regex = new RegExp($(this).val(), 'ig') }
catch (e) { $('#fancy-input').addClass('error') }
if (typeof regex !== 'undefined') {
$(this).removeClass('error');
if ($(this).val() != '')
$('#fancy-text').highlightRegex(regex);
}
})
});
//]]>
</script>
<style>
.highlight {
background: yellow;
text-decoration: underline;
}
#fancy-text {
float: left;
padding:10px;
margin: 0 10px 20px ;
border: 3px double red;
}
#fancy-input {
font-size: 100%;
background: #ABC;
}
#fancy-input.error {
background: red;
}
#input {
clear:left;
font-size: 200%;
}
</style>
</head>
<body>
<h1> jQuery highlightRegex Demonstration</h1>
<h2> Static </h2>
<div id="content">This is some text that will be highlighted with the regex <span id='regex'></span></div>
<a href='#' id='toggle-link'>click to highlight</a>
<hr/>
<h2> Dynamic </h2>
<div id='fancy-text'>
<h3>Type in the input field below to highlight anything in this outlined box.</h3>
<code><pre>(case insensitive and global)</code></pre>
<ul>
<li> You can use regular expressions.</li>
<li> It highlights children nodes recursively. </li>
</ul>
</div>
<div id='input'>Type Here: /<input type='text' id='fancy-input'/>/ig</div>
</body>
</html>