Skip to content

Commit b685498

Browse files
committed
The parameters of set() have changed. Now using length instead of end for ease of use and better support for negative numbers.
1 parent cb54268 commit b685498

File tree

4 files changed

+240
-210
lines changed

4 files changed

+240
-210
lines changed

bower.json

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
{
22
"name": "jquery-textrange",
3-
"version": "1.0.1",
3+
"version": "1.1.0",
44
"main": "jquery-textrange.js",
55
"dependencies": {
66
"jquery": ">=1.3"
77
},
88
"ignore": [
9-
"LICENSE",
10-
"README.md",
11-
"demo.html",
129
"textrange.jquery.json"
1310
]
1411
}

demo.html

+33-32
Original file line numberDiff line numberDiff line change
@@ -24,46 +24,47 @@
2424
</style>
2525
<script>
2626
$(document).ready(function() {
27-
var orange = false;
28-
setInterval(function() {
29-
orange = !orange;
30-
$('h1').css('border-color', orange ? 'transparent' : '#fa4500');
31-
}, 500);
27+
var orange = false;
3228

33-
$('#textarea').bind('updateInfo keyup mousedown mousemove mouseup', function() {
34-
var range = $(this).textrange();
29+
setInterval(function() {
30+
orange = !orange;
31+
$('h1').css('border-color', orange ? 'transparent' : '#fa4500');
32+
}, 500);
3533

36-
$('#info .property').each(function() {
37-
if(typeof range[$(this).attr('id')] !== 'undefined') {
38-
if($(this).attr('id') === 'text') {
39-
range[$(this).attr('id')] = range[$(this).attr('id')].replace(/\n/g, "\\n").replace(/\r/g, "\\r");
40-
}
34+
$('#textarea').bind('updateInfo keyup mousedown mousemove mouseup', function() {
35+
var range = $(this).textrange();
4136

42-
$(this).children('.value').html(range[$(this).attr('id')]);
43-
}
44-
});
45-
});
37+
$('#info .property').each(function() {
38+
if (typeof range[$(this).attr('id')] !== 'undefined') {
39+
if ($(this).attr('id') === 'text') {
40+
range[$(this).attr('id')] = range[$(this).attr('id')].replace(/\n/g, "\\n").replace(/\r/g, "\\r");
41+
}
4642

47-
$('#console-log').click(function() {
48-
var obj = {};
43+
$(this).children('.value').html(range[$(this).attr('id')]);
44+
}
45+
});
46+
});
4947

50-
$('#info .property').each(function() {
51-
var value = $(this).children('.value').html();
52-
obj[$(this).attr('id')] = isNaN(value) || value == '' ? value : parseInt(value);
53-
});
48+
$('#console-log').click(function() {
49+
var obj = {};
5450

55-
console.log(obj);
51+
$('#info .property').each(function() {
52+
var value = $(this).children('.value').html();
53+
obj[$(this).attr('id')] = isNaN(value) || value == '' ? value : parseInt(value);
54+
});
5655

57-
return false;
58-
});
56+
console.log(obj);
5957

60-
$('#selection-set').click(function() {
61-
$('#textarea').textrange('set', $('#char-start').val(), $('#char-end').val()).trigger('updateInfo').focus();
62-
});
58+
return false;
59+
});
6360

64-
$('#selection-replace').click(function() {
65-
$('#textarea').textrange('replace', $('#replace-text').val()).trigger('updateInfo').focus();
66-
});
61+
$('#selection-set').click(function() {
62+
$('#textarea').textrange('set', $('#char-start').val(), $('#char-end').val()).trigger('updateInfo').focus();
63+
});
64+
65+
$('#selection-replace').click(function() {
66+
$('#textarea').textrange('replace', $('#replace-text').val()).trigger('updateInfo').focus();
67+
});
6768
});
6869
</script>
6970
</head>
@@ -91,7 +92,7 @@ <h1><a href="https://github.com/dwieeb/jquery-textrange/">jquery-textrange</a></
9192
<input type="button" id="console-log" name="console-log" value="console.log() this bad boy">
9293
</div>
9394
<div>
94-
Select a substring starting at <input type="text" id="char-start" name="char-start" value="30"> and ending at <input type="text" id="char-end" name="char-end" value="55"> <input type="button" id="selection-set" name="selection-set" value="Go!!">
95+
Select a substring starting at <input type="text" id="char-start" name="char-start" value="30"> with a length of <input type="text" id="char-end" name="char-end" value="15"> <input type="button" id="selection-set" name="selection-set" value="Go!!">
9596
</div>
9697
<div>
9798
Replace the selected text with: <input type="text" id="replace-text" name="replace-text" value="some text"> <input type="button" id="selection-replace" name="selection-replace" value="Go!!">

0 commit comments

Comments
 (0)