-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwp-hoti-player-js.js
executable file
·382 lines (353 loc) · 13.3 KB
/
wp-hoti-player-js.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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
/*
hoti™ - Venezuelan Artistic Material
Copyright (C) 2013 Marcos Colina
GNU General Public License
Contributors
Marcos Colina <[email protected]>
Alexander Salas <[email protected]>
*/
jQuery(document).ready(function($){
/**INIT **/
$(".soundcloudMMLoading").css('display', 'none');
$("#soundcloudMMShowUsernames").click(function(e){
e.preventDefault();
$("#soundcloudMMUsermameTab").slideDown('fast');
$("#soundcloudMMHideUsernames").removeClass('hidden');
$(this).addClass('hidden');
});
$("#soundcloudMMHideUsernames").click(function(e){
e.preventDefault();
$("#soundcloudMMUsermameTab").slideUp('fast');
$("#soundcloudMMShowUsernames").removeClass('hidden');
$(this).addClass('hidden');
});
/*** OPTIONS ***/
/* CarouFredSel: an infinite, circular jQuery carousel.
Configuration created by the "Configuration Robot"
at caroufredsel.frebsite.nl
*/
$("#hotiUserError a").click(function(e){
e.preventDefault();
$(this).parent().fadeOut();
}).parent().css("display", "none");
carousel()
$("#soundcloudMMUsermameTab").slideUp('fast');
function carousel(){
$("#hotiUsernameCarousel").carouFredSel({
circular: false,
infinite: false,
width: 354,
height: 118,
align: "left",
padding: [0, 0, 0, 0],
margin: [0, 0, 0, 0],
items: {
visible: 3,
width: 118,
height: 118
},
auto: false,
pagination: "#hotiUsernameCarouselNav"
}).find("li .hotiRemoveUser").click(function() {
removeUser($(this).parent());
removeUserFromOptions($("div input:first", $(this).parent()).val(), false);
}).css("cursor", "pointer");
makeUserActive();
removeActiveUser();
}
/** Remove User **/
function removeUser(that){
that.animate({
opacity : 0
}, 500).animate({
width : 0,
margin : 0,
borderWidth : 0
}, 400, function() {
$("#hotiUsernameCarousel").trigger("removeItem", that);
});
}
/** Remove User From Options (Tab only) **/
function removeUserFromOptions(usernameToRemove, reload){
if($("#soundcloudMMUsermameTab").length){
console.log(usernameToRemove);
//Set request
var myData = {
action: 'hoti_delete_user',
request: 'hotiDeleteUser',
username: usernameToRemove
};
jQuery.post(ajaxurl, myData, function(response) {
if(response == 'done' && reload) location.reload();
});
}
}
/** Add new User **/
$("#hotiAddUser").click(function(e){
e.preventDefault();
$(".soundcloudMMLoading").fadeIn('fast');
//Set request
var myData = {
action: 'hoti_add_user',
request: 'hotiAddUser',
username: $("#hotiNewUser").val(),
updateOption : $("#soundcloudMMUsermameTab").length
};
jQuery.post(ajaxurl, myData, function(response) {
$(".soundcloudMMLoading").fadeOut('fast');
if(response != "error"){
var args = [response, "#hotiUsernameCarousel li:first", true, 0];
$("#hotiUsernameCarousel").trigger("insertItem", args);
carousel();
}else{
$("#hotiUserError p").html("wrong username").parent().fadeIn();
}
});
});
/** Make User Active **/
function makeUserActive(){
$("#hotiUsernameCarousel .hotiUserContainer div").click(function(){
previousActiveUser = $("#hotiActiveUserContainer .hotiUserContainer");
newActiveUser = $(this).parent();
//Remove from Carousel
$(this).parent().fadeOut(function(){
//Copy new Active User to the Active User container and move active user label
newActiveUser.clone().css("margin", "5px 4px").appendTo("#hotiActiveUserContainer").prepend($("#hotiActiveLabel")).fadeIn();
//Update hidden field for active user
$("#hotiActiveUser").val($('p', newActiveUser).html());
//Remove it from carousel
$("#hotiUsernameCarousel").trigger("removeItem", $(this));
//Move old active user to carousel
var args = [previousActiveUser, "#hotiUsernameCarousel li:first", true, 0];
$("#hotiUsernameCarousel").trigger("insertItem", args);
//Init Carousel
carousel();
//Tab: extra actions
if($("#soundcloudMMUsermameTab").length) {
$(".soundcloudMMLoading").fadeIn('fast');
//Set request
var myData = {
action: 'hoti_set_active_user',
request: 'hotiSetActiveUser',
username: $("#hotiActiveUser").val()
};
jQuery.post(ajaxurl, myData, function(response) {
if(response != "error"){
//Reload Tab
location.reload();
}else{
//Error
$("#hotiUserError p").html("wrong username").parent().fadeIn();
}
});
}
});
});
}
/** Remove Active user **/
function removeActiveUser(){
$("#hotiActiveUserContainer .hotiUserContainer .hotiRemoveUser").click(function(){
removeUserFromOptions($("input:first", $(this).parent()).val(), true);
activeUserToRemove = $(this).parent().parent();
activeUserToRemove.fadeOut(function(){
//Copy new Active User to the Active User container and move active user label
$("#hotiUsernameCarousel .hotiUserContainer:first").clone().css("margin", "5px 4px").appendTo("#hotiActiveUserContainer").prepend($("#hotiActiveLabel")).fadeIn();
//Delete Active User
$(this).remove();
//Move First User from Carousel to Active
$("#hotiUsernameCarousel .hotiUserContainer:first").fadeOut(function(){
//Remove it from carousel
removeUser($(this));
//Update hidden field for active user
$("#hotiActiveUser").val($('#hotiActiveUserContainer .hotiUserContainer div p').html());
});
});
});
}
/******************************************/
/** SOUNDCLOUD **/
/******************************************/
//Attach Events for Player Preview and Shortcode
$('.soundcloudMMMainWrapper').each(function(){
var mySelf = $(this);
//On changing settings
$('input[type=checkbox], input[type=radio], .soundcloudMMWPSelectedWidth, .soundcloudMMColorPickerClose', this).click(function(){
updateMe(mySelf, true);
});
$('.soundcloudMMCustomSelectedWidth, .soundcloudMMClasses', this).focusout(function(){
updateMe(mySelf, true);
});
//Initialize color Picker
initColorPicker(mySelf);
//(Tab View) Event: Load First Time preview when show clicked
if(!mySelf.hasClass('soundcloudMMOptions')){
$(".describe-toggle-on", mySelf.parent()).click(function(){
updateMe(mySelf, true);
});
}
});
//First Time On Option Page
if($(".soundcloudMMOptions").length) updateMe($(this), true);
function updateMe(parent, refresh){
//Collect Settings
if($('.soundcloudMMAutoPlay:checked', parent).val() == undefined) autoPlay = false;
else autoPlay = true;
if($('.soundcloudMMShowComments:checked', parent).val() == undefined) comments = false;
else comments = true;
if($('.soundcloudMMShowArtwork:checked', parent).val() == undefined) artwork = false;
else artwork = true;
//Set width
if($(".soundcloudMMWpWidth", parent).is(":checked")) width = $('.soundcloudMMWidth option:selected', parent).val();
if($(".soundcloudMMCustomWidth", parent).is(":checked")) width = $('input.soundcloudMMWidth', parent).val();
//Class
classes = $('.soundcloudMMClasses', parent).val();
//Player Type
$('.soundcloudMMPlayerType', parent).each(function(){
if( $(this).attr('checked') == 'checked' ) playerType = $(this).val();
});
//Color
color = $('.soundcloudMMColor', parent).val();
user = $('.hotiUserContainer div p').text();
//Format
if($('.soundcloudMMWrapper').hasClass('sets')) format = 'sets';
else format = 'tracks';
//Set Shortocode Attributes
if(!parent.hasClass('soundcloudMMOptions')) shortcode(parent, autoPlay, comments, width, classes, playerType, color, artwork, format);
//Refresh Preview if requested
if(refresh) preview(parent, user, autoPlay, comments, width, classes, playerType, color, artwork, format);
};
/********************************************/
/** INSERT TO POST **/
/********************************************/
$(".soundcloudMMInsert").click(function(){
var myID = getID($(this));
insertShortcode($('#soundcloudMMShortcode-'+myID).val());
});
function insertShortcode(sh){
//Insert Content at the end of the editor content
//parent.tinyMCE.activeEditor.setContent(parent.tinyMCE.activeEditor.getContent() + sh);
//Insert Content where the cursor is in the editor (plus refresh)
parent.tinyMCE.activeEditor.execCommand('mceInsertRawHTML', false, sh);
//Insert Content where the cursor is in the editor (no refresh)
//parent.tinyMCE.activeEditor.execCommand('mceInsertContent', false, sh);
//Close window
parent.jQuery("#TB_closeWindowButton").click();
}
/********************************************/
/** SHORTCODE **/
/********************************************/
function shortcode(parent, autoPlay, comments, width, classes, playerType, color, artwork, format){
var shortcode = "soundcloud id='"+getID($('.soundcloudMMId', parent))+"'";
if(comments != hotiComments_default) shortcode += " comments='"+comments+"'";
if(artwork != hotiArtwork_default) shortcode += " artwork='"+artwork+"'";
if(playerType != hotiPlayerType_default) shortcode += " playerType='"+playerType+"'";
if(autoPlay != hotiAutoPlay_default) shortcode += " autoPlay='"+autoPlay+"'";
if(width != hotiWidth_default) shortcode += " width='"+width+"'";
if(classes != hotiClasses_default) shortcode += " classes='"+classes+"'";
if(color != hotiColor_default) shortcode += " color='"+color+"'";
if(format != 'tracks') shortcode += " format='set'";
$('.soundcloudMMShortcode', parent).val("["+shortcode+"]");
}
/********************************************/
/** PREVIEW **/
/********************************************/
function preview(parent, user, autoPlay, comments, width, classes, playerType, color, artwork, format){
//Animate transition
switch(playerType){
case 'Mini':
newHeight = '18px';
break;
case 'Standard':
if(format == 'tracks') newHeight = '81px';
else newHeight = '165px';
break;
case 'Artwork':
width = '300px';
newHeight = width;
break;
case 'html5':
if(format == 'tracks') newHeight = '166px';
else newHeight = '450px';
break;
}
//Set request
var myData = {
action: 'hoti_player_preview',
request: 'gethotiPlayerPreview',
ID: getID($('.soundcloudMMId', parent)),
user: user,
comments: comments,
autoPlay: autoPlay,
artwork: artwork,
width: width,
classes: classes,
playerType: playerType,
color: color,
format: format
};
//Tell user it's loading
$('.soundcloudMMEmbed', parent).fadeOut('fast', function(){
$('.soundcloudMMPreviewLoading', parent).fadeIn();
$('.soundcloudMMPreviewLoading', parent).animate({
height: newHeight
}, 'slow', function(){
//The Ajax request
jQuery.post(ajaxurl, myData, function(response) {
if(response){
$('.soundcloudMMEmbed', parent).css('height', newHeight).html(response);
$('.soundcloudMMPreviewLoading', parent).fadeOut('fast', function(){
$(this).css('display', 'none');
$('.soundcloudMMEmbed', parent).fadeIn();
});
}
});
});
});
}
/********************************************/
/** COLOR PICKER **/
/********************************************/
function initColorPicker(parent){
$('.soundcloudMMColorPickerContainer', parent).each(function(){
var mySelf = $(this);
var colorWheel = $('.soundcloudMMColorPicker', this);
var colorInput = $('.soundcloudMMColor', this);
colorWheel.hide();
$('.soundcloudMMColorPicker .soundcloudMMColorPickerSelect', this).farbtastic(colorInput);
var soundcloudMMColorPicker = $.farbtastic($('.soundcloudMMColorPicker .soundcloudMMColorPickerSelect', this));
soundcloudMMColorPicker.setColor('#'+colorInput.val());
//Select Color (Open Color Wheel)
colorInput.click(function(){
colorWheel.css({'top' : $(this).position().top-colorWheel.height()*0.5, 'left' : $(this).position().left}).fadeIn();
});
//Close Color Wheel
$('.soundcloudMMColorPickerClose', this).click(function(){
colorInput.val(soundcloudMMColorPicker.color);
$(this).parent().fadeOut();
});
//Reset Color to Default
$('.soundcloudMMResetColor', this).click(function(e){
e.preventDefault();
soundcloudMMColorPicker.setColor(hotiColor_default);
colorInput.val(hotiColor_default).css('background-color', '#'+hotiColor_default);
updateMe(parent, true);
});
});
}
/************** ADVANCED SETTINGS **************/
$('.soundcloudMMAdvancedSettingsPanels').css('display', 'none');
var closedAvancedSettingText = $('.soundcloudMMAdvancedSettingsShowHide').text();
var openedAvancedSettingText = "It's too much for me, take it away.";
$('.soundcloudMMAdvancedSettingsShowHide').click(function(e) {
e.preventDefault();
if($(this).text() == closedAvancedSettingText) $(this).text(openedAvancedSettingText);
else $(this).text(closedAvancedSettingText);
$('~ .soundcloudMMAdvancedSettingsPanels', this).slideToggle('slow', function() {
// Animation complete.
});
});
function getID(t){
myID = t.attr('id').match(/[0-9]+./);
return myID[0];
}
});