-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.js
More file actions
89 lines (71 loc) · 2.14 KB
/
Copy pathutil.js
File metadata and controls
89 lines (71 loc) · 2.14 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
/**
* Utility functions
* *****************
*/
(function(scope){
/**
* Utility function to convert units of measure
* @param num
* @param unit
* @returns {number}
*/
scope.convertToFeet = function(num, unit, dimension){
if(!dimension) dimension = 1;
var feetPerMeter = 3.28084;
var conversion = 1;
if(unit){
if(unit == "Meters"){
conversion = feetPerMeter;
}
else if(unit == "Inches"){
conversion = 1 / 12.0;
}
else if(unit == "Centimeters"){
conversion = feetPerMeter/100;
}
}
var result = num * (Math.pow(conversion, dimension));
return result;
}
scope.convertToAcre = function(num, unit){
var numFeet = scope.convertToFeet(num, unit, 2);
var squareFeetInAcre = 43560.0;
return numFeet / squareFeetInAcre;
}
Object.size = function(obj) {
var size = 0, key;
for (key in obj) {
if (obj.hasOwnProperty(key)) size++;
}
return size;
};
function ActiveStackEventDispatcherDecorator(o){
var listeners = [];
o.emit = function(name, data){
var listener = null;
for (var i = 0; i < listeners.length; i++) {
var listener = listeners[i];
if (listener.name == name) {
listener.callback.call(null, {name: name, data: data});
}
}
}
o.on = function(name, callback){
listeners.push({name: name, callback: callback});
return o;
}
};
function Decorate(){};
Decorate.withEventDispatcher = function(o){
return new ActiveStackEventDispatcherDecorator(o);
}
scope.Decorate = Decorate;
function Utils(){};
Utils.randomUUID = function(){
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
return v.toString(16);
});
}
scope.Utils = Utils;
})(window);