-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRoblox.Thumbs.Image.js
144 lines (120 loc) · 3.96 KB
/
Roblox.Thumbs.Image.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
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
// Image.Js. Register the namespace for the control.
Type.registerNamespace('Roblox.Thumbs');
//
// Define the control properties.
//
Roblox.Thumbs.Image = function (element) {
Roblox.Thumbs.Image.initializeBase(this, [element]);
this._fileExtension = null;
this._spinnerUrl = null;
this._pollTime = 3000;
this._waitTime = 0;
this._webService = null;
this._requestThumbnail = null;
this._updateTimeout = null;
this._spinner = null;
};
//
// Create the prototype for the control.
//
Roblox.Thumbs.Image.prototype = {
initialize: function () {
Roblox.Thumbs.Image.callBaseMethod(this, 'initialize');
},
dispose: function () {
if (typeof (this._updateTimeout) !== 'undefined')
window.clearTimeout(this._updateTimeout);
Roblox.Thumbs.Image.callBaseMethod(this, 'dispose');
},
_showSpinner: function () {
if (this._spinner !== null)
return;
this.get_element().style.position = "relative";
this._spinner = document.createElement("img");
this._spinner.style.position = "absolute";
this._spinner.style.left = "0px";
this._spinner.style.top = "0px";
this._spinner.style.height = "16px";
this._spinner.style.width = "16px";
this._spinner.style.border = 0;
this._spinner.src = this._spinnerUrl;
this.get_element().appendChild(this._spinner);
},
_hideSpinner: function () {
if (!this._spinner)
return;
var e = this.get_element();
if (e) {
e.removeChild(this._spinner);
}
this._spinner = null;
},
_onUpdate: function () {
if (!this._webService) {
this._hideSpinner();
return;
}
this._showSpinner();
this._requestThumbnail();
},
_onUrl: function (result) {
if (!this.get_element()) {
this._hideSpinner();
return;
}
Roblox.Controls.Image.SetImageSrc(this.get_element(), result.url);
if ((!result.final || result.url.indexOf("unavail") > 0) && this._waitTime <= 40) // Give up after 40 times.
{
// Try again later
this._waitTime = parseInt(this._waitTime) + parseInt(1);
this._updateTimeout = window.setTimeout(Function.createDelegate(this, this._onUpdate), this._pollTime);
}
else
this._hideSpinner();
},
_onError: function (result) {
this._hideSpinner();
},
get_thumbnailFormatID: function () {
return this._thumbnailFormatID;
},
set_thumbnailFormatID: function (value) {
if (this._thumbnailFormatID !== value) {
this._thumbnailFormatID = value;
this.raisePropertyChanged('thumbnailFormatID');
}
},
get_pollTime: function () {
return this._pollTime.value;
},
set_pollTime: function (value) {
if (this._pollTime !== value) {
this._pollTime = value;
this.raisePropertyChanged('pollTime');
}
},
get_fileExtension: function () {
return this._fileExtension;
},
set_fileExtension: function (value) {
if (this._fileExtension !== value) {
this._fileExtension = value;
this.raisePropertyChanged('fileExtension');
}
},
get_spinnerUrl: function () {
return this._spinnerUrl;
},
set_spinnerUrl: function (value) {
if (this._spinnerUrl !== value) {
this._spinnerUrl = value;
this.raisePropertyChanged('spinnerUrl');
}
}
};
// Optional descriptor for JSON serialization.
Roblox.Thumbs.Image.descriptor = {
properties: []
};
// Register the class as a type that inherits from Sys.UI.Control.
Roblox.Thumbs.Image.registerClass('Roblox.Thumbs.Image', Sys.UI.Control);