/
crop-popin.js
62 lines (53 loc) · 2.13 KB
/
crop-popin.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
(function(global, $){
var CropPopin = global.CropPopin = new Class({
Extends: Popin,
initialize: function(){
this.parent.apply(this, arguments);
this.bindEvents();
this.createRequest();
},
createRequest: function(){
this.request = new Request({
url: settings.urls.shorten
});
},
bindEvents: function() {
this.shareButton = this.element.getElement('.share-button');
this.token = this.element.getElement('[name="csrfmiddlewaretoken"]');
this.shareButton.addEvent('click', this.share.bind(this));
this.shareArea = this.element.getElement('div.share-details');
this.croppedLink = this.element.getElement('a.url');
this.embedURL = this.element.getElement('span.url');
this.embedTitle = this.element.getElement('span.title');
this.embedComments = this.element.getElement('span.comment-page');
},
share: function(e) {
var self = this;
e.preventDefault();
var data = Object.clone(this.shareButton.retrieve('crop-info'));
data["id"] = this.image.id;
data[this.token.get('name')] = this.token.get('value');
this.request.addEvent('success', function(url) {
self.croppedLink.set('href', url);
self.croppedLink.set('text', self.image.title);
self.embedURL.set('text', url);
self.embedTitle.set('text', self.image.title);
self.embedComments.set('text', 'http://myimg.at/shared_photo/' + self.image.id);
self.shareArea.fade('in');
}).post(data);
},
show: function(tab) {
this.fireEvent('show');
if (tab) {
this.showTab(tab);
}
this.element.addClass('show');
this.shareArea.fade('out');
return this;
},
hide: function() {
this.fireEvent('hide').element.removeClass('show');
return this;
}
});
}(this, document.id));