]>
Commit | Line | Data |
---|---|---|
9e769c12 CP |
1 | Array.prototype.indexFromEnd = function(d) { |
2 | var p = this; | |
3 | ||
4 | if(d < 0) | |
5 | return p[p.length + d]; | |
6 | ||
7 | return p[d]; | |
8 | } | |
9 | ||
10 | /* how horribly inefficient */ | |
11 | String.prototype.replaceAll = function(f, t) { | |
12 | var i = this.indexOf(f); | |
13 | var c = this; | |
14 | ||
15 | while(i > -1) { | |
16 | c = c.replace(f, t); | |
17 | i = c.indexOf(f); | |
18 | } | |
19 | return c; | |
20 | } | |
21 | ||
22 | /* how horribly inefficient (again) */ | |
23 | String.prototype.splitMax = function(by, max) { | |
24 | var items = this.split(by); | |
25 | var newitems = items.slice(0, max-1); | |
26 | ||
27 | if(items.length >= max) | |
28 | newitems.push(items.slice(max-1).join(by)); | |
29 | ||
30 | return newitems; | |
31 | } | |
9b63b053 CP |
32 | |
33 | function setAtEnd(obj) { | |
34 | pos = obj.value.length; | |
35 | ||
36 | if(obj.createTextRange) { | |
37 | var range = obj.createTextRange(); | |
38 | range.move("character", pos); | |
39 | range.select(); | |
40 | } else if(obj.selectionStart) { | |
41 | obj.focus(); | |
42 | obj.setSelectionRange(pos, pos); | |
43 | } | |
44 | } |