-
Notifications
You must be signed in to change notification settings - Fork 4
/
pinterest.js
64 lines (46 loc) · 1.62 KB
/
pinterest.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
SirTrevor.Blocks.Pinterest = (function(){
return SirTrevor.Block.extend({
providers: {
pin: {
regex: /pinterest.com\/pin\/(.+)\//,
html: "<div style=\"text-align:center\"><a data-pin-do=\"embedPin\" href=\"http://pinterest.com/pin/{{remote_id}}/\">Pin on Pinterest</a> <script type=\"text/javascript\" async src=\"//assets.pinterest.com/js/pinit.js\"></script></div>"
}
},
type: "pinterest",
title: "Pinterest",
pastable: true,
paste_options: {
html: "<div style=\"text-align:center; padding:20px;\"><b>Pinterest</b><input type=\"text\" class=\"st-paste-block\" style=\"width: 100%\" placeholder=\"Enter code for Wordpress\"></div>"
},
icon_name: "image",
loadData: function(data) {
if (!this.providers.hasOwnProperty(data.source)) { return; }
var embed_string = this.providers[data.source].html
.replace("{{remote_id}}", data.remote_id);
this.$editor.html(embed_string);
},
onContentPasted: function(event){
this.handleDropPaste($(event.target).val());
},
handleDropPaste: function(url){
if(!_.isURI(url)) {
return;
}
var match, data;
_.each(this.providers, function(provider, index) {
match = provider.regex.exec(url);
if(match !== null && !_.isUndefined(match[1])) {
data = {
source: index,
remote_id: match[1]
};
this.setAndLoadData(data);
}
}, this);
},
onDrop: function(transferData){
var url = transferData.getData("text/plain");
this.handleDropPaste(url);
}
});
})();