forked from jabbany/CommentCoreLibrary
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunction.js
More file actions
91 lines (82 loc) · 2.17 KB
/
Function.js
File metadata and controls
91 lines (82 loc) · 2.17 KB
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
/**
* Global Functions
* @description Functions defined in the global namespace.
**/
function trace (msg) {
if (typeof msg === 'object') {
__trace(JSON.stringify(msg), 'log');
} else {
__trace(msg, 'log');
}
}
function load (library, onComplete) {
if (typeof Runtime === 'undefined' || Runtime === null) {
__trace('No runtime defined. Attempting to raw-load library!', 'warn');
importScripts(library + '.js');
} else {
// Delegate this to runtime
Runtime.requestLibrary(library, function (error, response) {
if (error) {
__trace('Load: ' + error, 'warn');
} else {
if (response.type === 'import') {
importScripts(response.location);
} else if (response.type === 'raw') {
try {
eval(response.code);
} catch (e) {
__trace('Load: ' + e, 'warn');
}
} else if (response.type === 'object') {
if (typeof self === 'object' && self !== null) {
self[response.name] = response.obj;
}
} else if (response.type === 'noop') {
// Don't do anything
// This means library was already loaded
}
// Execute the remaining code
if (typeof onComplete === 'function') {
onComplete();
}
}
});
}
}
function clone (target) {
if (null === target || 'object' !== typeof target) {
return target;
}
// Call the object's own clone method if possible
if (typeof target['clone'] === 'function') {
return target.clone();
}
// Clone an array
if (Array.isArray(target)) {
return target.slice(0);
}
// Perform a shallow clone
var copy = {};
copy.constructor = copy.constructor;
copy.prototype = copy.prototype;
for (var x in target) {
copy[x] = target[x];
}
return copy;
}
function foreach (enumerable, f) {
if (null === enumerable || "object" !== typeof enumerable) {
return;
}
// DisplayObjects do not have any enumerable properties
if (enumerable instanceof Display.DisplayObject) {
return;
}
for (var x in enumerable) {
if (enumerable.hasOwnProperty(x)) {
f(x, enumerable[x]);
}
}
return;
}
var none = null;