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
|
Object.extend(String.prototype, {
pad : function(side, len, chr) {
if (!chr) chr = ' ';
var s = this;
var left = side.toLowerCase()=='left';
while (s.length<len) s = left? chr + s : s + chr;
return s;
},
padLeft : function(len, chr) {
return this.pad('left',len,chr);
},
padRight : function(len, chr) {
return this.pad('right',len,chr);
},
zerofill : function(len) {
var s = this;
var ix = /^[+-]/.test(s) ? 1 : 0;
while (s.length<len) s = s.insert(ix, '0');
return s;
},
trim : function() {
return this.replace(/^\s+|\s+$/g,'');
},
trimLeft : function() {
return this.replace(/^\s+/,'');
},
trimRight : function() {
return this.replace(/\s+$/,'');
},
/**
* Convert period separated function names into a function reference.
* e.g. "Prado.AJAX.Callback.Action.setValue".toFunction() will return
* the actual function Prado.AJAX.Callback.Action.setValue()
* @return Function the corresponding function represented by the string.
*/
toFunction : function()
{
var commands = this.split(/\./);
var command = window;
commands.each(function(action)
{
if(command[new String(action)])
command=command[new String(action)];
});
if(isFunction(command))
return command;
else
{
if(typeof Logger != "undefined")
Logger.error("Missing function", this);
return Prototype.emptyFunction;
}
}
});
|