-
Notifications
You must be signed in to change notification settings - Fork 1
/
redactor-souncloud.js
114 lines (105 loc) · 3.66 KB
/
redactor-souncloud.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
(function ($) {
$.Redactor.prototype.soundcloud = function () {
return {
/**
* settings object
* @type {Object}
*/
settings: {
CLIENT_ID: 'yout soundcloud client id here',
RESOLVE_URL: 'https://api.soundcloud.com/resolve.json'
},
/**
* lang object
* default is en
* @type {Object}
*/
langs: {
en: {
'modalTitle': 'SoundCloud',
'description': 'insert SoundCloud track link'
},
pt_br: {
'modalTitle': 'SoundCloud',
'description': 'inserir link de faixa do SoundCloud'
}
},
/**
* this function return soundcloud modal html structure
* @return {string} modal html structure
*/
getTemplate: function () {
return '<div class="modal-section" id="redactor-modal-audio-insert">' +
'<section>' +
'<label>' + this.lang.get('description') + '</label>' +
'<input class="soundCloudLink" style="width: 100%;">' +
'</section>' +
'<section>' +
'<button id="redactor-modal-button-action">Insert</button>' +
'<button id="redactor-modal-button-cancel">Cancel</button>' +
'</section>' +
'</div>';
},
/**
* this function
* @param {string} uri api track url
* @return {string} soundcloud iframe html structure
*/
getPlayer: function (uri) {
return '<iframe width="100%"' +
'height="166"' +
'scrolling="no"' +
'frameborder="no"' +
'src="https://w.soundcloud.com/player/?url=' + uri + '&' +
'color=ff5500&' +
'auto_play=false&' +
'hide_related=false&' +
'show_comments=true&' +
'show_user=true&' +
'show_reposts=false">' +
'</iframe>';
},
/**
* this function add soundcloud button in menu
* and set your callback action
*/
init: function () {
var button = this.button.add('soundcloud', this.lang.get('modalTitle'));
this.button.setIcon(button, '<i class="fa fa-soundcloud"></i>');
this.button.addCallback(button, this.soundcloud.show);
},
/**
* this function show modal and set action on insert button
*/
show: function () {
this.modal.addTemplate('audio', this.soundcloud.getTemplate());
this.modal.load('audio', this.lang.get('modalTitle'), 700);
this.modal.getActionButton().text(this.lang.get('insert')).on('click', this.soundcloud.insert);
this.modal.show();
},
/**
* callback for insert button click
*/
insert: function () {
var soundcloudClass = this;
var url = this.soundcloud.settings.RESOLVE_URL;
var client_id = this.soundcloud.settings.CLIENT_ID;
var soundCloudLink = $('.soundCloudLink', '#redactor-modal-audio-insert').val();
$.ajax({
method: "GET",
url: url,
data: {
url: soundCloudLink,
client_id: client_id
}
}).done(function (res) {
var data = soundcloudClass.soundcloud.getPlayer(res.uri);
soundcloudClass.modal.close();
soundcloudClass.buffer.set();
soundcloudClass.air.collapsed();
soundcloudClass.insert.html(data);
});
}
};
};
})(jQuery);