-
Notifications
You must be signed in to change notification settings - Fork 4
/
spotify.js
55 lines (38 loc) · 1.34 KB
/
spotify.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
SirTrevor.Blocks.Spotify = (function(){
return SirTrevor.Block.extend({
provider: {
regex: /play.spotify.com\/track\/([[:alnum:]]*)/,
html: "<iframe src=\"https://embed.spotify.com/?uri=spotify:track:{{remote_id}}\" width=\"300\" height=\"380\" frameborder=\"0\" allowtransparency=\"true\"></iframe>"
},
type: "spotify",
title: "Spotify",
pastable: true,
paste_options: {
html: "<div style=\"text-align:center; padding:20px;\">Enter <b>Spotify</b> link of track<br /><input type=\"text\" class=\"st-paste-block\" style=\"width: 100%\"></div>"
},
icon_name: "image",
loadData: function(data) {
this.$editor.addClass("st-block__editor--with-square-media");
var embedString = this.provider.html
.replace("{{remote_id}}", data.remote_id);
this.$editor.html(embedString);
},
onContentPasted: function(event){
this.handleDropPaste($(event.target).val());
},
handleDropPaste: function(url){
var match, data;
match = this.provider.regex.exec(url);
if (match !== null && !_.isUndefined(match[1])) {
data = {
remote_id: match[1]
};
this.setAndLoadData(data);
}
},
onDrop: function(transferData){
var url = transferData.getData("text/plain");
this.handleDropPaste(url);
}
});
})();