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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
(function () {
Object.defineProperties(util,
{
/**
* Get the selected text in a webview
* @name getSelection
* @memberOf util
* @function
*
* @returns {String} The selected text or null if no text was selected
* */
"getSelection" :
{
value : function()
{
var frames = tabs.current.allFrames;
for (var i=frames.length-1; i>=0; --i)
{
var selection = JSON.parse(frames[i].inject("return document.getSelection().toString()"));
if (selection.length > 0)
return selection;
}
return null;
}
},
/**
* Converts camel-case string for usage with GObject properties to a
* non-camel-case String
* @name uncamelize
* @memberOf util
* @function
* @example
* util.uncamelize("fooBarBaz"); // "foo-bar-baz"
*
* @param {String} text The text to uncamelize
*
* @returns {String} The uncamelized String
*
* */
"uncamelize" :
{
value : function(text)
{
if (! text || text.length === 0)
return text;
return text.replace(/(.)?([A-Z])/g, function(x, s, m) {
return s ? s + "-" + m.toLowerCase() : m.toLowerCase();
});
}
},
/**
* Converts a non-camel-case string to a camel-case string
*
* @name camelize
* @memberOf util
* @function
* @example
* util.camelize("foo-bar-baz"); // "fooBarBaz"
*
* @param {String} text The text to camelize
*
* @returns {String} A camelcase String
* */
"camelize" :
{
value : function(text)
{
if (! text || text.length === 0)
return text;
return text.replace(/[-_]+(.)?/g, function(a, b) {
return b ? b.toUpperCase() : "";
});
}
},
/**
* Mixes properties of objects into an object. Properties are mixed in
* from left to right, so properties will not be overwritten in the
* leftmost object if they are already defined.
*
* @name mixin
* @memberOf util
* @function
*
* @param {Object} self
* The object to mixin the properties
* @param {...Object} varargs
* Variable number of objects to mix in.
*
* @returns {Object}
* <i>self</i> or a new object if <i>self</i> is null or undefined.
*
* @example
* var a = { a : 1, b : 2, c : 3 };
* var b = { b : 1, d : 2, e : 3 };
* var c = { e : 1, f : 2, g : 3 };
*
* a = util.mixin(a, b, c); // a = { a : 1, b : 2, c : 3, d : 2, e : 3, f : 2, g : 3}
* */
"mixin" :
{
value : function(self)
{
var i, l, key, o;
self = self || {};
for (i=1, l=arguments.length; i<l; i++)
{
o = arguments[i];
for (key in o)
{
if (!self.hasOwnProperty(key))
{
self[key] = o[key];
}
}
}
return self;
}
},
/**
* @name domainFromHost
* @memberOf util
* @function
* @deprecated use {@link net.domainFromHost}
* */
"domainFromHost" :
{
value : function()
{
return _deprecated("util.domainFromHost", "net.domainFromHost", arguments);
}
}
});
Object.freeze(util);
if (Object.prototype.forEach === undefined)
{
Object.defineProperty(Object.prototype, "forEach",
{
value : function (callback)
{
var key;
for (key in this)
{
if (this.hasOwnProperty(key))
callback(key, this[key], this);
}
}
});
}
})();
|