-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathtbe.js
63 lines (52 loc) · 1.48 KB
/
tbe.js
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
// TBE JS library - General utility methods
//
var TBE = {
CreateCanvasElement: function ()
{
var canvas = document.createElement('canvas');
canvas.style.position = 'absolute';
return canvas;
},
CreateSquareCanvasElement: function (size)
{
var canvas = TBE.CreateCanvasElement ();
canvas.setAttribute ('width', size);
canvas.setAttribute ('height', size);
return canvas;
},
// Get a Canvas context, given an element.
// Accepts either an element ID or a DOM object.
//
GetElement2DContext: function (element)
{
if (typeof (element) != 'object')
element = document.getElementById (element);
if (element && element.getContext)
return element.getContext('2d');
return null;
},
// Clear a canvas, per w3c specification.
// Accepts either an element ID or a DOM object.
//
ClearCanvas: function (element)
{
if (typeof (element) != 'object')
element = document.getElementById(element);
if (element)
element.setAttribute ('width', element.getAttribute ('width'));
},
defaultView: null, // Cache defaultView (like jQuery does)
GetElementComputedStyle: function (element)
{
if (!this.defaultView) this.defaultView = document.defaultView;
if (this.defaultView && this.defaultView.getComputedStyle)
return this.defaultView.getComputedStyle (element, null);
return null;
},
// Convert degrees to radians
//
Deg2Rad: function (theta)
{
return theta * Math.PI / 180.0;
}
};