-
Notifications
You must be signed in to change notification settings - Fork 0
/
Roblox.Thumbs.AssetImage.js
200 lines (169 loc) · 7.62 KB
/
Roblox.Thumbs.AssetImage.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
// AssetImage.js. Register the namespace for the control.
Type.registerNamespace('Roblox.Thumbs');
//
// Define the control properties.
//
Roblox.Thumbs.AssetImage = function (element) {
Roblox.Thumbs.AssetImage.initializeBase(this, [element]);
this._assetID = 0;
this._assetVersionID = null;
this._ov = false;
};
//
// Create the prototype for the control.
//
Roblox.Thumbs.AssetImage.prototype = {
initialize: function () {
Roblox.Thumbs.AssetImage.callBaseMethod(this, 'initialize');
this._webService = Roblox.Thumbs.Asset;
this._requestThumbnail = Function.createDelegate(this, this.requestThumbnail);
},
dispose: function () {
Roblox.Thumbs.AssetImage.callBaseMethod(this, 'dispose');
},
get_assetID: function () {
return this._assetID;
},
set_assetID: function (value) {
if (this._assetID !== value) {
this._assetID = value;
this.raisePropertyChanged('assetID');
}
},
get_assetVersionID: function () {
return this._assetVersionID;
},
set_assetVersionID: function (value) {
if (this._assetVersionID !== value) {
this._assetVersionID = value;
this.raisePropertyChanged('assetVersionID');
}
},
get_ov: function () {
return this._ov;
},
set_ov: function (value) {
if (this._ov !== value) {
this._ov = value;
this.raisePropertyChanged('ov');
}
},
requestThumbnail: function () {
var style = this.get_element().style;
var width = style.pixelWidth;
var height = style.pixelHeight;
var onSuccess = function (result, context) { context._onUrl(result); };
var onError = function (result, context) { context._onError(result); };
this._webService.RequestThumbnail_v2(this._assetID, this._assetVersionID, width, height, this._fileExtension, this._thumbnailFormatID, this._ov, onSuccess, onError, this);
}
};
// Optional descriptor for JSON serialization.
Roblox.Thumbs.AssetImage.descriptor = {
properties: []
};
// Register the class as a type that inherits from Sys.UI.Control.
Roblox.Thumbs.AssetImage.registerClass('Roblox.Thumbs.AssetImage', Roblox.Thumbs.Image);
Roblox.Thumbs.AssetImage.updateUrl = function(componentID) {
/// <summary>
/// This static function (that is intended to be called from script emitted
/// on the server)
/// </summary>
var a = $find(componentID);
if (a != null || a != undefined) {
a._onUpdate();
}
};
Roblox.Thumbs.AssetImage.mediaPlayer = null;
Roblox.Thumbs.AssetImage.isInitialized = false;
Roblox.Thumbs.AssetImage.currentlyPlayingAsset = null;
Roblox.Thumbs.AssetImage.InitMediaPlayer = function () {
if (typeof jQuery !== "undefined" && !Roblox.Thumbs.AssetImage.isInitialized) {
Roblox.Thumbs.AssetImage.isInitialized = true;
$(function () {
$(document).on("click", "div.MediaPlayerIcon", function (e) {
var assetButton = $(e.target);
assetButton.mediaUrl = assetButton.attr("data-mediathumb-url");
/// <summary>
/// Determines if the asset button and the given asset button are the same asset.
/// </summary>
assetButton.hasSameMediaAs = function (other) {
return assetButton.mediaUrl === other.mediaUrl;
};
/// <summary>
/// Plays or resumes the asset button's media and updates the button's visuals.
/// </summary>
assetButton.play = function () {
if (Roblox.Thumbs.AssetImage.currentlyPlayingAsset === null ||
!Roblox.Thumbs.AssetImage.currentlyPlayingAsset.hasSameMediaAs(assetButton)) {
// If another asset is playing then pause it first.
if (Roblox.Thumbs.AssetImage.currentlyPlayingAsset != null) {
Roblox.Thumbs.AssetImage.currentlyPlayingAsset.stop();
}
Roblox.Thumbs.AssetImage.mediaPlayer.jPlayer("setMedia", { mp3: assetButton.mediaUrl });
Roblox.Thumbs.AssetImage.currentlyPlayingAsset = assetButton;
Roblox.Thumbs.AssetImage.mediaPlayer.on($.jPlayer.event.ended, assetButton.onJPlayerEnded);
Roblox.Thumbs.AssetImage.mediaPlayer.on($.jPlayer.event.error, assetButton.onJPlayerError);
}
Roblox.Thumbs.AssetImage.mediaPlayer.jPlayer("play");
assetButton.removeClass("Play").addClass("Pause");
};
/// <summary>
/// Stops the asset button's media and resets the button.
/// </summary>
assetButton.stop = function () {
if (Roblox.Thumbs.AssetImage.currentlyPlayingAsset.hasSameMediaAs(assetButton)) {
Roblox.Thumbs.AssetImage.currentlyPlayingAsset = null;
Roblox.Thumbs.AssetImage.mediaPlayer.jPlayer("clearMedia");
Roblox.Thumbs.AssetImage.mediaPlayer.off($.jPlayer.event.ended);
Roblox.Thumbs.AssetImage.mediaPlayer.off($.jPlayer.event.error);
assetButton.removeClass("Pause").addClass("Play");
}
};
/// <summary>
/// Pauses the asset button's media and changes the button's visuals.
/// </summary>
assetButton.pause = function () {
if (Roblox.Thumbs.AssetImage.currentlyPlayingAsset.hasSameMediaAs(assetButton)) {
Roblox.Thumbs.AssetImage.mediaPlayer.jPlayer("pause");
assetButton.removeClass("Pause").addClass("Play");
}
}
/// <summary>
/// Handles the jPlayer error event.
/// </summary>
assetButton.onJPlayerError = function () {
assetButton.stop();
};
/// <summary>
/// Handles the jPlayer ended event.
/// </summary>
assetButton.onJPlayerEnded = function () {
assetButton.stop();
};
// If the media player isn't yet initialized then
// initialize it and begin playing when it's ready.
if (Roblox.Thumbs.AssetImage.mediaPlayer == null) {
Roblox.Thumbs.AssetImage.mediaPlayer = $("<div id='MediaPlayerSingleton'></div>").appendTo("body").jPlayer({
swfPath: '/js/jPlayer/2.9.2/jquery.jplayer.swf',
solution: "html, flash",
supplied: "mp3",
wmode: "transparent",
errorAlerts: false,
warningAlerts: false,
ready: function (event) {
assetButton.play();
}
});
}
else { // Otherwise, play or pause normally.
if (assetButton.hasClass("Pause")) {
assetButton.pause();
}
else {
assetButton.play();
}
}
});
});
}
}